Skip to content

Commit 6564369

Browse files
committed
src: make ReqWrap weak
This commit allows throwing an exception after creating `FSReqCallback`
1 parent 07d7e1b commit 6564369

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

lib/fs.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424

2525
'use strict';
2626

27-
// When using FSReqCallback, make sure to create the object only *after* all
28-
// parameter validation has happened, so that the objects are not kept in memory
29-
// in case they are created but never used due to an exception.
30-
3127
const {
3228
ArrayPrototypePush,
3329
BigIntPrototypeToString,

src/req_wrap-inl.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ ReqWrap<T>::ReqWrap(Environment* env,
2020
AsyncWrap::ProviderType provider)
2121
: AsyncWrap(env, object, provider),
2222
ReqWrapBase(env) {
23+
MakeWeak();
2324
Reset();
2425
}
2526

2627
template <typename T>
2728
ReqWrap<T>::~ReqWrap() {
28-
CHECK_EQ(false, persistent().IsEmpty());
2929
}
3030

3131
template <typename T>
@@ -138,7 +138,6 @@ template <typename T>
138138
template <typename LibuvFunction, typename... Args>
139139
int ReqWrap<T>::Dispatch(LibuvFunction fn, Args... args) {
140140
Dispatched();
141-
142141
// This expands as:
143142
//
144143
// int err = fn(env()->event_loop(), req(), arg1, arg2, Wrapper, arg3, ...)
@@ -158,8 +157,10 @@ int ReqWrap<T>::Dispatch(LibuvFunction fn, Args... args) {
158157
env()->event_loop(),
159158
req(),
160159
MakeLibuvRequestCallback<T, Args>::For(this, args)...);
161-
if (err >= 0)
160+
if (err >= 0) {
161+
ClearWeak();
162162
env()->IncreaseWaitingRequestCounter();
163+
}
163164
return err;
164165
}
165166

0 commit comments

Comments
 (0)