Skip to content

Commit a2f17f1

Browse files
trevnorrisMyles Borins
authored and
Myles Borins
committed
src: remove TryCatch in MakeCallback
After attempting to use ReThrow() and Reset() there were cases where firing the domain's error handlers was not happening. Or in some cases reentering MakeCallback would still cause the domain enter callback to abort (because the error had not been Reset yet). In order for the script to properly stop execution when a subsequent call to MakeCallback throws it must not be located within a TryCatch. Ref: #7048 PR-URL: #4507 Reviewed-By: Fedor Indutny <[email protected]>
1 parent 0860758 commit a2f17f1

File tree

3 files changed

+27
-41
lines changed

3 files changed

+27
-41
lines changed

src/async-wrap.cc

+11-17
Original file line numberDiff line numberDiff line change
@@ -196,43 +196,39 @@ Local<Value> AsyncWrap::MakeCallback(const Local<Function> cb,
196196
}
197197
}
198198

199-
TryCatch try_catch(env()->isolate());
200-
try_catch.SetVerbose(true);
201-
202199
if (has_domain) {
203200
Local<Value> enter_v = domain->Get(env()->enter_string());
204201
if (enter_v->IsFunction()) {
205-
enter_v.As<Function>()->Call(domain, 0, nullptr);
206-
if (try_catch.HasCaught())
207-
return Undefined(env()->isolate());
202+
if (enter_v.As<Function>()->Call(domain, 0, nullptr).IsEmpty()) {
203+
FatalError("node::AsyncWrap::MakeCallback",
204+
"domain enter callback threw, please report this");
205+
}
208206
}
209207
}
210208

211209
if (ran_init_callback() && !pre_fn.IsEmpty()) {
212-
pre_fn->Call(context, 0, nullptr);
213-
if (try_catch.HasCaught())
210+
if (pre_fn->Call(context, 0, nullptr).IsEmpty())
214211
FatalError("node::AsyncWrap::MakeCallback", "pre hook threw");
215212
}
216213

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

219216
if (ran_init_callback() && !post_fn.IsEmpty()) {
220-
post_fn->Call(context, 0, nullptr);
221-
if (try_catch.HasCaught())
217+
if (post_fn->Call(context, 0, nullptr).IsEmpty())
222218
FatalError("node::AsyncWrap::MakeCallback", "post hook threw");
223219
}
224220

225-
// If the return value is empty then the callback threw.
226221
if (ret.IsEmpty()) {
227222
return Undefined(env()->isolate());
228223
}
229224

230225
if (has_domain) {
231226
Local<Value> exit_v = domain->Get(env()->exit_string());
232227
if (exit_v->IsFunction()) {
233-
exit_v.As<Function>()->Call(domain, 0, nullptr);
234-
if (try_catch.HasCaught())
235-
return Undefined(env()->isolate());
228+
if (exit_v.As<Function>()->Call(domain, 0, nullptr).IsEmpty()) {
229+
FatalError("node::AsyncWrap::MakeCallback",
230+
"domain exit callback threw, please report this");
231+
}
236232
}
237233
}
238234

@@ -251,9 +247,7 @@ Local<Value> AsyncWrap::MakeCallback(const Local<Function> cb,
251247
return ret;
252248
}
253249

254-
env()->tick_callback_function()->Call(process, 0, nullptr);
255-
256-
if (try_catch.HasCaught()) {
250+
if (env()->tick_callback_function()->Call(process, 0, nullptr).IsEmpty()) {
257251
return Undefined(env()->isolate());
258252
}
259253

src/env.cc

+4-9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ using v8::Message;
1111
using v8::StackFrame;
1212
using v8::StackTrace;
1313
using v8::TryCatch;
14+
using v8::Value;
1415

1516
void Environment::PrintSyncTrace() const {
1617
if (!trace_sync_io_)
@@ -73,16 +74,10 @@ bool Environment::KickNextTick(Environment::AsyncCallbackScope* scope) {
7374
return true;
7475
}
7576

76-
// process nextTicks after call
77-
TryCatch try_catch(isolate());
78-
try_catch.SetVerbose(true);
79-
tick_callback_function()->Call(process_object(), 0, nullptr);
77+
Local<Value> ret =
78+
tick_callback_function()->Call(process_object(), 0, nullptr);
8079

81-
if (try_catch.HasCaught()) {
82-
return false;
83-
}
84-
85-
return true;
80+
return !ret.IsEmpty();
8681
}
8782

8883
} // namespace node

src/node.cc

+12-15
Original file line numberDiff line numberDiff line change
@@ -1154,48 +1154,45 @@ Local<Value> MakeCallback(Environment* env,
11541154
}
11551155
}
11561156

1157-
TryCatch try_catch(env->isolate());
1158-
try_catch.SetVerbose(true);
1159-
11601157
if (has_domain) {
11611158
Local<Value> enter_v = domain->Get(env->enter_string());
11621159
if (enter_v->IsFunction()) {
1163-
enter_v.As<Function>()->Call(domain, 0, nullptr);
1164-
if (try_catch.HasCaught())
1165-
return Undefined(env->isolate());
1160+
if (enter_v.As<Function>()->Call(domain, 0, nullptr).IsEmpty()) {
1161+
FatalError("node::MakeCallback",
1162+
"domain enter callback threw, please report this");
1163+
}
11661164
}
11671165
}
11681166

11691167
if (ran_init_callback && !pre_fn.IsEmpty()) {
1170-
pre_fn->Call(object, 0, nullptr);
1171-
if (try_catch.HasCaught())
1168+
if (pre_fn->Call(object, 0, nullptr).IsEmpty())
11721169
FatalError("node::MakeCallback", "pre hook threw");
11731170
}
11741171

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

11771174
if (ran_init_callback && !post_fn.IsEmpty()) {
1178-
post_fn->Call(object, 0, nullptr);
1179-
if (try_catch.HasCaught())
1175+
if (post_fn->Call(object, 0, nullptr).IsEmpty())
11801176
FatalError("node::MakeCallback", "post hook threw");
11811177
}
11821178

1183-
// If the return value is empty then the callback threw.
11841179
if (ret.IsEmpty()) {
11851180
return Undefined(env->isolate());
11861181
}
11871182

11881183
if (has_domain) {
11891184
Local<Value> exit_v = domain->Get(env->exit_string());
11901185
if (exit_v->IsFunction()) {
1191-
exit_v.As<Function>()->Call(domain, 0, nullptr);
1192-
if (try_catch.HasCaught())
1193-
return Undefined(env->isolate());
1186+
if (exit_v.As<Function>()->Call(domain, 0, nullptr).IsEmpty()) {
1187+
FatalError("node::MakeCallback",
1188+
"domain exit callback threw, please report this");
1189+
}
11941190
}
11951191
}
11961192

1197-
if (!env->KickNextTick(&callback_scope))
1193+
if (!env->KickNextTick(&callback_scope)) {
11981194
return Undefined(env->isolate());
1195+
}
11991196

12001197
return ret;
12011198
}

0 commit comments

Comments
 (0)