Skip to content

Commit 8849eb2

Browse files
addaleaxBridgeAR
authored andcommitted
src: handle exceptions from ToDetailString()
These methods may fail if execution is terminating. PR-URL: #28019 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 8a032fc commit 8849eb2

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/node_errors.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ void PrintException(Isolate* isolate,
180180
Local<Value> err,
181181
Local<Message> message) {
182182
node::Utf8Value reason(isolate,
183-
err->ToDetailString(context).ToLocalChecked());
183+
err->ToDetailString(context)
184+
.FromMaybe(Local<String>()));
184185
bool added_exception_line = false;
185186
std::string source =
186187
GetErrorSource(isolate, context, message, &added_exception_line);

src/node_util.cc

+4-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,10 @@ static void PreviewEntries(const FunctionCallbackInfo<Value>& args) {
125125

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

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

0 commit comments

Comments
 (0)