Browse Source

refactor: modify Node.js options object directly (#29939)

* refactor: modify Node.js options object directly

* chore: update patch to reflect upstream
Shelley Vohr 3 years ago
parent
commit
675bbfe092

+ 0 - 1
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

+ 0 - 56
patches/node/src_add_get_set_pair_for_unhandled_rejections_mode.patch

@@ -1,56 +0,0 @@
-From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
-From: Shelley Vohr <[email protected]>
-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;
- 

+ 6 - 1
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

+ 1 - 1
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());

+ 3 - 3
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);