diff --git a/ChangeLog.md b/ChangeLog.md index c8aec8d73c0a7..96197eaad601b 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -25,6 +25,11 @@ See docs/process.md for more on how version tagging works. This paves the way for marking the function as `async` which does not allow `new` to be used. This usage of `new` here was never documented and is considered and antipattern. (#23210) +- The factory function exposed in `-sMODULARIZE` mode is now marked as `async`, + which allows us to use `await` within it. One side effect of this is that + it is no longer possible to use this function with the `new` keyword. Prior + to this change it was technically possible to do `var m = new Module()`, but + this will not result in `Module is not a constructor`. (#23157) - `PATH.basename()` no longer calls `PATH.normalize()`, so that `PATH.basename("a/.")` returns `"."` instead of `"a"` and `PATH.basename("a/b/..")` returns `".."` instead of `"a"`. This is in line with diff --git a/src/preamble.js b/src/preamble.js index 4f4dc32dba0ca..2e91449ac76fc 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -1036,11 +1036,11 @@ function getWasmImports() { trueModule = null; #endif #if SHARED_MEMORY || RELOCATABLE - receiveInstance(result['instance'], result['module']); + return receiveInstance(result['instance'], result['module']); #else // TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193, the above line no longer optimizes out down to the following line. // When the regression is fixed, can restore the above PTHREADS-enabled path. - receiveInstance(result['instance']); + return receiveInstance(result['instance']); #endif } #endif // WASM_ASYNC_COMPILATION @@ -1076,8 +1076,7 @@ function getWasmImports() { // Instantiate from the module posted from the main thread. // We can just use sync instantiation in the worker. var instance = new WebAssembly.Instance(module, getWasmImports()); - receiveInstance(instance, module); - resolve(); + resolve(receiveInstance(instance, module)); }; }); } @@ -1095,16 +1094,16 @@ function getWasmImports() { try { #endif var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info); - receiveInstantiationResult(result); + var exports = receiveInstantiationResult(result); #if LOAD_SOURCE_MAP receiveSourceMapJSON(await getSourceMapAsync()); #endif - return result; + return exports; #if MODULARIZE } catch (e) { // If instantiation fails, reject the module ready promise. readyPromiseReject(e); - return; + return Promise.reject(e); } #endif #else // WASM_ASYNC_COMPILATION diff --git a/test/code_size/hello_webgl2_wasm.json b/test/code_size/hello_webgl2_wasm.json index 13919b590d957..d7738773ebc50 100644 --- a/test/code_size/hello_webgl2_wasm.json +++ b/test/code_size/hello_webgl2_wasm.json @@ -1,10 +1,10 @@ { "a.html": 454, "a.html.gz": 328, - "a.js": 4532, - "a.js.gz": 2315, + "a.js": 4538, + "a.js.gz": 2320, "a.wasm": 10402, "a.wasm.gz": 6703, - "total": 15388, - "total_gz": 9346 + "total": 15394, + "total_gz": 9351 } diff --git a/test/code_size/hello_webgl2_wasm2js.json b/test/code_size/hello_webgl2_wasm2js.json index d54f14a652c99..da83c09580bbe 100644 --- a/test/code_size/hello_webgl2_wasm2js.json +++ b/test/code_size/hello_webgl2_wasm2js.json @@ -1,8 +1,8 @@ { "a.html": 346, "a.html.gz": 262, - "a.js": 22200, - "a.js.gz": 11583, - "total": 22546, - "total_gz": 11845 + "a.js": 22206, + "a.js.gz": 11589, + "total": 22552, + "total_gz": 11851 } diff --git a/test/code_size/hello_webgl_wasm.json b/test/code_size/hello_webgl_wasm.json index e619b3f3321c3..e4c3af111aac8 100644 --- a/test/code_size/hello_webgl_wasm.json +++ b/test/code_size/hello_webgl_wasm.json @@ -1,10 +1,10 @@ { "a.html": 454, "a.html.gz": 328, - "a.js": 4070, - "a.js.gz": 2158, + "a.js": 4076, + "a.js.gz": 2163, "a.wasm": 10402, "a.wasm.gz": 6703, - "total": 14926, - "total_gz": 9189 + "total": 14932, + "total_gz": 9194 } diff --git a/test/code_size/hello_webgl_wasm2js.json b/test/code_size/hello_webgl_wasm2js.json index a01758dd16374..c2cb2b2deec67 100644 --- a/test/code_size/hello_webgl_wasm2js.json +++ b/test/code_size/hello_webgl_wasm2js.json @@ -1,8 +1,8 @@ { "a.html": 346, "a.html.gz": 262, - "a.js": 21726, - "a.js.gz": 11413, - "total": 22072, - "total_gz": 11675 + "a.js": 21732, + "a.js.gz": 11419, + "total": 22078, + "total_gz": 11681 } diff --git a/test/other/codesize/test_codesize_cxx_ctors1.gzsize b/test/other/codesize/test_codesize_cxx_ctors1.gzsize index f8c4d739e8274..737757b6409f6 100644 --- a/test/other/codesize/test_codesize_cxx_ctors1.gzsize +++ b/test/other/codesize/test_codesize_cxx_ctors1.gzsize @@ -1 +1 @@ -8482 +8479 diff --git a/test/other/codesize/test_codesize_cxx_ctors1.jssize b/test/other/codesize/test_codesize_cxx_ctors1.jssize index 3b3bc5532ae28..762198145a407 100644 --- a/test/other/codesize/test_codesize_cxx_ctors1.jssize +++ b/test/other/codesize/test_codesize_cxx_ctors1.jssize @@ -1 +1 @@ -20818 +20814 diff --git a/test/other/codesize/test_codesize_cxx_ctors2.gzsize b/test/other/codesize/test_codesize_cxx_ctors2.gzsize index 6ed96170748c2..4b2de216d1132 100644 --- a/test/other/codesize/test_codesize_cxx_ctors2.gzsize +++ b/test/other/codesize/test_codesize_cxx_ctors2.gzsize @@ -1 +1 @@ -8466 +8464 diff --git a/test/other/codesize/test_codesize_cxx_ctors2.jssize b/test/other/codesize/test_codesize_cxx_ctors2.jssize index 035c83c3d83de..8a83c476c8fbb 100644 --- a/test/other/codesize/test_codesize_cxx_ctors2.jssize +++ b/test/other/codesize/test_codesize_cxx_ctors2.jssize @@ -1 +1 @@ -20786 +20782 diff --git a/test/other/codesize/test_codesize_cxx_except.gzsize b/test/other/codesize/test_codesize_cxx_except.gzsize index e0a4790acc2ab..dcb81b5dcf759 100644 --- a/test/other/codesize/test_codesize_cxx_except.gzsize +++ b/test/other/codesize/test_codesize_cxx_except.gzsize @@ -1 +1 @@ -9516 +9515 diff --git a/test/other/codesize/test_codesize_cxx_except.jssize b/test/other/codesize/test_codesize_cxx_except.jssize index 5540250d5313e..be711e63391a0 100644 --- a/test/other/codesize/test_codesize_cxx_except.jssize +++ b/test/other/codesize/test_codesize_cxx_except.jssize @@ -1 +1 @@ -24663 +24659 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize index eb60637f84202..4b21b21bcebed 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm.gzsize +++ b/test/other/codesize/test_codesize_cxx_except_wasm.gzsize @@ -1 +1 @@ -8443 +8442 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm.jssize b/test/other/codesize/test_codesize_cxx_except_wasm.jssize index 61b087013e3d6..0acd83bc289ab 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm.jssize +++ b/test/other/codesize/test_codesize_cxx_except_wasm.jssize @@ -1 +1 @@ -20711 +20707 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize index eb60637f84202..4b21b21bcebed 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize +++ b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize @@ -1 +1 @@ -8443 +8442 diff --git a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.jssize b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.jssize index 61b087013e3d6..0acd83bc289ab 100644 --- a/test/other/codesize/test_codesize_cxx_except_wasm_exnref.jssize +++ b/test/other/codesize/test_codesize_cxx_except_wasm_exnref.jssize @@ -1 +1 @@ -20711 +20707 diff --git a/test/other/codesize/test_codesize_cxx_lto.jssize b/test/other/codesize/test_codesize_cxx_lto.jssize index 6b1a29e39cd0b..5710a05e36e4a 100644 --- a/test/other/codesize/test_codesize_cxx_lto.jssize +++ b/test/other/codesize/test_codesize_cxx_lto.jssize @@ -1 +1 @@ -20402 +20398 diff --git a/test/other/codesize/test_codesize_cxx_mangle.gzsize b/test/other/codesize/test_codesize_cxx_mangle.gzsize index 644357aa4e240..f3e9ad4de127c 100644 --- a/test/other/codesize/test_codesize_cxx_mangle.gzsize +++ b/test/other/codesize/test_codesize_cxx_mangle.gzsize @@ -1 +1 @@ -9523 +9520 diff --git a/test/other/codesize/test_codesize_cxx_mangle.jssize b/test/other/codesize/test_codesize_cxx_mangle.jssize index 5540250d5313e..be711e63391a0 100644 --- a/test/other/codesize/test_codesize_cxx_mangle.jssize +++ b/test/other/codesize/test_codesize_cxx_mangle.jssize @@ -1 +1 @@ -24663 +24659 diff --git a/test/other/codesize/test_codesize_cxx_noexcept.gzsize b/test/other/codesize/test_codesize_cxx_noexcept.gzsize index f8c4d739e8274..737757b6409f6 100644 --- a/test/other/codesize/test_codesize_cxx_noexcept.gzsize +++ b/test/other/codesize/test_codesize_cxx_noexcept.gzsize @@ -1 +1 @@ -8482 +8479 diff --git a/test/other/codesize/test_codesize_cxx_noexcept.jssize b/test/other/codesize/test_codesize_cxx_noexcept.jssize index 3b3bc5532ae28..762198145a407 100644 --- a/test/other/codesize/test_codesize_cxx_noexcept.jssize +++ b/test/other/codesize/test_codesize_cxx_noexcept.jssize @@ -1 +1 @@ -20818 +20814 diff --git a/test/other/codesize/test_codesize_cxx_wasmfs.gzsize b/test/other/codesize/test_codesize_cxx_wasmfs.gzsize index ac5764e2098c7..b61971c4899e0 100644 --- a/test/other/codesize/test_codesize_cxx_wasmfs.gzsize +++ b/test/other/codesize/test_codesize_cxx_wasmfs.gzsize @@ -1 +1 @@ -3769 +3767 diff --git a/test/other/codesize/test_codesize_cxx_wasmfs.jssize b/test/other/codesize/test_codesize_cxx_wasmfs.jssize index c5bde85823b0f..4d6a5c2242ae0 100644 --- a/test/other/codesize/test_codesize_cxx_wasmfs.jssize +++ b/test/other/codesize/test_codesize_cxx_wasmfs.jssize @@ -1 +1 @@ -8493 +8489 diff --git a/test/other/codesize/test_codesize_files_js_fs.gzsize b/test/other/codesize/test_codesize_files_js_fs.gzsize index 7afd85884af0e..9b4307790bc0a 100644 --- a/test/other/codesize/test_codesize_files_js_fs.gzsize +++ b/test/other/codesize/test_codesize_files_js_fs.gzsize @@ -1 +1 @@ -7621 +7619 diff --git a/test/other/codesize/test_codesize_files_js_fs.jssize b/test/other/codesize/test_codesize_files_js_fs.jssize index 9aa6c5e6556ea..4a1f1fc3b35f2 100644 --- a/test/other/codesize/test_codesize_files_js_fs.jssize +++ b/test/other/codesize/test_codesize_files_js_fs.jssize @@ -1 +1 @@ -18731 +18727 diff --git a/test/other/codesize/test_codesize_files_wasmfs.gzsize b/test/other/codesize/test_codesize_files_wasmfs.gzsize index f7374e5edea7f..fc6ded393e5f3 100644 --- a/test/other/codesize/test_codesize_files_wasmfs.gzsize +++ b/test/other/codesize/test_codesize_files_wasmfs.gzsize @@ -1 +1 @@ -2866 +2864 diff --git a/test/other/codesize/test_codesize_files_wasmfs.jssize b/test/other/codesize/test_codesize_files_wasmfs.jssize index c98f921104b33..b0e10db098a91 100644 --- a/test/other/codesize/test_codesize_files_wasmfs.jssize +++ b/test/other/codesize/test_codesize_files_wasmfs.jssize @@ -1 +1 @@ -6140 +6136 diff --git a/test/other/codesize/test_codesize_hello_O0.gzsize b/test/other/codesize/test_codesize_hello_O0.gzsize index 8ca7d7e2dcf2a..2e566b72e9754 100644 --- a/test/other/codesize/test_codesize_hello_O0.gzsize +++ b/test/other/codesize/test_codesize_hello_O0.gzsize @@ -1 +1 @@ -8003 +8001 diff --git a/test/other/codesize/test_codesize_hello_O0.jssize b/test/other/codesize/test_codesize_hello_O0.jssize index 1e88f55d68b32..ed158caffe7f4 100644 --- a/test/other/codesize/test_codesize_hello_O0.jssize +++ b/test/other/codesize/test_codesize_hello_O0.jssize @@ -1 +1 @@ -21535 +21526 diff --git a/test/other/codesize/test_codesize_hello_O1.gzsize b/test/other/codesize/test_codesize_hello_O1.gzsize index c98e88a99e28f..8361266fd249f 100644 --- a/test/other/codesize/test_codesize_hello_O1.gzsize +++ b/test/other/codesize/test_codesize_hello_O1.gzsize @@ -1 +1 @@ -2713 +2710 diff --git a/test/other/codesize/test_codesize_hello_O1.jssize b/test/other/codesize/test_codesize_hello_O1.jssize index 6fdb8ccd778a3..b1fed5923c9bd 100644 --- a/test/other/codesize/test_codesize_hello_O1.jssize +++ b/test/other/codesize/test_codesize_hello_O1.jssize @@ -1 +1 @@ -6921 +6909 diff --git a/test/other/codesize/test_codesize_hello_O2.gzsize b/test/other/codesize/test_codesize_hello_O2.gzsize index cc278bd694d3e..9b65630a860d2 100644 --- a/test/other/codesize/test_codesize_hello_O2.gzsize +++ b/test/other/codesize/test_codesize_hello_O2.gzsize @@ -1 +1 @@ -2369 +2367 diff --git a/test/other/codesize/test_codesize_hello_O2.jssize b/test/other/codesize/test_codesize_hello_O2.jssize index 30162af6fe2dd..8af67d43171a1 100644 --- a/test/other/codesize/test_codesize_hello_O2.jssize +++ b/test/other/codesize/test_codesize_hello_O2.jssize @@ -1 +1 @@ -4844 +4840 diff --git a/test/other/codesize/test_codesize_hello_O3.gzsize b/test/other/codesize/test_codesize_hello_O3.gzsize index cc6f0ac7ecffd..9294c7754fde1 100644 --- a/test/other/codesize/test_codesize_hello_O3.gzsize +++ b/test/other/codesize/test_codesize_hello_O3.gzsize @@ -1 +1 @@ -2283 +2281 diff --git a/test/other/codesize/test_codesize_hello_O3.jssize b/test/other/codesize/test_codesize_hello_O3.jssize index 9bce5583b99b7..54f5b2754d8c8 100644 --- a/test/other/codesize/test_codesize_hello_O3.jssize +++ b/test/other/codesize/test_codesize_hello_O3.jssize @@ -1 +1 @@ -4695 +4691 diff --git a/test/other/codesize/test_codesize_hello_Os.gzsize b/test/other/codesize/test_codesize_hello_Os.gzsize index cc6f0ac7ecffd..9294c7754fde1 100644 --- a/test/other/codesize/test_codesize_hello_Os.gzsize +++ b/test/other/codesize/test_codesize_hello_Os.gzsize @@ -1 +1 @@ -2283 +2281 diff --git a/test/other/codesize/test_codesize_hello_Os.jssize b/test/other/codesize/test_codesize_hello_Os.jssize index 9bce5583b99b7..54f5b2754d8c8 100644 --- a/test/other/codesize/test_codesize_hello_Os.jssize +++ b/test/other/codesize/test_codesize_hello_Os.jssize @@ -1 +1 @@ -4695 +4691 diff --git a/test/other/codesize/test_codesize_hello_Oz.gzsize b/test/other/codesize/test_codesize_hello_Oz.gzsize index 42752c3ef1f12..65629867eaa09 100644 --- a/test/other/codesize/test_codesize_hello_Oz.gzsize +++ b/test/other/codesize/test_codesize_hello_Oz.gzsize @@ -1 +1 @@ -2265 +2264 diff --git a/test/other/codesize/test_codesize_hello_Oz.jssize b/test/other/codesize/test_codesize_hello_Oz.jssize index 77d471ad303a9..092b8f173fcb7 100644 --- a/test/other/codesize/test_codesize_hello_Oz.jssize +++ b/test/other/codesize/test_codesize_hello_Oz.jssize @@ -1 +1 @@ -4662 +4658 diff --git a/test/other/codesize/test_codesize_hello_dylink.gzsize b/test/other/codesize/test_codesize_hello_dylink.gzsize index 06e102d5685af..457dba7d4e56d 100644 --- a/test/other/codesize/test_codesize_hello_dylink.gzsize +++ b/test/other/codesize/test_codesize_hello_dylink.gzsize @@ -1 +1 @@ -6150 +6155 diff --git a/test/other/codesize/test_codesize_hello_dylink.jssize b/test/other/codesize/test_codesize_hello_dylink.jssize index 7a9400801574e..95a7e2bcec768 100644 --- a/test/other/codesize/test_codesize_hello_dylink.jssize +++ b/test/other/codesize/test_codesize_hello_dylink.jssize @@ -1 +1 @@ -13609 +13626 diff --git a/test/other/codesize/test_codesize_hello_export_nothing.gzsize b/test/other/codesize/test_codesize_hello_export_nothing.gzsize index 15475a3d5fc2c..eeda1003324b0 100644 --- a/test/other/codesize/test_codesize_hello_export_nothing.gzsize +++ b/test/other/codesize/test_codesize_hello_export_nothing.gzsize @@ -1 +1 @@ -1667 +1664 diff --git a/test/other/codesize/test_codesize_hello_export_nothing.jssize b/test/other/codesize/test_codesize_hello_export_nothing.jssize index 5f3db86bbc3ea..01aa7a842cfcd 100644 --- a/test/other/codesize/test_codesize_hello_export_nothing.jssize +++ b/test/other/codesize/test_codesize_hello_export_nothing.jssize @@ -1 +1 @@ -3575 +3571 diff --git a/test/other/codesize/test_codesize_hello_wasmfs.gzsize b/test/other/codesize/test_codesize_hello_wasmfs.gzsize index cc6f0ac7ecffd..9294c7754fde1 100644 --- a/test/other/codesize/test_codesize_hello_wasmfs.gzsize +++ b/test/other/codesize/test_codesize_hello_wasmfs.gzsize @@ -1 +1 @@ -2283 +2281 diff --git a/test/other/codesize/test_codesize_hello_wasmfs.jssize b/test/other/codesize/test_codesize_hello_wasmfs.jssize index 9bce5583b99b7..54f5b2754d8c8 100644 --- a/test/other/codesize/test_codesize_hello_wasmfs.jssize +++ b/test/other/codesize/test_codesize_hello_wasmfs.jssize @@ -1 +1 @@ -4695 +4691 diff --git a/test/other/codesize/test_codesize_libcxxabi_message_O3.gzsize b/test/other/codesize/test_codesize_libcxxabi_message_O3.gzsize index 86fc8f4d80b5a..d9238636e9b56 100644 --- a/test/other/codesize/test_codesize_libcxxabi_message_O3.gzsize +++ b/test/other/codesize/test_codesize_libcxxabi_message_O3.gzsize @@ -1 +1 @@ -1862 +1859 diff --git a/test/other/codesize/test_codesize_libcxxabi_message_O3.jssize b/test/other/codesize/test_codesize_libcxxabi_message_O3.jssize index 58f5850ae5fcf..5e583deec4ef3 100644 --- a/test/other/codesize/test_codesize_libcxxabi_message_O3.jssize +++ b/test/other/codesize/test_codesize_libcxxabi_message_O3.jssize @@ -1 +1 @@ -3938 +3934 diff --git a/test/other/codesize/test_codesize_libcxxabi_message_O3_standalone.gzsize b/test/other/codesize/test_codesize_libcxxabi_message_O3_standalone.gzsize index 8bae76d7966a2..d9575c3ff89c3 100644 --- a/test/other/codesize/test_codesize_libcxxabi_message_O3_standalone.gzsize +++ b/test/other/codesize/test_codesize_libcxxabi_message_O3_standalone.gzsize @@ -1 +1 @@ -1899 +1897 diff --git a/test/other/codesize/test_codesize_libcxxabi_message_O3_standalone.jssize b/test/other/codesize/test_codesize_libcxxabi_message_O3_standalone.jssize index 6b2af3f880b0c..c5829fbe7542d 100644 --- a/test/other/codesize/test_codesize_libcxxabi_message_O3_standalone.jssize +++ b/test/other/codesize/test_codesize_libcxxabi_message_O3_standalone.jssize @@ -1 +1 @@ -3986 +3982 diff --git a/test/other/codesize/test_codesize_mem_O3.jssize b/test/other/codesize/test_codesize_mem_O3.jssize index ddeb3cf88bf70..a377090b30deb 100644 --- a/test/other/codesize/test_codesize_mem_O3.jssize +++ b/test/other/codesize/test_codesize_mem_O3.jssize @@ -1 +1 @@ -4830 +4826 diff --git a/test/other/codesize/test_codesize_mem_O3_grow.gzsize b/test/other/codesize/test_codesize_mem_O3_grow.gzsize index ea5f1c5174ecc..4edaf066bde20 100644 --- a/test/other/codesize/test_codesize_mem_O3_grow.gzsize +++ b/test/other/codesize/test_codesize_mem_O3_grow.gzsize @@ -1 +1 @@ -2461 +2459 diff --git a/test/other/codesize/test_codesize_mem_O3_grow.jssize b/test/other/codesize/test_codesize_mem_O3_grow.jssize index 581cc8f752a1c..f2e5995fa3eb6 100644 --- a/test/other/codesize/test_codesize_mem_O3_grow.jssize +++ b/test/other/codesize/test_codesize_mem_O3_grow.jssize @@ -1 +1 @@ -5115 +5110 diff --git a/test/other/codesize/test_codesize_mem_O3_grow_standalone.gzsize b/test/other/codesize/test_codesize_mem_O3_grow_standalone.gzsize index 5e7c8b88a0264..0b460a920465c 100644 --- a/test/other/codesize/test_codesize_mem_O3_grow_standalone.gzsize +++ b/test/other/codesize/test_codesize_mem_O3_grow_standalone.gzsize @@ -1 +1 @@ -2164 +2161 diff --git a/test/other/codesize/test_codesize_mem_O3_grow_standalone.jssize b/test/other/codesize/test_codesize_mem_O3_grow_standalone.jssize index 1f440269b96d4..d006b5a61362b 100644 --- a/test/other/codesize/test_codesize_mem_O3_grow_standalone.jssize +++ b/test/other/codesize/test_codesize_mem_O3_grow_standalone.jssize @@ -1 +1 @@ -4523 +4519 diff --git a/test/other/codesize/test_codesize_mem_O3_standalone.gzsize b/test/other/codesize/test_codesize_mem_O3_standalone.gzsize index 10c8452b2c3ab..37a8c942bc967 100644 --- a/test/other/codesize/test_codesize_mem_O3_standalone.gzsize +++ b/test/other/codesize/test_codesize_mem_O3_standalone.gzsize @@ -1 +1 @@ -2128 +2125 diff --git a/test/other/codesize/test_codesize_mem_O3_standalone.jssize b/test/other/codesize/test_codesize_mem_O3_standalone.jssize index ab5135ded797f..9fe1dca4db53f 100644 --- a/test/other/codesize/test_codesize_mem_O3_standalone.jssize +++ b/test/other/codesize/test_codesize_mem_O3_standalone.jssize @@ -1 +1 @@ -4455 +4451 diff --git a/test/other/codesize/test_codesize_mem_O3_standalone_lib.gzsize b/test/other/codesize/test_codesize_mem_O3_standalone_lib.gzsize index c34a5b9bd9c60..0b90508d29f8e 100644 --- a/test/other/codesize/test_codesize_mem_O3_standalone_lib.gzsize +++ b/test/other/codesize/test_codesize_mem_O3_standalone_lib.gzsize @@ -1 +1 @@ -1885 +1883 diff --git a/test/other/codesize/test_codesize_mem_O3_standalone_lib.jssize b/test/other/codesize/test_codesize_mem_O3_standalone_lib.jssize index 6cd1cb4835d89..db8dc2bc0d028 100644 --- a/test/other/codesize/test_codesize_mem_O3_standalone_lib.jssize +++ b/test/other/codesize/test_codesize_mem_O3_standalone_lib.jssize @@ -1 +1 @@ -3985 +3981 diff --git a/test/other/codesize/test_codesize_mem_O3_standalone_narg.gzsize b/test/other/codesize/test_codesize_mem_O3_standalone_narg.gzsize index 8bae76d7966a2..d9575c3ff89c3 100644 --- a/test/other/codesize/test_codesize_mem_O3_standalone_narg.gzsize +++ b/test/other/codesize/test_codesize_mem_O3_standalone_narg.gzsize @@ -1 +1 @@ -1899 +1897 diff --git a/test/other/codesize/test_codesize_mem_O3_standalone_narg.jssize b/test/other/codesize/test_codesize_mem_O3_standalone_narg.jssize index 6b2af3f880b0c..c5829fbe7542d 100644 --- a/test/other/codesize/test_codesize_mem_O3_standalone_narg.jssize +++ b/test/other/codesize/test_codesize_mem_O3_standalone_narg.jssize @@ -1 +1 @@ -3986 +3982 diff --git a/test/other/codesize/test_codesize_mem_O3_standalone_narg_flto.gzsize b/test/other/codesize/test_codesize_mem_O3_standalone_narg_flto.gzsize index 8bae76d7966a2..d9575c3ff89c3 100644 --- a/test/other/codesize/test_codesize_mem_O3_standalone_narg_flto.gzsize +++ b/test/other/codesize/test_codesize_mem_O3_standalone_narg_flto.gzsize @@ -1 +1 @@ -1899 +1897 diff --git a/test/other/codesize/test_codesize_mem_O3_standalone_narg_flto.jssize b/test/other/codesize/test_codesize_mem_O3_standalone_narg_flto.jssize index 6b2af3f880b0c..c5829fbe7542d 100644 --- a/test/other/codesize/test_codesize_mem_O3_standalone_narg_flto.jssize +++ b/test/other/codesize/test_codesize_mem_O3_standalone_narg_flto.jssize @@ -1 +1 @@ -3986 +3982 diff --git a/test/other/codesize/test_codesize_minimal_64.gzsize b/test/other/codesize/test_codesize_minimal_64.gzsize index 2a63ccf651217..4d851a7800ac5 100644 --- a/test/other/codesize/test_codesize_minimal_64.gzsize +++ b/test/other/codesize/test_codesize_minimal_64.gzsize @@ -1 +1 @@ -1439 +1441 diff --git a/test/other/codesize/test_codesize_minimal_64.jssize b/test/other/codesize/test_codesize_minimal_64.jssize index 31410c0cab693..9bcc9f43c3d2c 100644 --- a/test/other/codesize/test_codesize_minimal_64.jssize +++ b/test/other/codesize/test_codesize_minimal_64.jssize @@ -1 +1 @@ -3064 +3058 diff --git a/test/other/codesize/test_codesize_minimal_O1.gzsize b/test/other/codesize/test_codesize_minimal_O1.gzsize index f02edd5f91078..641d5f59ecacf 100644 --- a/test/other/codesize/test_codesize_minimal_O1.gzsize +++ b/test/other/codesize/test_codesize_minimal_O1.gzsize @@ -1 +1 @@ -1520 +1524 diff --git a/test/other/codesize/test_codesize_minimal_O1.jssize b/test/other/codesize/test_codesize_minimal_O1.jssize index 7cca7c9e17bf6..799c77152539d 100644 --- a/test/other/codesize/test_codesize_minimal_O1.jssize +++ b/test/other/codesize/test_codesize_minimal_O1.jssize @@ -1 +1 @@ -3664 +3653 diff --git a/test/other/codesize/test_codesize_minimal_O2.jssize b/test/other/codesize/test_codesize_minimal_O2.jssize index aa57446358cb9..ed4e7db85ed49 100644 --- a/test/other/codesize/test_codesize_minimal_O2.jssize +++ b/test/other/codesize/test_codesize_minimal_O2.jssize @@ -1 +1 @@ -2769 +2763 diff --git a/test/other/codesize/test_codesize_minimal_O3.gzsize b/test/other/codesize/test_codesize_minimal_O3.gzsize index 7345521b14101..a9449958c6a77 100644 --- a/test/other/codesize/test_codesize_minimal_O3.gzsize +++ b/test/other/codesize/test_codesize_minimal_O3.gzsize @@ -1 +1 @@ -1336 +1338 diff --git a/test/other/codesize/test_codesize_minimal_O3.jssize b/test/other/codesize/test_codesize_minimal_O3.jssize index 8ef17f6cef8d3..c98e88a99e28f 100644 --- a/test/other/codesize/test_codesize_minimal_O3.jssize +++ b/test/other/codesize/test_codesize_minimal_O3.jssize @@ -1 +1 @@ -2719 +2713 diff --git a/test/other/codesize/test_codesize_minimal_Os.gzsize b/test/other/codesize/test_codesize_minimal_Os.gzsize index 7345521b14101..a9449958c6a77 100644 --- a/test/other/codesize/test_codesize_minimal_Os.gzsize +++ b/test/other/codesize/test_codesize_minimal_Os.gzsize @@ -1 +1 @@ -1336 +1338 diff --git a/test/other/codesize/test_codesize_minimal_Os.jssize b/test/other/codesize/test_codesize_minimal_Os.jssize index 8ef17f6cef8d3..c98e88a99e28f 100644 --- a/test/other/codesize/test_codesize_minimal_Os.jssize +++ b/test/other/codesize/test_codesize_minimal_Os.jssize @@ -1 +1 @@ -2719 +2713 diff --git a/test/other/codesize/test_codesize_minimal_Oz-ctors.gzsize b/test/other/codesize/test_codesize_minimal_Oz-ctors.gzsize index d378cb0bf85c3..a38c571765e98 100644 --- a/test/other/codesize/test_codesize_minimal_Oz-ctors.gzsize +++ b/test/other/codesize/test_codesize_minimal_Oz-ctors.gzsize @@ -1 +1 @@ -1327 +1328 diff --git a/test/other/codesize/test_codesize_minimal_Oz-ctors.jssize b/test/other/codesize/test_codesize_minimal_Oz-ctors.jssize index f3bb5816bff9b..1c0fb1915fe42 100644 --- a/test/other/codesize/test_codesize_minimal_Oz-ctors.jssize +++ b/test/other/codesize/test_codesize_minimal_Oz-ctors.jssize @@ -1 +1 @@ -2704 +2698 diff --git a/test/other/codesize/test_codesize_minimal_Oz.gzsize b/test/other/codesize/test_codesize_minimal_Oz.gzsize index 7345521b14101..a9449958c6a77 100644 --- a/test/other/codesize/test_codesize_minimal_Oz.gzsize +++ b/test/other/codesize/test_codesize_minimal_Oz.gzsize @@ -1 +1 @@ -1336 +1338 diff --git a/test/other/codesize/test_codesize_minimal_Oz.jssize b/test/other/codesize/test_codesize_minimal_Oz.jssize index 8ef17f6cef8d3..c98e88a99e28f 100644 --- a/test/other/codesize/test_codesize_minimal_Oz.jssize +++ b/test/other/codesize/test_codesize_minimal_Oz.jssize @@ -1 +1 @@ -2719 +2713 diff --git a/test/other/codesize/test_codesize_minimal_esm.gzsize b/test/other/codesize/test_codesize_minimal_esm.gzsize index 84abd852d3092..3d86ec6498f3f 100644 --- a/test/other/codesize/test_codesize_minimal_esm.gzsize +++ b/test/other/codesize/test_codesize_minimal_esm.gzsize @@ -1 +1 @@ -1487 +1500 diff --git a/test/other/codesize/test_codesize_minimal_esm.jssize b/test/other/codesize/test_codesize_minimal_esm.jssize index 1877dcdd8387c..5fd68c5a45f3d 100644 --- a/test/other/codesize/test_codesize_minimal_esm.jssize +++ b/test/other/codesize/test_codesize_minimal_esm.jssize @@ -1 +1 @@ -3095 +3114 diff --git a/test/other/codesize/test_codesize_minimal_pthreads.gzsize b/test/other/codesize/test_codesize_minimal_pthreads.gzsize index 529e64fdfb43e..af9bc346b7a89 100644 --- a/test/other/codesize/test_codesize_minimal_pthreads.gzsize +++ b/test/other/codesize/test_codesize_minimal_pthreads.gzsize @@ -1 +1 @@ -4118 +4125 diff --git a/test/other/codesize/test_codesize_minimal_pthreads.jssize b/test/other/codesize/test_codesize_minimal_pthreads.jssize index e4b77e6fc2965..ef124865d8379 100644 --- a/test/other/codesize/test_codesize_minimal_pthreads.jssize +++ b/test/other/codesize/test_codesize_minimal_pthreads.jssize @@ -1 +1 @@ -8556 +8572 diff --git a/test/other/codesize/test_codesize_minimal_wasmfs.gzsize b/test/other/codesize/test_codesize_minimal_wasmfs.gzsize index 7345521b14101..a9449958c6a77 100644 --- a/test/other/codesize/test_codesize_minimal_wasmfs.gzsize +++ b/test/other/codesize/test_codesize_minimal_wasmfs.gzsize @@ -1 +1 @@ -1336 +1338 diff --git a/test/other/codesize/test_codesize_minimal_wasmfs.jssize b/test/other/codesize/test_codesize_minimal_wasmfs.jssize index 8ef17f6cef8d3..c98e88a99e28f 100644 --- a/test/other/codesize/test_codesize_minimal_wasmfs.jssize +++ b/test/other/codesize/test_codesize_minimal_wasmfs.jssize @@ -1 +1 @@ -2719 +2713 diff --git a/test/other/test_unoptimized_code_size.js.size b/test/other/test_unoptimized_code_size.js.size index 6f75fa3a9a413..f3f35fa00f766 100644 --- a/test/other/test_unoptimized_code_size.js.size +++ b/test/other/test_unoptimized_code_size.js.size @@ -1 +1 @@ -53709 +53731 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 e55af0c20aeb7..6a64d917e56ba 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 @@ -29018 +29040 diff --git a/test/other/test_unoptimized_code_size_strict.js.size b/test/other/test_unoptimized_code_size_strict.js.size index ca6f382d48289..b1e8288a3b676 100644 --- a/test/other/test_unoptimized_code_size_strict.js.size +++ b/test/other/test_unoptimized_code_size_strict.js.size @@ -1 +1 @@ -52531 +52553 diff --git a/test/test_unicode_js_library.out b/test/test_unicode_js_library.out index c96bed51b0188..aa42466399fb6 100644 --- a/test/test_unicode_js_library.out +++ b/test/test_unicode_js_library.out @@ -1,2 +1,2 @@ -Unicode postjs: àČšñéáúÍųåêâăščếệüçλληνικάбългарскиPусскийСрпскиУкраїнська한국어中文普通话(中国大陆)普通话(香港)中文(台灣)粵語(香港)日本語हिन्दीภาษาไทย Unicode snowman ☃ says hello! àČšñéáúÍųåêâăščếệüçλληνικάбългарскиPусскийСрпскиУкраїнська한국어中文普通话(中国大陆)普通话(香港)中文(台灣)粵語(香港)日本語हिन्दीภาษาไทย +Unicode postjs: àČšñéáúÍųåêâăščếệüçλληνικάбългарскиPусскийСрпскиУкраїнська한국어中文普通话(中国大陆)普通话(香港)中文(台灣)粵語(香港)日本語हिन्दीภาษาไทย diff --git a/tools/emscripten.py b/tools/emscripten.py index 250432f5462f7..5c4e549ea3885 100644 --- a/tools/emscripten.py +++ b/tools/emscripten.py @@ -893,6 +893,16 @@ def create_sending(metadata, library_symbols): return '{\n ' + ',\n '.join(elems) + '\n}' +def can_use_await(): + # In MODULARIZE mode we can use `await` since the factory function itself + # is marked as `async` and the generated code all lives inside that factory + # function. + # However, because closure does see this (it runs only on the inner code), + # it sees this as a top-level-await, which it does not yet support. + # FIXME(https://github.com/emscripten-core/emscripten/issues/23158) + return settings.MODULARIZE and not settings.USE_CLOSURE_COMPILER + + def make_export_wrappers(function_exports): assert not settings.MINIMAL_RUNTIME @@ -932,7 +942,7 @@ def install_wrapper(sym): # With assertions enabled we create a wrapper that are calls get routed through, for # the lifetime of the program. wrapper += f"createExportWrapper('{name}', {nargs});" - elif settings.WASM_ASYNC_COMPILATION or settings.PTHREADS: + elif (settings.WASM_ASYNC_COMPILATION and not can_use_await()) or settings.PTHREADS: # With WASM_ASYNC_COMPILATION wrapper will replace the global var and Module var on # first use. args = [f'a{i}' for i in range(nargs)] @@ -998,7 +1008,11 @@ def create_module(receiving, metadata, global_exports, library_symbols): if not settings.MINIMAL_RUNTIME: if settings.WASM_ASYNC_COMPILATION: - module.append("var wasmExports;\ncreateWasm();\n") + if can_use_await(): + # In modullize mode the generated code is within a factory function. + module.append("var wasmExports = await createWasm();\n") + else: + module.append("var wasmExports;\ncreateWasm();\n") else: module.append("var wasmExports = createWasm();\n") diff --git a/tools/link.py b/tools/link.py index 88ef0822e8a23..203078a8ae23a 100644 --- a/tools/link.py +++ b/tools/link.py @@ -2379,23 +2379,23 @@ def modularize(): logger.debug(f'Modularizing, assigning to var {settings.EXPORT_NAME}') generated_js = read_file(final_js) - # When targetting node and ES6 we use `await import ..` in the generated code - # so the outer function needs to be marked as async. - async_emit = '' - if settings.EXPORT_ES6 and settings.ENVIRONMENT_MAY_BE_NODE: - async_emit = 'async ' + if settings.WASM_ASYNC_COMPILATION or (settings.EXPORT_ES6 and settings.ENVIRONMENT_MAY_BE_NODE): + maybe_async = 'async ' + else: + maybe_async = '' if settings.MODULARIZE == 'instance': wrapper_function = ''' -export default async function init(moduleArg = {}) { +export default %(maybe_async)s function init(moduleArg = {}) { var moduleRtn; %(generated_js)s - return await moduleRtn; + return moduleRtn; } ''' % { - 'generated_js': generated_js + 'generated_js': generated_js, + 'maybe_async': maybe_async, } else: wrapper_function = ''' @@ -2407,7 +2407,7 @@ def modularize(): return moduleRtn; } ''' % { - 'maybe_async': async_emit, + 'maybe_async': maybe_async, 'generated_js': generated_js }