diff --git a/src/api/callback.cc b/src/api/callback.cc index fb0e5586eb400a..d6454c6f5d5bad 100644 --- a/src/api/callback.cc +++ b/src/api/callback.cc @@ -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; @@ -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); } }