Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7e2cd72

Browse filesBrowse files
committed
src: add callback scope for native immediates
This ensures that microtasks scheduled by native immediates are run after the tasks are done. In particular, this affects the inspector integration since 6f9f546. Fixes: #33002 Refs: #32523 Backport-PR-URL: #35241 PR-URL: #34366 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 1474405 commit 7e2cd72
Copy full SHA for 7e2cd72

File tree

Expand file treeCollapse file tree

3 files changed

+38
-7
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+38
-7
lines changed
Open diff view settings
Collapse file

‎src/env.cc‎

Copy file name to clipboardExpand all lines: src/env.cc
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,9 @@ void Environment::RunAndClearInterrupts() {
708708
void Environment::RunAndClearNativeImmediates(bool only_refed) {
709709
TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment),
710710
"RunAndClearNativeImmediates", this);
711+
HandleScope handle_scope(isolate_);
712+
InternalCallbackScope cb_scope(this, Object::New(isolate_), { 0, 0 });
713+
711714
size_t ref_count = 0;
712715

713716
// Handle interrupts first. These functions are not allowed to throw
Collapse file

‎test/async-hooks/test-late-hook-enable.js‎

Copy file name to clipboardExpand all lines: test/async-hooks/test-late-hook-enable.js
+9-7Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ const fnsToTest = [setTimeout, (cb) => {
1717
});
1818
});
1919
}, (cb) => {
20-
process.nextTick(() => {
21-
cb();
20+
setImmediate(() => {
21+
process.nextTick(() => {
22+
cb();
2223

23-
// We need to keep the event loop open for this to actually work
24-
// since destroy hooks are triggered in unrefed Immediates
25-
setImmediate(() => {
26-
hook.disable();
27-
assert.strictEqual(fnsToTest.length, 0);
24+
// We need to keep the event loop open for this to actually work
25+
// since destroy hooks are triggered in unrefed Immediates
26+
setImmediate(() => {
27+
hook.disable();
28+
assert.strictEqual(fnsToTest.length, 0);
29+
});
2830
});
2931
});
3032
}];
Collapse file

‎test/cctest/test_environment.cc‎

Copy file name to clipboardExpand all lines: test/cctest/test_environment.cc
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,3 +466,29 @@ TEST_F(EnvironmentTest, ExitHandlerTest) {
466466
node::LoadEnvironment(*env, "process.exit(42)").ToLocalChecked();
467467
EXPECT_EQ(callback_calls, 1);
468468
}
469+
470+
TEST_F(EnvironmentTest, SetImmediateMicrotasks) {
471+
int called = 0;
472+
473+
{
474+
const v8::HandleScope handle_scope(isolate_);
475+
const Argv argv;
476+
Env env {handle_scope, argv};
477+
478+
node::LoadEnvironment(*env,
479+
[&](const node::StartExecutionCallbackInfo& info)
480+
-> v8::MaybeLocal<v8::Value> {
481+
return v8::Object::New(isolate_);
482+
});
483+
484+
(*env)->SetImmediate([&](node::Environment* env_arg) {
485+
EXPECT_EQ(env_arg, *env);
486+
isolate_->EnqueueMicrotask([](void* arg) {
487+
++*static_cast<int*>(arg);
488+
}, &called);
489+
});
490+
uv_run(&current_loop, UV_RUN_DEFAULT);
491+
}
492+
493+
EXPECT_EQ(called, 1);
494+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.