Skip to content

Commit 0d93097

Browse files
fix: only set Node's WASM streaming callback when fetch is enabled (#… (#52240)
* fix: only set Node's WASM streaming callback when fetch is enabled (#51953) * fix: only set Node's WASM streaming callback when fetch is enabled Node.js v24.16.0 removed the experimental_fetch gate around isolate->SetWasmStreamingCallback() (nodejs/node#62759). When fix_allow_disabling_fetch_in_renderer_and_worker_processes.patch was rebased for the version bump, the flag was restored but the gate was not. As a result, Node.js unconditionally overrode Blink's WebAssembly streaming callback in renderer and worker processes, where Electron passes --no-experimental-fetch and skips the bootstrap file that registers Node's JS-side streaming implementation. Any call to WebAssembly.compileStreaming() or instantiateStreaming() in a renderer with nodeIntegration then failed the CHECK(\!impl.IsEmpty()) assertion in node_wasm_web_api.cc and crashed the renderer. Restore the gate so Blink's streaming callback stays in place in processes where Node's fetch is disabled. Fixes #51950 * test: cover WebAssembly streaming compilation in renderers with nodeIntegration * re-export node patches * update patches --------- Co-authored-by: Samuel Attard <[email protected]>
1 parent 35874b0 commit 0d93097

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

‎patches/node/api_delete_deprecated_fields_on_v8_isolate.patch‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Subject: Delete deprecated fields on v8::Isolate
66
https://chromium-review.googlesource.com/c/v8/v8/+/7081397
77

88
diff --git a/src/api/environment.cc b/src/api/environment.cc
9-
index bcb56906d6f6184ee0c98e9b8b51c8fcdb359c73..8efaff68cb3732c60b8c619ca7963aaf466ba8f5 100644
9+
index 9eb15de8acd850b615611a5401c1f66417ba57c8..99039575f7a502d0cff9551d2b41492cc861af9d 100644
1010
--- a/src/api/environment.cc
1111
+++ b/src/api/environment.cc
1212
@@ -227,8 +227,6 @@ void SetIsolateCreateParamsForNode(Isolate::CreateParams* params) {

‎patches/node/fix_allow_disabling_fetch_in_renderer_and_worker_processes.patch‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@ index 4a42dd66f451eece98fded909a72dd5ffcfd9708..a693e35135fc8f7e918e1410a104d460
7878
// https://websockets.spec.whatwg.org/
7979
function setupWebsocket() {
8080
if (getOptionValue('--no-experimental-websocket')) {
81+
diff --git a/src/api/environment.cc b/src/api/environment.cc
82+
index bcb56906d6f6184ee0c98e9b8b51c8fcdb359c73..9eb15de8acd850b615611a5401c1f66417ba57c8 100644
83+
--- a/src/api/environment.cc
84+
+++ b/src/api/environment.cc
85+
@@ -278,9 +278,13 @@ void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s) {
86+
isolate->SetModifyCodeGenerationFromStringsCallback(
87+
modify_code_generation_from_strings_callback);
88+
89+
- isolate->SetWasmStreamingCallback(wasm_web_api::StartStreamingCompilation);
90+
-
91+
Mutex::ScopedLock lock(node::per_process::cli_options_mutex);
92+
+ if (per_process::cli_options->get_per_isolate_options()
93+
+ ->get_per_env_options()
94+
+ ->experimental_fetch) {
95+
+ isolate->SetWasmStreamingCallback(wasm_web_api::StartStreamingCompilation);
96+
+ }
97+
+
98+
if (per_process::cli_options->get_per_isolate_options()
99+
->experimental_shadow_realm) {
100+
isolate->SetHostCreateShadowRealmContextCallback(
81101
diff --git a/src/node_options.cc b/src/node_options.cc
82102
index b7062241d590e36f797babffb5945060ef759322..ae895839723609dcdec2c037facb17208c757d58 100644
83103
--- a/src/node_options.cc

‎spec/chromium-spec.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,29 @@ describe('web security', () => {
452452
});
453453
});
454454

455+
describe('WebAssembly streaming compilation', () => {
456+
it('works in a renderer with nodeIntegration', async () => {
457+
const server = http.createServer((req, res) => {
458+
res.setHeader('Content-Type', 'application/wasm');
459+
res.setHeader('Access-Control-Allow-Origin', '*');
460+
// Minimal valid WebAssembly module (magic number + version).
461+
res.end(Buffer.from([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]));
462+
});
463+
const { url: serverUrl } = await listen(server);
464+
defer(() => server.close());
465+
466+
const w = new BrowserWindow({
467+
show: false,
468+
webPreferences: { nodeIntegration: true, contextIsolation: false }
469+
});
470+
await w.loadURL('about:blank');
471+
const result = await w.webContents.executeJavaScript(
472+
`WebAssembly.instantiateStreaming(fetch('${serverUrl}')).then(() => 'loaded')`
473+
);
474+
expect(result).to.equal('loaded');
475+
});
476+
});
477+
455478
describe('csp', () => {
456479
for (const sandbox of [true, false]) {
457480
describe(`when sandbox: ${sandbox}`, () => {

0 commit comments

Comments
 (0)