Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-09-10 00:43:21 +0300
committerDaniel Bevenius <daniel.bevenius@gmail.com>2019-09-16 06:53:43 +0300
commite095e645e52f14e135e80f0f910c812ca767ff31 (patch)
tree18f00969db2edd08b7e23627a71f88ef3ecb15f4 /src/node_task_queue.cc
parent233cdb64a95eaabce922d773f3e312565e18a9d4 (diff)
src: print exceptions from PromiseRejectCallback
Previously, leaving the exception lying around would leave the JS engine in an invalid state, as it was not expecting exceptions to be thrown from the C++ `PromiseRejectCallback`, and lead to hard crashes under some conditions (e.g. with coverage enabled). PR-URL: https://github.com/nodejs/node/pull/29513 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_task_queue.cc')
-rw-r--r--src/node_task_queue.cc10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/node_task_queue.cc b/src/node_task_queue.cc
index 4ff51bc3b80..b4e8c1de928 100644
--- a/src/node_task_queue.cc
+++ b/src/node_task_queue.cc
@@ -10,6 +10,7 @@
namespace node {
+using errors::TryCatchScope;
using v8::Array;
using v8::Context;
using v8::Function;
@@ -111,8 +112,17 @@ void PromiseRejectCallback(PromiseRejectMessage message) {
}
Local<Value> args[] = { type, promise, value };
+
+ // V8 does not expect this callback to have a scheduled exceptions once it
+ // returns, so we print them out in a best effort to do something about it
+ // without failing silently and without crashing the process.
+ TryCatchScope try_catch(env);
USE(callback->Call(
env->context(), Undefined(isolate), arraysize(args), args));
+ if (try_catch.HasCaught() && !try_catch.HasTerminated()) {
+ fprintf(stderr, "Exception in PromiseRejectCallback:\n");
+ PrintCaughtException(isolate, env->context(), try_catch);
+ }
}
static void SetPromiseRejectCallback(