From 3eeb346aa96790765234f8e4759dd5896754067f Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 19 Apr 2018 17:18:07 +0800 Subject: 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: https://github.com/nodejs/node/pull/20146 Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: Anna Henningsen Reviewed-By: James M Snell --- src/module_wrap.cc | 3 ++- src/node_contextify.cc | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/module_wrap.cc b/src/module_wrap.cc index 48af2daa13..9bcdb4dce7 100644 --- a/src/module_wrap.cc +++ b/src/module_wrap.cc @@ -279,7 +279,9 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo& 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. @@ -288,7 +290,6 @@ void ModuleWrap::Evaluate(const FunctionCallbackInfo& args) { } else if (received_signal) { env->ThrowError("Script execution interrupted."); } - env->isolate()->CancelTerminateExecution(); } if (try_catch.HasCaught()) { diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 68251004d5..e07d5ebcd2 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -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. @@ -860,7 +862,6 @@ class ContextifyScript : public BaseObject { } else if (received_signal) { env->ThrowError("Script execution interrupted."); } - env->isolate()->CancelTerminateExecution(); } if (try_catch.HasCaught()) { -- cgit v1.2.3