Skip to content

Commit a32b8fb

Browse files
trevnorrisMyles Borins
authored and
Myles Borins
committed
src: fix MakeCallback error handling
Implementations of error handling between node::MakeCallback() and AsyncWrap::MakeCallback() do not return at the same point. Make both executions work the same by moving the early return if there's a caught exception just after the AsyncWrap post callback. Since the domain's call stack is cleared on a caught exception there is no reason to call its exit() callback. Remove the SetVerbose() statement in the AsyncWrap pre/post callback calls since it does not affect the callback call. Ref: #7048 PR-URL: #4507 Reviewed-By: Fedor Indutny <[email protected]>
1 parent 7652f55 commit a32b8fb

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

src/async-wrap.cc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,25 +207,22 @@ Local<Value> AsyncWrap::MakeCallback(const Local<Function> cb,
207207
}
208208

209209
if (ran_init_callback() && !pre_fn.IsEmpty()) {
210-
try_catch.SetVerbose(false);
211210
pre_fn->Call(context, 0, nullptr);
212211
if (try_catch.HasCaught())
213212
FatalError("node::AsyncWrap::MakeCallback", "pre hook threw");
214-
try_catch.SetVerbose(true);
215213
}
216214

217215
Local<Value> ret = cb->Call(context, argc, argv);
218216

219-
if (try_catch.HasCaught()) {
220-
return Undefined(env()->isolate());
221-
}
222-
223217
if (ran_init_callback() && !post_fn.IsEmpty()) {
224-
try_catch.SetVerbose(false);
225218
post_fn->Call(context, 0, nullptr);
226219
if (try_catch.HasCaught())
227220
FatalError("node::AsyncWrap::MakeCallback", "post hook threw");
228-
try_catch.SetVerbose(true);
221+
}
222+
223+
// If the return value is empty then the callback threw.
224+
if (ret.IsEmpty()) {
225+
return Undefined(env()->isolate());
229226
}
230227

231228
if (has_domain) {

src/node.cc

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,21 +1165,22 @@ Local<Value> MakeCallback(Environment* env,
11651165
}
11661166

11671167
if (ran_init_callback && !pre_fn.IsEmpty()) {
1168-
try_catch.SetVerbose(false);
11691168
pre_fn->Call(object, 0, nullptr);
11701169
if (try_catch.HasCaught())
11711170
FatalError("node::MakeCallback", "pre hook threw");
1172-
try_catch.SetVerbose(true);
11731171
}
11741172

11751173
Local<Value> ret = callback->Call(recv, argc, argv);
11761174

11771175
if (ran_init_callback && !post_fn.IsEmpty()) {
1178-
try_catch.SetVerbose(false);
11791176
post_fn->Call(object, 0, nullptr);
11801177
if (try_catch.HasCaught())
11811178
FatalError("node::MakeCallback", "post hook threw");
1182-
try_catch.SetVerbose(true);
1179+
}
1180+
1181+
// If the return value is empty then the callback threw.
1182+
if (ret.IsEmpty()) {
1183+
return Undefined(env->isolate());
11831184
}
11841185

11851186
if (has_domain) {
@@ -1191,10 +1192,6 @@ Local<Value> MakeCallback(Environment* env,
11911192
}
11921193
}
11931194

1194-
if (try_catch.HasCaught()) {
1195-
return Undefined(env->isolate());
1196-
}
1197-
11981195
if (!env->KickNextTick())
11991196
return Undefined(env->isolate());
12001197

0 commit comments

Comments
 (0)