Skip to content

Commit

Permalink
src: CancelTerminateExecution before throwing errors
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
joyeecheung committed Apr 22, 2018
1 parent f31fc93 commit 3eeb346
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/module_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo<Value>& args) {
result = module->Evaluate(context);
}

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

if (try_catch.HasCaught()) {
Expand Down
3 changes: 2 additions & 1 deletion src/node_contextify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,9 @@ class ContextifyScript : public BaseObject {
result = script->Run(env->context());
}

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

if (try_catch.HasCaught()) {
Expand Down

0 comments on commit 3eeb346

Please sign in to comment.