Skip to content

Commit 6187e81

Browse files
addaleaxtargos
authored andcommitted
src: guard slightly costly check in MakeCallback more strongly
PR-URL: #41331 Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
1 parent bd8b95a commit 6187e81

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/api/callback.cc

+10-3
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,17 @@ InternalCallbackScope::InternalCallbackScope(Environment* env,
6464
Isolate* isolate = env->isolate();
6565

6666
HandleScope handle_scope(isolate);
67-
// If you hit this assertion, you forgot to enter the v8::Context first.
68-
CHECK_EQ(Environment::GetCurrent(isolate), env);
67+
Local<Context> current_context = isolate->GetCurrentContext();
68+
// If you hit this assertion, the caller forgot to enter the right Node.js
69+
// Environment's v8::Context first.
70+
// We first check `env->context() != current_context` because the contexts
71+
// likely *are* the same, in which case we can skip the slightly more
72+
// expensive Environment::GetCurrent() call.
73+
if (UNLIKELY(env->context() != current_context)) {
74+
CHECK_EQ(Environment::GetCurrent(isolate), env);
75+
}
6976

70-
env->isolate()->SetIdle(false);
77+
isolate->SetIdle(false);
7178

7279
env->async_hooks()->push_async_context(
7380
async_context_.async_id, async_context_.trigger_async_id, object);

0 commit comments

Comments
 (0)