From 8849eb24c1c5f3da68500c9c462c4c74e92f90a3 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 2 Jun 2019 15:47:53 +0200 Subject: [PATCH] src: handle exceptions from ToDetailString() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These methods may fail if execution is terminating. PR-URL: https://github.com/nodejs/node/pull/28019 Reviewed-By: Rich Trott Reviewed-By: Michaƫl Zasso Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater --- src/node_errors.cc | 3 ++- src/node_util.cc | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/node_errors.cc b/src/node_errors.cc index 603c9e415c3f54..baf08b30458677 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -180,7 +180,8 @@ void PrintException(Isolate* isolate, Local err, Local message) { node::Utf8Value reason(isolate, - err->ToDetailString(context).ToLocalChecked()); + err->ToDetailString(context) + .FromMaybe(Local())); bool added_exception_line = false; std::string source = GetErrorSource(isolate, context, message, &added_exception_line); diff --git a/src/node_util.cc b/src/node_util.cc index 9e506f0e6570de..ab54c84379de84 100644 --- a/src/node_util.cc +++ b/src/node_util.cc @@ -125,8 +125,10 @@ static void PreviewEntries(const FunctionCallbackInfo& args) { // Side effect-free stringification that will never throw exceptions. static void SafeToString(const FunctionCallbackInfo& args) { - auto context = args.GetIsolate()->GetCurrentContext(); - args.GetReturnValue().Set(args[0]->ToDetailString(context).ToLocalChecked()); + Local context = args.GetIsolate()->GetCurrentContext(); + Local detail_string; + if (args[0]->ToDetailString(context).ToLocal(&detail_string)) + args.GetReturnValue().Set(detail_string); } inline Local IndexToPrivateSymbol(Environment* env, uint32_t index) {