diff options
author | Anna Henningsen <anna@addaleax.net> | 2021-12-26 22:28:17 +0300 |
---|---|---|
committer | Node.js GitHub Bot <github-bot@iojs.org> | 2022-01-01 21:36:49 +0300 |
commit | 6932fb8bac3a4caf3f3fabee0a595a077f477f63 (patch) | |
tree | 7da45cf480df0b14e7e460c25da36b71a203b5e3 /src/api | |
parent | 5f07d00c60729d6b73b7f468d3094331c8708950 (diff) |
src: guard slightly costly check in MakeCallback more strongly
PR-URL: https://github.com/nodejs/node/pull/41331
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/callback.cc | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/api/callback.cc b/src/api/callback.cc index fb0e5586eb4..1287eb466fd 100644 --- a/src/api/callback.cc +++ b/src/api/callback.cc @@ -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); |