UNPKG

web-tree-sitter

Version:
4 lines 277 kB
{ "version": 3, "sources": ["lib/web-tree-sitter.cjs", "src/index.ts", "src/edit.ts", "src/constants.ts", "src/lookahead_iterator.ts", "src/tree.ts", "src/tree_cursor.ts", "src/node.ts", "src/marshal.ts", "src/language.ts", "src/bindings.ts", "src/parser.ts", "src/query.ts"], "sourcesContent": ["// This code implements the `-sMODULARIZE` settings by taking the generated\n// JS program code (INNER_JS_CODE) and wrapping it in a factory function.\n\n// Single threaded MINIMAL_RUNTIME programs do not need access to\n// document.currentScript, so a simple export declaration is enough.\nvar Module = (() => {\n // When MODULARIZE this JS may be executed later,\n // after document.currentScript is gone, so we save it.\n // In EXPORT_ES6 mode we can just use 'import.meta.url'.\n var _scriptName = typeof document != 'undefined' ? document.currentScript?.src : undefined;\n return async function(moduleArg = {}) {\n var moduleRtn;\n\n// include: shell.js\n// The Module object: Our interface to the outside world. We import\n// and export values on it. There are various ways Module can be used:\n// 1. Not defined. We create it here\n// 2. A function parameter, function(moduleArg) => Promise<Module>\n// 3. pre-run appended it, var Module = {}; ..generated code..\n// 4. External script tag defines var Module.\n// We need to check if Module already exists (e.g. case 3 above).\n// Substitution will be replaced with actual code on later stage of the build,\n// this way Closure Compiler will not mangle it (e.g. case 4. above).\n// Note that if you want to run closure, and also to use Module\n// after the generated code, you will need to define var Module = {};\n// before the code. Then that object will be used in the code, and you\n// can continue to use Module afterwards as well.\nvar Module = moduleArg;\n\n// Determine the runtime environment we are in. You can customize this by\n// setting the ENVIRONMENT setting at compile time (see settings.js).\n// Attempt to auto-detect the environment\nvar ENVIRONMENT_IS_WEB = typeof window == \"object\";\n\nvar ENVIRONMENT_IS_WORKER = typeof WorkerGlobalScope != \"undefined\";\n\n// N.b. Electron.js environment is simultaneously a NODE-environment, but\n// also a web environment.\nvar ENVIRONMENT_IS_NODE = typeof process == \"object\" && process.versions?.node && process.type != \"renderer\";\n\n// --pre-jses are emitted after the Module integration code, so that they can\n// refer to Module (if they choose; they can also define Module)\n// include: lib/binding_web/lib/prefix.js\nModule.currentQueryProgressCallback = null;\n\nModule.currentProgressCallback = null;\n\nModule.currentLogCallback = null;\n\nModule.currentParseCallback = null;\n\n// end include: lib/binding_web/lib/prefix.js\nvar arguments_ = [];\n\nvar thisProgram = \"./this.program\";\n\nvar quit_ = (status, toThrow) => {\n throw toThrow;\n};\n\nif (typeof __filename != \"undefined\") {\n // Node\n _scriptName = __filename;\n} else if (ENVIRONMENT_IS_WORKER) {\n _scriptName = self.location.href;\n}\n\n// `/` should be present at the end if `scriptDirectory` is not empty\nvar scriptDirectory = \"\";\n\nfunction locateFile(path) {\n if (Module[\"locateFile\"]) {\n return Module[\"locateFile\"](path, scriptDirectory);\n }\n return scriptDirectory + path;\n}\n\n// Hooks that are implemented differently in different runtime environments.\nvar readAsync, readBinary;\n\nif (ENVIRONMENT_IS_NODE) {\n // These modules will usually be used on Node.js. Load them eagerly to avoid\n // the complexity of lazy-loading.\n var fs = require(\"fs\");\n scriptDirectory = __dirname + \"/\";\n // include: node_shell_read.js\n readBinary = filename => {\n // We need to re-wrap `file://` strings to URLs.\n filename = isFileURI(filename) ? new URL(filename) : filename;\n var ret = fs.readFileSync(filename);\n return ret;\n };\n readAsync = async (filename, binary = true) => {\n // See the comment in the `readBinary` function.\n filename = isFileURI(filename) ? new URL(filename) : filename;\n var ret = fs.readFileSync(filename, binary ? undefined : \"utf8\");\n return ret;\n };\n // end include: node_shell_read.js\n if (process.argv.length > 1) {\n thisProgram = process.argv[1].replace(/\\\\/g, \"/\");\n }\n arguments_ = process.argv.slice(2);\n quit_ = (status, toThrow) => {\n process.exitCode = status;\n throw toThrow;\n };\n} else // Note that this includes Node.js workers when relevant (pthreads is enabled).\n// Node.js workers are detected as a combination of ENVIRONMENT_IS_WORKER and\n// ENVIRONMENT_IS_NODE.\nif (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {\n try {\n scriptDirectory = new URL(\".\", _scriptName).href;\n } catch {}\n {\n // include: web_or_worker_shell_read.js\n if (ENVIRONMENT_IS_WORKER) {\n readBinary = url => {\n var xhr = new XMLHttpRequest;\n xhr.open(\"GET\", url, false);\n xhr.responseType = \"arraybuffer\";\n xhr.send(null);\n return new Uint8Array(/** @type{!ArrayBuffer} */ (xhr.response));\n };\n }\n readAsync = async url => {\n // Fetch has some additional restrictions over XHR, like it can't be used on a file:// url.\n // See https://github.com/github/fetch/pull/92#issuecomment-140665932\n // Cordova or Electron apps are typically loaded from a file:// url.\n // So use XHR on webview if URL is a file URL.\n if (isFileURI(url)) {\n return new Promise((resolve, reject) => {\n var xhr = new XMLHttpRequest;\n xhr.open(\"GET\", url, true);\n xhr.responseType = \"arraybuffer\";\n xhr.onload = () => {\n if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) {\n // file URLs can return 0\n resolve(xhr.response);\n return;\n }\n reject(xhr.status);\n };\n xhr.onerror = reject;\n xhr.send(null);\n });\n }\n var response = await fetch(url, {\n credentials: \"same-origin\"\n });\n if (response.ok) {\n return response.arrayBuffer();\n }\n throw new Error(response.status + \" : \" + response.url);\n };\n }\n} else {}\n\nvar out = console.log.bind(console);\n\nvar err = console.error.bind(console);\n\n// end include: shell.js\n// include: preamble.js\n// === Preamble library stuff ===\n// Documentation for the public APIs defined in this file must be updated in:\n// site/source/docs/api_reference/preamble.js.rst\n// A prebuilt local version of the documentation is available at:\n// site/build/text/docs/api_reference/preamble.js.txt\n// You can also build docs locally as HTML or other formats in site/\n// An online HTML version (which may be of a different version of Emscripten)\n// is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html\nvar dynamicLibraries = [];\n\nvar wasmBinary;\n\n// Wasm globals\n//========================================\n// Runtime essentials\n//========================================\n// whether we are quitting the application. no code should run after this.\n// set in exit() and abort()\nvar ABORT = false;\n\n// set by exit() and abort(). Passed to 'onExit' handler.\n// NOTE: This is also used as the process return code code in shell environments\n// but only when noExitRuntime is false.\nvar EXITSTATUS;\n\n/**\n * Indicates whether filename is delivered via file protocol (as opposed to http/https)\n * @noinline\n */ var isFileURI = filename => filename.startsWith(\"file://\");\n\n// include: runtime_common.js\n// include: runtime_stack_check.js\n// end include: runtime_stack_check.js\n// include: runtime_exceptions.js\n// end include: runtime_exceptions.js\n// include: runtime_debug.js\n// end include: runtime_debug.js\nvar readyPromiseResolve, readyPromiseReject;\n\n// Memory management\nvar wasmMemory;\n\nvar /** @type {!Int8Array} */ HEAP8, /** @type {!Uint8Array} */ HEAPU8, /** @type {!Int16Array} */ HEAP16, /** @type {!Uint16Array} */ HEAPU16, /** @type {!Int32Array} */ HEAP32, /** @type {!Uint32Array} */ HEAPU32, /** @type {!Float32Array} */ HEAPF32, /** @type {!Float64Array} */ HEAPF64;\n\n// BigInt64Array type is not correctly defined in closure\nvar /** not-@type {!BigInt64Array} */ HEAP64, /* BigUint64Array type is not correctly defined in closure\n/** not-@type {!BigUint64Array} */ HEAPU64;\n\n/** @type {!DataView} */ var HEAP_DATA_VIEW;\n\nvar runtimeInitialized = false;\n\nfunction updateMemoryViews() {\n var b = wasmMemory.buffer;\n Module[\"HEAP8\"] = HEAP8 = new Int8Array(b);\n Module[\"HEAP16\"] = HEAP16 = new Int16Array(b);\n Module[\"HEAPU8\"] = HEAPU8 = new Uint8Array(b);\n Module[\"HEAPU16\"] = HEAPU16 = new Uint16Array(b);\n Module[\"HEAP32\"] = HEAP32 = new Int32Array(b);\n Module[\"HEAPU32\"] = HEAPU32 = new Uint32Array(b);\n Module[\"HEAPF32\"] = HEAPF32 = new Float32Array(b);\n Module[\"HEAPF64\"] = HEAPF64 = new Float64Array(b);\n Module[\"HEAP64\"] = HEAP64 = new BigInt64Array(b);\n Module[\"HEAPU64\"] = HEAPU64 = new BigUint64Array(b);\n Module[\"HEAP_DATA_VIEW\"] = HEAP_DATA_VIEW = new DataView(b);\n LE_HEAP_UPDATE();\n}\n\n// In non-standalone/normal mode, we create the memory here.\n// include: runtime_init_memory.js\n// Create the wasm memory. (Note: this only applies if IMPORTED_MEMORY is defined)\n// check for full engine support (use string 'subarray' to avoid closure compiler confusion)\nfunction initMemory() {\n if (Module[\"wasmMemory\"]) {\n wasmMemory = Module[\"wasmMemory\"];\n } else {\n var INITIAL_MEMORY = Module[\"INITIAL_MEMORY\"] || 33554432;\n /** @suppress {checkTypes} */ wasmMemory = new WebAssembly.Memory({\n \"initial\": INITIAL_MEMORY / 65536,\n // In theory we should not need to emit the maximum if we want \"unlimited\"\n // or 4GB of memory, but VMs error on that atm, see\n // https://github.com/emscripten-core/emscripten/issues/14130\n // And in the pthreads case we definitely need to emit a maximum. So\n // always emit one.\n \"maximum\": 32768\n });\n }\n updateMemoryViews();\n}\n\n// end include: runtime_init_memory.js\n// include: memoryprofiler.js\n// end include: memoryprofiler.js\n// end include: runtime_common.js\nvar __RELOC_FUNCS__ = [];\n\nfunction preRun() {\n if (Module[\"preRun\"]) {\n if (typeof Module[\"preRun\"] == \"function\") Module[\"preRun\"] = [ Module[\"preRun\"] ];\n while (Module[\"preRun\"].length) {\n addOnPreRun(Module[\"preRun\"].shift());\n }\n }\n // Begin ATPRERUNS hooks\n callRuntimeCallbacks(onPreRuns);\n}\n\nfunction initRuntime() {\n runtimeInitialized = true;\n callRuntimeCallbacks(__RELOC_FUNCS__);\n // No ATINITS hooks\n wasmExports[\"__wasm_call_ctors\"]();\n // Begin ATPOSTCTORS hooks\n callRuntimeCallbacks(onPostCtors);\n}\n\nfunction preMain() {}\n\nfunction postRun() {\n // PThreads reuse the runtime from the main thread.\n if (Module[\"postRun\"]) {\n if (typeof Module[\"postRun\"] == \"function\") Module[\"postRun\"] = [ Module[\"postRun\"] ];\n while (Module[\"postRun\"].length) {\n addOnPostRun(Module[\"postRun\"].shift());\n }\n }\n // Begin ATPOSTRUNS hooks\n callRuntimeCallbacks(onPostRuns);\n}\n\n/** @param {string|number=} what */ function abort(what) {\n Module[\"onAbort\"]?.(what);\n what = \"Aborted(\" + what + \")\";\n // TODO(sbc): Should we remove printing and leave it up to whoever\n // catches the exception?\n err(what);\n ABORT = true;\n what += \". Build with -sASSERTIONS for more info.\";\n // Use a wasm runtime error, because a JS error might be seen as a foreign\n // exception, which means we'd run destructors on it. We need the error to\n // simply make the program stop.\n // FIXME This approach does not work in Wasm EH because it currently does not assume\n // all RuntimeErrors are from traps; it decides whether a RuntimeError is from\n // a trap or not based on a hidden field within the object. So at the moment\n // we don't have a way of throwing a wasm trap from JS. TODO Make a JS API that\n // allows this in the wasm spec.\n // Suppress closure compiler warning here. Closure compiler's builtin extern\n // definition for WebAssembly.RuntimeError claims it takes no arguments even\n // though it can.\n // TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure gets fixed.\n /** @suppress {checkTypes} */ var e = new WebAssembly.RuntimeError(what);\n readyPromiseReject?.(e);\n // Throw the error whether or not MODULARIZE is set because abort is used\n // in code paths apart from instantiation where an exception is expected\n // to be thrown when abort is called.\n throw e;\n}\n\nvar wasmBinaryFile;\n\nfunction findWasmBinary() {\n return locateFile(\"web-tree-sitter.wasm\");\n}\n\nfunction getBinarySync(file) {\n if (file == wasmBinaryFile && wasmBinary) {\n return new Uint8Array(wasmBinary);\n }\n if (readBinary) {\n return readBinary(file);\n }\n // Throwing a plain string here, even though it not normally adviables since\n // this gets turning into an `abort` in instantiateArrayBuffer.\n throw \"both async and sync fetching of the wasm failed\";\n}\n\nasync function getWasmBinary(binaryFile) {\n // If we don't have the binary yet, load it asynchronously using readAsync.\n if (!wasmBinary) {\n // Fetch the binary using readAsync\n try {\n var response = await readAsync(binaryFile);\n return new Uint8Array(response);\n } catch {}\n }\n // Otherwise, getBinarySync should be able to get it synchronously\n return getBinarySync(binaryFile);\n}\n\nasync function instantiateArrayBuffer(binaryFile, imports) {\n try {\n var binary = await getWasmBinary(binaryFile);\n var instance = await WebAssembly.instantiate(binary, imports);\n return instance;\n } catch (reason) {\n err(`failed to asynchronously prepare wasm: ${reason}`);\n abort(reason);\n }\n}\n\nasync function instantiateAsync(binary, binaryFile, imports) {\n if (!binary && !isFileURI(binaryFile) && !ENVIRONMENT_IS_NODE) {\n try {\n var response = fetch(binaryFile, {\n credentials: \"same-origin\"\n });\n var instantiationResult = await WebAssembly.instantiateStreaming(response, imports);\n return instantiationResult;\n } catch (reason) {\n // We expect the most common failure cause to be a bad MIME type for the binary,\n // in which case falling back to ArrayBuffer instantiation should work.\n err(`wasm streaming compile failed: ${reason}`);\n err(\"falling back to ArrayBuffer instantiation\");\n }\n }\n return instantiateArrayBuffer(binaryFile, imports);\n}\n\nfunction getWasmImports() {\n // prepare imports\n return {\n \"env\": wasmImports,\n \"wasi_snapshot_preview1\": wasmImports,\n \"GOT.mem\": new Proxy(wasmImports, GOTHandler),\n \"GOT.func\": new Proxy(wasmImports, GOTHandler)\n };\n}\n\n// Create the wasm instance.\n// Receives the wasm imports, returns the exports.\nasync function createWasm() {\n // Load the wasm module and create an instance of using native support in the JS engine.\n // handle a generated wasm instance, receiving its exports and\n // performing other necessary setup\n /** @param {WebAssembly.Module=} module*/ function receiveInstance(instance, module) {\n wasmExports = instance.exports;\n wasmExports = relocateExports(wasmExports, 1024);\n var metadata = getDylinkMetadata(module);\n if (metadata.neededDynlibs) {\n dynamicLibraries = metadata.neededDynlibs.concat(dynamicLibraries);\n }\n mergeLibSymbols(wasmExports, \"main\");\n LDSO.init();\n loadDylibs();\n __RELOC_FUNCS__.push(wasmExports[\"__wasm_apply_data_relocs\"]);\n assignWasmExports(wasmExports);\n return wasmExports;\n }\n // Prefer streaming instantiation if available.\n function receiveInstantiationResult(result) {\n // 'result' is a ResultObject object which has both the module and instance.\n // receiveInstance() will swap in the exports (to Module.asm) so they can be called\n return receiveInstance(result[\"instance\"], result[\"module\"]);\n }\n var info = getWasmImports();\n // User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback\n // to manually instantiate the Wasm module themselves. This allows pages to\n // run the instantiation parallel to any other async startup actions they are\n // performing.\n // Also pthreads and wasm workers initialize the wasm instance through this\n // path.\n if (Module[\"instantiateWasm\"]) {\n return new Promise((resolve, reject) => {\n Module[\"instantiateWasm\"](info, (mod, inst) => {\n resolve(receiveInstance(mod, inst));\n });\n });\n }\n wasmBinaryFile ??= findWasmBinary();\n var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info);\n var exports = receiveInstantiationResult(result);\n return exports;\n}\n\n// end include: preamble.js\n// Begin JS library code\nclass ExitStatus {\n name=\"ExitStatus\";\n constructor(status) {\n this.message = `Program terminated with exit(${status})`;\n this.status = status;\n }\n}\n\nvar GOT = {};\n\nvar currentModuleWeakSymbols = new Set([]);\n\nvar GOTHandler = {\n get(obj, symName) {\n var rtn = GOT[symName];\n if (!rtn) {\n rtn = GOT[symName] = new WebAssembly.Global({\n \"value\": \"i32\",\n \"mutable\": true\n });\n }\n if (!currentModuleWeakSymbols.has(symName)) {\n // Any non-weak reference to a symbol marks it as `required`, which\n // enabled `reportUndefinedSymbols` to report undefined symbol errors\n // correctly.\n rtn.required = true;\n }\n return rtn;\n }\n};\n\nvar LE_ATOMICS_NATIVE_BYTE_ORDER = [];\n\nvar LE_HEAP_LOAD_F32 = byteOffset => HEAP_DATA_VIEW.getFloat32(byteOffset, true);\n\nvar LE_HEAP_LOAD_F64 = byteOffset => HEAP_DATA_VIEW.getFloat64(byteOffset, true);\n\nvar LE_HEAP_LOAD_I16 = byteOffset => HEAP_DATA_VIEW.getInt16(byteOffset, true);\n\nvar LE_HEAP_LOAD_I32 = byteOffset => HEAP_DATA_VIEW.getInt32(byteOffset, true);\n\nvar LE_HEAP_LOAD_I64 = byteOffset => HEAP_DATA_VIEW.getBigInt64(byteOffset, true);\n\nvar LE_HEAP_LOAD_U32 = byteOffset => HEAP_DATA_VIEW.getUint32(byteOffset, true);\n\nvar LE_HEAP_STORE_F32 = (byteOffset, value) => HEAP_DATA_VIEW.setFloat32(byteOffset, value, true);\n\nvar LE_HEAP_STORE_F64 = (byteOffset, value) => HEAP_DATA_VIEW.setFloat64(byteOffset, value, true);\n\nvar LE_HEAP_STORE_I16 = (byteOffset, value) => HEAP_DATA_VIEW.setInt16(byteOffset, value, true);\n\nvar LE_HEAP_STORE_I32 = (byteOffset, value) => HEAP_DATA_VIEW.setInt32(byteOffset, value, true);\n\nvar LE_HEAP_STORE_I64 = (byteOffset, value) => HEAP_DATA_VIEW.setBigInt64(byteOffset, value, true);\n\nvar LE_HEAP_STORE_U32 = (byteOffset, value) => HEAP_DATA_VIEW.setUint32(byteOffset, value, true);\n\nvar callRuntimeCallbacks = callbacks => {\n while (callbacks.length > 0) {\n // Pass the module as the first argument.\n callbacks.shift()(Module);\n }\n};\n\nvar onPostRuns = [];\n\nvar addOnPostRun = cb => onPostRuns.push(cb);\n\nvar onPreRuns = [];\n\nvar addOnPreRun = cb => onPreRuns.push(cb);\n\nvar UTF8Decoder = typeof TextDecoder != \"undefined\" ? new TextDecoder : undefined;\n\nvar findStringEnd = (heapOrArray, idx, maxBytesToRead, ignoreNul) => {\n var maxIdx = idx + maxBytesToRead;\n if (ignoreNul) return maxIdx;\n // TextDecoder needs to know the byte length in advance, it doesn't stop on\n // null terminator by itself.\n // As a tiny code save trick, compare idx against maxIdx using a negation,\n // so that maxBytesToRead=undefined/NaN means Infinity.\n while (heapOrArray[idx] && !(idx >= maxIdx)) ++idx;\n return idx;\n};\n\n/**\n * Given a pointer 'idx' to a null-terminated UTF8-encoded string in the given\n * array that contains uint8 values, returns a copy of that string as a\n * Javascript String object.\n * heapOrArray is either a regular array, or a JavaScript typed array view.\n * @param {number=} idx\n * @param {number=} maxBytesToRead\n * @param {boolean=} ignoreNul - If true, the function will not stop on a NUL character.\n * @return {string}\n */ var UTF8ArrayToString = (heapOrArray, idx = 0, maxBytesToRead, ignoreNul) => {\n var endPtr = findStringEnd(heapOrArray, idx, maxBytesToRead, ignoreNul);\n // When using conditional TextDecoder, skip it for short strings as the overhead of the native call is not worth it.\n if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {\n return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));\n }\n var str = \"\";\n while (idx < endPtr) {\n // For UTF8 byte structure, see:\n // http://en.wikipedia.org/wiki/UTF-8#Description\n // https://www.ietf.org/rfc/rfc2279.txt\n // https://tools.ietf.org/html/rfc3629\n var u0 = heapOrArray[idx++];\n if (!(u0 & 128)) {\n str += String.fromCharCode(u0);\n continue;\n }\n var u1 = heapOrArray[idx++] & 63;\n if ((u0 & 224) == 192) {\n str += String.fromCharCode(((u0 & 31) << 6) | u1);\n continue;\n }\n var u2 = heapOrArray[idx++] & 63;\n if ((u0 & 240) == 224) {\n u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;\n } else {\n u0 = ((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heapOrArray[idx++] & 63);\n }\n if (u0 < 65536) {\n str += String.fromCharCode(u0);\n } else {\n var ch = u0 - 65536;\n str += String.fromCharCode(55296 | (ch >> 10), 56320 | (ch & 1023));\n }\n }\n return str;\n};\n\nvar getDylinkMetadata = binary => {\n var offset = 0;\n var end = 0;\n function getU8() {\n return binary[offset++];\n }\n function getLEB() {\n var ret = 0;\n var mul = 1;\n while (1) {\n var byte = binary[offset++];\n ret += ((byte & 127) * mul);\n mul *= 128;\n if (!(byte & 128)) break;\n }\n return ret;\n }\n function getString() {\n var len = getLEB();\n offset += len;\n return UTF8ArrayToString(binary, offset - len, len);\n }\n function getStringList() {\n var count = getLEB();\n var rtn = [];\n while (count--) rtn.push(getString());\n return rtn;\n }\n /** @param {string=} message */ function failIf(condition, message) {\n if (condition) throw new Error(message);\n }\n if (binary instanceof WebAssembly.Module) {\n var dylinkSection = WebAssembly.Module.customSections(binary, \"dylink.0\");\n failIf(dylinkSection.length === 0, \"need dylink section\");\n binary = new Uint8Array(dylinkSection[0]);\n end = binary.length;\n } else {\n var int32View = new Uint32Array(new Uint8Array(binary.subarray(0, 24)).buffer);\n var magicNumberFound = int32View[0] == 1836278016 || int32View[0] == 6386541;\n failIf(!magicNumberFound, \"need to see wasm magic number\");\n // \\0asm\n // we should see the dylink custom section right after the magic number and wasm version\n failIf(binary[8] !== 0, \"need the dylink section to be first\");\n offset = 9;\n var section_size = getLEB();\n //section size\n end = offset + section_size;\n var name = getString();\n failIf(name !== \"dylink.0\");\n }\n var customSection = {\n neededDynlibs: [],\n tlsExports: new Set,\n weakImports: new Set,\n runtimePaths: []\n };\n var WASM_DYLINK_MEM_INFO = 1;\n var WASM_DYLINK_NEEDED = 2;\n var WASM_DYLINK_EXPORT_INFO = 3;\n var WASM_DYLINK_IMPORT_INFO = 4;\n var WASM_DYLINK_RUNTIME_PATH = 5;\n var WASM_SYMBOL_TLS = 256;\n var WASM_SYMBOL_BINDING_MASK = 3;\n var WASM_SYMBOL_BINDING_WEAK = 1;\n while (offset < end) {\n var subsectionType = getU8();\n var subsectionSize = getLEB();\n if (subsectionType === WASM_DYLINK_MEM_INFO) {\n customSection.memorySize = getLEB();\n customSection.memoryAlign = getLEB();\n customSection.tableSize = getLEB();\n customSection.tableAlign = getLEB();\n } else if (subsectionType === WASM_DYLINK_NEEDED) {\n customSection.neededDynlibs = getStringList();\n } else if (subsectionType === WASM_DYLINK_EXPORT_INFO) {\n var count = getLEB();\n while (count--) {\n var symname = getString();\n var flags = getLEB();\n if (flags & WASM_SYMBOL_TLS) {\n customSection.tlsExports.add(symname);\n }\n }\n } else if (subsectionType === WASM_DYLINK_IMPORT_INFO) {\n var count = getLEB();\n while (count--) {\n var modname = getString();\n var symname = getString();\n var flags = getLEB();\n if ((flags & WASM_SYMBOL_BINDING_MASK) == WASM_SYMBOL_BINDING_WEAK) {\n customSection.weakImports.add(symname);\n }\n }\n } else if (subsectionType === WASM_DYLINK_RUNTIME_PATH) {\n customSection.runtimePaths = getStringList();\n } else {\n // unknown subsection\n offset += subsectionSize;\n }\n }\n return customSection;\n};\n\n/**\n * @param {number} ptr\n * @param {string} type\n */ function getValue(ptr, type = \"i8\") {\n if (type.endsWith(\"*\")) type = \"*\";\n switch (type) {\n case \"i1\":\n return HEAP8[ptr];\n\n case \"i8\":\n return HEAP8[ptr];\n\n case \"i16\":\n return LE_HEAP_LOAD_I16(((ptr) >> 1) * 2);\n\n case \"i32\":\n return LE_HEAP_LOAD_I32(((ptr) >> 2) * 4);\n\n case \"i64\":\n return LE_HEAP_LOAD_I64(((ptr) >> 3) * 8);\n\n case \"float\":\n return LE_HEAP_LOAD_F32(((ptr) >> 2) * 4);\n\n case \"double\":\n return LE_HEAP_LOAD_F64(((ptr) >> 3) * 8);\n\n case \"*\":\n return LE_HEAP_LOAD_U32(((ptr) >> 2) * 4);\n\n default:\n abort(`invalid type for getValue: ${type}`);\n }\n}\n\nvar newDSO = (name, handle, syms) => {\n var dso = {\n refcount: Infinity,\n name,\n exports: syms,\n global: true\n };\n LDSO.loadedLibsByName[name] = dso;\n if (handle != undefined) {\n LDSO.loadedLibsByHandle[handle] = dso;\n }\n return dso;\n};\n\nvar LDSO = {\n loadedLibsByName: {},\n loadedLibsByHandle: {},\n init() {\n newDSO(\"__main__\", 0, wasmImports);\n }\n};\n\nvar ___heap_base = 78240;\n\nvar alignMemory = (size, alignment) => Math.ceil(size / alignment) * alignment;\n\nvar getMemory = size => {\n // After the runtime is initialized, we must only use sbrk() normally.\n if (runtimeInitialized) {\n // Currently we don't support freeing of static data when modules are\n // unloaded via dlclose. This function is tagged as `noleakcheck` to\n // avoid having this reported as leak.\n return _calloc(size, 1);\n }\n var ret = ___heap_base;\n // Keep __heap_base stack aligned.\n var end = ret + alignMemory(size, 16);\n ___heap_base = end;\n GOT[\"__heap_base\"].value = end;\n return ret;\n};\n\nvar isInternalSym = symName => [ \"__cpp_exception\", \"__c_longjmp\", \"__wasm_apply_data_relocs\", \"__dso_handle\", \"__tls_size\", \"__tls_align\", \"__set_stack_limits\", \"_emscripten_tls_init\", \"__wasm_init_tls\", \"__wasm_call_ctors\", \"__start_em_asm\", \"__stop_em_asm\", \"__start_em_js\", \"__stop_em_js\" ].includes(symName) || symName.startsWith(\"__em_js__\");\n\nvar uleb128EncodeWithLen = arr => {\n const n = arr.length;\n // Note: this LEB128 length encoding produces extra byte for n < 128,\n // but we don't care as it's only used in a temporary representation.\n return [ (n % 128) | 128, n >> 7, ...arr ];\n};\n\nvar wasmTypeCodes = {\n \"i\": 127,\n // i32\n \"p\": 127,\n // i32\n \"j\": 126,\n // i64\n \"f\": 125,\n // f32\n \"d\": 124,\n // f64\n \"e\": 111\n};\n\nvar generateTypePack = types => uleb128EncodeWithLen(Array.from(types, type => {\n var code = wasmTypeCodes[type];\n return code;\n}));\n\nvar convertJsFunctionToWasm = (func, sig) => {\n // Rest of the module is static\n var bytes = Uint8Array.of(0, 97, 115, 109, // magic (\"\\0asm\")\n 1, 0, 0, 0, // version: 1\n 1, // Type section code\n // The module is static, with the exception of the type section, which is\n // generated based on the signature passed in.\n ...uleb128EncodeWithLen([ 1, // count: 1\n 96, // param types\n ...generateTypePack(sig.slice(1)), // return types (for now only supporting [] if `void` and single [T] otherwise)\n ...generateTypePack(sig[0] === \"v\" ? \"\" : sig[0]) ]), // The rest of the module is static\n 2, 7, // import section\n // (import \"e\" \"f\" (func 0 (type 0)))\n 1, 1, 101, 1, 102, 0, 0, 7, 5, // export section\n // (export \"f\" (func 0 (type 0)))\n 1, 1, 102, 0, 0);\n // We can compile this wasm module synchronously because it is very small.\n // This accepts an import (at \"e.f\"), that it reroutes to an export (at \"f\")\n var module = new WebAssembly.Module(bytes);\n var instance = new WebAssembly.Instance(module, {\n \"e\": {\n \"f\": func\n }\n });\n var wrappedFunc = instance.exports[\"f\"];\n return wrappedFunc;\n};\n\nvar wasmTableMirror = [];\n\n/** @type {WebAssembly.Table} */ var wasmTable = new WebAssembly.Table({\n \"initial\": 31,\n \"element\": \"anyfunc\"\n});\n\nvar getWasmTableEntry = funcPtr => {\n var func = wasmTableMirror[funcPtr];\n if (!func) {\n /** @suppress {checkTypes} */ wasmTableMirror[funcPtr] = func = wasmTable.get(funcPtr);\n }\n return func;\n};\n\nvar updateTableMap = (offset, count) => {\n if (functionsInTableMap) {\n for (var i = offset; i < offset + count; i++) {\n var item = getWasmTableEntry(i);\n // Ignore null values.\n if (item) {\n functionsInTableMap.set(item, i);\n }\n }\n }\n};\n\nvar functionsInTableMap;\n\nvar getFunctionAddress = func => {\n // First, create the map if this is the first use.\n if (!functionsInTableMap) {\n functionsInTableMap = new WeakMap;\n updateTableMap(0, wasmTable.length);\n }\n return functionsInTableMap.get(func) || 0;\n};\n\nvar freeTableIndexes = [];\n\nvar getEmptyTableSlot = () => {\n // Reuse a free index if there is one, otherwise grow.\n if (freeTableIndexes.length) {\n return freeTableIndexes.pop();\n }\n // Grow the table\n return wasmTable[\"grow\"](1);\n};\n\nvar setWasmTableEntry = (idx, func) => {\n /** @suppress {checkTypes} */ wasmTable.set(idx, func);\n // With ABORT_ON_WASM_EXCEPTIONS wasmTable.get is overridden to return wrapped\n // functions so we need to call it here to retrieve the potential wrapper correctly\n // instead of just storing 'func' directly into wasmTableMirror\n /** @suppress {checkTypes} */ wasmTableMirror[idx] = wasmTable.get(idx);\n};\n\n/** @param {string=} sig */ var addFunction = (func, sig) => {\n // Check if the function is already in the table, to ensure each function\n // gets a unique index.\n var rtn = getFunctionAddress(func);\n if (rtn) {\n return rtn;\n }\n // It's not in the table, add it now.\n var ret = getEmptyTableSlot();\n // Set the new value.\n try {\n // Attempting to call this with JS function will cause of table.set() to fail\n setWasmTableEntry(ret, func);\n } catch (err) {\n if (!(err instanceof TypeError)) {\n throw err;\n }\n var wrapped = convertJsFunctionToWasm(func, sig);\n setWasmTableEntry(ret, wrapped);\n }\n functionsInTableMap.set(func, ret);\n return ret;\n};\n\nvar updateGOT = (exports, replace) => {\n for (var symName in exports) {\n if (isInternalSym(symName)) {\n continue;\n }\n var value = exports[symName];\n GOT[symName] ||= new WebAssembly.Global({\n \"value\": \"i32\",\n \"mutable\": true\n });\n if (replace || GOT[symName].value == 0) {\n if (typeof value == \"function\") {\n GOT[symName].value = addFunction(value);\n } else if (typeof value == \"number\") {\n GOT[symName].value = value;\n } else {\n err(`unhandled export type for '${symName}': ${typeof value}`);\n }\n }\n }\n};\n\n/** @param {boolean=} replace */ var relocateExports = (exports, memoryBase, replace) => {\n var relocated = {};\n for (var e in exports) {\n var value = exports[e];\n if (typeof value == \"object\") {\n // a breaking change in the wasm spec, globals are now objects\n // https://github.com/WebAssembly/mutable-global/issues/1\n value = value.value;\n }\n if (typeof value == \"number\") {\n value += memoryBase;\n }\n relocated[e] = value;\n }\n updateGOT(relocated, replace);\n return relocated;\n};\n\nvar isSymbolDefined = symName => {\n // Ignore 'stub' symbols that are auto-generated as part of the original\n // `wasmImports` used to instantiate the main module.\n var existing = wasmImports[symName];\n if (!existing || existing.stub) {\n return false;\n }\n return true;\n};\n\nvar dynCall = (sig, ptr, args = [], promising = false) => {\n var func = getWasmTableEntry(ptr);\n var rtn = func(...args);\n function convert(rtn) {\n return rtn;\n }\n return convert(rtn);\n};\n\nvar stackSave = () => _emscripten_stack_get_current();\n\nvar stackRestore = val => __emscripten_stack_restore(val);\n\nvar createInvokeFunction = sig => (ptr, ...args) => {\n var sp = stackSave();\n try {\n return dynCall(sig, ptr, args);\n } catch (e) {\n stackRestore(sp);\n // Create a try-catch guard that rethrows the Emscripten EH exception.\n // Exceptions thrown from C++ will be a pointer (number) and longjmp\n // will throw the number Infinity. Use the compact and fast \"e !== e+0\"\n // test to check if e was not a Number.\n if (e !== e + 0) throw e;\n _setThrew(1, 0);\n // In theory this if statement could be done on\n // creating the function, but I just added this to\n // save wasting code space as it only happens on exception.\n if (sig[0] == \"j\") return 0n;\n }\n};\n\nvar resolveGlobalSymbol = (symName, direct = false) => {\n var sym;\n if (isSymbolDefined(symName)) {\n sym = wasmImports[symName];\n } else if (symName.startsWith(\"invoke_\")) {\n // Create (and cache) new invoke_ functions on demand.\n sym = wasmImports[symName] = createInvokeFunction(symName.split(\"_\")[1]);\n }\n return {\n sym,\n name: symName\n };\n};\n\nvar onPostCtors = [];\n\nvar addOnPostCtor = cb => onPostCtors.push(cb);\n\n/**\n * Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the\n * emscripten HEAP, returns a copy of that string as a Javascript String object.\n *\n * @param {number} ptr\n * @param {number=} maxBytesToRead - An optional length that specifies the\n * maximum number of bytes to read. You can omit this parameter to scan the\n * string until the first 0 byte. If maxBytesToRead is passed, and the string\n * at [ptr, ptr+maxBytesToReadr[ contains a null byte in the middle, then the\n * string will cut short at that byte index.\n * @param {boolean=} ignoreNul - If true, the function will not stop on a NUL character.\n * @return {string}\n */ var UTF8ToString = (ptr, maxBytesToRead, ignoreNul) => ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead, ignoreNul) : \"\";\n\n/**\n * @param {string=} libName\n * @param {Object=} localScope\n * @param {number=} handle\n */ var loadWebAssemblyModule = (binary, flags, libName, localScope, handle) => {\n var metadata = getDylinkMetadata(binary);\n // loadModule loads the wasm module after all its dependencies have been loaded.\n // can be called both sync/async.\n function loadModule() {\n // alignments are powers of 2\n var memAlign = Math.pow(2, metadata.memoryAlign);\n // prepare memory\n var memoryBase = metadata.memorySize ? alignMemory(getMemory(metadata.memorySize + memAlign), memAlign) : 0;\n // TODO: add to cleanups\n var tableBase = metadata.tableSize ? wasmTable.length : 0;\n if (handle) {\n HEAP8[(handle) + (8)] = 1;\n LE_HEAP_STORE_U32((((handle) + (12)) >> 2) * 4, memoryBase);\n LE_HEAP_STORE_I32((((handle) + (16)) >> 2) * 4, metadata.memorySize);\n LE_HEAP_STORE_U32((((handle) + (20)) >> 2) * 4, tableBase);\n LE_HEAP_STORE_I32((((handle) + (24)) >> 2) * 4, metadata.tableSize);\n }\n if (metadata.tableSize) {\n wasmTable.grow(metadata.tableSize);\n }\n // This is the export map that we ultimately return. We declare it here\n // so it can be used within resolveSymbol. We resolve symbols against\n // this local symbol map in the case there they are not present on the\n // global Module object. We need this fallback because Modules sometime\n // need to import their own symbols\n var moduleExports;\n function resolveSymbol(sym) {\n var resolved = resolveGlobalSymbol(sym).sym;\n if (!resolved && localScope) {\n resolved = localScope[sym];\n }\n if (!resolved) {\n resolved = moduleExports[sym];\n }\n return resolved;\n }\n // TODO kill \u2193\u2193\u2193 (except \"symbols local to this module\", it will likely be\n // not needed if we require that if A wants symbols from B it has to link\n // to B explicitly: similarly to -Wl,--no-undefined)\n // wasm dynamic libraries are pure wasm, so they cannot assist in\n // their own loading. When side module A wants to import something\n // provided by a side module B that is loaded later, we need to\n // add a layer of indirection, but worse, we can't even tell what\n // to add the indirection for, without inspecting what A's imports\n // are. To do that here, we use a JS proxy (another option would\n // be to inspect the binary directly).\n var proxyHandler = {\n get(stubs, prop) {\n // symbols that should be local to this module\n switch (prop) {\n case \"__memory_base\":\n return memoryBase;\n\n case \"__table_base\":\n return tableBase;\n }\n if (prop in wasmImports && !wasmImports[prop].stub) {\n // No stub needed, symbol already exists in symbol table\n var res = wasmImports[prop];\n return res;\n }\n // Return a stub function that will resolve the symbol\n // when first called.\n if (!(prop in stubs)) {\n var resolved;\n stubs[prop] = (...args) => {\n resolved ||= resolveSymbol(prop);\n return resolved(...args);\n };\n }\n return stubs[prop];\n }\n };\n var proxy = new Proxy({}, proxyHandler);\n currentModuleWeakSymbols = metadata.weakImports;\n var info = {\n \"GOT.mem\": new Proxy({}, GOTHandler),\n \"GOT.func\": new Proxy({}, GOTHandler),\n \"env\": proxy,\n \"wasi_snapshot_preview1\": proxy\n };\n function postInstantiation(module, instance) {\n // add new entries to functionsInTableMap\n updateTableMap(tableBase, metadata.tableSize);\n moduleExports = relocateExports(instance.exports, memoryBase);\n if (!flags.allowUndefined) {\n reportUndefinedSymbols();\n }\n function addEmAsm(addr, body) {\n var args = [];\n var arity = 0;\n for (;arity < 16; arity++) {\n if (body.indexOf(\"$\" + arity) != -1) {\n args.push(\"$\" + arity);\n } else {\n break;\n }\n }\n args = args.join(\",\");\n var func = `(${args}) => { ${body} };`;\n ASM_CONSTS[start] = eval(func);\n }\n // Add any EM_ASM function that exist in the side module\n if (\"__start_em_asm\" in moduleExports) {\n var start = moduleExports[\"__start_em_asm\"];\n var stop = moduleExports[\"__stop_em_asm\"];\n while (start < stop) {\n var jsString = UTF8ToString(start);\n addEmAsm(start, jsString);\n start = HEAPU8.indexOf(0, start) + 1;\n }\n }\n function addEmJs(name, cSig, body) {\n // The signature here is a C signature (e.g. \"(int foo, char* bar)\").\n // See `create_em_js` in emcc.py` for the build-time version of this\n // code.\n var jsArgs = [];\n cSig = cSig.slice(1, -1);\n if (cSig != \"void\") {\n cSig = cSig.split(\",\");\n for (var i in cSig) {\n var jsArg = cSig[i].split(\" \").pop();\n jsArgs.push(jsArg.replace(\"*\", \"\"));\n }\n }\n var func = `(${jsArgs}) => ${body};`;\n moduleExports[name] = eval(func);\n }\n for (var name in moduleExports) {\n if (name.startsWith(\"__em_js__\")) {\n var start = moduleExports[name];\n var jsString = UTF8ToString(start);\n // EM_JS strings are stored in the data section in the form\n // SIG<::>BODY.\n var parts = jsString.split(\"<::>\");\n addEmJs(name.replace(\"__em_js__\", \"\"), parts[0], parts[1]);\n delete moduleExports[name];\n }\n }\n // initialize the module\n var applyRelocs = moduleExports[\"__wasm_apply_data_relocs\"];\n if (applyRelocs) {\n if (runtimeInitialized) {\n applyRelocs();\n } else {\n __RELOC_FUNCS__.push(applyRelocs);\n }\n }\n var init = moduleExports[\"__wasm_call_ctors\"];\n if (init) {\n if (runtimeInitialized) {\n init();\n } else {\n // we aren't ready to run compiled code yet\n addOnPostCtor(init);\n }\n }\n return moduleExports;\n }\n if (flags.loadAsync) {\n return (async () => {\n var instance;\n if (binary instanceof WebAssembly.Module) {\n instance = new WebAssembly.Instance(binary, info);\n } else {\n // Destructuring assignment without declaration has to be wrapped\n // with parens or parser will treat the l-value as an object\n // literal instead.\n (((({module: binary, instance} = await WebAssembly.instantiate(binary, info)))));\n }\n return postInstantiation(binary, instance);\n })();\n }\n var module = binary instanceof WebAssembly.Module ? binary : new WebAssembly.Module(binary);\n var instance = new WebAssembly.Instance(module, info);\n return postInstantiation(module, instance);\n }\n // We need to set rpath in flags based on the current library's rpath.\n // We can't mutate flags or else if a depends on b and c and b depends on d,\n // then c will be loaded with b's rpath instead of a's.\n flags = {\n ...flags,\n rpath: {\n parentLibPath: libName,\n paths: metadata.runtimePaths\n }\n };\n // now load needed libraries and the module itself.\n if (flags.loadAsync) {\n return metadata.neededDynlibs.reduce((chain, dynNeeded) => chain.then(() => loadDynamicLibrary(dynNeeded, flags, localScope)), Promise.resolve()).then(loadModule);\n }\n metadata.neededDynlibs.forEach(needed => loadDynamicLibrary(needed, flags, localScope));\n return loadModule();\n};\n\nvar mergeLibSymbols = (exports, libName) => {\n // add symbols into global namespace TODO: weak linking etc.\n for (var [sym, exp] of Object.entries(exports)) {\n // When RTLD_GLOBAL is enabled, the symbols defined by this shared object\n // will be made available for symbol resolution of subsequently loaded\n // shared objects.\n // We should copy the symbols (which include methods and variables) from\n // SIDE_MODULE to MAIN_MODULE.\n const setImport = target => {\n if (!isSymbolDefined(target)) {\n wasmImports[target] = exp;\n }\n };\n setImport(sym);\n // Special case for handling of main symbol: If a side module exports\n // `main` that also acts a definition for `__main_argc_argv` and vice\n // versa.\n const main_alias = \"__main_argc_argv\";\n if (sym == \"main\") {\n setImport(main_alias);\n }\n if (sym == main_alias) {\n setImport(\"main\");\n }\n }\n};\n\nvar asyncLoad = async url => {\n var arrayBuffer = await readAsync(url);\n return new Uint8Array(arrayBuffer);\n};\n\n/**\n * @param {number=} handle\n * @param {Object=} localScope\n */ function loadDynamicLibrary(libName, flags = {\n global: true,\n nodelete: true\n}, localScope, handle) {\n // when loadDynamicLibrary did not have flags, libraries were loaded\n // globally & permanently\n var dso = LDSO.loadedLibsByName[libName];\n if (dso) {\n // the library is being loaded or has been loaded already.\n if (!flags.global) {\n if (localScope) {\n Object.assign(localScope, dso.exports);\n }\n } else if (!dso.global) {\n // The library was previously loaded only locally but not\n // we have a request with global=true.\n dso.global = true;\n mergeLibSymbols(dso.exports, libName);\n }\n // same for \"nodelete\"\n if (flags.nodelete && dso.refcount !== Infinity) {\n dso.refcount = Infinity;\n }\n dso.refcount++;\n if (handle) {\n LDSO.loadedLibsByHandle[handle] = dso;\n }\n return flags.loadAsync ? Promise.resolve(true) : true;\n }\n // allocate new DSO\n dso = newDSO(libName, handle, \"loading\");\n dso.refcount = flags.nodelete ? Infinity : 1;\n dso.global = flags.global;\n // libName -> libData\n function loadLibData() {\n // for wasm, we can use fetch for async, but for fs mode we can only imitate it\n if (handle) {\n var data = LE_HEAP_LOAD_U32((((handle) + (28)) >> 2) * 4);\n var dataSize = LE_HEAP_LOAD_U32((((handle) + (32)) >> 2) * 4);\n if (data && dataSize) {\n var libData = HEAP8.slice(data, data + dataSize);\n return flags.loadAsync ? Promise.resolve(libData) : libData;\n }\n }\n var libFile = locateFile(libName);\n if (flags.loadAsync) {\n return asyncLoad(libFile);\n }\n // load the binary synchronously\n if (!readBinary) {\n throw new Error(`${libFile}: file not found, and synchronous loading of external files is not available`);\n }\n return readBinary(libFile);\n }\n // libName -> exports\n function getExports() {\n // module not preloaded - load lib data and create new module from it\n if (flags.loadAsync) {\n return loadLibData().then(libData => loadWebAssemblyModule(libData, flags, libName, localScope, handle));\n }\n return loadWebAssemblyModule(loadLibData(), flags, libName, localScope, handle);\n }\n // module for lib is loaded - update the dso & global namespace\n function moduleLoaded(exports) {\n if (dso.global) {\n mergeLibSymbols(exports, libName);\n } else if (localScope) {\n Object.assign(localScope, exports);\n }\n dso.exports = exports;\n }\n if (flags.loadAsync) {\n return getExports().then(exports => {\n moduleLoaded(exports);\n return true;\n });\n }\n moduleLoaded(getExports());\n return true;\n}\n\nvar reportUndefinedSymbols = () => {\n for (var [symName, entry] of Object.entries(GOT)) {\n if (entry.value == 0) {\n var value = resolveGlobalSymbol(symName, true).sym;\n if (!value && !entry.required) {\n // Ignore undefined symbols that are imported as weak.\n continue;\n }\n if (typeof value == \"function\") {\n /** @suppress {checkTypes} */ entry.value = addFunction(value, value.sig);\n } else if (typeof value == \"number\") {\n entry.value = value;\n } else {\n throw new Error(`bad export type for '${symName}': ${typeof value}`);\n }\n }\n }\n};\n\nvar runDependencies = 0;\n\nvar dependenciesFulfilled = null;\n\nvar removeRunDependency = id => {\n runDependencies--;\n Module[\"monitorRunDependencies\"]?.(runDependencies);\n if (runDependencies == 0) {\n if (dependenciesFulfilled) {\n var callback = dependenciesFulfilled;\n dependenciesFulfilled = null;\n callback();\n }\n }\n};\n\nvar addRunDependency = id => {\n runDependencies++;\n Module[\"monitorRunDependencies\"]?.(runDependencies);\n};\n\nvar loadDylibs = async () => {\n if (!dynamicLibraries.length) {\n reportUndefinedSymbols();\n return;\n }\n addRunDependency(\"loadDylibs\");\n // Load binaries asynchronously\n for (var lib of dynamicLibraries) {\n await loadDynamicLibrary(lib, {\n loadAsync: true,\n global: true,\n nodelete: true,\n allowUndefined: true\n });\n }\n // we got them all, wonderful\n reportUndefinedSymbols();\n removeRunDependency(\"loadDylibs\");\n};\n\nvar noExitRuntime = true;\n\n/**\n * @param {number} ptr\n * @param {number} value\n * @param {string} type\n */ function setValue(ptr, value, type = \"i8\") {\n if (type.endsWith(\"*\")) type = \"*\";\n switch (type) {\n case \"i1\":\n HEAP8[ptr] = value;\n break;\n\n case \"i8\":\n HEAP8[ptr] = value;\n break;\n\n case \"i16\":\n LE_HEAP_STORE_I16(((ptr) >> 1) * 2, value);\n break;\n\n case \"i32\":\n LE_HEAP_STORE_I32(((ptr) >> 2) * 4, value);\n break;\n\n case \"i64\":\n LE_HEAP_STORE_I64(((ptr) >> 3) * 8, BigInt(value));\n break;\n\n case \"float\":\n LE_HEAP_STORE_F32(((ptr) >> 2) * 4, value);\n break;\n\n case \"double\":\n LE_HEAP_STORE_F64(((ptr) >> 3) * 8, value);\n break;\n\n case \"*\":\n LE_HEAP_STORE_U32(((ptr) >> 2) * 4, value);\n break;\n\n default:\n abort(`invalid type for setValue: ${type}`);\n }\n}\n\nvar ___memory_base = new WebAssembly.Global({\n \"value\": \"i32\",\n \"mutable\": false\n}, 1024);\n\nvar ___stack_high = 78240;\n\nvar ___stack_low = 12704;\n\nvar ___stack_pointer = new WebAssembly.Global({\n \"value\": \"i32\",\n \"mutable\": true\n}, 78240);\n\nvar ___table_base = new WebAssembly.Global({\n \"value\": \"i32\",\n \"mutable\": false\n}, 1);\n\nvar __abort_js = () => abort(\"\");\n\n__abort_js.sig = \"v\";\n\nvar getHeapMax = () => // Stay one Wasm page short of 4GB: while e.g. Chrome is able to allocate\n