diff --git a/CHANGELOG.md b/CHANGELOG.md index ea5b86689a3..828cac738cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,9 @@ * Fixed a bug in `--experimental-reset-state-function` support for heap reset. [#4665](https://github.com/wasm-bindgen/wasm-bindgen/pull/4665) +* Quote names containing colons in generated .d.ts. + [#4488](https://github.com/rustwasm/wasm-bindgen/pull/4488) + ### Changed * Unconditionally use the global `TextEncoder`/`TextDecoder` for string encoding/decoding. The Node.js output now requires a minimum of Node.js v11. diff --git a/crates/cli-support/src/wasm2es6js.rs b/crates/cli-support/src/wasm2es6js.rs index 485b8054fa7..0aa6c1f3275 100644 --- a/crates/cli-support/src/wasm2es6js.rs +++ b/crates/cli-support/src/wasm2es6js.rs @@ -63,7 +63,11 @@ fn args_are_optional(name: &str) -> bool { pub fn interface(module: &Module) -> Result { let mut exports = String::new(); module_export_types(module, |name, ty| { - writeln!(exports, " readonly {name}: {ty};").unwrap(); + if name.contains(':') { + writeln!(exports, " readonly {name:?}: {ty};").unwrap(); + } else { + writeln!(exports, " readonly {name}: {ty};").unwrap(); + } }); Ok(exports) } diff --git a/crates/cli/tests/reference/wasm-export-types.d.ts b/crates/cli/tests/reference/wasm-export-types.d.ts index a5f399db59d..0726777f25e 100644 --- a/crates/cli/tests/reference/wasm-export-types.d.ts +++ b/crates/cli/tests/reference/wasm-export-types.d.ts @@ -2,6 +2,70 @@ /* eslint-disable */ export function example(a: number, b: bigint, c: any, d: string): string; export function example_128(a: bigint): bigint | undefined; +/** + * Handler for `console.log` invocations. + * + * If a test is currently running it takes the `args` array and stringifies + * it and appends it to the current output of the test. Otherwise it passes + * the arguments to the original `console.log` function, psased as + * `original`. + */ +export function __wbgtest_console_log(args: Array): void; +/** + * Handler for `console.debug` invocations. See above. + */ +export function __wbgtest_console_debug(args: Array): void; +/** + * Handler for `console.info` invocations. See above. + */ +export function __wbgtest_console_info(args: Array): void; +/** + * Handler for `console.warn` invocations. See above. + */ +export function __wbgtest_console_warn(args: Array): void; +/** + * Handler for `console.error` invocations. See above. + */ +export function __wbgtest_console_error(args: Array): void; +export function __wbgtest_cov_dump(): Uint8Array | undefined; +/** + * Runtime test harness support instantiated in JS. + * + * The node.js entry script instantiates a `Context` here which is used to + * drive test execution. + */ +export class WasmBindgenTestContext { + free(): void; + [Symbol.dispose](): void; + /** + * Creates a new context ready to run tests. + * + * A `Context` is the main structure through which test execution is + * coordinated, and this will collect output and results for all executed + * tests. + */ + constructor(); + /** + * Handle `--include-ignored` flag. + */ + include_ignored(include_ignored: boolean): void; + /** + * Handle filter argument. + */ + filtered_count(filtered: number): void; + /** + * Executes a list of tests, returning a promise representing their + * eventual completion. + * + * This is the main entry point for executing tests. All the tests passed + * in are the JS `Function` object that was plucked off the + * `WebAssembly.Instance` exports list. + * + * The promise returned resolves to either `true` if all tests passed or + * `false` if at least one test failed. + */ + run(tests: any[]): Promise; +} export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module; @@ -9,10 +73,29 @@ export interface InitOutput { readonly memory: WebAssembly.Memory; readonly example: (a: number, b: bigint, c: any, d: number, e: number) => [number, number]; readonly example_128: (a: bigint, b: bigint) => [number, bigint, bigint]; - readonly __wbindgen_export_0: WebAssembly.Table; + readonly "__wbgt__reference_test::example_test": (a: number) => void; + readonly __wbg_wasmbindgentestcontext_free: (a: number, b: number) => void; + readonly wasmbindgentestcontext_new: () => number; + readonly wasmbindgentestcontext_include_ignored: (a: number, b: number) => void; + readonly wasmbindgentestcontext_filtered_count: (a: number, b: number) => void; + readonly wasmbindgentestcontext_run: (a: number, b: number, c: number) => any; + readonly __wbgtest_console_log: (a: any) => void; + readonly __wbgtest_console_debug: (a: any) => void; + readonly __wbgtest_console_info: (a: any) => void; + readonly __wbgtest_console_warn: (a: any) => void; + readonly __wbgtest_console_error: (a: any) => void; + readonly __wbgtest_cov_dump: () => [number, number]; + readonly __externref_table_alloc: () => number; + readonly __wbindgen_export_1: WebAssembly.Table; readonly __wbindgen_malloc: (a: number, b: number) => number; readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number; + readonly __wbindgen_exn_store: (a: number) => void; + readonly __wbindgen_export_5: WebAssembly.Table; readonly __wbindgen_free: (a: number, b: number, c: number) => void; + readonly closure53_externref_shim: (a: number, b: number, c: any) => void; + readonly wasm_bindgen__convert__closures_____invoke__hc3e1c6a93eb88fad: (a: number, b: number) => void; + readonly closure69_externref_shim: (a: number, b: number, c: any, d: number, e: any) => void; + readonly closure65_externref_shim: (a: number, b: number, c: any, d: any) => void; readonly __wbindgen_start: () => void; } diff --git a/crates/cli/tests/reference/wasm-export-types.js b/crates/cli/tests/reference/wasm-export-types.js index 746a3a87b12..b90ac649792 100644 --- a/crates/cli/tests/reference/wasm-export-types.js +++ b/crates/cli/tests/reference/wasm-export-types.js @@ -1,5 +1,17 @@ let wasm; +function isLikeNone(x) { + return x === undefined || x === null; +} + +function addToExternrefTable0(obj) { + const idx = wasm.__externref_table_alloc(); + wasm.__wbindgen_export_1.set(idx, obj); + return idx; +} + +let WASM_VECTOR_LEN = 0; + let cachedUint8ArrayMemory0 = null; function getUint8ArrayMemory0() { @@ -9,29 +21,6 @@ function getUint8ArrayMemory0() { return cachedUint8ArrayMemory0; } -let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); - -cachedTextDecoder.decode(); - -const MAX_SAFARI_DECODE_BYTES = 2146435072; -let numBytesDecoded = 0; -function decodeText(ptr, len) { - numBytesDecoded += len; - if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) { - cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); - cachedTextDecoder.decode(); - numBytesDecoded = len; - } - return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); -} - -function getStringFromWasm0(ptr, len) { - ptr = ptr >>> 0; - return decodeText(ptr, len); -} - -let WASM_VECTOR_LEN = 0; - const cachedTextEncoder = new TextEncoder(); if (!('encodeInto' in cachedTextEncoder)) { @@ -83,6 +72,144 @@ function passStringToWasm0(arg, malloc, realloc) { WASM_VECTOR_LEN = offset; return ptr; } + +let cachedDataViewMemory0 = null; + +function getDataViewMemory0() { + if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) { + cachedDataViewMemory0 = new DataView(wasm.memory.buffer); + } + return cachedDataViewMemory0; +} + +function handleError(f, args) { + try { + return f.apply(this, args); + } catch (e) { + const idx = addToExternrefTable0(e); + wasm.__wbindgen_exn_store(idx); + } +} + +let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); + +cachedTextDecoder.decode(); + +const MAX_SAFARI_DECODE_BYTES = 2146435072; +let numBytesDecoded = 0; +function decodeText(ptr, len) { + numBytesDecoded += len; + if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) { + cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }); + cachedTextDecoder.decode(); + numBytesDecoded = len; + } + return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); +} + +function getStringFromWasm0(ptr, len) { + ptr = ptr >>> 0; + return decodeText(ptr, len); +} + +function debugString(val) { + // primitive types + const type = typeof val; + if (type == 'number' || type == 'boolean' || val == null) { + return `${val}`; + } + if (type == 'string') { + return `"${val}"`; + } + if (type == 'symbol') { + const description = val.description; + if (description == null) { + return 'Symbol'; + } else { + return `Symbol(${description})`; + } + } + if (type == 'function') { + const name = val.name; + if (typeof name == 'string' && name.length > 0) { + return `Function(${name})`; + } else { + return 'Function'; + } + } + // objects + if (Array.isArray(val)) { + const length = val.length; + let debug = '['; + if (length > 0) { + debug += debugString(val[0]); + } + for(let i = 1; i < length; i++) { + debug += ', ' + debugString(val[i]); + } + debug += ']'; + return debug; + } + // Test for built-in + const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val)); + let className; + if (builtInMatches && builtInMatches.length > 1) { + className = builtInMatches[1]; + } else { + // Failed to match the standard '[object ClassName]' + return toString.call(val); + } + if (className == 'Object') { + // we're a user defined class or Object + // JSON.stringify avoids problems with cycles, and is generally much + // easier than looping through ownProperties of `val`. + try { + return 'Object(' + JSON.stringify(val) + ')'; + } catch (_) { + return 'Object'; + } + } + // errors + if (val instanceof Error) { + return `${val.name}: ${val.message}\n${val.stack}`; + } + // TODO we could test for more things here, like `Set`s and `Map`s. + return className; +} + +const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined') + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry( +state => { + wasm.__wbindgen_export_5.get(state.dtor)(state.a, state.b); +} +); + +function makeMutClosure(arg0, arg1, dtor, f) { + const state = { a: arg0, b: arg1, cnt: 1, dtor }; + const real = (...args) => { + + // First up with a closure we increment the internal reference + // count. This ensures that the Rust closure environment won't + // be deallocated while we're invoking it. + state.cnt++; + const a = state.a; + state.a = 0; + try { + return f(a, state.b, ...args); + } finally { + if (--state.cnt === 0) { + wasm.__wbindgen_export_5.get(state.dtor)(a, state.b); + CLOSURE_DTORS.unregister(state); + } else { + state.a = a; + } + } + }; + real.original = state; + CLOSURE_DTORS.register(real, state, state); + return real; +} /** * @param {number} a * @param {bigint} b @@ -114,6 +241,164 @@ export function example_128(a) { return ret[0] === 0 ? undefined : (BigInt.asUintN(64, ret[1]) | (BigInt.asUintN(64, ret[2]) << BigInt(64))); } +function passArrayJsValueToWasm0(array, malloc) { + const ptr = malloc(array.length * 4, 4) >>> 0; + for (let i = 0; i < array.length; i++) { + const add = addToExternrefTable0(array[i]); + getDataViewMemory0().setUint32(ptr + 4 * i, add, true); + } + WASM_VECTOR_LEN = array.length; + return ptr; +} +/** + * Handler for `console.log` invocations. + * + * If a test is currently running it takes the `args` array and stringifies + * it and appends it to the current output of the test. Otherwise it passes + * the arguments to the original `console.log` function, psased as + * `original`. + * @param {Array} args + */ +export function __wbgtest_console_log(args) { + wasm.__wbgtest_console_log(args); +} + +/** + * Handler for `console.debug` invocations. See above. + * @param {Array} args + */ +export function __wbgtest_console_debug(args) { + wasm.__wbgtest_console_debug(args); +} + +/** + * Handler for `console.info` invocations. See above. + * @param {Array} args + */ +export function __wbgtest_console_info(args) { + wasm.__wbgtest_console_info(args); +} + +/** + * Handler for `console.warn` invocations. See above. + * @param {Array} args + */ +export function __wbgtest_console_warn(args) { + wasm.__wbgtest_console_warn(args); +} + +/** + * Handler for `console.error` invocations. See above. + * @param {Array} args + */ +export function __wbgtest_console_error(args) { + wasm.__wbgtest_console_error(args); +} + +function getArrayU8FromWasm0(ptr, len) { + ptr = ptr >>> 0; + return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len); +} +/** + * @returns {Uint8Array | undefined} + */ +export function __wbgtest_cov_dump() { + const ret = wasm.__wbgtest_cov_dump(); + let v1; + if (ret[0] !== 0) { + v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice(); + wasm.__wbindgen_free(ret[0], ret[1] * 1, 1); + } + return v1; +} + +function __wbg_adapter_8(arg0, arg1, arg2) { + wasm.closure53_externref_shim(arg0, arg1, arg2); +} + +function __wbg_adapter_36(arg0, arg1) { + wasm.wasm_bindgen__convert__closures_____invoke__hc3e1c6a93eb88fad(arg0, arg1); +} + +function __wbg_adapter_69(arg0, arg1, arg2, arg3, arg4) { + wasm.closure69_externref_shim(arg0, arg1, arg2, arg3, arg4); +} + +function __wbg_adapter_82(arg0, arg1, arg2, arg3) { + wasm.closure65_externref_shim(arg0, arg1, arg2, arg3); +} + +const WasmBindgenTestContextFinalization = (typeof FinalizationRegistry === 'undefined') + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry(ptr => wasm.__wbg_wasmbindgentestcontext_free(ptr >>> 0, 1)); +/** + * Runtime test harness support instantiated in JS. + * + * The node.js entry script instantiates a `Context` here which is used to + * drive test execution. + */ +export class WasmBindgenTestContext { + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + WasmBindgenTestContextFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_wasmbindgentestcontext_free(ptr, 0); + } + /** + * Creates a new context ready to run tests. + * + * A `Context` is the main structure through which test execution is + * coordinated, and this will collect output and results for all executed + * tests. + */ + constructor() { + const ret = wasm.wasmbindgentestcontext_new(); + this.__wbg_ptr = ret >>> 0; + WasmBindgenTestContextFinalization.register(this, this.__wbg_ptr, this); + return this; + } + /** + * Handle `--include-ignored` flag. + * @param {boolean} include_ignored + */ + include_ignored(include_ignored) { + wasm.wasmbindgentestcontext_include_ignored(this.__wbg_ptr, include_ignored); + } + /** + * Handle filter argument. + * @param {number} filtered + */ + filtered_count(filtered) { + wasm.wasmbindgentestcontext_filtered_count(this.__wbg_ptr, filtered); + } + /** + * Executes a list of tests, returning a promise representing their + * eventual completion. + * + * This is the main entry point for executing tests. All the tests passed + * in are the JS `Function` object that was plucked off the + * `WebAssembly.Instance` exports list. + * + * The promise returned resolves to either `true` if all tests passed or + * `false` if at least one test failed. + * @param {any[]} tests + * @returns {Promise} + */ + run(tests) { + const ptr0 = passArrayJsValueToWasm0(tests, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + const ret = wasm.wasmbindgentestcontext_run(this.__wbg_ptr, ptr0, len0); + return ret; + } +} +if (Symbol.dispose) WasmBindgenTestContext.prototype[Symbol.dispose] = WasmBindgenTestContext.prototype.free; + const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']); async function __wbg_load(module, imports) { @@ -152,11 +437,248 @@ async function __wbg_load(module, imports) { function __wbg_get_imports() { const imports = {}; imports.wbg = {}; + imports.wbg.__wbg_Deno_93f2ade36ef8b941 = function(arg0) { + const ret = arg0.Deno; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }; + imports.wbg.__wbg_String_e8f90bd4de25a510 = function(arg0, arg1) { + const ret = String(arg1); + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }; + imports.wbg.__wbg_call_2f8d426a20a307fe = function() { return handleError(function (arg0, arg1) { + const ret = arg0.call(arg1); + return ret; + }, arguments) }; + imports.wbg.__wbg_call_f53f0647ceb9c567 = function() { return handleError(function (arg0, arg1, arg2) { + const ret = arg0.call(arg1, arg2); + return ret; + }, arguments) }; + imports.wbg.__wbg_constructor_5c9bbc2584ed23dd = function(arg0) { + const ret = arg0.constructor; + return ret; + }; + imports.wbg.__wbg_error_206a2648f98d06ba = function(arg0, arg1) { + console.error(getStringFromWasm0(arg0, arg1)); + }; + imports.wbg.__wbg_forEach_6a71e9fb3d75a36e = function(arg0, arg1, arg2) { + try { + var state0 = {a: arg1, b: arg2}; + var cb0 = (arg0, arg1, arg2) => { + const a = state0.a; + state0.a = 0; + try { + return __wbg_adapter_69(a, state0.b, arg0, arg1, arg2); + } finally { + state0.a = a; + } + }; + arg0.forEach(cb0); + } finally { + state0.a = state0.b = 0; + } + }; + imports.wbg.__wbg_getElementById_2b37c25987166771 = function(arg0, arg1, arg2) { + const ret = arg0.getElementById(getStringFromWasm0(arg1, arg2)); + return ret; + }; + imports.wbg.__wbg_message_86bd7dcf158b1dda = function(arg0) { + const ret = arg0.message; + return ret; + }; + imports.wbg.__wbg_name_4eed68a70c7faf2a = function(arg0) { + const ret = arg0.name; + return ret; + }; + imports.wbg.__wbg_name_5e961678e9dc4106 = function(arg0, arg1) { + const ret = arg1.name; + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }; + imports.wbg.__wbg_new_6b0599b191ce656f = function() { + const ret = new Error(); + return ret; + }; + imports.wbg.__wbg_new_d5e3800b120e37e1 = function(arg0, arg1) { + try { + var state0 = {a: arg0, b: arg1}; + var cb0 = (arg0, arg1) => { + const a = state0.a; + state0.a = 0; + try { + return __wbg_adapter_82(a, state0.b, arg0, arg1); + } finally { + state0.a = a; + } + }; + const ret = new Promise(cb0); + return ret; + } finally { + state0.a = state0.b = 0; + } + }; + imports.wbg.__wbg_newnoargs_a81330f6e05d8aca = function(arg0, arg1) { + const ret = new Function(getStringFromWasm0(arg0, arg1)); + return ret; + }; + imports.wbg.__wbg_now_cc6eb9e54e3feab4 = function(arg0) { + const ret = arg0.now(); + return ret; + }; + imports.wbg.__wbg_performance_07bb05ede088a93d = function(arg0) { + const ret = arg0.performance; + return ret; + }; + imports.wbg.__wbg_queueMicrotask_bcc6e26d899696db = function(arg0) { + const ret = arg0.queueMicrotask; + return ret; + }; + imports.wbg.__wbg_queueMicrotask_f24a794d09c42640 = function(arg0) { + queueMicrotask(arg0); + }; + imports.wbg.__wbg_resolve_5775c0ef9222f556 = function(arg0) { + const ret = Promise.resolve(arg0); + return ret; + }; + imports.wbg.__wbg_self_230b28c2e693f306 = function(arg0) { + const ret = arg0.self; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }; + imports.wbg.__wbg_settextcontent_c6fbecf056964fda = function(arg0, arg1, arg2) { + arg0.textContent = getStringFromWasm0(arg1, arg2); + }; + imports.wbg.__wbg_stack_01b030a54f9dcda9 = function(arg0) { + const ret = arg0.stack; + return ret; + }; + imports.wbg.__wbg_stack_6ffc528c4f2849b0 = function(arg0, arg1) { + const ret = arg1.stack; + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }; + imports.wbg.__wbg_stack_9d490ba65e81b52d = function(arg0, arg1) { + const ret = arg1.stack; + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }; + imports.wbg.__wbg_stack_a89453c46e7b9be7 = function(arg0) { + const ret = arg0.stack; + return ret; + }; + imports.wbg.__wbg_static_accessor_DOCUMENT_cecff96b8851b566 = function() { + const ret = document; + return ret; + }; + imports.wbg.__wbg_static_accessor_GLOBAL_1f13249cc3acc96d = function() { + const ret = typeof global === 'undefined' ? null : global; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }; + imports.wbg.__wbg_static_accessor_GLOBAL_THIS_df7ae94b1e0ed6a3 = function() { + const ret = typeof globalThis === 'undefined' ? null : globalThis; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }; + imports.wbg.__wbg_static_accessor_SELF_6265471db3b3c228 = function() { + const ret = typeof self === 'undefined' ? null : self; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }; + imports.wbg.__wbg_static_accessor_WINDOW_16fb482f8ec52863 = function() { + const ret = typeof window === 'undefined' ? null : window; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }; + imports.wbg.__wbg_textcontent_0c7bbbdd775b9f5f = function(arg0, arg1) { + const ret = arg1.textContent; + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }; + imports.wbg.__wbg_then_9cc266be2bf537b6 = function(arg0, arg1) { + const ret = arg0.then(arg1); + return ret; + }; + imports.wbg.__wbg_wbgtestinvoke_e4ae19d4c8cfe087 = function() { return handleError(function (arg0, arg1) { + try { + var state0 = {a: arg0, b: arg1}; + var cb0 = () => { + const a = state0.a; + state0.a = 0; + try { + return __wbg_adapter_36(a, state0.b, ); + } finally { + state0.a = a; + } + }; + __wbg_test_invoke(cb0); + } finally { + state0.a = state0.b = 0; + } + }, arguments) }; + imports.wbg.__wbg_wbgtestogconsolelog_9b9958fbac7603ab = function(arg0, arg1) { + __wbgtest_og_console_log(getStringFromWasm0(arg0, arg1)); + }; + imports.wbg.__wbg_wbgtestoutputwriteln_61f711ecae1bf461 = function(arg0) { + __wbg_test_output_writeln(arg0); + }; + imports.wbg.__wbg_wbindgencbdrop_a85ed476c6a370b9 = function(arg0) { + const obj = arg0.original; + if (obj.cnt-- == 1) { + obj.a = 0; + return true; + } + const ret = false; + return ret; + }; + imports.wbg.__wbg_wbindgendebugstring_bb652b1bc2061b6d = function(arg0, arg1) { + const ret = debugString(arg1); + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }; + imports.wbg.__wbg_wbindgenisfunction_ea72b9d66a0e1705 = function(arg0) { + const ret = typeof(arg0) === 'function'; + return ret; + }; + imports.wbg.__wbg_wbindgenisundefined_71f08a6ade4354e7 = function(arg0) { + const ret = arg0 === undefined; + return ret; + }; + imports.wbg.__wbg_wbindgenstringget_43fe05afe34b0cb1 = function(arg0, arg1) { + const obj = arg1; + const ret = typeof(obj) === 'string' ? obj : undefined; + var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + var len1 = WASM_VECTOR_LEN; + getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true); + getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true); + }; imports.wbg.__wbg_wbindgenthrow_4c11a24fca429ccf = function(arg0, arg1) { throw new Error(getStringFromWasm0(arg0, arg1)); }; + imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) { + // Cast intrinsic for `Ref(String) -> Externref`. + const ret = getStringFromWasm0(arg0, arg1); + return ret; + }; + imports.wbg.__wbindgen_cast_753f65f9af634d2f = function(arg0, arg1) { + // Cast intrinsic for `Closure(Closure { dtor_idx: 54, function: Function { arguments: [Externref], shim_idx: 53, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`. + const ret = makeMutClosure(arg0, arg1, 54, __wbg_adapter_8); + return ret; + }; + imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) { + // Cast intrinsic for `F64 -> Externref`. + const ret = arg0; + return ret; + }; imports.wbg.__wbindgen_init_externref_table = function() { - const table = wasm.__wbindgen_export_0; + const table = wasm.__wbindgen_export_1; const offset = table.grow(4); table.set(0, undefined); table.set(offset + 0, undefined); @@ -176,6 +698,7 @@ function __wbg_init_memory(imports, memory) { function __wbg_finalize_init(instance, module) { wasm = instance.exports; __wbg_init.__wbindgen_wasm_module = module; + cachedDataViewMemory0 = null; cachedUint8ArrayMemory0 = null; diff --git a/crates/cli/tests/reference/wasm-export-types.rs b/crates/cli/tests/reference/wasm-export-types.rs index 06f89d912e0..598ca7f35bb 100644 --- a/crates/cli/tests/reference/wasm-export-types.rs +++ b/crates/cli/tests/reference/wasm-export-types.rs @@ -1,6 +1,8 @@ // FLAGS: --target=web +// DEPENDENCY: wasm-bindgen-test = { path = '{root}/crates/test' } use wasm_bindgen::prelude::*; +use wasm_bindgen_test::*; // This is for testing the type generation of the wasm-exported functions. // Here, example should be exported as `(arg0: number, arg1: bigint, arg2: any, arg3: number, arg4: number) => [number, number]`. @@ -15,3 +17,8 @@ pub fn example(a: u32, b: u64, c: JsValue, d: &str) -> String { pub fn example_128(a: u128) -> Option { None } + +#[wasm_bindgen_test] +fn example_test() { + assert_eq!(example_128(1), None) +} diff --git a/crates/cli/tests/reference/wasm-export-types.wat b/crates/cli/tests/reference/wasm-export-types.wat index 22ea36e51a4..4e2e29ba072 100644 --- a/crates/cli/tests/reference/wasm-export-types.wat +++ b/crates/cli/tests/reference/wasm-export-types.wat @@ -1,27 +1,127 @@ (module $reference_test.wasm (type (;0;) (func)) - (type (;1;) (func (param i32 i32))) - (type (;2;) (func (param i32 i32) (result i32))) - (type (;3;) (func (param i32 i32 i32))) - (type (;4;) (func (param i32 i32 i32 i32) (result i32))) - (type (;5;) (func (param i32 i64 externref i32 i32) (result i32 i32))) - (type (;6;) (func (param i64 i64) (result i32 i64 i64))) - (import "wbg" "__wbg_wbindgenthrow_4c11a24fca429ccf" (func (;0;) (type 1))) - (import "wbg" "__wbindgen_init_externref_table" (func (;1;) (type 0))) - (func $"example externref shim multivalue shim" (;2;) (type 5) (param i32 i64 externref i32 i32) (result i32 i32)) - (func $"example_128 multivalue shim" (;3;) (type 6) (param i64 i64) (result i32 i64 i64)) - (func $__wbindgen_malloc (;4;) (type 2) (param i32 i32) (result i32)) - (func $__wbindgen_realloc (;5;) (type 4) (param i32 i32 i32 i32) (result i32)) - (func $__wbindgen_free (;6;) (type 3) (param i32 i32 i32)) - (table (;0;) 128 externref) + (type (;1;) (func (result i32))) + (type (;2;) (func (result i32 i32))) + (type (;3;) (func (result externref))) + (type (;4;) (func (param i32))) + (type (;5;) (func (param i32 i32))) + (type (;6;) (func (param i32 i32) (result i32))) + (type (;7;) (func (param i32 i32) (result externref))) + (type (;8;) (func (param i32 i32 i32))) + (type (;9;) (func (param i32 i32 i32) (result externref))) + (type (;10;) (func (param i32 i32 i32 i32) (result i32))) + (type (;11;) (func (param i32 i32 externref))) + (type (;12;) (func (param i32 i32 externref i32 externref))) + (type (;13;) (func (param i32 i32 externref externref))) + (type (;14;) (func (param i32 i64 externref i32 i32) (result i32 i32))) + (type (;15;) (func (param i32 externref))) + (type (;16;) (func (param i64 i64) (result i32 i64 i64))) + (type (;17;) (func (param f64) (result externref))) + (type (;18;) (func (param externref))) + (type (;19;) (func (param externref) (result i32))) + (type (;20;) (func (param externref) (result f64))) + (type (;21;) (func (param externref) (result externref))) + (type (;22;) (func (param externref i32 i32))) + (type (;23;) (func (param externref i32 i32) (result externref))) + (type (;24;) (func (param externref externref) (result externref))) + (type (;25;) (func (param externref externref externref) (result externref))) + (import "wbg" "__wbg_Deno_93f2ade36ef8b941" (func (;0;) (type 19))) + (import "wbg" "__wbg_String_e8f90bd4de25a510" (func (;1;) (type 15))) + (import "wbg" "__wbg_call_2f8d426a20a307fe" (func (;2;) (type 24))) + (import "wbg" "__wbg_call_f53f0647ceb9c567" (func (;3;) (type 25))) + (import "wbg" "__wbg_constructor_5c9bbc2584ed23dd" (func (;4;) (type 21))) + (import "wbg" "__wbg_error_206a2648f98d06ba" (func (;5;) (type 5))) + (import "wbg" "__wbg_forEach_6a71e9fb3d75a36e" (func (;6;) (type 22))) + (import "wbg" "__wbg_getElementById_2b37c25987166771" (func (;7;) (type 23))) + (import "wbg" "__wbg_message_86bd7dcf158b1dda" (func (;8;) (type 21))) + (import "wbg" "__wbg_name_4eed68a70c7faf2a" (func (;9;) (type 21))) + (import "wbg" "__wbg_name_5e961678e9dc4106" (func (;10;) (type 15))) + (import "wbg" "__wbg_new_6b0599b191ce656f" (func (;11;) (type 3))) + (import "wbg" "__wbg_new_d5e3800b120e37e1" (func (;12;) (type 7))) + (import "wbg" "__wbg_newnoargs_a81330f6e05d8aca" (func (;13;) (type 7))) + (import "wbg" "__wbg_now_cc6eb9e54e3feab4" (func (;14;) (type 20))) + (import "wbg" "__wbg_performance_07bb05ede088a93d" (func (;15;) (type 21))) + (import "wbg" "__wbg_queueMicrotask_bcc6e26d899696db" (func (;16;) (type 21))) + (import "wbg" "__wbg_queueMicrotask_f24a794d09c42640" (func (;17;) (type 18))) + (import "wbg" "__wbg_resolve_5775c0ef9222f556" (func (;18;) (type 21))) + (import "wbg" "__wbg_self_230b28c2e693f306" (func (;19;) (type 19))) + (import "wbg" "__wbg_settextcontent_c6fbecf056964fda" (func (;20;) (type 22))) + (import "wbg" "__wbg_stack_01b030a54f9dcda9" (func (;21;) (type 21))) + (import "wbg" "__wbg_stack_6ffc528c4f2849b0" (func (;22;) (type 15))) + (import "wbg" "__wbg_stack_9d490ba65e81b52d" (func (;23;) (type 15))) + (import "wbg" "__wbg_stack_a89453c46e7b9be7" (func (;24;) (type 21))) + (import "wbg" "__wbg_static_accessor_DOCUMENT_cecff96b8851b566" (func (;25;) (type 3))) + (import "wbg" "__wbg_static_accessor_GLOBAL_1f13249cc3acc96d" (func (;26;) (type 1))) + (import "wbg" "__wbg_static_accessor_GLOBAL_THIS_df7ae94b1e0ed6a3" (func (;27;) (type 1))) + (import "wbg" "__wbg_static_accessor_SELF_6265471db3b3c228" (func (;28;) (type 1))) + (import "wbg" "__wbg_static_accessor_WINDOW_16fb482f8ec52863" (func (;29;) (type 1))) + (import "wbg" "__wbg_textcontent_0c7bbbdd775b9f5f" (func (;30;) (type 15))) + (import "wbg" "__wbg_then_9cc266be2bf537b6" (func (;31;) (type 24))) + (import "wbg" "__wbg_wbgtestinvoke_e4ae19d4c8cfe087" (func (;32;) (type 5))) + (import "wbg" "__wbg_wbgtestogconsolelog_9b9958fbac7603ab" (func (;33;) (type 5))) + (import "wbg" "__wbg_wbgtestoutputwriteln_61f711ecae1bf461" (func (;34;) (type 18))) + (import "wbg" "__wbg_wbindgencbdrop_a85ed476c6a370b9" (func (;35;) (type 19))) + (import "wbg" "__wbg_wbindgendebugstring_bb652b1bc2061b6d" (func (;36;) (type 15))) + (import "wbg" "__wbg_wbindgenisfunction_ea72b9d66a0e1705" (func (;37;) (type 19))) + (import "wbg" "__wbg_wbindgenisundefined_71f08a6ade4354e7" (func (;38;) (type 19))) + (import "wbg" "__wbg_wbindgenstringget_43fe05afe34b0cb1" (func (;39;) (type 15))) + (import "wbg" "__wbg_wbindgenthrow_4c11a24fca429ccf" (func (;40;) (type 5))) + (import "wbg" "__wbindgen_cast_2241b6af4c4b2941" (func (;41;) (type 7))) + (import "wbg" "__wbindgen_cast_753f65f9af634d2f" (func (;42;) (type 7))) + (import "wbg" "__wbindgen_cast_d6cd19b81560fd6e" (func (;43;) (type 17))) + (import "wbg" "__wbindgen_init_externref_table" (func (;44;) (type 0))) + (func $"example externref shim multivalue shim" (;45;) (type 14) (param i32 i64 externref i32 i32) (result i32 i32)) + (func $"example_128 multivalue shim" (;46;) (type 16) (param i64 i64) (result i32 i64 i64)) + (func $__wbgt__reference_test::example_test (;47;) (type 4) (param i32)) + (func $__wbg_wasmbindgentestcontext_free (;48;) (type 5) (param i32 i32)) + (func $wasmbindgentestcontext_new (;49;) (type 1) (result i32)) + (func $wasmbindgentestcontext_include_ignored (;50;) (type 5) (param i32 i32)) + (func $wasmbindgentestcontext_filtered_count (;51;) (type 5) (param i32 i32)) + (func $"wasmbindgentestcontext_run externref shim" (;52;) (type 9) (param i32 i32 i32) (result externref)) + (func $"__wbgtest_console_log externref shim" (;53;) (type 18) (param externref)) + (func $"__wbgtest_console_debug externref shim" (;54;) (type 18) (param externref)) + (func $"__wbgtest_console_info externref shim" (;55;) (type 18) (param externref)) + (func $"__wbgtest_console_warn externref shim" (;56;) (type 18) (param externref)) + (func $"__wbgtest_console_error externref shim" (;57;) (type 18) (param externref)) + (func $"__wbgtest_cov_dump multivalue shim" (;58;) (type 2) (result i32 i32)) + (func $__externref_table_alloc (;59;) (type 1) (result i32)) + (func $__wbindgen_malloc (;60;) (type 6) (param i32 i32) (result i32)) + (func $__wbindgen_realloc (;61;) (type 10) (param i32 i32 i32 i32) (result i32)) + (func $__wbindgen_exn_store (;62;) (type 4) (param i32)) + (func $__wbindgen_free (;63;) (type 8) (param i32 i32 i32)) + (func $"closure53 externref shim" (;64;) (type 11) (param i32 i32 externref)) + (func $wasm_bindgen::convert::closures::_::invoke::hc3e1c6a93eb88fad (;65;) (type 5) (param i32 i32)) + (func $"closure69 externref shim" (;66;) (type 12) (param i32 i32 externref i32 externref)) + (func $"closure65 externref shim" (;67;) (type 13) (param i32 i32 externref externref)) + (table (;0;) 129 129 funcref) + (table (;1;) 128 externref) (memory (;0;) 17) (export "memory" (memory 0)) (export "example" (func $"example externref shim multivalue shim")) (export "example_128" (func $"example_128 multivalue shim")) - (export "__wbindgen_export_0" (table 0)) + (export "__wbgt__reference_test::example_test" (func $__wbgt__reference_test::example_test)) + (export "__wbg_wasmbindgentestcontext_free" (func $__wbg_wasmbindgentestcontext_free)) + (export "wasmbindgentestcontext_new" (func $wasmbindgentestcontext_new)) + (export "wasmbindgentestcontext_include_ignored" (func $wasmbindgentestcontext_include_ignored)) + (export "wasmbindgentestcontext_filtered_count" (func $wasmbindgentestcontext_filtered_count)) + (export "wasmbindgentestcontext_run" (func $"wasmbindgentestcontext_run externref shim")) + (export "__wbgtest_console_log" (func $"__wbgtest_console_log externref shim")) + (export "__wbgtest_console_debug" (func $"__wbgtest_console_debug externref shim")) + (export "__wbgtest_console_info" (func $"__wbgtest_console_info externref shim")) + (export "__wbgtest_console_warn" (func $"__wbgtest_console_warn externref shim")) + (export "__wbgtest_console_error" (func $"__wbgtest_console_error externref shim")) + (export "__wbgtest_cov_dump" (func $"__wbgtest_cov_dump multivalue shim")) + (export "__externref_table_alloc" (func $__externref_table_alloc)) + (export "__wbindgen_export_1" (table 1)) (export "__wbindgen_malloc" (func $__wbindgen_malloc)) (export "__wbindgen_realloc" (func $__wbindgen_realloc)) + (export "__wbindgen_exn_store" (func $__wbindgen_exn_store)) + (export "__wbindgen_export_5" (table 0)) (export "__wbindgen_free" (func $__wbindgen_free)) - (export "__wbindgen_start" (func 1)) + (export "closure53_externref_shim" (func $"closure53 externref shim")) + (export "wasm_bindgen__convert__closures_____invoke__hc3e1c6a93eb88fad" (func $wasm_bindgen::convert::closures::_::invoke::hc3e1c6a93eb88fad)) + (export "closure69_externref_shim" (func $"closure69 externref shim")) + (export "closure65_externref_shim" (func $"closure65 externref shim")) + (export "__wbindgen_start" (func 44)) (@custom "target_features" (after code) "\08+\0bbulk-memory+\0fbulk-memory-opt+\16call-indirect-overlong+\0amultivalue+\0fmutable-globals+\13nontrapping-fptoint+\0freference-types+\08sign-ext") )