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 @@ -17,6 +17,7 @@ const {
1717const {
1818 getOptionValue,
1919 refreshOptions,
20+ getEmbedderOptions,
2021} = require ( 'internal/options' ) ;
2122const { reconnectZeroFillToggle } = require ( 'internal/buffer' ) ;
2223const {
@@ -233,7 +234,7 @@ function setupWarningHandler() {
233234
234235// https://fetch.spec.whatwg.org/
235236function setupFetch ( ) {
236- if ( process . config . variables . node_no_browser_globals ||
237+ if ( getEmbedderOptions ( ) . noBrowserGlobals ||
237238 getOptionValue ( '--no-experimental-fetch' ) ) {
238239 return ;
239240 }
@@ -283,7 +284,7 @@ function setupFetch() {
283284// TODO(aduh95): move this to internal/bootstrap/web/* when the CLI flag is
284285// removed.
285286function setupWebCrypto ( ) {
286- if ( process . config . variables . node_no_browser_globals ||
287+ if ( getEmbedderOptions ( ) . noBrowserGlobals ||
287288 getOptionValue ( '--no-experimental-global-webcrypto' ) ) {
288289 return ;
289290 }
@@ -331,7 +332,7 @@ function setupCodeCoverage() {
331332// TODO(daeyeon): move this to internal/bootstrap/web/* when the CLI flag is
332333// removed.
333334function setupCustomEvent ( ) {
334- if ( process . config . variables . node_no_browser_globals ||
335+ if ( getEmbedderOptions ( ) . noBrowserGlobals ||
335336 getOptionValue ( '--no-experimental-global-customevent' ) ) {
336337 return ;
337338 }
Original file line number Diff line number Diff line change @@ -1239,6 +1239,12 @@ void GetEmbedderOptions(const FunctionCallbackInfo<Value>& args) {
12391239 Boolean::New (isolate, env->no_global_search_paths ()))
12401240 .IsNothing ()) return ;
12411241
1242+ if (ret->Set (context,
1243+ FIXED_ONE_BYTE_STRING (env->isolate (), " noBrowserGlobals" ),
1244+ Boolean::New (isolate, env->no_browser_globals ()))
1245+ .IsNothing ())
1246+ return ;
1247+
12421248 args.GetReturnValue ().Set (ret);
12431249}
12441250
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