Skip to content

Commit

Permalink
src: allow preventing SetPrepareStackTraceCallback
Browse files Browse the repository at this point in the history
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: #36447
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
codebytere authored and targos committed Aug 8, 2021
1 parent 6fd5cd5 commit 68052e3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/api/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 68052e3

Please sign in to comment.