8000 fix: microtasks policy in CreateEnvironment by trop[bot] · Pull Request #29807 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: microtasks policy in CreateEnvironment #29807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions shell/common/node_bindings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<html>
<body>
<script>
// `setImmediate` schedules a function to be run on the next UV tick, which
// ensures that `window.open` is run from `UvRunOnce()`.
setImmediate(async () => {
if (!location.hash) {
const p = new Promise(resolve => {
window.addEventListener('message', resolve, { once: true });
});
window.open('#foo', '', 'nodeIntegration=no,show=no');
const e = await p;

window.close();
} else {
window.opener.postMessage('foo', '*');
}
});
</script>
</body>
</html>
6433
Original file line number Diff line number Diff line change
@@ -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();
});
0