Skip to content

Commit 2cb1594

Browse files
trevnorrisrvagg
authored andcommitted
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. PR-URL: #4507 Reviewed-By: Fedor Indutny <[email protected]>
1 parent 35c3832 commit 2cb1594

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

src/async-wrap.cc

+5-8
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

+5-8
Original file line numberDiff line numberDiff line change
@@ -1173,21 +1173,22 @@ Local<Value> MakeCallback(Environment* env,
11731173
}
11741174

11751175
if (ran_init_callback && !pre_fn.IsEmpty()) {
1176-
try_catch.SetVerbose(false);
11771176
pre_fn->Call(object, 0, nullptr);
11781177
if (try_catch.HasCaught())
11791178
FatalError("node::MakeCallback", "pre hook threw");
1180-
try_catch.SetVerbose(true);
11811179
}
11821180

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

11851183
if (ran_init_callback && !post_fn.IsEmpty()) {
1186-
try_catch.SetVerbose(false);
11871184
post_fn->Call(object, 0, nullptr);
11881185
if (try_catch.HasCaught())
11891186
FatalError("node::MakeCallback", "post hook threw");
1190-
try_catch.SetVerbose(true);
1187+
}
1188+
1189+
// If the return value is empty then the callback threw.
1190+
if (ret.IsEmpty()) {
1191+
return Undefined(env->isolate());
11911192
}
11921193

11931194
if (has_domain) {
@@ -1199,10 +1200,6 @@ Local<Value> MakeCallback(Environment* env,
11991200
}
12001201
}
12011202

1202-
if (try_catch.HasCaught()) {
1203-
return Undefined(env->isolate());
1204-
}
1205-
12061203
if (!env->KickNextTick())
12071204
return Undefined(env->isolate());
12081205

0 commit comments

Comments
 (0)