-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handling of JS keyword when causing invalid code gen (#4329)
- Loading branch information
1 parent
c60e807
commit 5f288bd
Showing
10 changed files
with
536 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
export function exported(): void; | ||
export function _function(): void; | ||
export function _var(): void; | ||
export function weird_arguments(_new: number, _var: number, _switch: number, _default: number, _arguments: number): void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
let wasm; | ||
export function __wbg_set_wasm(val) { | ||
wasm = val; | ||
} | ||
|
||
|
||
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; | ||
|
||
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); | ||
|
||
cachedTextDecoder.decode(); | ||
|
||
let cachedUint8ArrayMemory0 = null; | ||
|
||
function getUint8ArrayMemory0() { | ||
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { | ||
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); | ||
} | ||
return cachedUint8ArrayMemory0; | ||
} | ||
|
||
function getStringFromWasm0(ptr, len) { | ||
ptr = ptr >>> 0; | ||
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); | ||
} | ||
|
||
export function exported() { | ||
wasm.exported(); | ||
} | ||
|
||
export function _function() { | ||
wasm._function(); | ||
} | ||
|
||
export function _var() { | ||
wasm._var(); | ||
} | ||
|
||
/** | ||
* @param {number} _new | ||
* @param {number} _var | ||
* @param {number} _switch | ||
* @param {number} _default | ||
* @param {number} _arguments | ||
*/ | ||
export function weird_arguments(_new, _var, _switch, _default, _arguments) { | ||
wasm.weird_arguments(_new, _var, _switch, _default, _arguments); | ||
} | ||
|
||
export function __wbg_await_e0a0e75be8b6fef6() { | ||
await(); | ||
}; | ||
|
||
export function __wbg_let_8d461e9e0592bd8c(arg0) { | ||
arg0.let(); | ||
}; | ||
|
||
export function __wbg_new_4b026aaf1c1e4438() { | ||
const ret = A.new(); | ||
return ret; | ||
}; | ||
|
||
export function __wbg_new_d4bfd9add722b492() { | ||
const ret = window.__TAURI__.menu.Menu.new(); | ||
return ret; | ||
}; | ||
|
||
export function __wbg_new_e17dd7c5a1cd57d8() { | ||
B.new(); | ||
}; | ||
|
||
export function __wbg_static_accessor_TRUE_c6b68bf8545d99a3() { | ||
const ret = true; | ||
return ret; | ||
}; | ||
|
||
export function __wbindgen_init_externref_table() { | ||
const table = wasm.__wbindgen_export_0; | ||
const offset = table.grow(4); | ||
table.set(0, undefined); | ||
table.set(offset + 0, undefined); | ||
table.set(offset + 1, null); | ||
table.set(offset + 2, true); | ||
table.set(offset + 3, false); | ||
; | ||
}; | ||
|
||
export function __wbindgen_throw(arg0, arg1) { | ||
throw new Error(getStringFromWasm0(arg0, arg1)); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use wasm_bindgen::prelude::*; | ||
|
||
// Imports with keywords | ||
|
||
#[wasm_bindgen] | ||
extern "C" { | ||
#[wasm_bindgen] | ||
pub type A; | ||
|
||
#[wasm_bindgen(static_method_of = A, js_name = "new")] | ||
pub fn static_new() -> A; | ||
#[wasm_bindgen(js_namespace = ["B"], js_name = "new")] | ||
pub fn namespace_new(); | ||
|
||
#[wasm_bindgen(method, js_name = "let")] | ||
pub fn keyword_let(ptr: &A); | ||
|
||
// await is not a reserved keyword in JS | ||
pub fn r#await(); | ||
|
||
// true & false are reserved keywords in JS, but we allow them anyway | ||
#[wasm_bindgen(thread_local_v2, js_name = "true")] | ||
static TRUE: JsValue; | ||
} | ||
|
||
// https://github.com/rustwasm/wasm-bindgen/issues/4317 | ||
#[wasm_bindgen(js_namespace = ["window", "__TAURI__", "menu"])] | ||
extern "C" { | ||
#[wasm_bindgen] | ||
pub type Menu; | ||
|
||
#[wasm_bindgen(static_method_of = Menu)] | ||
pub fn new() -> Menu; | ||
} | ||
|
||
// This function ensures the imported stuff isn't optimized out | ||
#[wasm_bindgen] | ||
pub fn exported() { | ||
let a = A::static_new(); | ||
let _ = a.keyword_let(); | ||
let _ = namespace_new(); | ||
let _ = r#await(); | ||
std::hint::black_box(&TRUE); | ||
|
||
let _ = Menu::new(); | ||
} | ||
|
||
// Exports with keywords that we allow and are renamed automatically. | ||
|
||
#[wasm_bindgen] | ||
pub fn function() {} | ||
|
||
#[wasm_bindgen(js_name = "var")] | ||
pub fn sane_name() {} | ||
|
||
#[wasm_bindgen] | ||
pub fn weird_arguments(new: u32, var: u32, r#switch: u32, default: u32, arguments: u32) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(module $reference_test.wasm | ||
(type (;0;) (func)) | ||
(type (;1;) (func (param i32 i32 i32 i32 i32))) | ||
(import "./reference_test_bg.js" "__wbindgen_init_externref_table" (func (;0;) (type 0))) | ||
(func $weird_arguments (;1;) (type 1) (param i32 i32 i32 i32 i32)) | ||
(func $exported (;2;) (type 0)) | ||
(func $_function (;3;) (type 0)) | ||
(func $_var (;4;) (type 0)) | ||
(table (;0;) 128 externref) | ||
(memory (;0;) 17) | ||
(export "memory" (memory 0)) | ||
(export "exported" (func $exported)) | ||
(export "_function" (func $_function)) | ||
(export "_var" (func $_var)) | ||
(export "weird_arguments" (func $weird_arguments)) | ||
(export "__wbindgen_export_0" (table 0)) | ||
(export "__wbindgen_start" (func 0)) | ||
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext") | ||
) | ||
|
Oops, something went wrong.