@@ -534,12 +534,12 @@ void AsyncWrap::GetProviderType(const FunctionCallbackInfo<Value>& args) {
534534}
535535
536536
537- void AsyncWrap::EmitDestroy () {
537+ void AsyncWrap::EmitDestroy (bool from_gc ) {
538538 AsyncWrap::EmitDestroy (env (), async_id_);
539539 // Ensure no double destroy is emitted via AsyncReset().
540540 async_id_ = kInvalidAsyncId ;
541541
542- if (!persistent ().IsEmpty ()) {
542+ if (!persistent ().IsEmpty () && !from_gc ) {
543543 HandleScope handle_scope (env ()->isolate ());
544544 USE (object ()->Set (env ()->context (), env ()->resource_symbol (), object ()));
545545 }
@@ -727,7 +727,7 @@ bool AsyncWrap::IsDoneInitializing() const {
727727
728728AsyncWrap::~AsyncWrap () {
729729 EmitTraceEventDestroy ();
730- EmitDestroy ();
730+ EmitDestroy (true /* from gc */ );
731731}
732732
733733void AsyncWrap::EmitTraceEventDestroy () {
@@ -853,7 +853,7 @@ MaybeLocal<Value> AsyncWrap::MakeCallback(const Local<Function> cb,
853853 ProviderType provider = provider_type ();
854854 async_context context { get_async_id (), get_trigger_async_id () };
855855 MaybeLocal<Value> ret = InternalMakeCallback (
856- env (), GetResource (), object (), cb, argc, argv, context);
856+ env (), object (), object (), cb, argc, argv, context);
857857
858858 // This is a static call with cached values because the `this` object may
859859 // no longer be alive at this point.
0 commit comments