diff --git a/src/async_wrap.cc b/src/async_wrap.cc index 11ce5a387a950c..87c50950faadcc 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -398,6 +398,7 @@ static void DisablePromiseHook(const FunctionCallbackInfo& args) { class DestroyParam { public: double asyncId; + Environment* env; Persistent target; Persistent propBag; }; @@ -406,13 +407,12 @@ class DestroyParam { void AsyncWrap::WeakCallback(const v8::WeakCallbackInfo& info) { HandleScope scope(info.GetIsolate()); - Environment* env = Environment::GetCurrent(info.GetIsolate()); std::unique_ptr p{info.GetParameter()}; Local prop_bag = PersistentToLocal(info.GetIsolate(), p->propBag); - Local val = prop_bag->Get(env->destroyed_string()); + Local val = prop_bag->Get(p->env->destroyed_string()); if (val->IsFalse()) { - AsyncWrap::EmitDestroy(env, p->asyncId); + AsyncWrap::EmitDestroy(p->env, p->asyncId); } // unique_ptr goes out of scope here and pointer is deleted. } @@ -426,6 +426,7 @@ static void RegisterDestroyHook(const FunctionCallbackInfo& args) { Isolate* isolate = args.GetIsolate(); DestroyParam* p = new DestroyParam(); p->asyncId = args[1].As()->Value(); + p->env = Environment::GetCurrent(args); p->target.Reset(isolate, args[0].As()); p->propBag.Reset(isolate, args[2].As()); p->target.SetWeak(