From 658a266cd4455ab15f0db76009417e2c1312f988 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 8 Dec 2020 09:51:31 -0800 Subject: [PATCH] src: allow preventing SetPrepareStackTraceCallback Node.js sets a stack trace handler specific to the v8::Context corresponding to the current Environment. When Electron is running in a non-Node.js v8::Context (e.g in the renderer process with contextIsolation enabled), there will be no correspondent Environment - we therefore need to prevent this handler being set so that Blink falls back to its default handling and displays the correct stacktrace. PR-URL: https://github.com/nodejs/node/pull/36447 Reviewed-By: Colin Ihrig Reviewed-By: Gus Caplan Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott --- src/api/environment.cc | 8 +++++--- src/node.h | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/api/environment.cc b/src/api/environment.cc index 5426d5392a29fc..8aa230c8a60421 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -228,9 +228,11 @@ void SetIsolateErrorHandlers(v8::Isolate* isolate, const IsolateSettings& s) { s.fatal_error_callback : OnFatalError; isolate->SetFatalErrorHandler(fatal_error_cb); - auto* prepare_stack_trace_cb = s.prepare_stack_trace_callback ? - s.prepare_stack_trace_callback : PrepareStackTraceCallback; - isolate->SetPrepareStackTraceCallback(prepare_stack_trace_cb); + if ((s.flags & SHOULD_NOT_SET_PREPARE_STACK_TRACE_CALLBACK) == 0) { + auto* prepare_stack_trace_cb = s.prepare_stack_trace_callback ? + s.prepare_stack_trace_callback : PrepareStackTraceCallback; + isolate->SetPrepareStackTraceCallback(prepare_stack_trace_cb); + } } void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s) { diff --git a/src/node.h b/src/node.h index b3412d151b4819..b5c268eed685f1 100644 --- a/src/node.h +++ b/src/node.h @@ -336,7 +336,8 @@ class NODE_EXTERN MultiIsolatePlatform : public v8::Platform { enum IsolateSettingsFlags { MESSAGE_LISTENER_WITH_ERROR_LEVEL = 1 << 0, DETAILED_SOURCE_POSITIONS_FOR_PROFILING = 1 << 1, - SHOULD_NOT_SET_PROMISE_REJECTION_CALLBACK = 1 << 2 + SHOULD_NOT_SET_PROMISE_REJECTION_CALLBACK = 1 << 2, + SHOULD_NOT_SET_PREPARE_STACK_TRACE_CALLBACK = 1 << 3 }; struct IsolateSettings {