From 03c71a95e236484fc65a171308dac5a2b55cf618 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Thu, 21 Feb 2019 11:46:58 +0800 Subject: [PATCH] src: use the config binding to carry --no-browser-globals Instead of setting it in the process object, since this is a configure-time option. Also added a shim that can be deprecated and removed some time later. PR-URL: https://github.com/nodejs/node/pull/26228 Reviewed-By: Daniel Bevenius Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater --- lib/internal/bootstrap/node.js | 3 +-- lib/internal/bootstrap/pre_execution.js | 14 ++++++++++++++ src/node_config.cc | 7 +++++++ src/node_process_object.cc | 5 ----- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index eb1f3e582045ae..aa6c6b262a4c2d 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -180,8 +180,7 @@ if (config.hasInspector) { internalBinding('inspector').registerAsyncHook(enable, disable); } -const browserGlobals = !process._noBrowserGlobals; -if (browserGlobals) { +if (!config.noBrowserGlobals) { // Override global console from the one provided by the VM // to the one implemented by Node.js // https://console.spec.whatwg.org/#console-namespace diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index 992c0c1983e722..1ba6c7a7580f49 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -136,6 +136,20 @@ function initializeDeprecations() { 'DEP0103') : types[name]; } + + // TODO(joyeecheung): this is a legacy property exposed to process. + // Now that we use the config binding to carry this information, remove + // it from the process. We may consider exposing it properly in + // process.features. + const { noBrowserGlobals } = internalBinding('config'); + if (noBrowserGlobals) { + Object.defineProperty(process, '_noBrowserGlobals', { + writable: false, + enumerable: true, + configurable: true, + value: noBrowserGlobals + }); + } } function setupChildProcessIpcChannel() { diff --git a/src/node_config.cc b/src/node_config.cc index b89a668419ce65..a0d7d25ec86634 100644 --- a/src/node_config.cc +++ b/src/node_config.cc @@ -64,6 +64,13 @@ static void Initialize(Local target, READONLY_FALSE_PROPERTY(target, "hasInspector"); #endif +// configure --no-browser-globals +#ifdef NODE_NO_BROWSER_GLOBALS + READONLY_TRUE_PROPERTY(target, "noBrowserGlobals"); +#else + READONLY_FALSE_PROPERTY(target, "noBrowserGlobals"); +#endif // NODE_NO_BROWSER_GLOBALS + READONLY_PROPERTY(target, "bits", Number::New(env->isolate(), 8 * sizeof(intptr_t))); diff --git a/src/node_process_object.cc b/src/node_process_object.cc index ece0eb76a5ae14..3e0bac6d2397f1 100644 --- a/src/node_process_object.cc +++ b/src/node_process_object.cc @@ -233,11 +233,6 @@ MaybeLocal CreateProcessObject( READONLY_PROPERTY(process, "throwDeprecation", True(env->isolate())); } -#ifdef NODE_NO_BROWSER_GLOBALS - // configure --no-browser-globals - READONLY_PROPERTY(process, "_noBrowserGlobals", True(env->isolate())); -#endif // NODE_NO_BROWSER_GLOBALS - // --prof-process // TODO(addaleax): Remove this. if (env->options()->prof_process) {