diff --git a/src/async_wrap.cc b/src/async_wrap.cc index ae3e5f90e6276f..2f8904432588c2 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -534,12 +534,12 @@ void AsyncWrap::GetProviderType(const FunctionCallbackInfo& args) { } -void AsyncWrap::EmitDestroy() { +void AsyncWrap::EmitDestroy(bool from_gc) { AsyncWrap::EmitDestroy(env(), async_id_); // Ensure no double destroy is emitted via AsyncReset(). async_id_ = kInvalidAsyncId; - if (!persistent().IsEmpty()) { + if (!persistent().IsEmpty() && !from_gc) { HandleScope handle_scope(env()->isolate()); USE(object()->Set(env()->context(), env()->resource_symbol(), object())); } @@ -727,7 +727,7 @@ bool AsyncWrap::IsDoneInitializing() const { AsyncWrap::~AsyncWrap() { EmitTraceEventDestroy(); - EmitDestroy(); + EmitDestroy(true /* from gc */); } void AsyncWrap::EmitTraceEventDestroy() { @@ -853,7 +853,7 @@ MaybeLocal AsyncWrap::MakeCallback(const Local cb, ProviderType provider = provider_type(); async_context context { get_async_id(), get_trigger_async_id() }; MaybeLocal ret = InternalMakeCallback( - env(), GetResource(), object(), cb, argc, argv, context); + env(), object(), object(), cb, argc, argv, context); // This is a static call with cached values because the `this` object may // no longer be alive at this point. diff --git a/src/async_wrap.h b/src/async_wrap.h index f84a1d529d99b6..6004801117ba5a 100644 --- a/src/async_wrap.h +++ b/src/async_wrap.h @@ -152,7 +152,7 @@ class AsyncWrap : public BaseObject { static void EmitAfter(Environment* env, double async_id); static void EmitPromiseResolve(Environment* env, double async_id); - void EmitDestroy(); + void EmitDestroy(bool from_gc = false); void EmitTraceEventBefore(); static void EmitTraceEventAfter(ProviderType type, double async_id);