diff --git a/shell/common/node_bindings.cc b/shell/common/node_bindings.cc index a1e46fd9a3ed..e1c6634306b7 100644 --- a/shell/common/node_bindings.cc +++ b/shell/common/node_bindings.cc @@ -482,9 +482,13 @@ node::Environment* NodeBindings::CreateEnvironment( // Node.js requires that microtask checkpoints be explicitly invoked. is.policy = v8::MicrotasksPolicy::kExplicit; } else { - // Match Blink's behavior by allowing microtasks invocation to be controlled - // by MicrotasksScope objects. - is.policy = v8::MicrotasksPolicy::kScoped; + // Blink expects the microtasks policy to be kScoped, but Node.js expects it + // to be kExplicit. In the renderer, there can be many contexts within the + // same isolate, so we don't want to change the existing policy here, which + // could be either kExplicit or kScoped depending on whether we're executing + // from within a Node.js or a Blink entrypoint. Instead, the policy is + // toggled to kExplicit when entering Node.js through UvRunOnce. + is.policy = context->GetIsolate()->GetMicrotasksPolicy(); // We do not want to use Node.js' message listener as it interferes with // Blink's. diff --git a/spec-main/fixtures/crash-cases/setimmediate-window-open-crash/index.html b/spec-main/fixtures/crash-cases/setimmediate-window-open-crash/index.html new file mode 100644 index 000000000000..9bb131aef454 --- /dev/null +++ b/spec-main/fixtures/crash-cases/setimmediate-window-open-crash/index.html @@ -0,0 +1,21 @@ + + + + + diff --git a/spec-main/fixtures/crash-cases/setimmediate-window-open-crash/index.js b/spec-main/fixtures/crash-cases/setimmediate-window-open-crash/index.js new file mode 100644 index 000000000000..2032f096c11c --- /dev/null +++ b/spec-main/fixtures/crash-cases/setimmediate-window-open-crash/index.js @@ -0,0 +1,21 @@ +const { app, BrowserWindow } = require('electron'); + +function createWindow () { + const mainWindow = new BrowserWindow({ + webPreferences: { + nodeIntegration: true, + contextIsolation: false, + nativeWindowOpen: true + } + }); + + mainWindow.on('close', () => { + app.quit(); + }); + + mainWindow.loadFile('index.html'); +} + +app.whenReady().then(() => { + createWindow(); +});