Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2eb097f

Browse filesBrowse files
trevnorrisMyles Borins
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. Ref: #7048 PR-URL: #4507 Reviewed-By: Fedor Indutny <fedor@indutny.com>
1 parent da9595f commit 2eb097f
Copy full SHA for 2eb097f

File tree

Expand file treeCollapse file tree

2 files changed

+10
-16
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-16
lines changed
Open diff view settings
Collapse file

‎src/async-wrap.cc‎

Copy file name to clipboardExpand all lines: src/async-wrap.cc
+5-8Lines 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) {
Collapse file

‎src/node.cc‎

Copy file name to clipboardExpand all lines: src/node.cc
+5-8Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.