From 675bbfe0925ec0c1f1d920ed9006167d5606fda9 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 30 Jun 2021 16:07:28 +0200 Subject: [PATCH] refactor: modify Node.js options object directly (#29939) * refactor: modify Node.js options object directly * chore: update patch to reflect upstream --- patches/node/.patches | 1 - ...t_pair_for_unhandled_rejections_mode.patch | 56 ------------------- ...to_provide_a_custom_pageallocator_to.patch | 7 ++- shell/browser/electron_browser_main_parts.cc | 2 +- shell/renderer/electron_renderer_client.cc | 6 +- 5 files changed, 10 insertions(+), 62 deletions(-) delete mode 100644 patches/node/src_add_get_set_pair_for_unhandled_rejections_mode.patch diff --git a/patches/node/.patches b/patches/node/.patches index 707f46399c82..1b1ff06c158e 100644 --- a/patches/node/.patches +++ b/patches/node/.patches @@ -23,5 +23,4 @@ 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 fix_crypto_tests_to_run_with_bssl.patch -src_add_get_set_pair_for_unhandled_rejections_mode.patch fix_account_for_debugger_agent_race_condition.patch diff --git a/patches/node/src_add_get_set_pair_for_unhandled_rejections_mode.patch b/patches/node/src_add_get_set_pair_for_unhandled_rejections_mode.patch deleted file mode 100644 index 264c07490b54..000000000000 --- a/patches/node/src_add_get_set_pair_for_unhandled_rejections_mode.patch +++ /dev/null @@ -1,56 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Shelley Vohr -Date: Thu, 3 Jun 2021 19:32:09 +0200 -Subject: src: add get/set pair for unhandled rejections mode - -This PR adds a get/set pair for unhandled rejections modes. - -We do not want unhandled rejections to crash the process and want to -be able to control this effectively from C++ and not cli flag -which is the only option right now. - -Upstreamed at https://github.com/nodejs/node/pull/38915. - -diff --git a/src/env-inl.h b/src/env-inl.h -index dc37298aa0e13bb79030123f38070d0254691b28..6b9c340fee164c09ec51037121efc91ec0ab4a8b 100644 ---- a/src/env-inl.h -+++ b/src/env-inl.h -@@ -570,6 +570,24 @@ inline bool Environment::abort_on_uncaught_exception() const { - return options_->abort_on_uncaught_exception; - } - -+inline void Environment::set_unhandled_rejections_mode( -+ const std::string& mode) { -+ if (!mode.empty() && -+ mode != "warn-with-error-code" && -+ mode != "throw" && -+ mode != "strict" && -+ mode != "warn" && -+ mode != "none") { -+ fprintf(stderr, "Invalid unhandled rejections mode: %s\n", mode.c_str()); -+ } else { -+ options_->unhandled_rejections = mode; -+ } -+} -+ -+inline std::string Environment::unhandled_rejections_mode() const { -+ return options_->unhandled_rejections; -+} -+ - inline void Environment::set_force_context_aware(bool value) { - options_->force_context_aware = value; - } -diff --git a/src/env.h b/src/env.h -index eaf8a17c99aa6a4135c54616f68b15e0620e4378..dcc163be2c2fa632660dde78012440fe50b03aa3 100644 ---- a/src/env.h -+++ b/src/env.h -@@ -1121,6 +1121,9 @@ class Environment : public MemoryRetainer { - void PrintSyncTrace() const; - inline void set_trace_sync_io(bool value); - -+ inline void set_unhandled_rejections_mode(const std::string& mode); -+ inline std::string unhandled_rejections_mode() const; -+ - inline void set_force_context_aware(bool value); - inline bool force_context_aware() const; - diff --git a/patches/node/src_allow_embedders_to_provide_a_custom_pageallocator_to.patch b/patches/node/src_allow_embedders_to_provide_a_custom_pageallocator_to.patch index 5cc81e979421..92276d143327 100644 --- a/patches/node/src_allow_embedders_to_provide_a_custom_pageallocator_to.patch +++ b/patches/node/src_allow_embedders_to_provide_a_custom_pageallocator_to.patch @@ -4,7 +4,12 @@ Date: Tue, 3 Nov 2020 16:17:38 -0800 Subject: src: allow embedders to provide a custom PageAllocator to NodePlatform -For certain embedder use cases there are more complex memory allocation requirements that the default V8 page allocator does not handle, for example using MAP_JIT when running under a hardened runtime environment on macOS. This allows such embedders to provide their own allocator that does handle these cases. +For certain embedder use cases there are more complex memory allocation requirements that +the default V8 page allocator does not handle, for example using MAP_JIT when running under +a hardened runtime environment on macOS. This allows such embedders to provide their own +allocator that does handle these cases. + +Upstreamed in https://github.com/nodejs/node/pull/38362. diff --git a/src/api/environment.cc b/src/api/environment.cc index 09c0d22ff91856704f61024646c946a39baf53d8..b060a8e980432637c430bd66a5216095984e4381 100644 diff --git a/shell/browser/electron_browser_main_parts.cc b/shell/browser/electron_browser_main_parts.cc index 07b2bd9bff67..be430e878361 100644 --- a/shell/browser/electron_browser_main_parts.cc +++ b/shell/browser/electron_browser_main_parts.cc @@ -250,7 +250,7 @@ void ElectronBrowserMainParts::PostEarlyInitialization() { env->set_trace_sync_io(env->options()->trace_sync_io); // We do not want to crash the main process on unhandled rejections. - env->set_unhandled_rejections_mode("warn"); + env->options()->unhandled_rejections = "warn"; // Add Electron extended APIs. electron_bindings_->BindTo(js_env_->isolate(), env->process_object()); diff --git a/shell/renderer/electron_renderer_client.cc b/shell/renderer/electron_renderer_client.cc index 78c95a895494..a7a98839fb54 100644 --- a/shell/renderer/electron_renderer_client.cc +++ b/shell/renderer/electron_renderer_client.cc @@ -110,11 +110,11 @@ void ElectronRendererClient::DidCreateScriptContext( node_bindings_->CreateEnvironment(renderer_context, nullptr); // If we have disabled the site instance overrides we should prevent loading - // any non-context aware native module - env->set_force_context_aware(true); + // any non-context aware native module. + env->options()->force_context_aware = true; // We do not want to crash the renderer process on unhandled rejections. - env->set_unhandled_rejections_mode("warn"); + env->options()->unhandled_rejections = "warn"; environments_.insert(env);