diff --git a/crates/cli-support/src/js/mod.rs b/crates/cli-support/src/js/mod.rs index 22bd9246e6a..2466c07972b 100644 --- a/crates/cli-support/src/js/mod.rs +++ b/crates/cli-support/src/js/mod.rs @@ -1173,6 +1173,10 @@ __wbg_set_wasm(wasm);" // the linked list of heap slots that are free. self.global(&format!( " + /** + * @param {{number}} idx + * @returns {{void}} + */ function dropObject(idx) {{ if (idx < {}) return; heap[idx] = heap_next; @@ -1313,10 +1317,14 @@ __wbg_set_wasm(wasm);" // a `SharedArrayBuffer` is in use. let shared = self.module.memories.get(memory).shared; + let js_doc = + "/** @type {(arg: string, view: Uint8Array) => TextEncoderEncodeIntoResult} */"; + match self.config.encode_into { EncodeInto::Always if !shared => { self.global(&format!( " + {js_doc} const encodeString = {}; ", encode_into @@ -1325,6 +1333,7 @@ __wbg_set_wasm(wasm);" EncodeInto::Test if !shared => { self.global(&format!( " + {js_doc} const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' ? {} : {}); @@ -1335,6 +1344,7 @@ __wbg_set_wasm(wasm);" _ => { self.global(&format!( " + {js_doc} const encodeString = {}; ", encode @@ -1378,7 +1388,14 @@ __wbg_set_wasm(wasm);" ); self.global(&format!( - "function {name}(arg, malloc, realloc) {{ + " + /** + * @param {{string}} arg + * @param {{(size: number, align: number) => number}} malloc + * @param {{(ptr: number, oldSize: number, newSize: number, align: number) => number}} [realloc] + * @returns {{number}} + */ + function {name}(arg, malloc, realloc) {{ {debug} {ascii} if (offset !== len) {{ @@ -1395,7 +1412,8 @@ __wbg_set_wasm(wasm);" WASM_VECTOR_LEN = offset; return ptr; - }}", + }} + ", name = ret, debug = debug, ascii = encode_as_ascii, @@ -1457,6 +1475,11 @@ __wbg_set_wasm(wasm);" let add = self.expose_add_to_externref_table(table, alloc)?; self.global(&format!( " + /** + * @param {{ArrayLike}} array + * @param {{(size: number, align: number) => number}} malloc + * @returns {{number}} + */ function {}(array, malloc) {{ const ptr = malloc(array.length * 4, 4) >>> 0; const mem = {}(); @@ -1474,6 +1497,11 @@ __wbg_set_wasm(wasm);" self.expose_add_heap_object(); self.global(&format!( " + /** + * @param {{ArrayLike}} array + * @param {{(size: number, align: number) => number}} malloc + * @returns {{number}} + */ function {}(array, malloc) {{ const ptr = malloc(array.length * 4, 4) >>> 0; const mem = {}(); @@ -1507,6 +1535,11 @@ __wbg_set_wasm(wasm);" self.expose_wasm_vector_len(); self.global(&format!( " + /** + * @param {{ArrayLike}} arg + * @param {{(size: number, align: number) => number}} malloc + * @returns {{number}} + */ function {}(arg, malloc) {{ const ptr = malloc(arg.length * {size}, {size}) >>> 0; {}().set(arg, ptr / {size}); @@ -1564,6 +1597,7 @@ __wbg_set_wasm(wasm);" args: &str, init: Option<&str>, ) -> Result<(), Error> { + let js_doc = format!("/** @type {{{s}}} */\n"); match &self.config.mode { OutputMode::Node { .. } => { let name = self.import_name(&JsImport { @@ -1573,25 +1607,23 @@ __wbg_set_wasm(wasm);" }, fields: Vec::new(), })?; - self.global(&format!("let cached{} = new {}{};", s, name, args)); + self.global(&format!("{js_doc}let cached{} = new {}{};", s, name, args)); } OutputMode::Bundler { browser_only: false, } => { - self.global(&format!( - " - const l{0} = typeof {0} === 'undefined' ? \ - (0, module.require)('util').{0} : {0};\ - ", - s - )); - self.global(&format!("let cached{0} = new l{0}{1};", s, args)); + // this is a mix between the web and node version. + // we check if Text{En,De}coder is available (web) and if not, we require it (node). + let type_expr = format!( + "typeof {s} === 'undefined' ? (0, module.require)('util').{s} : {s}" + ); + self.global(&format!("{js_doc}let cached{s} = new ({type_expr}){args};")); } OutputMode::Deno | OutputMode::Web | OutputMode::NoModules { .. } | OutputMode::Bundler { browser_only: true } => { - self.global(&format!("const cached{0} = (typeof {0} !== 'undefined' ? new {0}{1} : {{ {2}: () => {{ throw Error('{0} not available') }} }} );", s, args, op)) + self.global(&format!("{js_doc}const cached{0} = (typeof {0} !== 'undefined' ? new {0}{1} : {{ {2}: () => {{ throw Error('{0} not available') }} }} );", s, args, op)) } }; @@ -1639,6 +1671,11 @@ __wbg_set_wasm(wasm);" self.global(&format!( " + /** + * @param {{number}} ptr + * @param {{number}} len + * @returns {{string}} + */ function {}(ptr, len) {{ ptr = ptr >>> 0; return cachedTextDecoder.decode({}().{}(ptr, ptr + len)); @@ -1810,6 +1847,10 @@ __wbg_set_wasm(wasm);" } self.global(&format!( " + /** + * @param {{number}} ptr + * @param {{number}} len + */ function {name}(ptr, len) {{ ptr = ptr >>> 0; return {mem}().subarray(ptr / {size}, ptr / {size} + len); @@ -1898,10 +1939,10 @@ __wbg_set_wasm(wasm);" format!("{cache}.byteLength === 0", cache = cache) }; - self.global(&format!("let {cache} = null;\n")); - self.global(&format!( " + /** @type {{{kind} | null}} */ + let {cache} = null; function {name}() {{ if ({cache} === null || {resized_check}) {{ {cache} = new {kind}(wasm.{mem}.buffer); @@ -1946,6 +1987,10 @@ __wbg_set_wasm(wasm);" } self.global( " + /** + * @param {unknown} instance + * @param {Function} klass + */ function _assertClass(instance, klass) { if (!(instance instanceof klass)) { throw new Error(`expected instance of ${klass.name}`); @@ -1993,6 +2038,10 @@ __wbg_set_wasm(wasm);" self.expose_drop_ref(); self.global( " + /** + * @param {number} idx + * @returns {any} + */ function takeObject(idx) { const ret = getObject(idx); dropObject(idx); @@ -2024,6 +2073,10 @@ __wbg_set_wasm(wasm);" // one more slot and use that. self.global(&format!( " + /** + * @param {{unknown}} obj + * @returns {{number}} + */ function addHeapObject(obj) {{ if (heap_next === heap.length) heap.push(heap.length + 1); const idx = heap_next; @@ -2183,6 +2236,10 @@ __wbg_set_wasm(wasm);" } self.global( " + /** + * @param {unknown} x + * @returns {x is undefined | null} + */ function isLikeNone(x) { return x === undefined || x === null; } @@ -3941,7 +3998,11 @@ __wbg_set_wasm(wasm);" self.global( " - function debugString(val) { + /** + * @param {any} val + * @returns {string} + */ + function debugString(val) { // primitive types const type = typeof val; if (type == 'number' || type == 'boolean' || val == null) { diff --git a/crates/cli/tests/reference/anyref-import-catch.js b/crates/cli/tests/reference/anyref-import-catch.js index d89f629f896..edaa63add14 100644 --- a/crates/cli/tests/reference/anyref-import-catch.js +++ b/crates/cli/tests/reference/anyref-import-catch.js @@ -4,14 +4,13 @@ export function __wbg_set_wasm(val) { } -const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; - -let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); +/** @type {TextDecoder} */ +let cachedTextDecoder = new (typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder)('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); +/** @type {Uint8Array | null} */ let cachedUint8ArrayMemory0 = null; - function getUint8ArrayMemory0() { if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); @@ -19,6 +18,11 @@ function getUint8ArrayMemory0() { return cachedUint8ArrayMemory0; } +/** + * @param {number} ptr + * @param {number} len + * @returns {string} + */ function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); @@ -39,8 +43,8 @@ function handleError(f, args) { } } +/** @type {DataView | null} */ 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); diff --git a/crates/cli/tests/reference/builder.js b/crates/cli/tests/reference/builder.js index 1781b4dbe06..39c39ed9356 100644 --- a/crates/cli/tests/reference/builder.js +++ b/crates/cli/tests/reference/builder.js @@ -4,14 +4,13 @@ export function __wbg_set_wasm(val) { } -const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; - -let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); +/** @type {TextDecoder} */ +let cachedTextDecoder = new (typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder)('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); +/** @type {Uint8Array | null} */ let cachedUint8ArrayMemory0 = null; - function getUint8ArrayMemory0() { if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); @@ -19,6 +18,11 @@ function getUint8ArrayMemory0() { return cachedUint8ArrayMemory0; } +/** + * @param {number} ptr + * @param {number} len + * @returns {string} + */ function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); diff --git a/crates/cli/tests/reference/constructor.js b/crates/cli/tests/reference/constructor.js index e55a1e9e9bf..a222278a5ad 100644 --- a/crates/cli/tests/reference/constructor.js +++ b/crates/cli/tests/reference/constructor.js @@ -4,14 +4,13 @@ export function __wbg_set_wasm(val) { } -const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; - -let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); +/** @type {TextDecoder} */ +let cachedTextDecoder = new (typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder)('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); +/** @type {Uint8Array | null} */ let cachedUint8ArrayMemory0 = null; - function getUint8ArrayMemory0() { if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); @@ -19,6 +18,11 @@ function getUint8ArrayMemory0() { return cachedUint8ArrayMemory0; } +/** + * @param {number} ptr + * @param {number} len + * @returns {string} + */ function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); diff --git a/crates/cli/tests/reference/enums.js b/crates/cli/tests/reference/enums.js index 0af1ffd6404..464ca571334 100644 --- a/crates/cli/tests/reference/enums.js +++ b/crates/cli/tests/reference/enums.js @@ -4,14 +4,13 @@ export function __wbg_set_wasm(val) { } -const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; - -let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); +/** @type {TextDecoder} */ +let cachedTextDecoder = new (typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder)('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); +/** @type {Uint8Array | null} */ let cachedUint8ArrayMemory0 = null; - function getUint8ArrayMemory0() { if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); @@ -19,6 +18,11 @@ function getUint8ArrayMemory0() { return cachedUint8ArrayMemory0; } +/** + * @param {number} ptr + * @param {number} len + * @returns {string} + */ function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); @@ -32,6 +36,10 @@ export function enum_echo(color) { return ret; } +/** + * @param {unknown} x + * @returns {x is undefined | null} + */ function isLikeNone(x) { return x === undefined || x === null; } diff --git a/crates/cli/tests/reference/import-catch.js b/crates/cli/tests/reference/import-catch.js index 4c4d0284851..c3e81ca915a 100644 --- a/crates/cli/tests/reference/import-catch.js +++ b/crates/cli/tests/reference/import-catch.js @@ -10,6 +10,10 @@ heap.push(undefined, null, true, false); let heap_next = heap.length; +/** + * @param {unknown} obj + * @returns {number} + */ function addHeapObject(obj) { if (heap_next === heap.length) heap.push(heap.length + 1); const idx = heap_next; @@ -27,8 +31,8 @@ function handleError(f, args) { } } +/** @type {DataView | null} */ 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); @@ -38,12 +42,20 @@ function getDataViewMemory0() { function getObject(idx) { return heap[idx]; } +/** + * @param {number} idx + * @returns {void} + */ function dropObject(idx) { if (idx < 132) return; heap[idx] = heap_next; heap_next = idx; } +/** + * @param {number} idx + * @returns {any} + */ function takeObject(idx) { const ret = getObject(idx); dropObject(idx); diff --git a/crates/cli/tests/reference/raw.js b/crates/cli/tests/reference/raw.js index 6c6e36065ee..a172ac3c15f 100644 --- a/crates/cli/tests/reference/raw.js +++ b/crates/cli/tests/reference/raw.js @@ -6,14 +6,13 @@ export function __wbg_set_wasm(val) { } -const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; - -let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); +/** @type {TextDecoder} */ +let cachedTextDecoder = new (typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder)('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); +/** @type {Uint8Array | null} */ let cachedUint8ArrayMemory0 = null; - function getUint8ArrayMemory0() { if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); @@ -21,6 +20,11 @@ function getUint8ArrayMemory0() { return cachedUint8ArrayMemory0; } +/** + * @param {number} ptr + * @param {number} len + * @returns {string} + */ function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); @@ -34,12 +38,20 @@ function getObject(idx) { return heap[idx]; } let heap_next = heap.length; +/** + * @param {number} idx + * @returns {void} + */ function dropObject(idx) { if (idx < 132) return; heap[idx] = heap_next; heap_next = idx; } +/** + * @param {number} idx + * @returns {any} + */ function takeObject(idx) { const ret = getObject(idx); dropObject(idx); @@ -54,6 +66,10 @@ export function test1(test) { return ret >>> 0; } +/** + * @param {unknown} obj + * @returns {number} + */ function addHeapObject(obj) { if (heap_next === heap.length) heap.push(heap.length + 1); const idx = heap_next; diff --git a/crates/cli/tests/reference/result-string.js b/crates/cli/tests/reference/result-string.js index caa17738225..ed1c4e136cc 100644 --- a/crates/cli/tests/reference/result-string.js +++ b/crates/cli/tests/reference/result-string.js @@ -10,6 +10,10 @@ heap.push(undefined, null, true, false); let heap_next = heap.length; +/** + * @param {unknown} obj + * @returns {number} + */ function addHeapObject(obj) { if (heap_next === heap.length) heap.push(heap.length + 1); const idx = heap_next; @@ -19,8 +23,8 @@ function addHeapObject(obj) { return idx; } +/** @type {DataView | null} */ 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); @@ -30,26 +34,33 @@ function getDataViewMemory0() { function getObject(idx) { return heap[idx]; } +/** + * @param {number} idx + * @returns {void} + */ function dropObject(idx) { if (idx < 132) return; heap[idx] = heap_next; heap_next = idx; } +/** + * @param {number} idx + * @returns {any} + */ function takeObject(idx) { const ret = getObject(idx); dropObject(idx); return ret; } -const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; - -let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); +/** @type {TextDecoder} */ +let cachedTextDecoder = new (typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder)('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); +/** @type {Uint8Array | null} */ let cachedUint8ArrayMemory0 = null; - function getUint8ArrayMemory0() { if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); @@ -57,6 +68,11 @@ function getUint8ArrayMemory0() { return cachedUint8ArrayMemory0; } +/** + * @param {number} ptr + * @param {number} len + * @returns {string} + */ function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); diff --git a/crates/cli/tests/reference/self-type.js b/crates/cli/tests/reference/self-type.js index ba2f992bc57..4a8712f1b6f 100644 --- a/crates/cli/tests/reference/self-type.js +++ b/crates/cli/tests/reference/self-type.js @@ -4,14 +4,13 @@ export function __wbg_set_wasm(val) { } -const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; - -let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); +/** @type {TextDecoder} */ +let cachedTextDecoder = new (typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder)('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); +/** @type {Uint8Array | null} */ let cachedUint8ArrayMemory0 = null; - function getUint8ArrayMemory0() { if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); @@ -19,6 +18,11 @@ function getUint8ArrayMemory0() { return cachedUint8ArrayMemory0; } +/** + * @param {number} ptr + * @param {number} len + * @returns {string} + */ function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); diff --git a/crates/cli/tests/reference/string-arg.js b/crates/cli/tests/reference/string-arg.js index cc037461669..e09bf56c5a9 100644 --- a/crates/cli/tests/reference/string-arg.js +++ b/crates/cli/tests/reference/string-arg.js @@ -4,14 +4,13 @@ export function __wbg_set_wasm(val) { } -const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; - -let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); +/** @type {TextDecoder} */ +let cachedTextDecoder = new (typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder)('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); +/** @type {Uint8Array | null} */ let cachedUint8ArrayMemory0 = null; - function getUint8ArrayMemory0() { if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); @@ -19,6 +18,11 @@ function getUint8ArrayMemory0() { return cachedUint8ArrayMemory0; } +/** + * @param {number} ptr + * @param {number} len + * @returns {string} + */ function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); @@ -26,10 +30,10 @@ function getStringFromWasm0(ptr, len) { let WASM_VECTOR_LEN = 0; -const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder; - -let cachedTextEncoder = new lTextEncoder('utf-8'); +/** @type {TextEncoder} */ +let cachedTextEncoder = new (typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder)('utf-8'); +/** @type {(arg: string, view: Uint8Array) => TextEncoderEncodeIntoResult} */ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' ? function (arg, view) { return cachedTextEncoder.encodeInto(arg, view); @@ -43,6 +47,12 @@ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' }; }); +/** + * @param {string} arg + * @param {(size: number, align: number) => number} malloc + * @param {(ptr: number, oldSize: number, newSize: number, align: number) => number} [realloc] + * @returns {number} + */ function passStringToWasm0(arg, malloc, realloc) { if (realloc === undefined) { diff --git a/crates/cli/tests/reference/web-sys.js b/crates/cli/tests/reference/web-sys.js index 7e4cc173aa7..c706ae77aa0 100644 --- a/crates/cli/tests/reference/web-sys.js +++ b/crates/cli/tests/reference/web-sys.js @@ -10,6 +10,10 @@ heap.push(undefined, null, true, false); function getObject(idx) { return heap[idx]; } +/** + * @param {any} val + * @returns {string} + */ function debugString(val) { // primitive types const type = typeof val; @@ -77,8 +81,8 @@ function debugString(val) { let WASM_VECTOR_LEN = 0; +/** @type {Uint8Array | null} */ let cachedUint8ArrayMemory0 = null; - function getUint8ArrayMemory0() { if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) { cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); @@ -86,10 +90,10 @@ function getUint8ArrayMemory0() { return cachedUint8ArrayMemory0; } -const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder; - -let cachedTextEncoder = new lTextEncoder('utf-8'); +/** @type {TextEncoder} */ +let cachedTextEncoder = new (typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder)('utf-8'); +/** @type {(arg: string, view: Uint8Array) => TextEncoderEncodeIntoResult} */ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' ? function (arg, view) { return cachedTextEncoder.encodeInto(arg, view); @@ -103,6 +107,12 @@ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' }; }); +/** + * @param {string} arg + * @param {(size: number, align: number) => number} malloc + * @param {(ptr: number, oldSize: number, newSize: number, align: number) => number} [realloc] + * @returns {number} + */ function passStringToWasm0(arg, malloc, realloc) { if (realloc === undefined) { @@ -142,8 +152,8 @@ function passStringToWasm0(arg, malloc, realloc) { return ptr; } +/** @type {DataView | null} */ 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); @@ -151,12 +161,16 @@ function getDataViewMemory0() { return cachedDataViewMemory0; } -const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder; - -let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true }); +/** @type {TextDecoder} */ +let cachedTextDecoder = new (typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder)('utf-8', { ignoreBOM: true, fatal: true }); cachedTextDecoder.decode(); +/** + * @param {number} ptr + * @param {number} len + * @returns {string} + */ function getStringFromWasm0(ptr, len) { ptr = ptr >>> 0; return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len)); @@ -164,12 +178,20 @@ function getStringFromWasm0(ptr, len) { let heap_next = heap.length; +/** + * @param {number} idx + * @returns {void} + */ function dropObject(idx) { if (idx < 132) return; heap[idx] = heap_next; heap_next = idx; } +/** + * @param {number} idx + * @returns {any} + */ function takeObject(idx) { const ret = getObject(idx); dropObject(idx); @@ -191,6 +213,10 @@ export function get_media_source() { return __wbindgen_enum_MediaSourceEnum[ret]; } +/** + * @param {unknown} obj + * @returns {number} + */ function addHeapObject(obj) { if (heap_next === heap.length) heap.push(heap.length + 1); const idx = heap_next;