Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stack traces in non-Node.js contexts #26820

Merged
merged 1 commit into from Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions patches/node/.patches
Expand Up @@ -29,3 +29,4 @@ fix_-wincompatible-pointer-types-discards-qualifiers_error.patch
fix_add_v8_enable_reverse_jsargs_defines_in_common_gypi.patch
fix_allow_preventing_initializeinspector_in_env.patch
src_allow_embedders_to_provide_a_custom_pageallocator_to.patch
allow_preventing_preparestacktracecallback.patch
44 changes: 44 additions & 0 deletions patches/node/allow_preventing_preparestacktracecallback.patch
@@ -0,0 +1,44 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shelley Vohr <shelley.vohr@gmail.com>
Date: Mon, 7 Dec 2020 16:54:23 -0800
Subject: Allow preventing PrepareStackTraceCallback

Node.js sets a stack trace handler specific to the v8::Context
corresponding to the current Environment. When we're running in a
non-Node.js v8::Context, 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.

diff --git a/src/api/environment.cc b/src/api/environment.cc
index a8cf0d763f78c2752e3aa22479dadd9fa53c222f..8ccc0638b32039571c4a56725e21f0353b592984 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 14893ad605b9f8c64b0b8fc28625e235655dcd63..f150725b54ee1315476d202797963369490d5152 100644
--- a/src/node.h
+++ b/src/node.h
@@ -340,7 +340,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 {
7 changes: 7 additions & 0 deletions shell/common/node_bindings.cc
Expand Up @@ -503,6 +503,13 @@ node::Environment* NodeBindings::CreateEnvironment(
// context. We need to use the one Blink already provides.
is.flags |=
node::IsolateSettingsFlags::SHOULD_NOT_SET_PROMISE_REJECTION_CALLBACK;

// We do not want to use the stack trace callback that Node.js uses,
// because it relies on Node.js being aware of the current Context and
// that's not always the case. We need to use the one Blink already
// provides.
is.flags |=
node::IsolateSettingsFlags::SHOULD_NOT_SET_PREPARE_STACK_TRACE_CALLBACK;
}

node::SetIsolateUpForNode(context->GetIsolate(), is);
Expand Down