Files
electron/patches/node/fix_assert_module_in_the_renderer_process.patch
electron-roller[bot] 38512efd25 chore: bump node to v20.17.0 (main) (#43428)
* chore: bump node in DEPS to v20.17.0

* module: disallow CJS <-> ESM edges in a cycle from require(esm)

https://github.com/nodejs/node/pull/52264

* src: expose LookupAndCompile with parameters

https://github.com/nodejs/node/pull/53886

* src: fix -Wshadow warning

https://github.com/nodejs/node/pull/53885

* lib: convert WeakMaps in cjs loader with symbol properties

https://github.com/nodejs/node/pull/52095

* src: reduce unnecessary serialization of CLI options in C++

https://github.com/nodejs/node/pull/52451

* build: ensure v8_pointer_compression_sandbox is enabled on 64bit

https://github.com/nodejs/node/pull/53884

* lib: improve error message when index not found on cjs

https://github.com/nodejs/node/pull/53859

* src,lib: expose getCategoryEnabledBuffer to use on node.http

https://github.com/nodejs/node/pull/53602

* deps: update c-ares to v1.32.2

https://github.com/nodejs/node/pull/53865

* chore: fixup patch indices

* deps: update V8 to 12.2

https://github.com/nodejs/node/pull/51362

* stream: Expose DuplexPair API

https://github.com/nodejs/node/pull/34111

---------

Co-authored-by: electron-roller[bot] <84116207+electron-roller[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
2024-08-26 15:09:33 -04:00

82 lines
3.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shelley Vohr <shelley.vohr@gmail.com>
Date: Wed, 16 Aug 2023 19:15:29 +0200
Subject: fix: assert module in the renderer process
When creating a Node.js Environment, embedders have the option to disable Node.js'
default overriding of Error.prepareStackTrace. However, the assert module depends on
a WeakMap that is populated with the error stacktraces in the overridden function.
This adds handling to fall back to the default implementation if Error.prepareStackTrace
if the override has been disabled.
This will be upstreamed.
diff --git a/lib/assert.js b/lib/assert.js
index eadc3844c20128bb9f9a269e5d599f8febf17421..e4615e55c0847d969e9c95295ddecfc640019c99 100644
--- a/lib/assert.js
+++ b/lib/assert.js
@@ -66,6 +66,7 @@ const { inspect } = require('internal/util/inspect');
const { isPromise, isRegExp } = require('internal/util/types');
const { EOL } = require('internal/constants');
const { BuiltinModule } = require('internal/bootstrap/realm');
+const { getEmbedderOptions } = require('internal/options');
const { isError, deprecate } = require('internal/util');
const errorCache = new SafeMap();
@@ -294,8 +295,16 @@ function getErrMessage(message, fn) {
ErrorCaptureStackTrace(err, fn);
if (errorStackTraceLimitIsWritable) Error.stackTraceLimit = tmpLimit;
- overrideStackTrace.set(err, (_, stack) => stack);
- const call = err.stack[0];
+ let call;
+ if (getEmbedderOptions().hasPrepareStackTraceCallback) {
+ overrideStackTrace.set(err, (_, stack) => stack);
+ call = err.stack[0];
+ } else {
+ const tmpPrepare = Error.prepareStackTrace;
+ Error.prepareStackTrace = (_, stack) => stack;
+ call = err.stack[0];
+ Error.prepareStackTrace = tmpPrepare;
+ }
let filename = call.getFileName();
const line = call.getLineNumber() - 1;
diff --git a/src/api/environment.cc b/src/api/environment.cc
index fe41619f45913fe31a59771c8d1af6cde3b89f66..bb6c6d51846fed1d160ec9dcd5a5dd67b4fef911 100644
--- a/src/api/environment.cc
+++ b/src/api/environment.cc
@@ -244,6 +244,9 @@ void SetIsolateErrorHandlers(v8::Isolate* isolate, const IsolateSettings& s) {
auto* prepare_stack_trace_cb = s.prepare_stack_trace_callback ?
s.prepare_stack_trace_callback : PrepareStackTraceCallback;
isolate->SetPrepareStackTraceCallback(prepare_stack_trace_cb);
+ } else {
+ auto env = Environment::GetCurrent(isolate);
+ env->set_prepare_stack_trace_callback(Local<Function>());
}
}
diff --git a/src/node_options.cc b/src/node_options.cc
index 74955717117001393e8b55809b4e4a1424019dad..409c6e3918e3ef7c9d35f87e093cb965cb889dd7 100644
--- a/src/node_options.cc
+++ b/src/node_options.cc
@@ -1393,14 +1393,16 @@ void GetEmbedderOptions(const FunctionCallbackInfo<Value>& args) {
}
Isolate* isolate = args.GetIsolate();
- constexpr size_t kOptionsSize = 4;
+ constexpr size_t kOptionsSize = 5;
std::array<Local<Name>, kOptionsSize> names = {
+ FIXED_ONE_BYTE_STRING(env->isolate(), "hasPrepareStackTraceCallback"),
FIXED_ONE_BYTE_STRING(env->isolate(), "shouldNotRegisterESMLoader"),
FIXED_ONE_BYTE_STRING(env->isolate(), "noGlobalSearchPaths"),
FIXED_ONE_BYTE_STRING(env->isolate(), "noBrowserGlobals"),
FIXED_ONE_BYTE_STRING(env->isolate(), "hasEmbedderPreload")};
std::array<Local<Value>, kOptionsSize> values = {
+ Boolean::New(isolate, env->prepare_stack_trace_callback().IsEmpty()),
Boolean::New(isolate, env->should_not_register_esm_loader()),
Boolean::New(isolate, env->no_global_search_paths()),
Boolean::New(isolate, env->no_browser_globals()),