diff --git a/emscripten.py b/emscripten.py index a571363c34d4..f057392e6144 100644 --- a/emscripten.py +++ b/emscripten.py @@ -2436,15 +2436,18 @@ def create_em_js(forwarded_json, metadata): def add_standard_wasm_imports(send_items_map): - # memory was already allocated (so that js could use the buffer); import it - memory_import = 'wasmMemory' - if shared.Settings.MODULARIZE and shared.Settings.USE_PTHREADS: - # Pthreads assign wasmMemory in their worker startup. In MODULARIZE mode, they cannot assign inside the - # Module scope, so lookup via Module as well. - memory_import += " || Module['wasmMemory']" - send_items_map['memory'] = memory_import - - send_items_map['table'] = 'wasmTable' + # Normally we import these into the wasm (so that JS could use them even + # before the wasm loads), while in standalone mode we do not depend + # on JS to create them, but create them in the wasm and export them. + if not shared.Settings.STANDALONE_WASM: + memory_import = 'wasmMemory' + if shared.Settings.MODULARIZE and shared.Settings.USE_PTHREADS: + # Pthreads assign wasmMemory in their worker startup. In MODULARIZE mode, they cannot assign inside the + # Module scope, so lookup via Module as well. + memory_import += " || Module['wasmMemory']" + send_items_map['memory'] = memory_import + + send_items_map['table'] = 'wasmTable' # With the wasm backend __memory_base and __table_base and only needed for # relocatable output. diff --git a/tests/other/metadce/mem_O3_ALLOW_MEMORY_GROWTH_STANDALONE_WASM.sent b/tests/other/metadce/mem_O3_ALLOW_MEMORY_GROWTH_STANDALONE_WASM.sent index 2ed4d441a51d..6f1c4741d9b0 100644 --- a/tests/other/metadce/mem_O3_ALLOW_MEMORY_GROWTH_STANDALONE_WASM.sent +++ b/tests/other/metadce/mem_O3_ALLOW_MEMORY_GROWTH_STANDALONE_WASM.sent @@ -1,6 +1,4 @@ args_get args_sizes_get emscripten_notify_memory_growth -memory proc_exit -table diff --git a/tests/other/metadce/mem_O3_STANDALONE_WASM.sent b/tests/other/metadce/mem_O3_STANDALONE_WASM.sent index ae5545e94425..ddf9d81904bb 100644 --- a/tests/other/metadce/mem_O3_STANDALONE_WASM.sent +++ b/tests/other/metadce/mem_O3_STANDALONE_WASM.sent @@ -1,5 +1,3 @@ args_get args_sizes_get -memory proc_exit -table diff --git a/tests/test_other.py b/tests/test_other.py index 4be23302a5e5..cb52b7c521eb 100644 --- a/tests/test_other.py +++ b/tests/test_other.py @@ -8119,13 +8119,13 @@ def test_metadce_hello_fastcomp(self, *args): 3, [], [], 6100, 2, 3, 5), # noqa # argc/argv support code etc. is in the wasm 'O3_standalone': (['-O3', '-s', 'STANDALONE_WASM'], - 5, [], [], 6423, 3, 4, 5), # noqa + 3, [], [], 6423, 3, 4, 5), # noqa # Growth support code is in JS, no significant change in the wasm 'O3_grow': (['-O3', '-s', 'ALLOW_MEMORY_GROWTH'], 3, [], [], 6098, 2, 3, 5), # noqa # Growth support code is in the wasm 'O3_grow_standalone': (['-O3', '-s', 'ALLOW_MEMORY_GROWTH', '-s', 'STANDALONE_WASM'], - 6, [], [], 6563, 4, 4, 6), # noqa + 4, [], [], 6563, 4, 4, 6), # noqa }) @no_fastcomp() def test_metadce_mem(self, *args):