Skip to content
Closed
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: 8 additions & 2 deletions src/api/callback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ InternalCallbackScope::InternalCallbackScope(Environment* env,
CHECK_NOT_NULL(env);
env->PushAsyncCallbackScope();

// Skip costly pushing/popping if we pass zeroes as async context
if (async_context_.async_id == 0) {
pushed_ids_ = false;
return;
}

if (!env->can_call_into_js()) {
failed_ = true;
return;
Expand All @@ -74,10 +80,10 @@ InternalCallbackScope::InternalCallbackScope(Environment* env,

pushed_ids_ = true;

if (asyncContext.async_id != 0 && !skip_hooks_) {
if (!skip_hooks_) {
// No need to check a return value because the application will exit if
// an exception occurs.
AsyncWrap::EmitBefore(env, asyncContext.async_id);
AsyncWrap::EmitBefore(env, async_context_.async_id);
}
}

Expand Down