Skip to content
Permalink
Browse files

src: handle exceptions from ToDetailString()

These methods may fail if execution is terminating.

PR-URL: #28019
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information...
addaleax committed Jun 2, 2019
1 parent 890223d commit 626f24374741c4ee83c7da45542b99e67855707d
Showing with 6 additions and 3 deletions.
  1. +2 −1 src/node_errors.cc
  2. +4 −2 src/node_util.cc
@@ -180,7 +180,8 @@ void PrintException(Isolate* isolate,
Local<Value> err, Local<Value> err,
Local<Message> message) { Local<Message> message) {
node::Utf8Value reason(isolate, node::Utf8Value reason(isolate,
err->ToDetailString(context).ToLocalChecked()); err->ToDetailString(context)
.FromMaybe(Local<String>()));
bool added_exception_line = false; bool added_exception_line = false;
std::string source = std::string source =
GetErrorSource(isolate, context, message, &added_exception_line); GetErrorSource(isolate, context, message, &added_exception_line);
@@ -125,8 +125,10 @@ static void PreviewEntries(const FunctionCallbackInfo<Value>& args) {


// Side effect-free stringification that will never throw exceptions. // Side effect-free stringification that will never throw exceptions.
static void SafeToString(const FunctionCallbackInfo<Value>& args) { static void SafeToString(const FunctionCallbackInfo<Value>& args) {
auto context = args.GetIsolate()->GetCurrentContext(); Local<Context> context = args.GetIsolate()->GetCurrentContext();
args.GetReturnValue().Set(args[0]->ToDetailString(context).ToLocalChecked()); Local<String> detail_string;
if (args[0]->ToDetailString(context).ToLocal(&detail_string))
args.GetReturnValue().Set(detail_string);
} }


inline Local<Private> IndexToPrivateSymbol(Environment* env, uint32_t index) { inline Local<Private> IndexToPrivateSymbol(Environment* env, uint32_t index) {

0 comments on commit 626f243

Please sign in to comment.
You can’t perform that action at this time.