From 656436913a0cb276adc395da22b1aecce624f7d8 Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Tue, 26 Jul 2022 10:53:00 -0300 Subject: [PATCH] src: make ReqWrap weak This commit allows throwing an exception after creating `FSReqCallback` --- lib/fs.js | 4 ---- src/req_wrap-inl.h | 7 ++++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 874b6259431ba0..8dcea37596cde5 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -24,10 +24,6 @@ 'use strict'; -// When using FSReqCallback, make sure to create the object only *after* all -// parameter validation has happened, so that the objects are not kept in memory -// in case they are created but never used due to an exception. - const { ArrayPrototypePush, BigIntPrototypeToString, diff --git a/src/req_wrap-inl.h b/src/req_wrap-inl.h index c905b605cbde97..e175dd68d1d955 100644 --- a/src/req_wrap-inl.h +++ b/src/req_wrap-inl.h @@ -20,12 +20,12 @@ ReqWrap::ReqWrap(Environment* env, AsyncWrap::ProviderType provider) : AsyncWrap(env, object, provider), ReqWrapBase(env) { + MakeWeak(); Reset(); } template ReqWrap::~ReqWrap() { - CHECK_EQ(false, persistent().IsEmpty()); } template @@ -138,7 +138,6 @@ template template int ReqWrap::Dispatch(LibuvFunction fn, Args... args) { Dispatched(); - // This expands as: // // int err = fn(env()->event_loop(), req(), arg1, arg2, Wrapper, arg3, ...) @@ -158,8 +157,10 @@ int ReqWrap::Dispatch(LibuvFunction fn, Args... args) { env()->event_loop(), req(), MakeLibuvRequestCallback::For(this, args)...); - if (err >= 0) + if (err >= 0) { + ClearWeak(); env()->IncreaseWaitingRequestCounter(); + } return err; }