diff --git a/lib/internal/process/pre_execution.js b/lib/internal/process/pre_execution.js index c3cf39e52a78be..5d6bcca220cc4e 100644 --- a/lib/internal/process/pre_execution.js +++ b/lib/internal/process/pre_execution.js @@ -25,6 +25,7 @@ const { const { getOptionValue, refreshOptions, + getEmbedderOptions, } = require('internal/options'); const { reconnectZeroFillToggle } = require('internal/buffer'); const { @@ -241,7 +242,7 @@ function setupWarningHandler() { // https://fetch.spec.whatwg.org/ function setupFetch() { - if (process.config.variables.node_no_browser_globals || + if (getEmbedderOptions().noBrowserGlobals || getOptionValue('--no-experimental-fetch')) { return; } @@ -291,7 +292,7 @@ function setupFetch() { // TODO(aduh95): move this to internal/bootstrap/web/* when the CLI flag is // removed. function setupWebCrypto() { - if (process.config.variables.node_no_browser_globals || + if (getEmbedderOptions().noBrowserGlobals || getOptionValue('--no-experimental-global-webcrypto')) { return; } @@ -339,7 +340,7 @@ function setupCodeCoverage() { // TODO(daeyeon): move this to internal/bootstrap/web/* when the CLI flag is // removed. function setupCustomEvent() { - if (process.config.variables.node_no_browser_globals || + if (getEmbedderOptions().noBrowserGlobals || getOptionValue('--no-experimental-global-customevent')) { return; } diff --git a/src/node_options.cc b/src/node_options.cc index e54b51a59ed96c..c02752464c4ab5 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -1243,6 +1243,12 @@ void GetEmbedderOptions(const FunctionCallbackInfo& args) { Boolean::New(isolate, env->no_global_search_paths())) .IsNothing()) return; + if (ret->Set(context, + FIXED_ONE_BYTE_STRING(env->isolate(), "noBrowserGlobals"), + Boolean::New(isolate, env->no_browser_globals())) + .IsNothing()) + return; + args.GetReturnValue().Set(ret); } diff --git a/test/cctest/test_environment.cc b/test/cctest/test_environment.cc index 09dcb1dccc1b28..2e747c7be58922 100644 --- a/test/cctest/test_environment.cc +++ b/test/cctest/test_environment.cc @@ -38,6 +38,39 @@ class EnvironmentTest : public EnvironmentTestFixture { } }; +TEST_F(EnvironmentTest, EnvironmentWithoutBrowserGlobals) { + const v8::HandleScope handle_scope(isolate_); + Argv argv; + Env env{handle_scope, argv, node::EnvironmentFlags::kNoBrowserGlobals}; + + SetProcessExitHandler(*env, [&](node::Environment* env_, int exit_code) { + EXPECT_EQ(*env, env_); + EXPECT_EQ(exit_code, 0); + node::Stop(*env); + }); + + node::LoadEnvironment( + *env, + "const assert = require('assert');" + "const path = require('path');" + "const relativeRequire = " + " require('module').createRequire(path.join(process.cwd(), 'stub.js'));" + "const { intrinsics, nodeGlobals } = " + " relativeRequire('./test/common/globals');" + "const items = Object.getOwnPropertyNames(globalThis);" + "const leaks = [];" + "for (const item of items) {" + " if (intrinsics.has(item)) {" + " continue;" + " }" + " if (nodeGlobals.has(item)) {" + " continue;" + " }" + " leaks.push(item);" + "}" + "assert.deepStrictEqual(leaks, []);"); +} + TEST_F(EnvironmentTest, EnvironmentWithESMLoader) { const v8::HandleScope handle_scope(isolate_); Argv argv;