Skip to content

Commit

Permalink
fix crashing of promise hooks when not under a node context
Browse files Browse the repository at this point in the history
Fixes issue nodejs#19104
  • Loading branch information
xaviergonz authored Mar 4, 2018
1 parent f2d9379 commit d8b34c4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,12 @@ bool Environment::EmitNapiWarning() {
void Environment::EnvPromiseHook(v8::PromiseHookType type,
v8::Local<v8::Promise> promise,
v8::Local<v8::Value> parent) {
Environment* env = Environment::GetCurrent(promise->CreationContext());
auto context = promise->CreationContext();
// if the context is undefined (not a node context) then skip
if (context->GetEmbedderData(32)->IsNullOrUndefined()) {
return;
}
Environment* env = Environment::GetCurrent(context);
for (const PromiseHookCallback& hook : env->promise_hooks_) {
hook.cb_(type, promise, parent, hook.arg_);
}
Expand Down

0 comments on commit d8b34c4

Please sign in to comment.