diff --git a/crates/cli-support/src/wasm2es6js.rs b/crates/cli-support/src/wasm2es6js.rs index c16eb0a4504..f2e90255e75 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..06c20335d92 100644 --- a/crates/cli/tests/reference/wasm-export-types.d.ts +++ b/crates/cli/tests/reference/wasm-export-types.d.ts @@ -2,6 +2,69 @@ /* 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; + /** + * 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 +72,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 __wbgtest_cov_dump: () => [number, number]; + 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 __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 closure51_externref_shim: (a: number, b: number, c: any) => void; + readonly wasm_bindgen__convert__closures__invoke0_mut__h99d1e3009d33d179: (a: number, b: number) => void; + readonly closure81_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 de290e90502..33217ff2216 100644 --- a/crates/cli/tests/reference/wasm-export-types.js +++ b/crates/cli/tests/reference/wasm-export-types.js @@ -1,8 +1,16 @@ let wasm; -const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } ); +function isLikeNone(x) { + return x === undefined || x === null; +} -if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); }; +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; @@ -13,13 +21,6 @@ function getUint8ArrayMemory0() { return cachedUint8ArrayMemory0; } -function getStringFromWasm0(ptr, len) { - ptr = ptr >>> 0; - return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); -} - -let WASM_VECTOR_LEN = 0; - const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } ); const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' @@ -73,6 +74,129 @@ 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); + } +} + +const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } ); + +if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); }; + +function getStringFromWasm0(ptr, len) { + ptr = ptr >>> 0; + return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); +} + +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; +} + +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; +} /** * @param {number} a * @param {bigint} b @@ -104,6 +228,163 @@ 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_24(arg0, arg1, arg2) { + wasm.closure51_externref_shim(arg0, arg1, arg2); +} + +function __wbg_adapter_70(arg0, arg1) { + wasm.wasm_bindgen__convert__closures__invoke0_mut__h99d1e3009d33d179(arg0, arg1); +} + +function __wbg_adapter_81(arg0, arg1, arg2, arg3, arg4) { + wasm.closure81_externref_shim(arg0, arg1, arg2, arg3, arg4); +} + +function __wbg_adapter_94(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; + } +} + async function __wbg_load(module, imports) { if (typeof Response === 'function' && module instanceof Response) { if (typeof WebAssembly.instantiateStreaming === 'function') { @@ -138,8 +419,218 @@ async function __wbg_load(module, imports) { function __wbg_get_imports() { const imports = {}; imports.wbg = {}; + imports.wbg.__wbg_Deno_5e0f323eeba20aa4 = function(arg0) { + const ret = arg0.Deno; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }; + imports.wbg.__wbg_String_6f4330ab5fd77ef6 = 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_672a4d21634d4a24 = function() { return handleError(function (arg0, arg1) { + const ret = arg0.call(arg1); + return ret; + }, arguments) }; + imports.wbg.__wbg_call_7cccdd69e0791ae2 = function() { return handleError(function (arg0, arg1, arg2) { + const ret = arg0.call(arg1, arg2); + return ret; + }, arguments) }; + imports.wbg.__wbg_constructor_75c512bc262c1ab2 = function(arg0) { + const ret = arg0.constructor; + return ret; + }; + imports.wbg.__wbg_error_f19acdc6b5fafb26 = function(arg0, arg1) { + console.error(getStringFromWasm0(arg0, arg1)); + }; + imports.wbg.__wbg_forEach_d6a05ca96422eff9 = 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_81(a, state0.b, arg0, arg1, arg2); + } finally { + state0.a = a; + } + }; + arg0.forEach(cb0); + } finally { + state0.a = state0.b = 0; + } + }; + imports.wbg.__wbg_getElementById_727e92dd724c370c = function(arg0, arg1, arg2) { + const ret = arg0.getElementById(getStringFromWasm0(arg1, arg2)); + return ret; + }; + imports.wbg.__wbg_message_97a2af9b89d693a3 = function(arg0) { + const ret = arg0.message; + return ret; + }; + imports.wbg.__wbg_name_0b327d569f00ebee = function(arg0) { + const ret = arg0.name; + return ret; + }; + imports.wbg.__wbg_name_ac50ab7b6b731bdc = 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_23a2665fac83c611 = 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_94(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_new_78093c5bd701d017 = function() { + const ret = new Error(); + return ret; + }; + imports.wbg.__wbg_newnoargs_105ed471475aaf50 = function(arg0, arg1) { + const ret = new Function(getStringFromWasm0(arg0, arg1)); + return ret; + }; + imports.wbg.__wbg_now_832024c17817dc01 = function(arg0) { + const ret = arg0.now(); + return ret; + }; + imports.wbg.__wbg_performance_ae5e84dd26af6765 = function(arg0) { + const ret = arg0.performance; + return ret; + }; + imports.wbg.__wbg_queueMicrotask_97d92b4fcc8a61c5 = function(arg0) { + queueMicrotask(arg0); + }; + imports.wbg.__wbg_queueMicrotask_d3219def82552485 = function(arg0) { + const ret = arg0.queueMicrotask; + return ret; + }; + imports.wbg.__wbg_resolve_4851785c9c5f573d = function(arg0) { + const ret = Promise.resolve(arg0); + return ret; + }; + imports.wbg.__wbg_self_67c28212685dfde2 = function(arg0) { + const ret = arg0.self; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }; + imports.wbg.__wbg_settextcontent_4516425a935f461b = function(arg0, arg1, arg2) { + arg0.textContent = getStringFromWasm0(arg1, arg2); + }; + imports.wbg.__wbg_stack_54b23675007f71bb = 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_8e0a01ea26c1db11 = 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_d6edc2612f9df83f = function(arg0) { + const ret = arg0.stack; + return ret; + }; + imports.wbg.__wbg_stack_f851a06e9c78be1d = function(arg0) { + const ret = arg0.stack; + return ret; + }; + imports.wbg.__wbg_static_accessor_DOCUMENT_2badde8ae57cc9f7 = function() { + const ret = document; + return ret; + }; + imports.wbg.__wbg_static_accessor_GLOBAL_88a902d13a557d07 = function() { + const ret = typeof global === 'undefined' ? null : global; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }; + imports.wbg.__wbg_static_accessor_GLOBAL_THIS_56578be7e9f832b0 = function() { + const ret = typeof globalThis === 'undefined' ? null : globalThis; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }; + imports.wbg.__wbg_static_accessor_SELF_37c5d418e4bf5819 = function() { + const ret = typeof self === 'undefined' ? null : self; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }; + imports.wbg.__wbg_static_accessor_WINDOW_5de37043a91a9c40 = function() { + const ret = typeof window === 'undefined' ? null : window; + return isLikeNone(ret) ? 0 : addToExternrefTable0(ret); + }; + imports.wbg.__wbg_textcontent_9581a1676431df94 = 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_44b73946d2fb3e7d = function(arg0, arg1) { + const ret = arg0.then(arg1); + return ret; + }; + imports.wbg.__wbg_wbgtestinvoke_d8e1edfc10304da7 = 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_70(a, state0.b, ); + } finally { + state0.a = a; + } + }; + __wbg_test_invoke(cb0); + } finally { + state0.a = state0.b = 0; + } + }, arguments) }; + imports.wbg.__wbg_wbgtestogconsolelog_2c6a12219a99cdb3 = function(arg0, arg1) { + __wbgtest_og_console_log(getStringFromWasm0(arg0, arg1)); + }; + imports.wbg.__wbg_wbgtestoutputwriteln_be640e64b2946d47 = function(arg0) { + __wbg_test_output_writeln(arg0); + }; + imports.wbg.__wbindgen_cb_drop = function(arg0) { + const obj = arg0.original; + if (obj.cnt-- == 1) { + obj.a = 0; + return true; + } + const ret = false; + return ret; + }; + imports.wbg.__wbindgen_closure_wrapper751 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 52, __wbg_adapter_24); + return ret; + }; + imports.wbg.__wbindgen_debug_string = 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.__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); @@ -148,6 +639,30 @@ function __wbg_get_imports() { table.set(offset + 3, false); ; }; + imports.wbg.__wbindgen_is_function = function(arg0) { + const ret = typeof(arg0) === 'function'; + return ret; + }; + imports.wbg.__wbindgen_is_undefined = function(arg0) { + const ret = arg0 === undefined; + return ret; + }; + imports.wbg.__wbindgen_number_new = function(arg0) { + const ret = arg0; + return ret; + }; + imports.wbg.__wbindgen_string_get = 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.__wbindgen_string_new = function(arg0, arg1) { + const ret = getStringFromWasm0(arg0, arg1); + return ret; + }; imports.wbg.__wbindgen_throw = function(arg0, arg1) { throw new Error(getStringFromWasm0(arg0, arg1)); }; @@ -162,6 +677,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 195c25a5723..676a69b194e 100644 --- a/crates/cli/tests/reference/wasm-export-types.wat +++ b/crates/cli/tests/reference/wasm-export-types.wat @@ -1,25 +1,72 @@ (module $reference_test.wasm (type (;0;) (func)) - (type (;1;) (func (param i32 i32) (result i32))) - (type (;2;) (func (param i32 i32 i32))) - (type (;3;) (func (param i32 i32 i32 i32) (result i32))) - (type (;4;) (func (param i32 i64 externref i32 i32) (result i32 i32))) - (type (;5;) (func (param i64 i64) (result i32 i64 i64))) + (type (;1;) (func (result i32))) + (type (;2;) (func (result i32 i32))) + (type (;3;) (func (param i32))) + (type (;4;) (func (param i32 i32))) + (type (;5;) (func (param i32 i32) (result i32))) + (type (;6;) (func (param i32 i32 i32))) + (type (;7;) (func (param i32 i32 i32) (result externref))) + (type (;8;) (func (param i32 i32 i32 i32) (result i32))) + (type (;9;) (func (param i32 i32 externref))) + (type (;10;) (func (param i32 i32 externref i32 externref))) + (type (;11;) (func (param i32 i32 externref externref))) + (type (;12;) (func (param i32 i64 externref i32 i32) (result i32 i32))) + (type (;13;) (func (param i64 i64) (result i32 i64 i64))) + (type (;14;) (func (param externref))) (import "wbg" "__wbindgen_init_externref_table" (func (;0;) (type 0))) - (func $__wbindgen_realloc (;1;) (type 3) (param i32 i32 i32 i32) (result i32)) - (func $__wbindgen_malloc (;2;) (type 1) (param i32 i32) (result i32)) - (func $__wbindgen_free (;3;) (type 2) (param i32 i32 i32)) - (func $"example externref shim multivalue shim" (;4;) (type 4) (param i32 i64 externref i32 i32) (result i32 i32)) - (func $"example_128 multivalue shim" (;5;) (type 5) (param i64 i64) (result i32 i64 i64)) - (table (;0;) 128 externref) + (func $__wbindgen_realloc (;1;) (type 8) (param i32 i32 i32 i32) (result i32)) + (func $__wbindgen_malloc (;2;) (type 5) (param i32 i32) (result i32)) + (func $__wbindgen_exn_store (;3;) (type 3) (param i32)) + (func $wasmbindgentestcontext_include_ignored (;4;) (type 4) (param i32 i32)) + (func $wasmbindgentestcontext_filtered_count (;5;) (type 4) (param i32 i32)) + (func $__wbgt__reference_test::example_test (;6;) (type 3) (param i32)) + (func $wasm_bindgen::convert::closures::invoke0_mut::h99d1e3009d33d179 (;7;) (type 4) (param i32 i32)) + (func $__wbindgen_free (;8;) (type 6) (param i32 i32 i32)) + (func $__wbg_wasmbindgentestcontext_free (;9;) (type 4) (param i32 i32)) + (func $wasmbindgentestcontext_new (;10;) (type 1) (result i32)) + (func $"example externref shim multivalue shim" (;11;) (type 12) (param i32 i64 externref i32 i32) (result i32 i32)) + (func $"example_128 multivalue shim" (;12;) (type 13) (param i64 i64) (result i32 i64 i64)) + (func $"__wbgtest_console_log externref shim" (;13;) (type 14) (param externref)) + (func $"__wbgtest_console_debug externref shim" (;14;) (type 14) (param externref)) + (func $"__wbgtest_console_info externref shim" (;15;) (type 14) (param externref)) + (func $"__wbgtest_console_warn externref shim" (;16;) (type 14) (param externref)) + (func $"__wbgtest_console_error externref shim" (;17;) (type 14) (param externref)) + (func $"__wbgtest_cov_dump multivalue shim" (;18;) (type 2) (result i32 i32)) + (func $"closure81 externref shim" (;19;) (type 10) (param i32 i32 externref i32 externref)) + (func $__externref_table_alloc (;20;) (type 1) (result i32)) + (func $"closure65 externref shim" (;21;) (type 11) (param i32 i32 externref externref)) + (func $"wasmbindgentestcontext_run externref shim" (;22;) (type 7) (param i32 i32 i32) (result externref)) + (func $"closure51 externref shim" (;23;) (type 9) (param i32 i32 externref)) + (table (;0;) 128 128 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 "__wbgtest_cov_dump" (func $"__wbgtest_cov_dump multivalue shim")) + (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 "__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 "closure51_externref_shim" (func $"closure51 externref shim")) + (export "wasm_bindgen__convert__closures__invoke0_mut__h99d1e3009d33d179" (func $wasm_bindgen::convert::closures::invoke0_mut::h99d1e3009d33d179)) + (export "closure81_externref_shim" (func $"closure81 externref shim")) + (export "closure65_externref_shim" (func $"closure65 externref shim")) (export "__wbindgen_start" (func 0)) (@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext") )