diff --git a/src/env-inl.h b/src/env-inl.h index 1e85bc07a4cc29..14757419db00b2 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -892,6 +892,15 @@ inline bool Environment::no_global_search_paths() const { !options_->global_search_paths; } +inline bool Environment::no_browser_globals() const { + // configure --no-browser-globals +#ifdef NODE_NO_BROWSER_GLOBALS + return true; +#else + return flags_ & EnvironmentFlags::kNoBrowserGlobals; +#endif +} + bool Environment::filehandle_close_warning() const { return emit_filehandle_warning_; } diff --git a/src/env.h b/src/env.h index 0c3715151488f4..a9773c016ab3fd 100644 --- a/src/env.h +++ b/src/env.h @@ -1204,6 +1204,7 @@ class Environment : public MemoryRetainer { inline bool tracks_unmanaged_fds() const; inline bool hide_console_windows() const; inline bool no_global_search_paths() const; + inline bool no_browser_globals() const; inline uint64_t thread_id() const; inline worker::Worker* worker_context() const; Environment* worker_parent_env() const; diff --git a/src/node.h b/src/node.h index f34ed3939704bc..0c596b0ee6166d 100644 --- a/src/node.h +++ b/src/node.h @@ -418,7 +418,9 @@ enum Flags : uint64_t { // $HOME/.node_modules and $NODE_PATH. This is used by standalone apps that // do not expect to have their behaviors changed because of globally // installed modules. - kNoGlobalSearchPaths = 1 << 7 + kNoGlobalSearchPaths = 1 << 7, + // Do not export browser globals like setTimeout, console, etc. + kNoBrowserGlobals = 1 << 8, }; } // namespace EnvironmentFlags diff --git a/src/node_config.cc b/src/node_config.cc index 176daa88b0fab1..27bd8dc8ec570f 100644 --- a/src/node_config.cc +++ b/src/node_config.cc @@ -68,12 +68,10 @@ 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 + if (env->no_browser_globals()) + READONLY_TRUE_PROPERTY(target, "noBrowserGlobals"); + else + READONLY_FALSE_PROPERTY(target, "noBrowserGlobals"); READONLY_PROPERTY(target, "bits",