File tree Expand file tree Collapse file tree 3 files changed +43
-3
lines changed Expand file tree Collapse file tree 3 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ const {
2525const {
2626 getOptionValue,
2727 refreshOptions,
28+ getEmbedderOptions,
2829} = require ( 'internal/options' ) ;
2930const { reconnectZeroFillToggle } = require ( 'internal/buffer' ) ;
3031const {
@@ -241,7 +242,7 @@ function setupWarningHandler() {
241242
242243// https://fetch.spec.whatwg.org/
243244function setupFetch ( ) {
244- if ( process . config . variables . node_no_browser_globals ||
245+ if ( getEmbedderOptions ( ) . noBrowserGlobals ||
245246 getOptionValue ( '--no-experimental-fetch' ) ) {
246247 return ;
247248 }
@@ -291,7 +292,7 @@ function setupFetch() {
291292// TODO(aduh95): move this to internal/bootstrap/web/* when the CLI flag is
292293// removed.
293294function setupWebCrypto ( ) {
294- if ( process . config . variables . node_no_browser_globals ||
295+ if ( getEmbedderOptions ( ) . noBrowserGlobals ||
295296 getOptionValue ( '--no-experimental-global-webcrypto' ) ) {
296297 return ;
297298 }
@@ -339,7 +340,7 @@ function setupCodeCoverage() {
339340// TODO(daeyeon): move this to internal/bootstrap/web/* when the CLI flag is
340341// removed.
341342function setupCustomEvent ( ) {
342- if ( process . config . variables . node_no_browser_globals ||
343+ if ( getEmbedderOptions ( ) . noBrowserGlobals ||
343344 getOptionValue ( '--no-experimental-global-customevent' ) ) {
344345 return ;
345346 }
Original file line number Diff line number Diff line change @@ -1243,6 +1243,12 @@ void GetEmbedderOptions(const FunctionCallbackInfo<Value>& args) {
12431243 Boolean::New (isolate, env->no_global_search_paths ()))
12441244 .IsNothing ()) return ;
12451245
1246+ if (ret->Set (context,
1247+ FIXED_ONE_BYTE_STRING (env->isolate (), " noBrowserGlobals" ),
1248+ Boolean::New (isolate, env->no_browser_globals ()))
1249+ .IsNothing ())
1250+ return ;
1251+
12461252 args.GetReturnValue ().Set (ret);
12471253}
12481254
Original file line number Diff line number Diff line change @@ -38,6 +38,39 @@ class EnvironmentTest : public EnvironmentTestFixture {
3838 }
3939};
4040
41+ TEST_F (EnvironmentTest, EnvironmentWithoutBrowserGlobals) {
42+ const v8::HandleScope handle_scope (isolate_);
43+ Argv argv;
44+ Env env{handle_scope, argv, node::EnvironmentFlags::kNoBrowserGlobals };
45+
46+ SetProcessExitHandler (*env, [&](node::Environment* env_, int exit_code) {
47+ EXPECT_EQ (*env, env_);
48+ EXPECT_EQ (exit_code, 0 );
49+ node::Stop (*env);
50+ });
51+
52+ node::LoadEnvironment (
53+ *env,
54+ " const assert = require('assert');"
55+ " const path = require('path');"
56+ " const relativeRequire = "
57+ " require('module').createRequire(path.join(process.cwd(), 'stub.js'));"
58+ " const { intrinsics, nodeGlobals } = "
59+ " relativeRequire('./test/common/globals');"
60+ " const items = Object.getOwnPropertyNames(globalThis);"
61+ " const leaks = [];"
62+ " for (const item of items) {"
63+ " if (intrinsics.has(item)) {"
64+ " continue;"
65+ " }"
66+ " if (nodeGlobals.has(item)) {"
67+ " continue;"
68+ " }"
69+ " leaks.push(item);"
70+ " }"
71+ " assert.deepStrictEqual(leaks, []);" );
72+ }
73+
4174TEST_F (EnvironmentTest, EnvironmentWithESMLoader) {
4275 const v8::HandleScope handle_scope (isolate_);
4376 Argv argv;
You can’t perform that action at this time.
0 commit comments