diff --git a/src/closure-externs/closure-externs.js b/src/closure-externs/closure-externs.js index 54484b15cca31..20f1126daa77d 100644 --- a/src/closure-externs/closure-externs.js +++ b/src/closure-externs/closure-externs.js @@ -214,3 +214,8 @@ ArrayBuffer.prototype.resizable; /** @type {boolean} */ SharedArrayBuffer.prototype.growable; + +/** + * @return {!ReadableStream} + */ +Blob.prototype.stream = function() {}; diff --git a/src/closure-externs/node-externs.js b/src/closure-externs/node-externs.js index 35c1d058dc19a..30cf9f0099a40 100644 --- a/src/closure-externs/node-externs.js +++ b/src/closure-externs/node-externs.js @@ -131,6 +131,14 @@ fs.Stats.prototype.ctimeMs; */ fs.Stats.prototype.blksize; +/** + * @param {string|!Buffer|!URL} path + * @param {{type: (string|undefined)}=} options + * @return {!Promise} + * @nosideeffects + */ +fs.openAsBlob = function (path, options) {}; + /** * @param {string} p * @return {boolean} diff --git a/src/postamble_minimal.js b/src/postamble_minimal.js index a721f98a42259..7033a7a15c11b 100644 --- a/src/postamble_minimal.js +++ b/src/postamble_minimal.js @@ -107,7 +107,7 @@ function run() { #else // Run a persistent (never-exiting) application starting at main(). _main({{{ argc_argv() }}}); -#endif +#endif #if STACK_OVERFLOW_CHECK checkStackCookie(); @@ -189,10 +189,13 @@ var imports = { {{{ #if EXPORT_ES6 && !ENVIRONMENT_MAY_BE_AUDIO_WORKLET const moduleUrl = `new URL('${TARGET_BASENAME}.wasm', import.meta.url)`; +const nodeWasmPath = `require('node:url').fileURLToPath(${moduleUrl})`; #elif !EXPORT_ES6 || AUDIO_WORKLET const moduleUrl = `'${TARGET_BASENAME}.wasm'`; +const nodeWasmPath = `__dirname + '/${TARGET_BASENAME}.wasm'`; #else const moduleUrl = `ENVIRONMENT_IS_AUDIO_WORKLET ? '${TARGET_BASENAME}.wasm' : new URL('${TARGET_BASENAME}.wasm', import.meta.url)`; +const nodeWasmPath = `__dirname + '/${TARGET_BASENAME}.wasm'`; #endif }}} // https://caniuse.com/#feat=wasm and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming @@ -206,13 +209,18 @@ assert(WebAssembly.instantiateStreaming || Module['wasm'], 'Must load WebAssembl instantiatePromise = #endif (WebAssembly.instantiateStreaming -#if ENVIRONMENT_MAY_BE_NODE - // Avoid using instantiateStreaming() on Node.js since the `fetch()` API - // does not support `file://` URLs. - // See: https://github.com/emscripten-core/emscripten/pull/16917 - && !ENVIRONMENT_IS_NODE -#endif - ? WebAssembly.instantiateStreaming(fetch({{{ moduleUrl }}}), imports) + ? (ENVIRONMENT_IS_NODE + // Avoid using `fetch()` API on Node.js since it does not support `file://` + // URLs. Instead, provide a Response that wraps a blob with the correct + // MIME type. + // See: https://github.com/emscripten-core/emscripten/pull/16917 + ? WebAssembly.instantiateStreaming( + require('node:fs') + .openAsBlob({{{ nodeWasmPath }}}) + .then((blob) => new Response(blob.stream(), { headers: { 'Content-Type': 'application/wasm' } })), + imports, + ) + : WebAssembly.instantiateStreaming(fetch({{{ moduleUrl }}}), imports)) : WebAssembly.instantiate(Module['wasm'], imports)).then((output) => { #else #if MODULARIZE || AUDIO_WORKLET diff --git a/src/preamble.js b/src/preamble.js index 54b537db5e8cc..84b53facded61 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -708,9 +708,8 @@ async function instantiateAsync(binary, binaryFile, imports) { && !isFileURI(binaryFile) #endif #if ENVIRONMENT_MAY_BE_NODE - // Avoid using instantiateStreaming() on Node.js since the `fetch()` API - // does not support `file://` URLs. - // See: https://github.com/emscripten-core/emscripten/pull/16917 + // Node.js is handled in its own branch below, since it can't use fetch() + // to stream a `file://` URL && !ENVIRONMENT_IS_NODE #endif #if ENVIRONMENT_MAY_BE_SHELL @@ -730,6 +729,30 @@ async function instantiateAsync(binary, binaryFile, imports) { // fall back of instantiateArrayBuffer below }; } +#if ENVIRONMENT_MAY_BE_NODE + else if (!binary && ENVIRONMENT_IS_NODE) { + // Avoid using `fetch()` API on Node.js since it does not support `file://` + // URLs. Instead, provide a Response that wraps a fs read stream with the + // correct MIME type. + // See: https://github.com/emscripten-core/emscripten/pull/16917 + try { + var url = require('node:url'); + var nodeBinaryFile = isFileURI(binaryFile) ? url.fileURLToPath(binaryFile) : binaryFile; + var response = fs.openAsBlob(nodeBinaryFile).then( + (blob) => + new Response(blob.stream(), { + headers: { 'Content-Type': 'application/wasm' }, + }), + ); + var instantiationResult = await WebAssembly.instantiateStreaming(response, imports); + return instantiationResult; + } catch (reason) { + err(`wasm streaming compile failed: ${reason}`); + err('falling back to ArrayBuffer instantiation'); + // fall back of instantiateArrayBuffer below + }; + } +#endif #endif // !SINGLE_FILE return instantiateArrayBuffer(binaryFile, imports); } diff --git a/test/codesize/test_codesize_cxx_ctors1.json b/test/codesize/test_codesize_cxx_ctors1.json index ef85ddc7054d5..536f31b502053 100644 --- a/test/codesize/test_codesize_cxx_ctors1.json +++ b/test/codesize/test_codesize_cxx_ctors1.json @@ -1,10 +1,10 @@ { - "a.out.js": 19224, - "a.out.js.gz": 8124, + "a.out.js": 19546, + "a.out.js.gz": 8232, "a.out.nodebug.wasm": 133971, "a.out.nodebug.wasm.gz": 51271, - "total": 153195, - "total_gz": 59395, + "total": 153517, + "total_gz": 59503, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_cxx_ctors2.json b/test/codesize/test_codesize_cxx_ctors2.json index 9745a6316785d..d6256808f4015 100644 --- a/test/codesize/test_codesize_cxx_ctors2.json +++ b/test/codesize/test_codesize_cxx_ctors2.json @@ -1,10 +1,10 @@ { - "a.out.js": 19201, - "a.out.js.gz": 8107, + "a.out.js": 19523, + "a.out.js.gz": 8215, "a.out.nodebug.wasm": 133403, "a.out.nodebug.wasm.gz": 50959, - "total": 152604, - "total_gz": 59066, + "total": 152926, + "total_gz": 59174, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_cxx_except.json b/test/codesize/test_codesize_cxx_except.json index 8e083d22ec62b..20cfd3e84d81c 100644 --- a/test/codesize/test_codesize_cxx_except.json +++ b/test/codesize/test_codesize_cxx_except.json @@ -1,10 +1,10 @@ { - "a.out.js": 22917, - "a.out.js.gz": 9082, + "a.out.js": 23238, + "a.out.js.gz": 9194, "a.out.nodebug.wasm": 176383, "a.out.nodebug.wasm.gz": 58776, - "total": 199300, - "total_gz": 67858, + "total": 199621, + "total_gz": 67970, "sent": [ "__cxa_begin_catch", "__cxa_end_catch", diff --git a/test/codesize/test_codesize_cxx_except_wasm.json b/test/codesize/test_codesize_cxx_except_wasm.json index acce5eb08a6f9..8959a9ee486fb 100644 --- a/test/codesize/test_codesize_cxx_except_wasm.json +++ b/test/codesize/test_codesize_cxx_except_wasm.json @@ -1,10 +1,10 @@ { - "a.out.js": 19023, - "a.out.js.gz": 8039, + "a.out.js": 19345, + "a.out.js.gz": 8151, "a.out.nodebug.wasm": 149640, "a.out.nodebug.wasm.gz": 56311, - "total": 168663, - "total_gz": 64350, + "total": 168985, + "total_gz": 64462, "sent": [ "_abort_js", "_tzset_js", diff --git a/test/codesize/test_codesize_cxx_except_wasm_legacy.json b/test/codesize/test_codesize_cxx_except_wasm_legacy.json index 7d2e3ac6023e4..a0bdc5ed08a98 100644 --- a/test/codesize/test_codesize_cxx_except_wasm_legacy.json +++ b/test/codesize/test_codesize_cxx_except_wasm_legacy.json @@ -1,10 +1,10 @@ { - "a.out.js": 19101, - "a.out.js.gz": 8065, + "a.out.js": 19423, + "a.out.js.gz": 8174, "a.out.nodebug.wasm": 147422, "a.out.nodebug.wasm.gz": 55982, - "total": 166523, - "total_gz": 64047, + "total": 166845, + "total_gz": 64156, "sent": [ "_abort_js", "_tzset_js", diff --git a/test/codesize/test_codesize_cxx_lto.json b/test/codesize/test_codesize_cxx_lto.json index 5bf114b165af0..ee0d9a34b1358 100644 --- a/test/codesize/test_codesize_cxx_lto.json +++ b/test/codesize/test_codesize_cxx_lto.json @@ -1,10 +1,10 @@ { - "a.out.js": 18568, - "a.out.js.gz": 7818, + "a.out.js": 18890, + "a.out.js.gz": 7931, "a.out.nodebug.wasm": 101064, "a.out.nodebug.wasm.gz": 38292, - "total": 119632, - "total_gz": 46110, + "total": 119954, + "total_gz": 46223, "sent": [ "a (emscripten_resize_heap)", "b (_setitimer_js)", diff --git a/test/codesize/test_codesize_cxx_mangle.json b/test/codesize/test_codesize_cxx_mangle.json index a9df7ddb5796f..545ac3d1d0e2e 100644 --- a/test/codesize/test_codesize_cxx_mangle.json +++ b/test/codesize/test_codesize_cxx_mangle.json @@ -1,10 +1,10 @@ { - "a.out.js": 22967, - "a.out.js.gz": 9103, + "a.out.js": 23288, + "a.out.js.gz": 9214, "a.out.nodebug.wasm": 242663, "a.out.nodebug.wasm.gz": 81001, - "total": 265630, - "total_gz": 90104, + "total": 265951, + "total_gz": 90215, "sent": [ "__cxa_begin_catch", "__cxa_end_catch", diff --git a/test/codesize/test_codesize_cxx_noexcept.json b/test/codesize/test_codesize_cxx_noexcept.json index 608a59b681293..6988c47d39d40 100644 --- a/test/codesize/test_codesize_cxx_noexcept.json +++ b/test/codesize/test_codesize_cxx_noexcept.json @@ -1,10 +1,10 @@ { - "a.out.js": 19224, - "a.out.js.gz": 8124, + "a.out.js": 19546, + "a.out.js.gz": 8232, "a.out.nodebug.wasm": 135882, "a.out.nodebug.wasm.gz": 51885, - "total": 155106, - "total_gz": 60009, + "total": 155428, + "total_gz": 60117, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_cxx_wasmfs.json b/test/codesize/test_codesize_cxx_wasmfs.json index a50f193ba380b..2af66e642002b 100644 --- a/test/codesize/test_codesize_cxx_wasmfs.json +++ b/test/codesize/test_codesize_cxx_wasmfs.json @@ -1,10 +1,10 @@ { - "a.out.js": 6604, - "a.out.js.gz": 3154, + "a.out.js": 6926, + "a.out.js.gz": 3270, "a.out.nodebug.wasm": 173607, "a.out.nodebug.wasm.gz": 64636, - "total": 180211, - "total_gz": 67790, + "total": 180533, + "total_gz": 67906, "sent": [ "__cxa_throw", "_abort_js", diff --git a/test/codesize/test_codesize_file_preload.expected.js b/test/codesize/test_codesize_file_preload.expected.js index 6999515586248..a2d2f87a194db 100644 --- a/test/codesize/test_codesize_file_preload.expected.js +++ b/test/codesize/test_codesize_file_preload.expected.js @@ -428,6 +428,25 @@ async function instantiateAsync(binary, binaryFile, imports) { err(`wasm streaming compile failed: ${reason}`); err("falling back to ArrayBuffer instantiation"); } + } else if (!binary && ENVIRONMENT_IS_NODE) { + // Avoid using `fetch()` API on Node.js since it does not support `file://` + // URLs. Instead, provide a Response that wraps a fs read stream with the + // correct MIME type. + // See: https://github.com/emscripten-core/emscripten/pull/16917 + try { + var url = require("node:url"); + var nodeBinaryFile = isFileURI(binaryFile) ? url.fileURLToPath(binaryFile) : binaryFile; + var response = fs.openAsBlob(nodeBinaryFile).then(blob => new Response(blob.stream(), { + headers: { + "Content-Type": "application/wasm" + } + })); + var instantiationResult = await WebAssembly.instantiateStreaming(response, imports); + return instantiationResult; + } catch (reason) { + err(`wasm streaming compile failed: ${reason}`); + err("falling back to ArrayBuffer instantiation"); + } } return instantiateArrayBuffer(binaryFile, imports); } diff --git a/test/codesize/test_codesize_file_preload.json b/test/codesize/test_codesize_file_preload.json index 8a288445877b2..ed326d938c155 100644 --- a/test/codesize/test_codesize_file_preload.json +++ b/test/codesize/test_codesize_file_preload.json @@ -1,10 +1,10 @@ { - "a.out.js": 22203, - "a.out.js.gz": 9267, + "a.out.js": 22525, + "a.out.js.gz": 9372, "a.out.nodebug.wasm": 1198, "a.out.nodebug.wasm.gz": 730, - "total": 23401, - "total_gz": 9997, + "total": 23723, + "total_gz": 10102, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_codesize_files_js_fs.json b/test/codesize/test_codesize_files_js_fs.json index 0c033a7242071..3317f62590734 100644 --- a/test/codesize/test_codesize_files_js_fs.json +++ b/test/codesize/test_codesize_files_js_fs.json @@ -1,10 +1,10 @@ { - "a.out.js": 17871, - "a.out.js.gz": 7460, + "a.out.js": 18193, + "a.out.js.gz": 7575, "a.out.nodebug.wasm": 381, "a.out.nodebug.wasm.gz": 258, - "total": 18252, - "total_gz": 7718, + "total": 18574, + "total_gz": 7833, "sent": [ "a (fd_write)", "b (fd_read)", diff --git a/test/codesize/test_codesize_files_wasmfs.json b/test/codesize/test_codesize_files_wasmfs.json index 5326a3c193b07..cd7fb05aadf75 100644 --- a/test/codesize/test_codesize_files_wasmfs.json +++ b/test/codesize/test_codesize_files_wasmfs.json @@ -1,10 +1,10 @@ { - "a.out.js": 4979, - "a.out.js.gz": 2409, + "a.out.js": 5301, + "a.out.js.gz": 2523, "a.out.nodebug.wasm": 58252, "a.out.nodebug.wasm.gz": 18292, - "total": 63231, - "total_gz": 20701, + "total": 63553, + "total_gz": 20815, "sent": [ "a (emscripten_date_now)", "b (emscripten_err)", diff --git a/test/codesize/test_codesize_hello_O0.json b/test/codesize/test_codesize_hello_O0.json index 0a131354a605f..8aacacc638840 100644 --- a/test/codesize/test_codesize_hello_O0.json +++ b/test/codesize/test_codesize_hello_O0.json @@ -1,10 +1,10 @@ { - "a.out.js": 23596, - "a.out.js.gz": 8582, + "a.out.js": 23995, + "a.out.js.gz": 8698, "a.out.nodebug.wasm": 14279, "a.out.nodebug.wasm.gz": 7101, - "total": 37875, - "total_gz": 15683, + "total": 38274, + "total_gz": 15799, "sent": [ "fd_write" ], diff --git a/test/codesize/test_codesize_hello_O1.json b/test/codesize/test_codesize_hello_O1.json index e0f7a25ea23c8..78b35ab452bb9 100644 --- a/test/codesize/test_codesize_hello_O1.json +++ b/test/codesize/test_codesize_hello_O1.json @@ -1,10 +1,10 @@ { - "a.out.js": 5516, - "a.out.js.gz": 2242, + "a.out.js": 5915, + "a.out.js.gz": 2366, "a.out.nodebug.wasm": 2050, "a.out.nodebug.wasm.gz": 1231, - "total": 7566, - "total_gz": 3473, + "total": 7965, + "total_gz": 3597, "sent": [ "fd_write" ], diff --git a/test/codesize/test_codesize_hello_O2.json b/test/codesize/test_codesize_hello_O2.json index 5cc957a275f08..30e76b1f37351 100644 --- a/test/codesize/test_codesize_hello_O2.json +++ b/test/codesize/test_codesize_hello_O2.json @@ -1,10 +1,10 @@ { - "a.out.js": 3855, - "a.out.js.gz": 1966, + "a.out.js": 4176, + "a.out.js.gz": 2078, "a.out.nodebug.wasm": 1444, "a.out.nodebug.wasm.gz": 922, - "total": 5299, - "total_gz": 2888, + "total": 5620, + "total_gz": 3000, "sent": [ "fd_write" ], diff --git a/test/codesize/test_codesize_hello_O3.json b/test/codesize/test_codesize_hello_O3.json index 832365a8f1c6b..75778b81fe942 100644 --- a/test/codesize/test_codesize_hello_O3.json +++ b/test/codesize/test_codesize_hello_O3.json @@ -1,10 +1,10 @@ { - "a.out.js": 3797, - "a.out.js.gz": 1925, + "a.out.js": 4118, + "a.out.js.gz": 2036, "a.out.nodebug.wasm": 1198, "a.out.nodebug.wasm.gz": 730, - "total": 4995, - "total_gz": 2655, + "total": 5316, + "total_gz": 2766, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_codesize_hello_Os.json b/test/codesize/test_codesize_hello_Os.json index 55e52acdc3ab6..7c5848683838b 100644 --- a/test/codesize/test_codesize_hello_Os.json +++ b/test/codesize/test_codesize_hello_Os.json @@ -1,10 +1,10 @@ { - "a.out.js": 3797, - "a.out.js.gz": 1925, + "a.out.js": 4118, + "a.out.js.gz": 2036, "a.out.nodebug.wasm": 1188, "a.out.nodebug.wasm.gz": 732, - "total": 4985, - "total_gz": 2657, + "total": 5306, + "total_gz": 2768, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_codesize_hello_Oz.json b/test/codesize/test_codesize_hello_Oz.json index 1739d3afc7aaf..e73679e7a4985 100644 --- a/test/codesize/test_codesize_hello_Oz.json +++ b/test/codesize/test_codesize_hello_Oz.json @@ -1,10 +1,10 @@ { - "a.out.js": 3434, - "a.out.js.gz": 1729, + "a.out.js": 3756, + "a.out.js.gz": 1842, "a.out.nodebug.wasm": 1188, "a.out.nodebug.wasm.gz": 732, - "total": 4622, - "total_gz": 2461, + "total": 4944, + "total_gz": 2574, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_codesize_hello_dylink.json b/test/codesize/test_codesize_hello_dylink.json index 27c28e6b09a79..de302b2298d9e 100644 --- a/test/codesize/test_codesize_hello_dylink.json +++ b/test/codesize/test_codesize_hello_dylink.json @@ -1,10 +1,10 @@ { - "a.out.js": 26188, - "a.out.js.gz": 11168, + "a.out.js": 26511, + "a.out.js.gz": 11289, "a.out.nodebug.wasm": 16992, "a.out.nodebug.wasm.gz": 8679, - "total": 43180, - "total_gz": 19847, + "total": 43503, + "total_gz": 19968, "sent": [ "__syscall_stat64", "emscripten_resize_heap", diff --git a/test/codesize/test_codesize_hello_dylink_all.json b/test/codesize/test_codesize_hello_dylink_all.json index 2599da95e6573..1fa53754171a1 100644 --- a/test/codesize/test_codesize_hello_dylink_all.json +++ b/test/codesize/test_codesize_hello_dylink_all.json @@ -1,7 +1,7 @@ { - "a.out.js": 270695, + "a.out.js": 271019, "a.out.nodebug.wasm": 588289, - "total": 858984, + "total": 859308, "sent": [ "IMG_Init", "IMG_Load", diff --git a/test/codesize/test_codesize_hello_export_nothing.json b/test/codesize/test_codesize_hello_export_nothing.json index c4012b3373c4f..d8fd623e58cc8 100644 --- a/test/codesize/test_codesize_hello_export_nothing.json +++ b/test/codesize/test_codesize_hello_export_nothing.json @@ -1,10 +1,10 @@ { - "a.out.js": 2642, - "a.out.js.gz": 1290, + "a.out.js": 2964, + "a.out.js.gz": 1404, "a.out.nodebug.wasm": 43, "a.out.nodebug.wasm.gz": 59, - "total": 2685, - "total_gz": 1349, + "total": 3007, + "total_gz": 1463, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_hello_wasmfs.json b/test/codesize/test_codesize_hello_wasmfs.json index 832365a8f1c6b..75778b81fe942 100644 --- a/test/codesize/test_codesize_hello_wasmfs.json +++ b/test/codesize/test_codesize_hello_wasmfs.json @@ -1,10 +1,10 @@ { - "a.out.js": 3797, - "a.out.js.gz": 1925, + "a.out.js": 4118, + "a.out.js.gz": 2036, "a.out.nodebug.wasm": 1198, "a.out.nodebug.wasm.gz": 730, - "total": 4995, - "total_gz": 2655, + "total": 5316, + "total_gz": 2766, "sent": [ "a (fd_write)" ], diff --git a/test/codesize/test_codesize_libcxxabi_message_O3.json b/test/codesize/test_codesize_libcxxabi_message_O3.json index a3d564f5f2563..ce50074a8c1e1 100644 --- a/test/codesize/test_codesize_libcxxabi_message_O3.json +++ b/test/codesize/test_codesize_libcxxabi_message_O3.json @@ -1,10 +1,10 @@ { - "a.out.js": 3010, - "a.out.js.gz": 1480, + "a.out.js": 3331, + "a.out.js.gz": 1591, "a.out.nodebug.wasm": 89, "a.out.nodebug.wasm.gz": 98, - "total": 3099, - "total_gz": 1578, + "total": 3420, + "total_gz": 1689, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_libcxxabi_message_O3_standalone.json b/test/codesize/test_codesize_libcxxabi_message_O3_standalone.json index 2cc7597db55ab..d25a95beeb928 100644 --- a/test/codesize/test_codesize_libcxxabi_message_O3_standalone.json +++ b/test/codesize/test_codesize_libcxxabi_message_O3_standalone.json @@ -1,10 +1,10 @@ { - "a.out.js": 3093, - "a.out.js.gz": 1530, + "a.out.js": 3415, + "a.out.js.gz": 1648, "a.out.nodebug.wasm": 222, "a.out.nodebug.wasm.gz": 206, - "total": 3315, - "total_gz": 1736, + "total": 3637, + "total_gz": 1854, "sent": [ "proc_exit" ], diff --git a/test/codesize/test_codesize_mem_O3.json b/test/codesize/test_codesize_mem_O3.json index 886be4087c960..4ef3ea96eca4d 100644 --- a/test/codesize/test_codesize_mem_O3.json +++ b/test/codesize/test_codesize_mem_O3.json @@ -1,10 +1,10 @@ { - "a.out.js": 3875, - "a.out.js.gz": 1925, + "a.out.js": 4196, + "a.out.js.gz": 2038, "a.out.nodebug.wasm": 5268, "a.out.nodebug.wasm.gz": 2433, - "total": 9143, - "total_gz": 4358, + "total": 9464, + "total_gz": 4471, "sent": [ "a (emscripten_resize_heap)" ], diff --git a/test/codesize/test_codesize_mem_O3_grow.json b/test/codesize/test_codesize_mem_O3_grow.json index 425b77043764f..b82aa14f6886b 100644 --- a/test/codesize/test_codesize_mem_O3_grow.json +++ b/test/codesize/test_codesize_mem_O3_grow.json @@ -1,10 +1,10 @@ { - "a.out.js": 4209, - "a.out.js.gz": 2101, + "a.out.js": 4531, + "a.out.js.gz": 2214, "a.out.nodebug.wasm": 5269, "a.out.nodebug.wasm.gz": 2433, - "total": 9478, - "total_gz": 4534, + "total": 9800, + "total_gz": 4647, "sent": [ "a (emscripten_resize_heap)" ], diff --git a/test/codesize/test_codesize_mem_O3_grow_standalone.json b/test/codesize/test_codesize_mem_O3_grow_standalone.json index bbf629f321167..0f5433d8b37d1 100644 --- a/test/codesize/test_codesize_mem_O3_grow_standalone.json +++ b/test/codesize/test_codesize_mem_O3_grow_standalone.json @@ -1,10 +1,10 @@ { - "a.out.js": 3657, - "a.out.js.gz": 1834, + "a.out.js": 3979, + "a.out.js.gz": 1945, "a.out.nodebug.wasm": 5649, "a.out.nodebug.wasm.gz": 2669, - "total": 9306, - "total_gz": 4503, + "total": 9628, + "total_gz": 4614, "sent": [ "args_get", "args_sizes_get", diff --git a/test/codesize/test_codesize_mem_O3_standalone.json b/test/codesize/test_codesize_mem_O3_standalone.json index 61f177858fad1..507f6e1ec4671 100644 --- a/test/codesize/test_codesize_mem_O3_standalone.json +++ b/test/codesize/test_codesize_mem_O3_standalone.json @@ -1,10 +1,10 @@ { - "a.out.js": 3567, - "a.out.js.gz": 1784, + "a.out.js": 3889, + "a.out.js.gz": 1898, "a.out.nodebug.wasm": 5573, "a.out.nodebug.wasm.gz": 2608, - "total": 9140, - "total_gz": 4392, + "total": 9462, + "total_gz": 4506, "sent": [ "args_get", "args_sizes_get", diff --git a/test/codesize/test_codesize_mem_O3_standalone_lib.json b/test/codesize/test_codesize_mem_O3_standalone_lib.json index c12751084994c..1da1e504666bc 100644 --- a/test/codesize/test_codesize_mem_O3_standalone_lib.json +++ b/test/codesize/test_codesize_mem_O3_standalone_lib.json @@ -1,10 +1,10 @@ { - "a.out.js": 3086, - "a.out.js.gz": 1523, + "a.out.js": 3408, + "a.out.js.gz": 1637, "a.out.nodebug.wasm": 5248, "a.out.nodebug.wasm.gz": 2368, - "total": 8334, - "total_gz": 3891, + "total": 8656, + "total_gz": 4005, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_mem_O3_standalone_narg.json b/test/codesize/test_codesize_mem_O3_standalone_narg.json index 34167a05ea85c..78c558d46ec36 100644 --- a/test/codesize/test_codesize_mem_O3_standalone_narg.json +++ b/test/codesize/test_codesize_mem_O3_standalone_narg.json @@ -1,10 +1,10 @@ { - "a.out.js": 3093, - "a.out.js.gz": 1530, + "a.out.js": 3415, + "a.out.js.gz": 1648, "a.out.nodebug.wasm": 5362, "a.out.nodebug.wasm.gz": 2451, - "total": 8455, - "total_gz": 3981, + "total": 8777, + "total_gz": 4099, "sent": [ "proc_exit" ], diff --git a/test/codesize/test_codesize_mem_O3_standalone_narg_flto.json b/test/codesize/test_codesize_mem_O3_standalone_narg_flto.json index d1c92228a1005..803ccbeb139ac 100644 --- a/test/codesize/test_codesize_mem_O3_standalone_narg_flto.json +++ b/test/codesize/test_codesize_mem_O3_standalone_narg_flto.json @@ -1,10 +1,10 @@ { - "a.out.js": 3093, - "a.out.js.gz": 1530, + "a.out.js": 3415, + "a.out.js.gz": 1648, "a.out.nodebug.wasm": 4293, "a.out.nodebug.wasm.gz": 2147, - "total": 7386, - "total_gz": 3677, + "total": 7708, + "total_gz": 3795, "sent": [ "proc_exit" ], diff --git a/test/codesize/test_codesize_minimal_64.json b/test/codesize/test_codesize_minimal_64.json index 22e523cfc996e..d83b72d54d316 100644 --- a/test/codesize/test_codesize_minimal_64.json +++ b/test/codesize/test_codesize_minimal_64.json @@ -1,10 +1,10 @@ { - "a.out.js": 2364, - "a.out.js.gz": 1155, + "a.out.js": 2685, + "a.out.js.gz": 1267, "a.out.nodebug.wasm": 75, "a.out.nodebug.wasm.gz": 88, - "total": 2439, - "total_gz": 1243, + "total": 2760, + "total_gz": 1355, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_O0.expected.js b/test/codesize/test_codesize_minimal_O0.expected.js index 61b5952de1fd0..d09fbd9b8b270 100644 --- a/test/codesize/test_codesize_minimal_O0.expected.js +++ b/test/codesize/test_codesize_minimal_O0.expected.js @@ -651,9 +651,8 @@ async function instantiateAsync(binary, binaryFile, imports) { if (!binary // Don't use streaming for file:// delivered objects in a webview, fetch them synchronously. && !isFileURI(binaryFile) - // Avoid using instantiateStreaming() on Node.js since the `fetch()` API - // does not support `file://` URLs. - // See: https://github.com/emscripten-core/emscripten/pull/16917 + // Node.js is handled in its own branch below, since it can't use fetch() + // to stream a `file://` URL && !ENVIRONMENT_IS_NODE ) { try { @@ -668,6 +667,28 @@ async function instantiateAsync(binary, binaryFile, imports) { // fall back of instantiateArrayBuffer below }; } + else if (!binary && ENVIRONMENT_IS_NODE) { + // Avoid using `fetch()` API on Node.js since it does not support `file://` + // URLs. Instead, provide a Response that wraps a fs read stream with the + // correct MIME type. + // See: https://github.com/emscripten-core/emscripten/pull/16917 + try { + var url = require('node:url'); + var nodeBinaryFile = isFileURI(binaryFile) ? url.fileURLToPath(binaryFile) : binaryFile; + var response = fs.openAsBlob(nodeBinaryFile).then( + (blob) => + new Response(blob.stream(), { + headers: { 'Content-Type': 'application/wasm' }, + }), + ); + var instantiationResult = await WebAssembly.instantiateStreaming(response, imports); + return instantiationResult; + } catch (reason) { + err(`wasm streaming compile failed: ${reason}`); + err('falling back to ArrayBuffer instantiation'); + // fall back of instantiateArrayBuffer below + }; + } return instantiateArrayBuffer(binaryFile, imports); } diff --git a/test/codesize/test_codesize_minimal_O0.json b/test/codesize/test_codesize_minimal_O0.json index f960557acfdd1..047d4d2550008 100644 --- a/test/codesize/test_codesize_minimal_O0.json +++ b/test/codesize/test_codesize_minimal_O0.json @@ -1,10 +1,10 @@ { - "a.out.js": 18801, - "a.out.js.gz": 6758, + "a.out.js": 19200, + "a.out.js.gz": 6879, "a.out.nodebug.wasm": 1071, "a.out.nodebug.wasm.gz": 636, - "total": 19872, - "total_gz": 7394, + "total": 20271, + "total_gz": 7515, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_O1.json b/test/codesize/test_codesize_minimal_O1.json index 19ff15d14dac8..6bd0957a3902d 100644 --- a/test/codesize/test_codesize_minimal_O1.json +++ b/test/codesize/test_codesize_minimal_O1.json @@ -1,10 +1,10 @@ { - "a.out.js": 2670, - "a.out.js.gz": 1167, + "a.out.js": 3069, + "a.out.js.gz": 1290, "a.out.nodebug.wasm": 505, "a.out.nodebug.wasm.gz": 378, - "total": 3175, - "total_gz": 1545, + "total": 3574, + "total_gz": 1668, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_O2.json b/test/codesize/test_codesize_minimal_O2.json index bd4d07eef5864..f2fa6d370d5ef 100644 --- a/test/codesize/test_codesize_minimal_O2.json +++ b/test/codesize/test_codesize_minimal_O2.json @@ -1,10 +1,10 @@ { - "a.out.js": 2052, - "a.out.js.gz": 1058, + "a.out.js": 2374, + "a.out.js.gz": 1169, "a.out.nodebug.wasm": 326, "a.out.nodebug.wasm.gz": 263, - "total": 2378, - "total_gz": 1321, + "total": 2700, + "total_gz": 1432, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_O3.json b/test/codesize/test_codesize_minimal_O3.json index 5fe4c0860fef6..e329561280605 100644 --- a/test/codesize/test_codesize_minimal_O3.json +++ b/test/codesize/test_codesize_minimal_O3.json @@ -1,10 +1,10 @@ { - "a.out.js": 1998, - "a.out.js.gz": 1027, + "a.out.js": 2320, + "a.out.js.gz": 1137, "a.out.nodebug.wasm": 75, "a.out.nodebug.wasm.gz": 87, - "total": 2073, - "total_gz": 1114, + "total": 2395, + "total_gz": 1224, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_Os.json b/test/codesize/test_codesize_minimal_Os.json index 5fe4c0860fef6..e329561280605 100644 --- a/test/codesize/test_codesize_minimal_Os.json +++ b/test/codesize/test_codesize_minimal_Os.json @@ -1,10 +1,10 @@ { - "a.out.js": 1998, - "a.out.js.gz": 1027, + "a.out.js": 2320, + "a.out.js.gz": 1137, "a.out.nodebug.wasm": 75, "a.out.nodebug.wasm.gz": 87, - "total": 2073, - "total_gz": 1114, + "total": 2395, + "total_gz": 1224, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_Oz-ctors.json b/test/codesize/test_codesize_minimal_Oz-ctors.json index 01649ef200d36..86694f6d09ae9 100644 --- a/test/codesize/test_codesize_minimal_Oz-ctors.json +++ b/test/codesize/test_codesize_minimal_Oz-ctors.json @@ -1,10 +1,10 @@ { - "a.out.js": 1980, - "a.out.js.gz": 1012, + "a.out.js": 2302, + "a.out.js.gz": 1123, "a.out.nodebug.wasm": 64, "a.out.nodebug.wasm.gz": 80, - "total": 2044, - "total_gz": 1092, + "total": 2366, + "total_gz": 1203, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_Oz.json b/test/codesize/test_codesize_minimal_Oz.json index 5fe4c0860fef6..e329561280605 100644 --- a/test/codesize/test_codesize_minimal_Oz.json +++ b/test/codesize/test_codesize_minimal_Oz.json @@ -1,10 +1,10 @@ { - "a.out.js": 1998, - "a.out.js.gz": 1027, + "a.out.js": 2320, + "a.out.js.gz": 1137, "a.out.nodebug.wasm": 75, "a.out.nodebug.wasm.gz": 87, - "total": 2073, - "total_gz": 1114, + "total": 2395, + "total_gz": 1224, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_esm.json b/test/codesize/test_codesize_minimal_esm.json index fe01e4510c897..7655c3cfb9c26 100644 --- a/test/codesize/test_codesize_minimal_esm.json +++ b/test/codesize/test_codesize_minimal_esm.json @@ -1,10 +1,10 @@ { - "a.out.js": 2137, - "a.out.js.gz": 1050, + "a.out.js": 2451, + "a.out.js.gz": 1152, "a.out.nodebug.wasm": 75, "a.out.nodebug.wasm.gz": 87, - "total": 2212, - "total_gz": 1137, + "total": 2526, + "total_gz": 1239, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_codesize_minimal_pthreads.json b/test/codesize/test_codesize_minimal_pthreads.json index f897ee3214106..0b3cc7a28e3c1 100644 --- a/test/codesize/test_codesize_minimal_pthreads.json +++ b/test/codesize/test_codesize_minimal_pthreads.json @@ -1,10 +1,10 @@ { - "a.out.js": 6900, - "a.out.js.gz": 3432, + "a.out.js": 7222, + "a.out.js.gz": 3546, "a.out.nodebug.wasm": 19147, "a.out.nodebug.wasm.gz": 8834, - "total": 26047, - "total_gz": 12266, + "total": 26369, + "total_gz": 12380, "sent": [ "a (memory)", "b (exit)", diff --git a/test/codesize/test_codesize_minimal_pthreads_memgrowth.json b/test/codesize/test_codesize_minimal_pthreads_memgrowth.json index 5124575dc3ca5..2b837d800b28b 100644 --- a/test/codesize/test_codesize_minimal_pthreads_memgrowth.json +++ b/test/codesize/test_codesize_minimal_pthreads_memgrowth.json @@ -1,10 +1,10 @@ { - "a.out.js": 7358, - "a.out.js.gz": 3648, + "a.out.js": 7680, + "a.out.js.gz": 3763, "a.out.nodebug.wasm": 19148, "a.out.nodebug.wasm.gz": 8835, - "total": 26506, - "total_gz": 12483, + "total": 26828, + "total_gz": 12598, "sent": [ "a (memory)", "b (exit)", diff --git a/test/codesize/test_codesize_minimal_wasmfs.json b/test/codesize/test_codesize_minimal_wasmfs.json index 5fe4c0860fef6..e329561280605 100644 --- a/test/codesize/test_codesize_minimal_wasmfs.json +++ b/test/codesize/test_codesize_minimal_wasmfs.json @@ -1,10 +1,10 @@ { - "a.out.js": 1998, - "a.out.js.gz": 1027, + "a.out.js": 2320, + "a.out.js.gz": 1137, "a.out.nodebug.wasm": 75, "a.out.nodebug.wasm.gz": 87, - "total": 2073, - "total_gz": 1114, + "total": 2395, + "total_gz": 1224, "sent": [], "imports": [], "exports": [ diff --git a/test/codesize/test_unoptimized_code_size.json b/test/codesize/test_unoptimized_code_size.json index a6bc588a5bc49..b70b6a4ac3fb9 100644 --- a/test/codesize/test_unoptimized_code_size.json +++ b/test/codesize/test_unoptimized_code_size.json @@ -1,16 +1,16 @@ { - "hello_world.js": 54705, - "hello_world.js.gz": 17355, + "hello_world.js": 55588, + "hello_world.js.gz": 17582, "hello_world.wasm": 14279, "hello_world.wasm.gz": 7101, - "no_asserts.js": 23596, - "no_asserts.js.gz": 8277, + "no_asserts.js": 24479, + "no_asserts.js.gz": 8497, "no_asserts.wasm": 11393, "no_asserts.wasm.gz": 5646, - "strict.js": 51856, - "strict.js.gz": 16348, + "strict.js": 52739, + "strict.js.gz": 16580, "strict.wasm": 14279, "strict.wasm.gz": 7098, - "total": 170108, - "total_gz": 61825 + "total": 172757, + "total_gz": 62504 }