@@ -398,6 +398,7 @@ static void DisablePromiseHook(const FunctionCallbackInfo<Value>& args) {
398398class DestroyParam {
399399 public:
400400 double asyncId;
401+ Environment* env;
401402 Persistent<Object> target;
402403 Persistent<Object> propBag;
403404};
@@ -406,13 +407,12 @@ class DestroyParam {
406407void AsyncWrap::WeakCallback (const v8::WeakCallbackInfo<DestroyParam>& info) {
407408 HandleScope scope (info.GetIsolate ());
408409
409- Environment* env = Environment::GetCurrent (info.GetIsolate ());
410410 std::unique_ptr<DestroyParam> p{info.GetParameter ()};
411411 Local<Object> prop_bag = PersistentToLocal (info.GetIsolate (), p->propBag );
412412
413- Local<Value> val = prop_bag->Get (env->destroyed_string ());
413+ Local<Value> val = prop_bag->Get (p-> env ->destroyed_string ());
414414 if (val->IsFalse ()) {
415- AsyncWrap::EmitDestroy (env, p->asyncId );
415+ AsyncWrap::EmitDestroy (p-> env , p->asyncId );
416416 }
417417 // unique_ptr goes out of scope here and pointer is deleted.
418418}
@@ -426,6 +426,7 @@ static void RegisterDestroyHook(const FunctionCallbackInfo<Value>& args) {
426426 Isolate* isolate = args.GetIsolate ();
427427 DestroyParam* p = new DestroyParam ();
428428 p->asyncId = args[1 ].As <Number>()->Value ();
429+ p->env = Environment::GetCurrent (args);
429430 p->target .Reset (isolate, args[0 ].As <Object>());
430431 p->propBag .Reset (isolate, args[2 ].As <Object>());
431432 p->target .SetWeak (
0 commit comments