Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bootstrap: hide experimental web globals with flag kNoBrowserGlobals #48545

Merged
merged 1 commit into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/internal/process/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
const {
getOptionValue,
refreshOptions,
getEmbedderOptions,
} = require('internal/options');
const { reconnectZeroFillToggle } = require('internal/buffer');
const {
Expand Down Expand Up @@ -220,7 +221,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;
}
Expand Down Expand Up @@ -270,7 +271,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;
}
Expand Down Expand Up @@ -318,7 +319,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;
}
Expand Down
6 changes: 6 additions & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,12 @@ void GetEmbedderOptions(const FunctionCallbackInfo<Value>& 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);
}

Expand Down
33 changes: 33 additions & 0 deletions test/cctest/test_environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down