Skip to content

Commit 51164dd

Browse files
joyeecheungjasnell
authored andcommitted
src: CancelTerminateExecution before throwing errors
Terminating the execution of a script would create a pending exception, therefore we should cancel the termination *before* throwing a new exception, otherwise the attempt to create a custom error may fail. PR-URL: #20146 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent e8ea61b commit 51164dd

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/module_wrap.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo<Value>& args) {
279279
result = module->Evaluate(context);
280280
}
281281

282+
// Convert the termination exception into a regular exception.
282283
if (timed_out || received_signal) {
284+
env->isolate()->CancelTerminateExecution();
283285
// It is possible that execution was terminated by another timeout in
284286
// which this timeout is nested, so check whether one of the watchdogs
285287
// from this invocation is responsible for termination.
@@ -288,7 +290,6 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo<Value>& args) {
288290
} else if (received_signal) {
289291
env->ThrowError("Script execution interrupted.");
290292
}
291-
env->isolate()->CancelTerminateExecution();
292293
}
293294

294295
if (try_catch.HasCaught()) {

src/node_contextify.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,9 @@ class ContextifyScript : public BaseObject {
851851
result = script->Run(env->context());
852852
}
853853

854+
// Convert the termination exception into a regular exception.
854855
if (timed_out || received_signal) {
856+
env->isolate()->CancelTerminateExecution();
855857
// It is possible that execution was terminated by another timeout in
856858
// which this timeout is nested, so check whether one of the watchdogs
857859
// from this invocation is responsible for termination.
@@ -860,7 +862,6 @@ class ContextifyScript : public BaseObject {
860862
} else if (received_signal) {
861863
env->ThrowError("Script execution interrupted.");
862864
}
863-
env->isolate()->CancelTerminateExecution();
864865
}
865866

866867
if (try_catch.HasCaught()) {

0 commit comments

Comments
 (0)