UNPKG

web-tree-sitter

Version:
4 lines 349 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\nvar ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;\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 const isNode = typeof process == \"object\" && process.versions?.node && process.type != \"renderer\";\n if (!isNode) throw new Error(\"not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)\");\n var nodeVersion = process.versions.node;\n var numericVersion = nodeVersion.split(\".\").slice(0, 3);\n numericVersion = (numericVersion[0] * 1e4) + (numericVersion[1] * 100) + (numericVersion[2].split(\"-\")[0] * 1);\n if (numericVersion < 16e4) {\n throw new Error(\"This emscripten-generated code requires node v16.0.0 (detected v\" + nodeVersion + \")\");\n }\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 assert(Buffer.isBuffer(ret));\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 assert(binary ? Buffer.isBuffer(ret) : typeof ret == \"string\");\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 if (ENVIRONMENT_IS_SHELL) {\n const isNode = typeof process == \"object\" && process.versions?.node && process.type != \"renderer\";\n if (isNode || typeof window == \"object\" || typeof WorkerGlobalScope != \"undefined\") throw new Error(\"not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)\");\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 if (!(typeof window == \"object\" || typeof WorkerGlobalScope != \"undefined\")) throw new Error(\"not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)\");\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 throw new Error(\"environment detection error\");\n}\n\nvar out = console.log.bind(console);\n\nvar err = console.error.bind(console);\n\nvar IDBFS = \"IDBFS is no longer included by default; build with -lidbfs.js\";\n\nvar PROXYFS = \"PROXYFS is no longer included by default; build with -lproxyfs.js\";\n\nvar WORKERFS = \"WORKERFS is no longer included by default; build with -lworkerfs.js\";\n\nvar FETCHFS = \"FETCHFS is no longer included by default; build with -lfetchfs.js\";\n\nvar ICASEFS = \"ICASEFS is no longer included by default; build with -licasefs.js\";\n\nvar JSFILEFS = \"JSFILEFS is no longer included by default; build with -ljsfilefs.js\";\n\nvar OPFS = \"OPFS is no longer included by default; build with -lopfs.js\";\n\nvar NODEFS = \"NODEFS is no longer included by default; build with -lnodefs.js\";\n\n// perform assertions in shell.js after we set up out() and err(), as otherwise\n// if an assertion fails it cannot print the message\nassert(!ENVIRONMENT_IS_SHELL, \"shell environment detected but not enabled at build time. Add `shell` to `-sENVIRONMENT` to enable.\");\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\nif (typeof WebAssembly != \"object\") {\n err(\"no native wasm support detected\");\n}\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// In STRICT mode, we only define assert() when ASSERTIONS is set. i.e. we\n// don't define it at all in release modes. This matches the behaviour of\n// MINIMAL_RUNTIME.\n// TODO(sbc): Make this the default even without STRICT enabled.\n/** @type {function(*, string=)} */ function assert(condition, text) {\n if (!condition) {\n abort(\"Assertion failed\" + (text ? \": \" + text : \"\"));\n }\n}\n\n// We used to include malloc/free by default in the past. Show a helpful error in\n// builds with assertions.\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// Initializes the stack cookie. Called at the startup of main and at the startup of each thread in pthreads mode.\nfunction writeStackCookie() {\n var max = _emscripten_stack_get_end();\n assert((max & 3) == 0);\n // If the stack ends at address zero we write our cookies 4 bytes into the\n // stack. This prevents interference with SAFE_HEAP and ASAN which also\n // monitor writes to address zero.\n if (max == 0) {\n max += 4;\n }\n // The stack grow downwards towards _emscripten_stack_get_end.\n // We write cookies to the final two words in the stack and detect if they are\n // ever overwritten.\n LE_HEAP_STORE_U32(SAFE_HEAP_INDEX(HEAPU32, ((max) >> 2), \"storing\") * 4, 34821223);\n LE_HEAP_STORE_U32(SAFE_HEAP_INDEX(HEAPU32, (((max) + (4)) >> 2), \"storing\") * 4, 2310721022);\n}\n\nfunction checkStackCookie() {\n if (ABORT) return;\n var max = _emscripten_stack_get_end();\n // See writeStackCookie().\n if (max == 0) {\n max += 4;\n }\n var cookie1 = LE_HEAP_LOAD_U32(SAFE_HEAP_INDEX(HEAPU32, ((max) >> 2), \"loading\") * 4);\n var cookie2 = LE_HEAP_LOAD_U32(SAFE_HEAP_INDEX(HEAPU32, (((max) + (4)) >> 2), \"loading\") * 4);\n if (cookie1 != 34821223 || cookie2 != 2310721022) {\n abort(`Stack overflow! Stack cookie has been overwritten at ${ptrToString(max)}, expected hex dwords 0x89BACDFE and 0x2135467, but received ${ptrToString(cookie2)} ${ptrToString(cookie1)}`);\n }\n}\n\n// end include: runtime_stack_check.js\n// include: runtime_exceptions.js\n// end include: runtime_exceptions.js\n// include: runtime_debug.js\nvar runtimeDebug = true;\n\n// Switch to false at runtime to disable logging at the right times\n// Used by XXXXX_DEBUG settings to output debug messages.\nfunction dbg(...args) {\n if (!runtimeDebug && typeof runtimeDebug != \"undefined\") return;\n // TODO(sbc): Make this configurable somehow. Its not always convenient for\n // logging to show up as warnings.\n console.warn(...args);\n}\n\n// Endianness check\nfunction consumedModuleProp(prop) {\n if (!Object.getOwnPropertyDescriptor(Module, prop)) {\n Object.defineProperty(Module, prop, {\n configurable: true,\n set() {\n abort(`Attempt to set \\`Module.${prop}\\` after it has already been processed. This can happen, for example, when code is injected via '--post-js' rather than '--pre-js'`);\n }\n });\n }\n}\n\nfunction makeInvalidEarlyAccess(name) {\n return () => assert(false, `call to '${name}' via reference taken before Wasm module initialization`);\n}\n\nfunction ignoredModuleProp(prop) {\n if (Object.getOwnPropertyDescriptor(Module, prop)) {\n abort(`\\`Module.${prop}\\` was supplied but \\`${prop}\\` not included in INCOMING_MODULE_JS_API`);\n }\n}\n\n// forcing the filesystem exports a few things by default\nfunction isExportedByForceFilesystem(name) {\n return name === \"FS_createPath\" || name === \"FS_createDataFile\" || name === \"FS_createPreloadedFile\" || name === \"FS_preloadFile\" || name === \"FS_unlink\" || name === \"addRunDependency\" || // The old FS has some functionality that WasmFS lacks.\n name === \"FS_createLazyFile\" || name === \"FS_createDevice\" || name === \"removeRunDependency\";\n}\n\nfunction missingLibrarySymbol(sym) {\n // Any symbol that is not included from the JS library is also (by definition)\n // not exported on the Module object.\n unexportedRuntimeSymbol(sym);\n}\n\nfunction unexportedRuntimeSymbol(sym) {\n if (!Object.getOwnPropertyDescriptor(Module, sym)) {\n Object.defineProperty(Module, sym, {\n configurable: true,\n get() {\n var msg = `'${sym}' was not exported. add it to EXPORTED_RUNTIME_METHODS (see the Emscripten FAQ)`;\n if (isExportedByForceFilesystem(sym)) {\n msg += \". Alternatively, forcing filesystem support (-sFORCE_FILESYSTEM) can export this for you\";\n }\n abort(msg);\n }\n });\n }\n}\n\n// end include: runtime_debug.js\n// include: runtime_safe_heap.js\nfunction SAFE_HEAP_INDEX(arr, idx, action) {\n const bytes = arr.BYTES_PER_ELEMENT;\n const dest = idx * bytes;\n if (idx <= 0) abort(`segmentation fault ${action} ${bytes} bytes at address ${dest}`);\n if (runtimeInitialized) {\n var brk = _sbrk(0);\n if (dest + bytes > brk) abort(`segmentation fault, exceeded the top of the available dynamic heap when ${action} ${bytes} bytes at address ${dest}. DYNAMICTOP=${brk}`);\n if (brk < _emscripten_stack_get_base()) abort(`brk >= _emscripten_stack_get_base() (brk=${brk}, _emscripten_stack_get_base()=${_emscripten_stack_get_base()})`);\n // sbrk-managed memory must be above the stack\n if (brk > wasmMemory.buffer.byteLength) abort(`brk <= wasmMemory.buffer.byteLength (brk=${brk}, wasmMemory.buffer.byteLength=${wasmMemory.buffer.byteLength})`);\n }\n return idx;\n}\n\nfunction segfault() {\n abort(\"segmentation fault\");\n}\n\nfunction alignfault() {\n abort(\"alignment fault\");\n}\n\n// end include: runtime_safe_heap.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 assert(INITIAL_MEMORY >= 65536, \"INITIAL_MEMORY should be larger than STACK_SIZE, was \" + INITIAL_MEMORY + \"! (STACK_SIZE=\" + 65536 + \")\");\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\nassert(typeof Int32Array != \"undefined\" && typeof Float64Array !== \"undefined\" && Int32Array.prototype.subarray != undefined && Int32Array.prototype.set != undefined, \"JS engine does not provide full typed array support\");\n\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 consumedModuleProp(\"preRun\");\n // Begin ATPRERUNS hooks\n callRuntimeCallbacks(onPreRuns);\n}\n\nfunction initRuntime() {\n assert(!runtimeInitialized);\n runtimeInitialized = true;\n checkStackCookie();\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 checkStackCookie();\n}\n\nfunction postRun() {\n checkStackCookie();\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 consumedModuleProp(\"postRun\");\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 // 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\n// show errors on likely calls to FS when it was not included\nvar FS = {\n error() {\n abort(\"Filesystem support (FS) was not included. The problem is that you are using files from JS, but files were not used from C/C++, so filesystem support was not auto-included. You can force-include filesystem support with -sFORCE_FILESYSTEM\");\n },\n init() {\n FS.error();\n },\n createDataFile() {\n FS.error();\n },\n createPreloadedFile() {\n FS.error();\n },\n createLazyFile() {\n FS.error();\n },\n open() {\n FS.error();\n },\n mkdev() {\n FS.error();\n },\n registerDevice() {\n FS.error();\n },\n analyzePath() {\n FS.error();\n },\n ErrnoError() {\n FS.error();\n }\n};\n\nfunction createExportWrapper(name, nargs) {\n return (...args) => {\n assert(runtimeInitialized, `native function \\`${name}\\` called before runtime initialization`);\n var f = wasmExports[name];\n assert(f, `exported native function \\`${name}\\` not found`);\n // Only assert for too many arguments. Too few can be valid since the missing arguments will be zero filled.\n assert(args.length <= nargs, `native function \\`${name}\\` called with ${args.length} args but expects ${nargs}`);\n return f(...args);\n };\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 // Warn on some common problems.\n if (isFileURI(binaryFile)) {\n err(`warning: Loading from a file URI (${binaryFile}) is not supported in most browsers. See https://emscripten.org/docs/getting_started/FAQ.html#how-do-i-run-a-local-webserver-for-testing-why-does-my-program-stall-in-downloading-or-preparing`);\n }\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 // Async compilation can be confusing when an error on the page overwrites Module\n // (for example, if the order of elements is wrong, and the one defining Module is\n // later), so we save Module and check it later.\n var trueModule = Module;\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 assert(Module === trueModule, \"the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?\");\n trueModule = null;\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 try {\n Module[\"instantiateWasm\"](info, (mod, inst) => {\n resolve(receiveInstance(mod, inst));\n });\n } catch (e) {\n err(`Module.instantiateWasm callback failed with error: ${e}`);\n reject(e);\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_ADD = (heap, offset, value) => {\n const order = LE_ATOMICS_NATIVE_BYTE_ORDER[heap.BYTES_PER_ELEMENT - 1];\n const res = order(Atomics.add(heap, offset, order(value)));\n return heap.unsigned ? heap.unsigned(res) : res;\n};\n\nvar LE_ATOMICS_AND = (heap, offset, value) => {\n const order = LE_ATOMICS_NATIVE_BYTE_ORDER[heap.BYTES_PER_ELEMENT - 1];\n const res = order(Atomics.and(heap, offset, order(value)));\n return heap.unsigned ? heap.unsigned(res) : res;\n};\n\nvar LE_ATOMICS_COMPAREEXCHANGE = (heap, offset, expected, replacement) => {\n const order = LE_ATOMICS_NATIVE_BYTE_ORDER[heap.BYTES_PER_ELEMENT - 1];\n const res = order(Atomics.compareExchange(heap, offset, order(expected), order(replacement)));\n return heap.unsigned ? heap.unsigned(res) : res;\n};\n\nvar LE_ATOMICS_EXCHANGE = (heap, offset, value) => {\n const order = LE_ATOMICS_NATIVE_BYTE_ORDER[heap.BYTES_PER_ELEMENT - 1];\n const res = order(Atomics.exchange(heap, offset, order(value)));\n return heap.unsigned ? heap.unsigned(res) : res;\n};\n\nvar LE_ATOMICS_ISLOCKFREE = size => Atomics.isLockFree(size);\n\nvar LE_ATOMICS_LOAD = (heap, offset) => {\n const order = LE_ATOMICS_NATIVE_BYTE_ORDER[heap.BYTES_PER_ELEMENT - 1];\n const res = order(Atomics.load(heap, offset));\n return heap.unsigned ? heap.unsigned(res) : res;\n};\n\nvar LE_ATOMICS_NATIVE_BYTE_ORDER = [];\n\nvar LE_ATOMICS_NOTIFY = (heap, offset, count) => Atomics.notify(heap, offset, count);\n\nvar LE_ATOMICS_OR = (heap, offset, value) => {\n const order = LE_ATOMICS_NATIVE_BYTE_ORDER[heap.BYTES_PER_ELEMENT - 1];\n const res = order(Atomics.or(heap, offset, order(value)));\n return heap.unsigned ? heap.unsigned(res) : res;\n};\n\nvar LE_ATOMICS_STORE = (heap, offset, value) => {\n const order = LE_ATOMICS_NATIVE_BYTE_ORDER[heap.BYTES_PER_ELEMENT - 1];\n Atomics.store(heap, offset, order(value));\n};\n\nvar LE_ATOMICS_SUB = (heap, offset, value) => {\n const order = LE_ATOMICS_NATIVE_BYTE_ORDER[heap.BYTES_PER_ELEMENT - 1];\n const res = order(Atomics.sub(heap, offset, order(value)));\n return heap.unsigned ? heap.unsigned(res) : res;\n};\n\nvar LE_ATOMICS_WAIT = (heap, offset, value, timeout) => {\n const order = LE_ATOMICS_NATIVE_BYTE_ORDER[heap.BYTES_PER_ELEMENT - 1];\n return Atomics.wait(heap, offset, order(value), timeout);\n};\n\nvar LE_ATOMICS_WAITASYNC = (heap, offset, value, timeout) => {\n const order = LE_ATOMICS_NATIVE_BYTE_ORDER[heap.BYTES_PER_ELEMENT - 1];\n return Atomics.waitAsync(heap, offset, order(value), timeout);\n};\n\nvar LE_ATOMICS_XOR = (heap, offset, value) => {\n const order = LE_ATOMICS_NATIVE_BYTE_ORDER[heap.BYTES_PER_ELEMENT - 1];\n const res = order(Atomics.xor(heap, offset, order(value)));\n return heap.unsigned ? heap.unsigned(res) : res;\n};\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_U16 = byteOffset => HEAP_DATA_VIEW.getUint16(byteOffset, true);\n\nvar LE_HEAP_LOAD_U32 = byteOffset => HEAP_DATA_VIEW.getUint32(byteOffset, true);\n\nvar LE_HEAP_LOAD_U64 = byteOffset => HEAP_DATA_VIEW.getBigUint64(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_U16 = (byteOffset, value) => HEAP_DATA_VIEW.setUint16(byteOffset, value, true);\n\nvar LE_HEAP_STORE_U32 = (byteOffset, value) => HEAP_DATA_VIEW.setUint32(byteOffset, value, true);\n\nvar LE_HEAP_STORE_U64 = (byteOffset, value) => HEAP_DATA_VIEW.setBigUint64(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\nvar warnOnce = text => {\n warnOnce.shown ||= {};\n if (!warnOnce.shown[text]) {\n warnOnce.shown[text] = 1;\n if (ENVIRONMENT_IS_NODE) text = \"warning: \" + text;\n err(text);\n }\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 if ((u0 & 248) != 240) warnOnce(\"Invalid UTF-8 leading byte \" + ptrToString(u0) + \" encountered when deserializing a UTF-8 string in wasm memory to a JS string!\");\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 err(\"unknown dylink.0 subsection:\", subsectionType);\n // unknown subsection\n offset += subsectionSize;\n }\n }\n var tableAlign = Math.pow(2, customSection.tableAlign);\n assert(tableAlign === 1, `invalid tableAlign ${tableAlign}`);\n assert(offset == end);\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[SAFE_HEAP_INDEX(HEAP8, ptr, \"loading\")];\n\n case \"i8\":\n return HEAP8[SAFE_HEAP_INDEX(HEAP8, ptr, \"loading\")];\n\n case \"i16\":\n return LE_HEAP_LOAD_I16(SAFE_HEAP_INDEX(HEAP16, ((ptr) >> 1), \"loading\") * 2);\n\n case \"i32\":\n return LE_HEAP_LOAD_I32(SAFE_HEAP_INDEX(HEAP32, ((ptr) >> 2), \"loading\") * 4);\n\n case \"i64\":\n return LE_HEAP_LOAD_I64(SAFE_HEAP_INDEX(HEAP64, ((ptr) >> 3), \"loading\") * 8);\n\n case \"float\":\n return LE_HEAP_LOAD_F32(SAFE_HEAP_INDEX(HEAPF32, ((ptr) >> 2), \"loading\") * 4);\n\n case \"double\":\n return LE_HEAP_LOAD_F64(SAFE_HEAP_INDEX(HEAPF64, ((ptr) >> 3), \"loading\") * 8);\n\n case \"*\":\n return LE_HEAP_LOAD_U32(SAFE_HEAP_INDEX(HEAPU32, ((ptr) >> 2), \"loading\") * 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 // This function needs to run after the initial wasmImports object\n // as been created.\n assert(wasmImports);\n newDSO(\"__main__\", 0, wasmImports);\n }\n};\n\nvar ___heap_base = 78224;\n\nvar alignMemory = (size, alignment) => {\n assert(alignment, \"alignment argument is required\");\n return Math.ceil(size / alignment) * alignment;\n};\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 assert(end <= HEAP8.length, \"failure to getMemory - memory growth etc. is not supported there, call malloc/sbrk directly or increase INITIAL_MEMORY\");\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 assert(n < 16384);\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 assert(code, `invalid signature char: ${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 /** @suppress {checkTypes} */ assert(wasmTable.get(funcPtr) == func, \"JavaScript-side Wasm function table mirror is out of date!\");\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 try {\n // Grow the table\n return wasmTable[\"grow\"](1);\n } catch (err) {\n if (!(err instanceof RangeError)) {\n throw err;\n }\n abort(\"Unable to grow wasm table. Set ALLOW_TABLE_GROWTH.\");\n }\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 assert(typeof func != \"undefined\");\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 assert(typeof sig != \"undefined\", \"Missing signature argument to addFunction: \" + func);\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 assert(!promising, \"async dynCall is not supported in this mode\");\n assert(getWasmTableEntry(ptr), `missing table entry in dynCall: ${ptr}`);\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