#if LOAD_SOURCE_MAP
#include "source_map_support.js"
#endif
#if HAS_MAIN
#if EXIT_RUNTIME
function exitRuntime(ret) {
<<< ATEXITS >>>
#if PTHREADS
PThread.terminateAllThreads();
#endif
#if ASSERTIONS
runtimeExited = true;
#endif
_proc_exit(ret);
#if STACK_OVERFLOW_CHECK
checkStackCookie();
#endif
}
#endif
{{{ globalThis.argc_argv = function(condition) {
if (!MAIN_READS_PARAMS) return '';
return `argc, ${to64('argv')}`;
}
globalThis.HEAPptr = MEMORY64 ? 'HEAPU64' : 'HEAPU32';
null;
}}}
function run() {
#if MEMORYPROFILER
emscriptenMemoryProfiler.onPreloadComplete();
#endif
<<< ATMAINS >>>
#if MAIN_READS_PARAMS
var args =
#if ENVIRONMENT_MAY_BE_NODE
ENVIRONMENT_IS_NODE ? process.argv.slice(1) :
#endif
[location.href.split('?')[0], ...location.search.slice(1).split('&').map(decodeURIComponent)];
var arg,
argc = args.length,
argv = stackAlloc(argc * {{{ POINTER_SIZE }}} + {{{ POINTER_SIZE }}}),
argvIndex = argv / {{{ POINTER_SIZE }}};
for (arg of args) {{{ HEAPptr }}}[argvIndex++] = {{{ to64('stringToUTF8OnStack(arg)') }}};
{{{ HEAPptr }}}[argvIndex] = {{{ to64(0) }}};
#endif
#if PROXY_TO_PTHREAD
__emscripten_proxy_main({{{ argc_argv() }}});
#elif ASYNCIFY == 2 && EXIT_RUNTIME
_main({{{ argc_argv() }}}).then(exitRuntime);
#elif EXIT_RUNTIME
try {
exitRuntime(_main({{{ argc_argv() }}}));
} catch(e) {
var exitCode = e.match(/^exit\((\d+)\)$/);
if (exitCode) {
#if RUNTIME_DEBUG
dbg(`main() called ${e}.`);
#endif
#if expectToReceiveOnModule('onExit')
Module['onExit']?.(exitCode[1]|0);
#endif
} else {
#if RUNTIME_DEBUG
dbg(`main() threw an exception: ${e}.`);
#endif
throw e;
}
}
#else
_main({{{ argc_argv() }}});
#endif
#if STACK_OVERFLOW_CHECK
checkStackCookie();
#endif
<<< ATPOSTRUNS >>>
}
#endif
function initRuntime(wasmExports) {
#if ASSERTIONS || SAFE_HEAP || USE_ASAN || MODULARIZE
runtimeInitialized = true;
#endif
#if PTHREADS
PThread.tlsInitFunctions.push(wasmExports['_emscripten_tls_init']);
if (ENVIRONMENT_IS_PTHREAD) return;
#endif
#if WASM_WORKERS
if (ENVIRONMENT_IS_WASM_WORKER) return _wasmWorkerInitializeRuntime();
#endif
#if STACK_OVERFLOW_CHECK
_emscripten_stack_init();
#if STACK_OVERFLOW_CHECK >= 2
setStackLimits();
#endif
writeStackCookie();
#endif
<<< ATINITS >>>
#if hasExportedSymbol('__wasm_call_ctors')
wasmExports['__wasm_call_ctors']();
#endif
<<< ATPOSTCTORS >>>
}
#if SINGLE_FILE && SINGLE_FILE_BINARY_ENCODE && !WASM2JS
Module['wasm'] = binaryDecode("<<< WASM_BINARY_DATA >>>");
#elif SINGLE_FILE && WASM == 1 && !WASM2JS
Module['wasm'] = base64Decode('<<< WASM_BINARY_DATA >>>');
#endif
#if LibraryManager.has('libexports.js')
var wasmExports;
#endif
#if PTHREADS || WASM_WORKERS
var wasmModule;
function loadModule() {
assignWasmImports();
#endif
#if ASYNCIFY
Asyncify.instrumentWasmImports(wasmImports);
#endif
var imports = {
#if MINIFY_WASM_IMPORTED_MODULES
'a': wasmImports,
#else
'env': wasmImports,
'{{{ WASI_MODULE_NAME }}}': wasmImports,
#endif
};
#if MINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION
{{{
#if EXPORT_ES6 && !ENVIRONMENT_MAY_BE_AUDIO_WORKLET
const moduleUrl = `new URL('${TARGET_BASENAME}.wasm', import.meta.url)`;
#elif !EXPORT_ES6 || AUDIO_WORKLET
const moduleUrl = `'${TARGET_BASENAME}.wasm'`;
#else
const moduleUrl = `ENVIRONMENT_IS_AUDIO_WORKLET ? '${TARGET_BASENAME}.wasm' : new URL('${TARGET_BASENAME}.wasm', import.meta.url)`;
#endif
}}}
#if MIN_SAFARI_VERSION < 150000 || ENVIRONMENT_MAY_BE_NODE
#if ASSERTIONS && !WASM2JS
assert(WebAssembly.instantiateStreaming || Module['wasm'], 'Must load WebAssembly Module in to variable Module.wasm before adding compiled output .js script to the DOM');
#endif
#if AUDIO_WORKLET
instantiatePromise =
#endif
(WebAssembly.instantiateStreaming
#if ENVIRONMENT_MAY_BE_NODE
&& !ENVIRONMENT_IS_NODE
#endif
? WebAssembly.instantiateStreaming(fetch({{{ moduleUrl }}}), imports)
: WebAssembly.instantiate(Module['wasm'], imports)).then((output) => {
#else
#if AUDIO_WORKLET
instantiatePromise =
#endif
WebAssembly.instantiateStreaming(fetch({{{ moduleUrl }}}), imports).then((output) => {
#endif
#else
#if ASSERTIONS && !WASM2JS
assert(Module['wasm'], 'Must load WebAssembly Module in to variable Module.wasm before adding compiled output .js script to the DOM');
#endif
<<< ATMODULES >>>
{{{ exportJSSymbols() }}}
#if AUDIO_WORKLET
instantiatePromise =
#endif
WebAssembly.instantiate(Module['wasm'], imports).then( (output) => {
#endif
#if !LibraryManager.has('libexports.js') && ASYNCIFY != 1
var
#endif
#if PTHREADS || WASM_WORKERS
wasmExports = (output.instance || output).exports;
wasmModule = output.module || Module['wasm'];
#elif MINIMAL_RUNTIME_STREAMING_WASM_COMPILATION
wasmExports = output.exports;
#else
wasmExports = output.instance.exports;
#endif
#if ASYNCIFY
wasmExports = Asyncify.instrumentWasmExports(wasmExports);
#endif
#if MEMORY64 || CAN_ADDRESS_2GB
wasmExports = applySignatureConversions(wasmExports);
#endif
assignWasmExports(wasmExports);
#if !IMPORTED_MEMORY
updateMemoryViews();
#endif
<<< ATPRERUNS >>>
initRuntime(wasmExports);
{{{ function waitOnStartupPromisesAndEmitReady() {
var promises = [];
if (PTHREADS && PTHREAD_POOL_SIZE) {
promises.push('PThread.loadWasmModuleToAllWorkers()');
}
if (LOAD_SOURCE_MAP) {
promises.push('getSourceMapAsync().then(json=>{receiveSourceMapJSON(json)})');
}
if (promises.length == 0) {
return 'ready();'
} else if (promises.length == 1) {
return `${promises[0]}.then(ready);`;
} else {
return `Promise.all(${', '.join(promises)}).then(ready);`
}
}
null;
}}}
#if PTHREADS && PTHREAD_POOL_SIZE && PTHREAD_POOL_DELAY_LOAD
PThread.loadWasmModuleToAllWorkers();
#endif
{{{ waitOnStartupPromisesAndEmitReady(); }}}
}
#if WASM == 2
, (error) => {
#if ASSERTIONS
console.error(error);
#endif
#if ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL
if (globalThis.location) {
#endif
var search = location.search;
if (search.indexOf('_rwasm=0') < 0) {
location.href += (search ? search + '&' : '?') + '_rwasm=0';
}
#if ENVIRONMENT_MAY_BE_NODE || ENVIRONMENT_MAY_BE_SHELL
}
#endif
}
#endif
);
#if PTHREADS || WASM_WORKERS
}
{{{ runIfMainThread('loadModule();') }}}
#endif