src: handle exceptions from ToDetailString()

These methods may fail if execution is terminating.

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Anna Henningsen 2019-06-02 15:47:53 +02:00
parent 890223dede
commit 626f243747
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
2 changed files with 6 additions and 3 deletions

View File

@ -180,7 +180,8 @@ void PrintException(Isolate* isolate,
Local<Value> err,
Local<Message> message) {
node::Utf8Value reason(isolate,
err->ToDetailString(context).ToLocalChecked());
err->ToDetailString(context)
.FromMaybe(Local<String>()));
bool added_exception_line = false;
std::string source =
GetErrorSource(isolate, context, message, &added_exception_line);

View File

@ -125,8 +125,10 @@ static void PreviewEntries(const FunctionCallbackInfo<Value>& args) {
// Side effect-free stringification that will never throw exceptions.
static void SafeToString(const FunctionCallbackInfo<Value>& args) {
auto context = args.GetIsolate()->GetCurrentContext();
args.GetReturnValue().Set(args[0]->ToDetailString(context).ToLocalChecked());
Local<Context> context = args.GetIsolate()->GetCurrentContext();
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) {