Skip to content

Commit

Permalink
src: guard slightly costly check in MakeCallback more strongly
Browse files Browse the repository at this point in the history
PR-URL: #41331
Reviewed-By: Gerhard Stöbich <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Darshan Sen <[email protected]>
  • Loading branch information
addaleax authored and targos committed Jan 14, 2022
1 parent bd8b95a commit 6187e81
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/api/callback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,17 @@ InternalCallbackScope::InternalCallbackScope(Environment* env,
Isolate* isolate = env->isolate();

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

env->isolate()->SetIdle(false);
isolate->SetIdle(false);

env->async_hooks()->push_async_context(
async_context_.async_id, async_context_.trigger_async_id, object);
Expand Down

0 comments on commit 6187e81

Please sign in to comment.