diff --git a/ChangeLog.md b/ChangeLog.md index ba8f4442d621..8c1a97a6f620 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -27,6 +27,10 @@ See docs/process.md for more on how version tagging works. - The internal `read_` and `readAsync` functions no longer handle date URIs. This only effects builds that use `-sSINGLE_FILE` or `--memory-init-file`. (#19792) +- The `asm` property of the Module object (which held the raw exports of the + wasm module) has been removed. Internally, this is now accessed via the + `wasmExports` global. If necessary, it is possible to export `wasmExports` + on the Module object using `-sEXPORTED_RUNTIME_METHODS=wasmExports`. (#19816) 3.1.43 - 07/10/23 ----------------- diff --git a/emscripten.py b/emscripten.py index d5f744d24fe0..3ed1b2267f53 100644 --- a/emscripten.py +++ b/emscripten.py @@ -762,7 +762,7 @@ def install_wrapper(sym): # first use. args = [f'a{i}' for i in range(nargs)] args = ', '.join(args) - wrapper += f"({args}) => ({mangled} = {exported}Module['asm']['{name}'])({args});" + wrapper += f"({args}) => ({mangled} = {exported}wasmExports['{name}'])({args});" else: wrapper += 'asm["%s"]' % name diff --git a/site/source/docs/optimizing/Module-Splitting.rst b/site/source/docs/optimizing/Module-Splitting.rst index 7206942979fb..851127d9a6ed 100644 --- a/site/source/docs/optimizing/Module-Splitting.rst +++ b/site/source/docs/optimizing/Module-Splitting.rst @@ -124,7 +124,7 @@ included in the profile. Here’s the function to write the profile and our new main function:: EM_JS(void, write_profile, (), { - var __write_profile = Module['asm']['__write_profile']; + var __write_profile = wasmExports['__write_profile']; if (__write_profile) { // Get the size of the profile and allocate a buffer for it. @@ -338,7 +338,7 @@ be called either. When eagerly instantiating the secondary module, the imports object should be:: - {'primary': Module['asm']} + {'primary': wasmExports} Debugging --------- diff --git a/src/library_async.js b/src/library_async.js index 776a084a97ac..aa3dc22b4d5e 100644 --- a/src/library_async.js +++ b/src/library_async.js @@ -267,9 +267,9 @@ mergeInto(LibraryManager.library, { getDataRewindFunc: function(ptr) { var id = {{{ makeGetValue('ptr', C_STRUCTS.asyncify_data_s.rewind_id, 'i32') }}}; var name = Asyncify.callStackIdToName[id]; - var func = Module['asm'][name]; + var func = wasmExports[name]; #if RELOCATABLE - // Exported functions in side modules are not listed in `Module['asm']`, + // Exported functions in side modules are not listed in `wasmExports`, // So we should use `resolveGlobalSymbol` helper function, which is defined in `library_dylink.js`. if (!func) { func = resolveGlobalSymbol(name, false).sym; @@ -522,8 +522,8 @@ mergeInto(LibraryManager.library, { _load_secondary_module__sig: 'v', _load_secondary_module: async function() { // Mark the module as loading for the wasm module (so it doesn't try to load it again). - Module['asm']['load_secondary_module_status'].value = 1; - var imports = {'primary': Module['asm']}; + wasmExports['load_secondary_module_status'].value = 1; + var imports = {'primary': wasmExports}; // Replace '.wasm' suffix with '.deferred.wasm'. var deferred = wasmBinaryFile.slice(0, -5) + '.deferred.wasm'; await new Promise((resolve) => { diff --git a/src/library_exceptions.js b/src/library_exceptions.js index 18a5df50cc70..f4a481903c6a 100644 --- a/src/library_exceptions.js +++ b/src/library_exceptions.js @@ -331,7 +331,7 @@ var LibraryExceptions = { #if RELOCATABLE return ___cpp_exception; // defined in library.js #else - return Module['asm']['__cpp_exception']; + return wasmExports['__cpp_exception']; #endif }, diff --git a/src/library_exports.js b/src/library_exports.js index b04839b7e2ae..62a6cf8b2362 100644 --- a/src/library_exports.js +++ b/src/library_exports.js @@ -16,7 +16,7 @@ mergeInto(LibraryManager.library, { var exportedFunc = asm[name]; #else // In regular runtime, exports are available on the Module object. - var exportedFunc = Module['asm'][name]; + var exportedFunc = wasmExports[name]; #endif if (exportedFunc) { // Record the created function pointer to each function object, diff --git a/src/modules.js b/src/modules.js index 20200c5fd419..f662d65b19dc 100644 --- a/src/modules.js +++ b/src/modules.js @@ -382,6 +382,8 @@ function exportRuntime() { 'abort', 'keepRuntimeAlive', 'wasmMemory', + 'wasmTable', + 'wasmExports', ]; // These are actually native wasm functions these days but we allow exporting diff --git a/src/parseTools.js b/src/parseTools.js index 4c9ba4af8c24..60882d38b3ec 100644 --- a/src/parseTools.js +++ b/src/parseTools.js @@ -865,6 +865,16 @@ function hasExportedSymbol(sym) { return WASM_EXPORTS.has(sym); } +// Called when global runtime symbols such as wasmMemory, wasmExports and +// wasmTable are set. In this case we maybe need to re-export them on the +// Module object. +function receivedSymbol(sym) { + if (EXPORTED_RUNTIME_METHODS.includes(sym)) { + return `Module['${sym}'] = ${sym};` + } + return ''; +} + // JS API I64 param handling: if we have BigInt support, the ABI is simple, // it is a BigInt. Otherwise, we legalize into pairs of i32s. function defineI64Param(name) { diff --git a/src/postamble_minimal.js b/src/postamble_minimal.js index 55c12852b3d6..0813e184fbd4 100644 --- a/src/postamble_minimal.js +++ b/src/postamble_minimal.js @@ -142,7 +142,7 @@ WebAssembly.instantiate(Module['wasm'], imports).then((output) => { #if !LibraryManager.has('library_exports.js') && !EMBIND // If not using the emscripten_get_exported_function() API or embind, keep the - // 'asm' exports variable in local scope to this instantiate function to save + // `asm` exports variable in local scope to this instantiate function to save // code size. (otherwise access it without to export it to outer scope) var #endif diff --git a/src/preamble.js b/src/preamble.js index c89c522ef3ab..719a82973497 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -53,6 +53,7 @@ if (typeof WebAssembly != 'object') { // Wasm globals var wasmMemory; +var wasmExports; #if SHARED_MEMORY // For sending to workers. @@ -471,7 +472,7 @@ function abort(what) { #if WASM_EXCEPTIONS == 1 // See above, in the meantime, we resort to wasm code for trapping. // - // In case abort() is called before the module is initialized, Module['asm'] + // In case abort() is called before the module is initialized, wasmExports // and its exported '__trap' function is not available, in which case we throw // a RuntimeError. // @@ -527,7 +528,7 @@ function createExportWrapper(name) { #if EXIT_RUNTIME assert(!runtimeExited, `native function \`${name}\` called after runtime exit (use NO_EXIT_RUNTIME to keep it alive after main() exits)`); #endif - var f = Module['asm'][name]; + var f = wasmExports[name]; assert(f, `exported native function \`${name}\` not found`); return f.apply(null, arguments); }; @@ -714,7 +715,7 @@ var splitModuleProxyHandler = { throw new Error('Placeholder function "' + prop + '" should not be called when using JSPI.'); #else err('placeholder function called: ' + prop); - var imports = {'primary': Module['asm']}; + var imports = {'primary': wasmExports}; // Replace '.wasm' suffix with '.deferred.wasm'. var deferred = wasmBinaryFile.slice(0, -5) + '.deferred.wasm' loadSplitModule(deferred, imports, prop); @@ -979,18 +980,20 @@ function createWasm() { exports = applySignatureConversions(exports); #endif - Module['asm'] = exports; + wasmExports = exports; + {{{ receivedSymbol('wasmExports') }}} #if PTHREADS #if MAIN_MODULE - registerTLSInit(Module['asm']['_emscripten_tls_init'], instance.exports, metadata); + registerTLSInit(wasmExports['_emscripten_tls_init'], instance.exports, metadata); #else - registerTLSInit(Module['asm']['_emscripten_tls_init']); + registerTLSInit(wasmExports['_emscripten_tls_init']); #endif #endif #if !IMPORTED_MEMORY - wasmMemory = Module['asm']['memory']; + wasmMemory = wasmExports['memory']; + {{{ receivedSymbol('wasmMemory') }}} #if ASSERTIONS assert(wasmMemory, "memory not found in wasm exports"); // This assertion doesn't hold when emscripten is run in --post-link @@ -1005,7 +1008,8 @@ function createWasm() { #endif #if !RELOCATABLE - wasmTable = Module['asm']['__indirect_function_table']; + wasmTable = wasmExports['__indirect_function_table']; + {{{ receivedSymbol('wasmTable') }}} #if ASSERTIONS && !PURE_WASI assert(wasmTable, "table not found in wasm exports"); #endif @@ -1019,11 +1023,11 @@ function createWasm() { #endif #if hasExportedSymbol('__wasm_call_ctors') - addOnInit(Module['asm']['__wasm_call_ctors']); + addOnInit(wasmExports['__wasm_call_ctors']); #endif #if hasExportedSymbol('__wasm_apply_data_relocs') - __RELOC_FUNCS__.push(Module['asm']['__wasm_apply_data_relocs']); + __RELOC_FUNCS__.push(wasmExports['__wasm_apply_data_relocs']); #endif #if ABORT_ON_WASM_EXCEPTIONS diff --git a/src/runtime_debug.js b/src/runtime_debug.js index db482e376e06..2ab30a8a5d36 100644 --- a/src/runtime_debug.js +++ b/src/runtime_debug.js @@ -6,12 +6,14 @@ #if ASSERTIONS -function legacyModuleProp(prop, newName) { +function legacyModuleProp(prop, newName, incomming=true) { if (!Object.getOwnPropertyDescriptor(Module, prop)) { Object.defineProperty(Module, prop, { configurable: true, get() { - abort('Module.' + prop + ' has been replaced with plain ' + newName + ' (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)'); + let extra = incomming ? ' (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)' : ''; + abort(`\`Module.${prop}\` has been replaced by \`${newName}\`` + extra); + } }); } @@ -19,7 +21,7 @@ function legacyModuleProp(prop, newName) { function ignoredModuleProp(prop) { if (Object.getOwnPropertyDescriptor(Module, prop)) { - abort('`Module.' + prop + '` was supplied but `' + prop + '` not included in INCOMING_MODULE_JS_API'); + abort(`\`Module.${prop}\` was supplied but \`${prop}\` not included in INCOMING_MODULE_JS_API`); } } diff --git a/src/shell.js b/src/shell.js index a997e51d0c3a..266377187387 100644 --- a/src/shell.js +++ b/src/shell.js @@ -477,6 +477,7 @@ assert(typeof Module['readAsync'] == 'undefined', 'Module.readAsync option was r assert(typeof Module['readBinary'] == 'undefined', 'Module.readBinary option was removed (modify readBinary in JS)'); assert(typeof Module['setWindowTitle'] == 'undefined', 'Module.setWindowTitle option was removed (modify setWindowTitle in JS)'); assert(typeof Module['TOTAL_MEMORY'] == 'undefined', 'Module.TOTAL_MEMORY has been renamed Module.INITIAL_MEMORY'); +{{{ makeRemovedModuleAPIAssert('asm', 'wasmExports', false) }}} {{{ makeRemovedModuleAPIAssert('read', 'read_') }}} {{{ makeRemovedModuleAPIAssert('readAsync') }}} {{{ makeRemovedModuleAPIAssert('readBinary') }}} diff --git a/test/optimizer/applyDCEGraphRemovals-output.js b/test/optimizer/applyDCEGraphRemovals-output.js index 8037ddb96f47..6e70e4c9d26e 100644 --- a/test/optimizer/applyDCEGraphRemovals-output.js +++ b/test/optimizer/applyDCEGraphRemovals-output.js @@ -17,15 +17,15 @@ var expD5 = asm["expD5"]; var expD6; -var expI1 = Module["expI1"] = () => (expI1 = Module["expI1"] = Module["asm"]["expI1"])(); +var expI1 = Module["expI1"] = () => (expI1 = Module["expI1"] = wasmExports["expI1"])(); -var expI2 = Module["expI2"] = () => (expI2 = Module["expI2"] = Module["asm"]["expI2"])(); +var expI2 = Module["expI2"] = () => (expI2 = Module["expI2"] = wasmExports["expI2"])(); -var expI3 = Module["expI3"] = () => (expI3 = Module["expI3"] = Module["asm"]["expI3"])(); +var expI3 = Module["expI3"] = () => (expI3 = Module["expI3"] = wasmExports["expI3"])(); var expI4; -var expI5 = () => (expI5 = Module["asm"]["expI5"])(); +var expI5 = () => (expI5 = wasmExports["expI5"])(); var expI6; diff --git a/test/optimizer/applyDCEGraphRemovals.js b/test/optimizer/applyDCEGraphRemovals.js index 7fe977e3e33f..2401d772fc3f 100644 --- a/test/optimizer/applyDCEGraphRemovals.js +++ b/test/optimizer/applyDCEGraphRemovals.js @@ -11,14 +11,14 @@ var expD5 = asm['expD5']; var expD6 = asm['expD6']; // exports gotten indirectly (async compilation -var expI1 = Module['expI1'] = () => (expI1 = Module['expI1'] = Module['asm']['expI1'])(); -var expI2 = Module['expI2'] = () => (expI2 = Module['expI2'] = Module['asm']['expI2'])(); -var expI3 = Module['expI3'] = () => (expI3 = Module['expI3'] = Module['asm']['expI3'])(); -var expI4 = Module['expI4'] = () => (expI4 = Module['expI4'] = Module['asm']['expI4'])(); +var expI1 = Module['expI1'] = () => (expI1 = Module['expI1'] = wasmExports['expI1'])(); +var expI2 = Module['expI2'] = () => (expI2 = Module['expI2'] = wasmExports['expI2'])(); +var expI3 = Module['expI3'] = () => (expI3 = Module['expI3'] = wasmExports['expI3'])(); +var expI4 = Module['expI4'] = () => (expI4 = Module['expI4'] = wasmExports['expI4'])(); // Like above, but not exported on the Module -var expI5 = () => (expI5 = Module['asm']['expI5'])(); -var expI6 = () => (expI6 = Module['asm']['expI6'])(); +var expI5 = () => (expI5 = wasmExports['expI5'])(); +var expI6 = () => (expI6 = wasmExports['expI6'])(); // add uses for some of them, leave *4 as non-roots expD1; diff --git a/test/optimizer/applyImportAndExportNameChanges-output.js b/test/optimizer/applyImportAndExportNameChanges-output.js index d8e836a4f4f1..00d82577fefd 100644 --- a/test/optimizer/applyImportAndExportNameChanges-output.js +++ b/test/optimizer/applyImportAndExportNameChanges-output.js @@ -17,5 +17,5 @@ var wasmImports = { var expD1 = Module["expD1"] = asm["c"]; var expI1 = Module["expI1"] = function() { - return Module["asm"]["d"].apply(null, arguments); + return wasmExports["d"].apply(null, arguments); }; diff --git a/test/optimizer/applyImportAndExportNameChanges.js b/test/optimizer/applyImportAndExportNameChanges.js index 39754cc73ff1..ebdc723961a2 100644 --- a/test/optimizer/applyImportAndExportNameChanges.js +++ b/test/optimizer/applyImportAndExportNameChanges.js @@ -18,7 +18,7 @@ var expD1 = Module['expD1'] = asm['expD1']; // exports gotten indirectly (async compilation var expI1 = Module['expI1'] = (function() { - return Module['asm']['expI1'].apply(null, arguments); + return wasmExports['expI1'].apply(null, arguments); }); // EXTRA_INFO: { "mapping": {"save1" : "a", "number": "A", "expD1": "c", "expI1": "d", "__wasm_call_ctors": "e", "stackRestore": "h", "stackAlloc": "g", "__syscall140": "d", "main": "f", "__syscall146": "q", "__syscall54": "c", "__syscall6": "b" }} diff --git a/test/optimizer/emitDCEGraph.js b/test/optimizer/emitDCEGraph.js index 5a696f3d6149..57f1d680fe37 100644 --- a/test/optimizer/emitDCEGraph.js +++ b/test/optimizer/emitDCEGraph.js @@ -53,13 +53,13 @@ var expD4 = Module['expD4'] = asm['expD4']; var expD5 = asm['expD5']; // exports gotten indirectly (async compilation -var expI1 = Module['expI1'] = () => (expI1 = Module['expI1'] = Module['asm']['expI1'])(); -var expI2 = Module['expI2'] = () => (expI2 = Module['expI2'] = Module['asm']['expI2'])(); -var expI3 = Module['expI3'] = () => (expI3 = Module['expI3'] = Module['asm']['expI3'])(); -var expI4 = Module['expI4'] = () => (expI4 = Module['expI4'] = Module['asm']['expI4'])(); +var expI1 = Module['expI1'] = () => (expI1 = Module['expI1'] = wasmExports['expI1'])(); +var expI2 = Module['expI2'] = () => (expI2 = Module['expI2'] = wasmExports['expI2'])(); +var expI3 = Module['expI3'] = () => (expI3 = Module['expI3'] = wasmExports['expI3'])(); +var expI4 = Module['expI4'] = () => (expI4 = Module['expI4'] = wasmExports['expI4'])(); // Same as above but not export on the Module. -var expI5 = () => (expI5 = Module['asm']['expI5'])(); +var expI5 = () => (expI5 = wasmExports['expI5'])(); // add uses for some of them expD1; @@ -68,7 +68,7 @@ asm['expD3']; expI1; Module['expI2']; -Module['asm']['expI3']; +wasmExports['expI3']; // deep uses, that we can't scan function usedFromDeep() { @@ -86,10 +86,10 @@ var func = function() { }; // dyncalls -var dynCall_v = Module["dynCall_v"] = () => Module["asm"]["dynCall_v"](); -var dynCall_vi = Module["dynCall_vi"] = () => Module["asm"]["dynCall_vi"](); -var dynCall_vii = Module["dynCall_vii"] = () => Module["asm"]["dynCall_vii"](); -var dynCall_viii = Module["dynCall_viii"] = () => Module["asm"]["dynCall_viii"](); +var dynCall_v = Module["dynCall_v"] = () => wasmExports["dynCall_v"](); +var dynCall_vi = Module["dynCall_vi"] = () => wasmExports["dynCall_vi"](); +var dynCall_vii = Module["dynCall_vii"] = () => wasmExports["dynCall_vii"](); +var dynCall_viii = Module["dynCall_viii"] = () => wasmExports["dynCall_viii"](); dynCall_v(ptr); // use directly Module['dynCall_vi'](ptr, 1); // use on module diff --git a/test/optimizer/emitDCEGraph2.js b/test/optimizer/emitDCEGraph2.js index 36c0c5b82553..2dc97f6ec4bb 100644 --- a/test/optimizer/emitDCEGraph2.js +++ b/test/optimizer/emitDCEGraph2.js @@ -1,8 +1,8 @@ // dyncalls -var dynCall_v = Module["dynCall_v"] = () => Module["asm"]["dynCall_v"](); -var dynCall_vi = Module["dynCall_vi"] = () => Module["asm"]["dynCall_vi"](); -var dynCall_vii = Module["dynCall_vii"] = () => Module["asm"]["dynCall_vii"](); -var dynCall_viii = Module["dynCall_viii"] = () => Module["asm"]["dynCall_viii"](); +var dynCall_v = Module["dynCall_v"] = () => wasmExports["dynCall_v"](); +var dynCall_vi = Module["dynCall_vi"] = () => wasmExports["dynCall_vi"](); +var dynCall_vii = Module["dynCall_vii"] = () => wasmExports["dynCall_vii"](); +var dynCall_viii = Module["dynCall_viii"] = () => wasmExports["dynCall_viii"](); // a dynamic dynCall function dynCall(sig) { diff --git a/test/optimizer/emitDCEGraph3.js b/test/optimizer/emitDCEGraph3.js index 86649d06adf1..de8d6a1d5aed 100644 --- a/test/optimizer/emitDCEGraph3.js +++ b/test/optimizer/emitDCEGraph3.js @@ -1,8 +1,8 @@ // dyncalls -var dynCall_v = Module["dynCall_v"] = () => Module["asm"]["dynCall_v"](); -var dynCall_vi = Module["dynCall_vi"] = () => Module["asm"]["dynCall_vi"](); -var dynCall_vii = Module["dynCall_vii"] = () => Module["asm"]["dynCall_vii"](); -var dynCall_viii = Module["dynCall_viii"] = () => Module["asm"]["dynCall_viii"](); +var dynCall_v = Module["dynCall_v"] = () => wasmExports["dynCall_v"](); +var dynCall_vi = Module["dynCall_vi"] = () => wasmExports["dynCall_vi"](); +var dynCall_vii = Module["dynCall_vii"] = () => wasmExports["dynCall_vii"](); +var dynCall_viii = Module["dynCall_viii"] = () => wasmExports["dynCall_viii"](); // a dynamic dynCall function dynCall(sig) { diff --git a/test/optimizer/emitDCEGraph4.js b/test/optimizer/emitDCEGraph4.js index 01a2b5ba3c4e..0cb8e4fe2cb1 100644 --- a/test/optimizer/emitDCEGraph4.js +++ b/test/optimizer/emitDCEGraph4.js @@ -1,8 +1,8 @@ // dyncalls -var dynCall_v = Module["dynCall_v"] = () => Module["asm"]["dynCall_v"](); -var dynCall_vi = Module["dynCall_vi"] = () => Module["asm"]["dynCall_vi"](); -var dynCall_vii = Module["dynCall_vii"] = () => Module["asm"]["dynCall_vii"](); -var dynCall_viii = Module["dynCall_viii"] = () => Module["asm"]["dynCall_viii"](); +var dynCall_v = Module["dynCall_v"] = () => wasmExports["dynCall_v"](); +var dynCall_vi = Module["dynCall_vi"] = () => wasmExports["dynCall_vi"](); +var dynCall_vii = Module["dynCall_vii"] = () => wasmExports["dynCall_vii"](); +var dynCall_viii = Module["dynCall_viii"] = () => wasmExports["dynCall_viii"](); // a dynamic dynCall function dynCall(sig) { diff --git a/test/optimizer/emitDCEGraph5.js b/test/optimizer/emitDCEGraph5.js index 1fe3255725eb..5a8f284fd811 100644 --- a/test/optimizer/emitDCEGraph5.js +++ b/test/optimizer/emitDCEGraph5.js @@ -1,14 +1,14 @@ // wasm backend notation has one fewer _ in the wasm __GLOBAL__I_000101(); // var use -var __GLOBAL__I_000101 = Module["__GLOBAL__I_000101"] = () => Module["asm"]["_GLOBAL__I_000101"](); +var __GLOBAL__I_000101 = Module["__GLOBAL__I_000101"] = () => wasmExports["_GLOBAL__I_000101"](); __ATINIT__.push({ func: function() { __GLOBAL__I_iostream() } }); // var use inside other scope -var __GLOBAL__I_iostream = Module["__GLOBAL__I_iostream"] = () => Module["asm"]["_GLOBAL__I_iostream.cpp"](); +var __GLOBAL__I_iostream = Module["__GLOBAL__I_iostream"] = () => wasmExports["_GLOBAL__I_iostream.cpp"](); Module["__DUB"](); // module use -var __DUB = Module["__DUB"] = () => Module["asm"]["_DUB"](); +var __DUB = Module["__DUB"] = () => wasmExports["_DUB"](); -var __UNUSED = Module["__UNUSED"] = () => Module["asm"]["_UNUSED"](); +var __UNUSED = Module["__UNUSED"] = () => wasmExports["_UNUSED"](); var wasmImports = { }; diff --git a/test/other/metadce/test_metadce_cxx_ctors1.jssize b/test/other/metadce/test_metadce_cxx_ctors1.jssize index 932008f58260..9c7dcb5f10ca 100644 --- a/test/other/metadce/test_metadce_cxx_ctors1.jssize +++ b/test/other/metadce/test_metadce_cxx_ctors1.jssize @@ -1 +1 @@ -25162 +25131 diff --git a/test/other/metadce/test_metadce_cxx_ctors2.jssize b/test/other/metadce/test_metadce_cxx_ctors2.jssize index 7d6f9f4fcb11..29e6c7956ce8 100644 --- a/test/other/metadce/test_metadce_cxx_ctors2.jssize +++ b/test/other/metadce/test_metadce_cxx_ctors2.jssize @@ -1 +1 @@ -25126 +25099 diff --git a/test/other/metadce/test_metadce_cxx_except.jssize b/test/other/metadce/test_metadce_cxx_except.jssize index 31382fbfc5b6..2e168b495c58 100644 --- a/test/other/metadce/test_metadce_cxx_except.jssize +++ b/test/other/metadce/test_metadce_cxx_except.jssize @@ -1 +1 @@ -29381 +29309 diff --git a/test/other/metadce/test_metadce_cxx_except_wasm.jssize b/test/other/metadce/test_metadce_cxx_except_wasm.jssize index 9f5a6b7e142b..1ed3deaf231a 100644 --- a/test/other/metadce/test_metadce_cxx_except_wasm.jssize +++ b/test/other/metadce/test_metadce_cxx_except_wasm.jssize @@ -1 +1 @@ -24934 +24899 diff --git a/test/other/metadce/test_metadce_cxx_mangle.jssize b/test/other/metadce/test_metadce_cxx_mangle.jssize index bf13479dc9db..2e04db4e448d 100644 --- a/test/other/metadce/test_metadce_cxx_mangle.jssize +++ b/test/other/metadce/test_metadce_cxx_mangle.jssize @@ -1 +1 @@ -29380 +29308 diff --git a/test/other/metadce/test_metadce_cxx_noexcept.jssize b/test/other/metadce/test_metadce_cxx_noexcept.jssize index 932008f58260..9c7dcb5f10ca 100644 --- a/test/other/metadce/test_metadce_cxx_noexcept.jssize +++ b/test/other/metadce/test_metadce_cxx_noexcept.jssize @@ -1 +1 @@ -25162 +25131 diff --git a/test/other/metadce/test_metadce_cxx_wasmfs.jssize b/test/other/metadce/test_metadce_cxx_wasmfs.jssize index 061a3386086a..d715aa47f772 100644 --- a/test/other/metadce/test_metadce_cxx_wasmfs.jssize +++ b/test/other/metadce/test_metadce_cxx_wasmfs.jssize @@ -1 +1 @@ -12782 +12738 diff --git a/test/other/metadce/test_metadce_files_js_fs.jssize b/test/other/metadce/test_metadce_files_js_fs.jssize index d40d40ee4a8c..28928313b7c1 100644 --- a/test/other/metadce/test_metadce_files_js_fs.jssize +++ b/test/other/metadce/test_metadce_files_js_fs.jssize @@ -1 +1 @@ -20017 +20006 diff --git a/test/other/metadce/test_metadce_files_wasmfs.jssize b/test/other/metadce/test_metadce_files_wasmfs.jssize index 4f4038188096..d0e457884211 100644 --- a/test/other/metadce/test_metadce_files_wasmfs.jssize +++ b/test/other/metadce/test_metadce_files_wasmfs.jssize @@ -1 +1 @@ -7261 +7248 diff --git a/test/other/metadce/test_metadce_hello_O0.jssize b/test/other/metadce/test_metadce_hello_O0.jssize index cf408f75c258..c1e0a1605ef6 100644 --- a/test/other/metadce/test_metadce_hello_O0.jssize +++ b/test/other/metadce/test_metadce_hello_O0.jssize @@ -1 +1 @@ -23608 +23618 diff --git a/test/other/metadce/test_metadce_hello_O1.jssize b/test/other/metadce/test_metadce_hello_O1.jssize index e6f91cf78f61..f1a81086075e 100644 --- a/test/other/metadce/test_metadce_hello_O1.jssize +++ b/test/other/metadce/test_metadce_hello_O1.jssize @@ -1 +1 @@ -8120 +8099 diff --git a/test/other/metadce/test_metadce_hello_O2.jssize b/test/other/metadce/test_metadce_hello_O2.jssize index f6cc210c14d5..da710c1aba58 100644 --- a/test/other/metadce/test_metadce_hello_O2.jssize +++ b/test/other/metadce/test_metadce_hello_O2.jssize @@ -1 +1 @@ -5770 +5753 diff --git a/test/other/metadce/test_metadce_hello_O3.jssize b/test/other/metadce/test_metadce_hello_O3.jssize index a0096d7853f1..39a15f6e7326 100644 --- a/test/other/metadce/test_metadce_hello_O3.jssize +++ b/test/other/metadce/test_metadce_hello_O3.jssize @@ -1 +1 @@ -5612 +5599 diff --git a/test/other/metadce/test_metadce_hello_Os.jssize b/test/other/metadce/test_metadce_hello_Os.jssize index a0096d7853f1..39a15f6e7326 100644 --- a/test/other/metadce/test_metadce_hello_Os.jssize +++ b/test/other/metadce/test_metadce_hello_Os.jssize @@ -1 +1 @@ -5612 +5599 diff --git a/test/other/metadce/test_metadce_hello_Oz.jssize b/test/other/metadce/test_metadce_hello_Oz.jssize index a9842242a955..41fe758666ae 100644 --- a/test/other/metadce/test_metadce_hello_Oz.jssize +++ b/test/other/metadce/test_metadce_hello_Oz.jssize @@ -1 +1 @@ -5579 +5566 diff --git a/test/other/metadce/test_metadce_hello_dylink.jssize b/test/other/metadce/test_metadce_hello_dylink.jssize index 275ec65133eb..3581a17bb1bf 100644 --- a/test/other/metadce/test_metadce_hello_dylink.jssize +++ b/test/other/metadce/test_metadce_hello_dylink.jssize @@ -1 +1 @@ -14984 +14947 diff --git a/test/other/metadce/test_metadce_hello_export_nothing.jssize b/test/other/metadce/test_metadce_hello_export_nothing.jssize index 47a5f696c312..38e1efbb3805 100644 --- a/test/other/metadce/test_metadce_hello_export_nothing.jssize +++ b/test/other/metadce/test_metadce_hello_export_nothing.jssize @@ -1 +1 @@ -4399 +4387 diff --git a/test/other/metadce/test_metadce_hello_wasmfs.jssize b/test/other/metadce/test_metadce_hello_wasmfs.jssize index a0096d7853f1..39a15f6e7326 100644 --- a/test/other/metadce/test_metadce_hello_wasmfs.jssize +++ b/test/other/metadce/test_metadce_hello_wasmfs.jssize @@ -1 +1 @@ -5612 +5599 diff --git a/test/other/metadce/test_metadce_libcxxabi_message_O3.jssize b/test/other/metadce/test_metadce_libcxxabi_message_O3.jssize index e8ca47dace4b..9110c0a1f5e4 100644 --- a/test/other/metadce/test_metadce_libcxxabi_message_O3.jssize +++ b/test/other/metadce/test_metadce_libcxxabi_message_O3.jssize @@ -1 +1 @@ -4900 +4884 diff --git a/test/other/metadce/test_metadce_libcxxabi_message_O3_standalone.jssize b/test/other/metadce/test_metadce_libcxxabi_message_O3_standalone.jssize index 032c24666054..f32a182f1e94 100644 --- a/test/other/metadce/test_metadce_libcxxabi_message_O3_standalone.jssize +++ b/test/other/metadce/test_metadce_libcxxabi_message_O3_standalone.jssize @@ -1 +1 @@ -4955 +4943 diff --git a/test/other/metadce/test_metadce_mem_O3.jssize b/test/other/metadce/test_metadce_mem_O3.jssize index 33f6a20952b6..a3e3339d9add 100644 --- a/test/other/metadce/test_metadce_mem_O3.jssize +++ b/test/other/metadce/test_metadce_mem_O3.jssize @@ -1 +1 @@ -5791 +5774 diff --git a/test/other/metadce/test_metadce_mem_O3_grow.jssize b/test/other/metadce/test_metadce_mem_O3_grow.jssize index 124a6d8c38ff..3dec17560473 100644 --- a/test/other/metadce/test_metadce_mem_O3_grow.jssize +++ b/test/other/metadce/test_metadce_mem_O3_grow.jssize @@ -1 +1 @@ -6111 +6094 diff --git a/test/other/metadce/test_metadce_mem_O3_grow_standalone.jssize b/test/other/metadce/test_metadce_mem_O3_grow_standalone.jssize index ceaeb5c589e5..5de66124ada4 100644 --- a/test/other/metadce/test_metadce_mem_O3_grow_standalone.jssize +++ b/test/other/metadce/test_metadce_mem_O3_grow_standalone.jssize @@ -1 +1 @@ -5534 +5524 diff --git a/test/other/metadce/test_metadce_mem_O3_standalone.jssize b/test/other/metadce/test_metadce_mem_O3_standalone.jssize index 4e8a6e6d26b4..af7b5602a296 100644 --- a/test/other/metadce/test_metadce_mem_O3_standalone.jssize +++ b/test/other/metadce/test_metadce_mem_O3_standalone.jssize @@ -1 +1 @@ -5464 +5454 diff --git a/test/other/metadce/test_metadce_mem_O3_standalone_lib.jssize b/test/other/metadce/test_metadce_mem_O3_standalone_lib.jssize index a98eb3384ccb..b95028bcc655 100644 --- a/test/other/metadce/test_metadce_mem_O3_standalone_lib.jssize +++ b/test/other/metadce/test_metadce_mem_O3_standalone_lib.jssize @@ -1 +1 @@ -4947 +4931 diff --git a/test/other/metadce/test_metadce_mem_O3_standalone_narg.jssize b/test/other/metadce/test_metadce_mem_O3_standalone_narg.jssize index 032c24666054..f32a182f1e94 100644 --- a/test/other/metadce/test_metadce_mem_O3_standalone_narg.jssize +++ b/test/other/metadce/test_metadce_mem_O3_standalone_narg.jssize @@ -1 +1 @@ -4955 +4943 diff --git a/test/other/metadce/test_metadce_mem_O3_standalone_narg_flto.jssize b/test/other/metadce/test_metadce_mem_O3_standalone_narg_flto.jssize index 032c24666054..f32a182f1e94 100644 --- a/test/other/metadce/test_metadce_mem_O3_standalone_narg_flto.jssize +++ b/test/other/metadce/test_metadce_mem_O3_standalone_narg_flto.jssize @@ -1 +1 @@ -4955 +4943 diff --git a/test/other/metadce/test_metadce_minimal_64.jssize b/test/other/metadce/test_metadce_minimal_64.jssize index 069ccfea1e73..e78293ac9dd3 100644 --- a/test/other/metadce/test_metadce_minimal_64.jssize +++ b/test/other/metadce/test_metadce_minimal_64.jssize @@ -1 +1 @@ -3816 +3800 diff --git a/test/other/metadce/test_metadce_minimal_O0.jssize b/test/other/metadce/test_metadce_minimal_O0.jssize index f13838c964c6..c1a965883efa 100644 --- a/test/other/metadce/test_metadce_minimal_O0.jssize +++ b/test/other/metadce/test_metadce_minimal_O0.jssize @@ -1 +1 @@ -20071 +20085 diff --git a/test/other/metadce/test_metadce_minimal_O1.jssize b/test/other/metadce/test_metadce_minimal_O1.jssize index e796b990fedb..5b9e54fbbe92 100644 --- a/test/other/metadce/test_metadce_minimal_O1.jssize +++ b/test/other/metadce/test_metadce_minimal_O1.jssize @@ -1 +1 @@ -4594 +4581 diff --git a/test/other/metadce/test_metadce_minimal_O2.jssize b/test/other/metadce/test_metadce_minimal_O2.jssize index f10d1076aa29..142b126313a0 100644 --- a/test/other/metadce/test_metadce_minimal_O2.jssize +++ b/test/other/metadce/test_metadce_minimal_O2.jssize @@ -1 +1 @@ -3518 +3504 diff --git a/test/other/metadce/test_metadce_minimal_O3.jssize b/test/other/metadce/test_metadce_minimal_O3.jssize index 50f95fc714b7..d0f1d7566f6d 100644 --- a/test/other/metadce/test_metadce_minimal_O3.jssize +++ b/test/other/metadce/test_metadce_minimal_O3.jssize @@ -1 +1 @@ -3447 +3433 diff --git a/test/other/metadce/test_metadce_minimal_Os.jssize b/test/other/metadce/test_metadce_minimal_Os.jssize index 50f95fc714b7..d0f1d7566f6d 100644 --- a/test/other/metadce/test_metadce_minimal_Os.jssize +++ b/test/other/metadce/test_metadce_minimal_Os.jssize @@ -1 +1 @@ -3447 +3433 diff --git a/test/other/metadce/test_metadce_minimal_Oz-ctors.jssize b/test/other/metadce/test_metadce_minimal_Oz-ctors.jssize index d6ff78ac4e40..7295ecbcfb36 100644 --- a/test/other/metadce/test_metadce_minimal_Oz-ctors.jssize +++ b/test/other/metadce/test_metadce_minimal_Oz-ctors.jssize @@ -1 +1 @@ -3428 +3418 diff --git a/test/other/metadce/test_metadce_minimal_Oz.jssize b/test/other/metadce/test_metadce_minimal_Oz.jssize index 50f95fc714b7..d0f1d7566f6d 100644 --- a/test/other/metadce/test_metadce_minimal_Oz.jssize +++ b/test/other/metadce/test_metadce_minimal_Oz.jssize @@ -1 +1 @@ -3447 +3433 diff --git a/test/other/metadce/test_metadce_minimal_pthreads.jssize b/test/other/metadce/test_metadce_minimal_pthreads.jssize index 9f678c8e9b1a..399387840961 100644 --- a/test/other/metadce/test_metadce_minimal_pthreads.jssize +++ b/test/other/metadce/test_metadce_minimal_pthreads.jssize @@ -1 +1 @@ -14608 +14536 diff --git a/test/other/metadce/test_metadce_minimal_wasmfs.jssize b/test/other/metadce/test_metadce_minimal_wasmfs.jssize index 50f95fc714b7..d0f1d7566f6d 100644 --- a/test/other/metadce/test_metadce_minimal_wasmfs.jssize +++ b/test/other/metadce/test_metadce_minimal_wasmfs.jssize @@ -1 +1 @@ -3447 +3433 diff --git a/test/other/test_split_module.post.js b/test/other/test_split_module.post.js index a8e5a51aa369..4dba106b6759 100644 --- a/test/other/test_split_module.post.js +++ b/test/other/test_split_module.post.js @@ -1,5 +1,5 @@ function saveProfileData() { - var __write_profile = Module['asm']['__write_profile']; + var __write_profile = wasmExports['__write_profile']; if (__write_profile) { var len = __write_profile(0, 0); var offset = _malloc(len); diff --git a/test/other/test_unoptimized_code_size.js.size b/test/other/test_unoptimized_code_size.js.size index 73e9bd10685b..74419340f193 100644 --- a/test/other/test_unoptimized_code_size.js.size +++ b/test/other/test_unoptimized_code_size.js.size @@ -1 +1 @@ -58144 +58278 diff --git a/test/other/test_unoptimized_code_size_no_asserts.js.size b/test/other/test_unoptimized_code_size_no_asserts.js.size index c71d392167be..699f9230a6da 100644 --- a/test/other/test_unoptimized_code_size_no_asserts.js.size +++ b/test/other/test_unoptimized_code_size_no_asserts.js.size @@ -1 +1 @@ -31977 +31987 diff --git a/test/other/test_unoptimized_code_size_strict.js.size b/test/other/test_unoptimized_code_size_strict.js.size index 73b60adfbfa9..4a2d303f895a 100644 --- a/test/other/test_unoptimized_code_size_strict.js.size +++ b/test/other/test_unoptimized_code_size_strict.js.size @@ -1 +1 @@ -57110 +57244 diff --git a/test/test_other.py b/test/test_other.py index 531446132820..b773faab915d 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -3281,29 +3281,36 @@ def test_exported_runtime_methods(self): create_file('count.c', ''' #include int count(const char *str) { - return (int)strlen(str); + return (int)strlen(str); } ''') create_file('index.js', ''' const count = require('./count.js'); - console.log(count.FS_writeFile); + count.onRuntimeInitialized = () => { + if (count.wasmExports && 'count' in count.wasmExports) { + console.log('wasmExports found'); + } else { + console.log('wasmExports NOT found'); + } + }; ''') - reference_error_text = 'undefined' - - self.run_process([EMCC, 'count.c', '-sFORCE_FILESYSTEM', - '-sEXPORTED_RUNTIME_METHODS=FS_writeFile', '-o', 'count.js']) + self.run_process([EMCC, 'count.c', '-sFORCE_FILESYSTEM', '-sEXPORTED_FUNCTIONS=_count', + '-sEXPORTED_RUNTIME_METHODS=FS_writeFile,wasmExports', '-o', 'count.js']) # Check that the Module.FS_writeFile exists - self.assertNotContained(reference_error_text, self.run_js('index.js')) + out = self.run_js('index.js') + self.assertNotContained('undefined', out) + self.assertContained('wasmExports found', out) self.run_process([EMCC, 'count.c', '-sFORCE_FILESYSTEM', '-o', 'count.js']) # Check that the Module.FS_writeFile is not exported - out = self.run_js('index.js') - self.assertContained(reference_error_text, out) + out = self.run_js('index.js', assert_returncode=NON_ZERO) + self.assertContained('undefined', out), + self.assertContained("Aborted('wasmExports' was not exported. add it to EXPORTED_RUNTIME_METHODS", out) def test_exported_runtime_methods_from_js_library(self): create_file('pre.js', ''' @@ -10802,10 +10809,20 @@ def test_assertions_on_internal_api_changes(self): } catch(e) { out('error: ' + e); } + try { + Module['asm']; + out('it should not be there'); + } catch(e) { + out('error: ' + e); + } }); } ''') - self.do_runf('src.c', 'Module.read has been replaced with plain read', emcc_args=['-sASSERTIONS']) + expected = [ + '`Module.read` has been replaced by `read_`', + '`Module.asm` has been replaced by `wasmExports`', + ] + self.do_runf('src.c', expected, assert_all=True, emcc_args=['-sASSERTIONS']) def test_assertions_on_incoming_module_api_changes(self): create_file('pre.js', 'Module.read = () => {};') @@ -10834,9 +10851,9 @@ def test_assertions_on_outgoing_module_api_changes(self): } ''') expected = ''' -Aborted(Module.read has been replaced with plain read_ (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)) -Aborted(Module.wasmBinary has been replaced with plain wasmBinary (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)) -Aborted(Module.arguments has been replaced with plain arguments_ (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)) +Aborted(`Module.read` has been replaced by `read_` (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)) +Aborted(`Module.wasmBinary` has been replaced by `wasmBinary` (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)) +Aborted(`Module.arguments` has been replaced by `arguments_` (the initial value can be provided on Module, but after startup the value is only looked for on a local variable of that name)) ''' self.do_runf('src.cpp', expected, emcc_args=['-sASSERTIONS']) diff --git a/tools/acorn-optimizer.js b/tools/acorn-optimizer.js index abb405a49357..4ae42317fe65 100755 --- a/tools/acorn-optimizer.js +++ b/tools/acorn-optimizer.js @@ -465,22 +465,23 @@ function getWasmImportsValue(node) { return node.declarations[0].init; } -function isAsmUse(node) { +function isExportUse(node) { + // MINIMAL_RUNTIME calls exports global variable `asm`, whereas regualar + // runtime calls it `wasmExports`. + // + // Here we match either: + // wasmExports['X'] + // or: + // asm['X'] return ( node.type === 'MemberExpression' && - ((node.object.type === 'Identifier' && // asm['X'] - node.object.name === 'asm' && - node.property.type === 'Literal') || - (node.object.type === 'MemberExpression' && // Module['asm']['X'] - node.object.object.type === 'Identifier' && - node.object.object.name === 'Module' && - node.object.property.type === 'Literal' && - node.object.property.value === 'asm' && - isLiteralString(node.property))) + node.object.type === 'Identifier' && + isLiteralString(node.property) && + (node.object.name === 'wasmExports' || node.object.name === 'asm') ); } -function getAsmOrModuleUseName(node) { +function getExportOrModuleUseName(node) { return node.property.value; } @@ -493,19 +494,6 @@ function isModuleUse(node) { ); } -function isModuleAsmUse(node) { - // Module['asm'][..string..] - return ( - node.type === 'MemberExpression' && - node.object.type === 'MemberExpression' && - node.object.object.type === 'Identifier' && - node.object.object.name === 'Module' && - node.object.property.type === 'Literal' && - node.object.property.value === 'asm' && - isLiteralString(node.property) - ); -} - // Apply import/export name changes (after minifying them) function applyImportAndExportNameChanges(ast) { const mapping = extraInfo.mapping; @@ -520,26 +508,20 @@ function applyImportAndExportNameChanges(ast) { } else if (node.type === 'AssignmentExpression') { const target = node.left; const value = node.right; - if (isAsmUse(value)) { + if (isExportUse(value)) { const name = value.property.value; if (mapping[name]) { setLiteralValue(value.property, mapping[name]); } } - } else if (node.type === 'CallExpression' && isAsmUse(node.callee)) { + } else if (node.type === 'CallExpression' && isExportUse(node.callee)) { // asm["___wasm_call_ctors"](); -> asm["M"](); const callee = node.callee; const name = callee.property.value; if (mapping[name]) { setLiteralValue(callee.property, mapping[name]); } - } else if (isModuleAsmUse(node)) { - const prop = node.property; - const name = prop.value; - if (mapping[name]) { - setLiteralValue(prop, mapping[name]); - } - } else if (isAsmUse(node)) { + } else if (isExportUse(node)) { const prop = node.property; const name = prop.value; if (mapping[name]) { @@ -585,7 +567,7 @@ function isDynamicDynCall(node) { // Matches the wasm export wrappers generated by emcc (see make_export_wrappers // in emscripten.py). For example: // -// var _foo = (a0, a1) => (_foo = Module['asm']['foo'])(a0, a1): +// var _foo = (a0, a1) => (_foo = wasmExports['foo'])(a0, a1): // function isExportWrapperFunction(f) { if (f.body.type != 'CallExpression') return null; @@ -594,9 +576,9 @@ function isExportWrapperFunction(f) { callee = callee.expression; } if (callee.type != 'AssignmentExpression' || callee.right.type != 'MemberExpression') return null; - const rhs = callee.right; - if (rhs.object.type != 'MemberExpression' || !isModuleUse(rhs.object)) return null; - return getAsmOrModuleUseName(rhs); + var rhs = callee.right; + if (rhs.type != 'MemberExpression' || !isExportUse(rhs)) return null; + return getExportOrModuleUseName(rhs); } // @@ -659,9 +641,7 @@ function emitDCEGraph(ast) { // // or // - // var _malloc = Module['_malloc'] = (function() { - // return Module['asm']['_malloc'].apply(null, arguments); - // }); + // var _malloc = Module['_malloc'] = (x) => wasmExports['_malloc'](x); // // or, in the minimal runtime, it looks like // @@ -717,15 +697,17 @@ function emitDCEGraph(ast) { const item = node.declarations[0]; const name = item.id.name; const value = item.init; - if (value && isAsmUse(value)) { - const asmName = getAsmOrModuleUseName(value); + if (value && isExportUse(value)) { + const asmName = getExportOrModuleUseName(value); // this is // var _x = asm['x']; + // or + // var _x = wasmExports['x']; saveAsmExport(name, asmName); emptyOut(node); } else if (value && value.type === 'ArrowFunctionExpression') { // this is - // var x = () => (x = Module['asm']['x'])(..) + // var x = () => (x = wasmExports['x'])(..) let asmName = isExportWrapperFunction(value); if (asmName) { saveAsmExport(name, asmName); @@ -733,16 +715,16 @@ function emitDCEGraph(ast) { } } else if (value && value.type === 'AssignmentExpression') { const assigned = value.left; - if (isModuleUse(assigned) && getAsmOrModuleUseName(assigned) === name) { + if (isModuleUse(assigned) && getExportOrModuleUseName(assigned) === name) { // this is // var x = Module['x'] = ? // which looks like a wasm export being received. confirm with the asm use let found = 0; let asmName; fullWalk(value.right, (node) => { - if (isAsmUse(node)) { + if (isExportUse(node)) { found++; - asmName = getAsmOrModuleUseName(node); + asmName = getExportOrModuleUseName(node); } }); // in the wasm backend, the asm name may have one fewer "_" prefixed @@ -891,7 +873,7 @@ function emitDCEGraph(ast) { reached = nameToGraphName[name]; } } else if (isModuleUse(node)) { - const name = getAsmOrModuleUseName(node); + const name = getExportOrModuleUseName(node); if (modulePropertyToGraphName.hasOwnProperty(name)) { reached = modulePropertyToGraphName[name]; } @@ -900,9 +882,9 @@ function emitDCEGraph(ast) { } else if (isDynamicDynCall(node)) { // this can reach *all* dynCall_* targets, we can't narrow it down reached = dynCallNames; - } else if (isAsmUse(node)) { + } else if (isExportUse(node)) { // any remaining asm uses are always rooted in any case - const name = getAsmOrModuleUseName(node); + const name = getExportOrModuleUseName(node); if (exportNameToGraphName.hasOwnProperty(name)) { infos[exportNameToGraphName[name]].root = true; } @@ -977,11 +959,11 @@ function applyDCEGraphRemovals(ast) { // when we assign to a thing we don't need, we can just remove the assign // var x = Module['x'] = asm['x']; const target = node.left; - if (isAsmUse(target) || isModuleUse(target)) { - const name = getAsmOrModuleUseName(target); + if (isExportUse(target) || isModuleUse(target)) { + const name = getExportOrModuleUseName(target); const full = 'emcc$export$' + name; const value = node.right; - if (unused.has(full) && (isAsmUse(value) || !hasSideEffects(value))) { + if (unused.has(full) && (isExportUse(value) || !hasSideEffects(value))) { // This will be in a var init, and we just remove that value. convertToNothingInVarInit(node); } @@ -993,8 +975,8 @@ function applyDCEGraphRemovals(ast) { // var x = function() { return (x = asm['x']).apply(...) }; const init = node.declarations[0].init; if (init) { - if (isAsmUse(init)) { - const name = getAsmOrModuleUseName(init); + if (isExportUse(init)) { + const name = getExportOrModuleUseName(init); const full = 'emcc$export$' + name; if (unused.has(full)) { convertToNothingInVarInit(init); @@ -1012,9 +994,9 @@ function applyDCEGraphRemovals(ast) { // In the minimal runtime code pattern we have just // x = asm['x'] // and never in a var. - if (expr.operator === '=' && expr.left.type === 'Identifier' && isAsmUse(expr.right)) { + if (expr.operator === '=' && expr.left.type === 'Identifier' && isExportUse(expr.right)) { const name = expr.left.name; - if (name === getAsmOrModuleUseName(expr.right)) { + if (name === getExportOrModuleUseName(expr.right)) { const full = 'emcc$export$' + name; if (unused.has(full)) { emptyOut(node); diff --git a/tools/building.py b/tools/building.py index 21c54cc7771d..8c424b2f9769 100644 --- a/tools/building.py +++ b/tools/building.py @@ -371,7 +371,7 @@ def eval_ctors(js_file, wasm_file, debug_info): if settings.MINIMAL_RUNTIME: CTOR_ADD_PATTERN = f"asm['{WASM_CALL_CTORS}']();" # TODO test else: - CTOR_ADD_PATTERN = f"addOnInit(Module['asm']['{WASM_CALL_CTORS}']);" + CTOR_ADD_PATTERN = f"addOnInit(wasmExports['{WASM_CALL_CTORS}']);" js = utils.read_file(js_file)