From bc15550bf62c9bfb71ce48eb38d597ccf106b9a8 Mon Sep 17 00:00:00 2001 From: Daeyeon Jeong Date: Sun, 9 Oct 2022 19:41:55 -0500 Subject: [PATCH] lib: enable global CustomEvent by default Refs: https://github.com/nodejs/node/pull/43885 Signed-off-by: Daeyeon Jeong PR-URL: https://github.com/nodejs/node/pull/44860 Reviewed-By: James M Snell Reviewed-By: Antoine du Hamel (cherry picked from commit 80270994d6ba6019a6a74adc1b97a0cc1bd343ed) --- doc/api/cli.md | 10 +++++++++- doc/api/globals.md | 9 +++++++-- doc/node.1 | 6 +++--- lib/internal/process/pre_execution.js | 2 +- src/node_options.cc | 3 ++- src/node_options.h | 2 +- test/parallel/test-global-customevent-disabled.js | 7 +++++++ test/parallel/test-global-customevent.js | 2 +- test/parallel/test-repl-tab-complete.js | 2 +- test/wpt/test-events.js | 2 -- 10 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 test/parallel/test-global-customevent-disabled.js diff --git a/doc/api/cli.md b/doc/api/cli.md index e17d4c25f8bedb..78b827cbebe0b4 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -462,6 +462,14 @@ added: v18.0.0 Disable experimental support for the [Fetch API][]. +### `--no-experimental-global-customevent` + + + +Disable exposition of [CustomEvent Web API][] on the global scope. + ### `--no-experimental-repl-await` -> Stability: 1 - Experimental. Enable this API with the -> [`--experimental-global-customevent`][] CLI flag. +> Stability: 1 - Experimental. Disable this API with the +> [`--no-experimental-global-customevent`][] CLI flag. @@ -888,6 +892,7 @@ A browser-compatible implementation of [`WritableStreamDefaultWriter`][]. [`--experimental-global-customevent`]: cli.md#--experimental-global-customevent [`--experimental-global-webcrypto`]: cli.md#--experimental-global-webcrypto [`--no-experimental-fetch`]: cli.md#--no-experimental-fetch +[`--no-experimental-global-customevent`]: cli.md#--no-experimental-global-customevent [`AbortController`]: https://developer.mozilla.org/en-US/docs/Web/API/AbortController [`ByteLengthQueuingStrategy`]: webstreams.md#class-bytelengthqueuingstrategy [`CompressionStream`]: webstreams.md#class-compressionstream diff --git a/doc/node.1 b/doc/node.1 index ea2a9dab11ef17..0f9a01fb537768 100644 --- a/doc/node.1 +++ b/doc/node.1 @@ -145,9 +145,6 @@ Interpret as either ES modules or CommonJS modules input via --eval or STDIN, wh .js or extensionless files with no sibling or parent package.json; .js or extensionless files whose nearest parent package.json lacks a "type" field, unless under node_modules. . -.It Fl -experimental-global-customevent -Expose the CustomEvent on the global scope. -. .It Fl -experimental-global-webcrypto Expose the Web Crypto API on the global scope. . @@ -174,6 +171,9 @@ Enable code coverage in the test runner. .It Fl -no-experimental-fetch Disable experimental support for the Fetch API. . +.It Fl -no-experimental-global-customevent +Disable exposition of the CustomEvent on the global scope. +. .It Fl -no-experimental-repl-await Disable top-level await keyword support in REPL. . diff --git a/lib/internal/process/pre_execution.js b/lib/internal/process/pre_execution.js index 4795be82e74b6c..1d39f1089efea4 100644 --- a/lib/internal/process/pre_execution.js +++ b/lib/internal/process/pre_execution.js @@ -345,7 +345,7 @@ function setupCodeCoverage() { // removed. function setupCustomEvent() { if (process.config.variables.node_no_browser_globals || - !getOptionValue('--experimental-global-customevent')) { + getOptionValue('--no-experimental-global-customevent')) { return; } const { CustomEvent } = require('internal/event_target'); diff --git a/src/node_options.cc b/src/node_options.cc index 6ee79f7df8a1f8..f68c029e61a969 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -385,7 +385,8 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { AddOption("--experimental-global-customevent", "expose experimental CustomEvent on the global scope", &EnvironmentOptions::experimental_global_customevent, - kAllowedInEnvvar); + kAllowedInEnvironment, + true); AddOption("--experimental-global-webcrypto", "expose experimental Web Crypto API on the global scope", &EnvironmentOptions::experimental_global_web_crypto, diff --git a/src/node_options.h b/src/node_options.h index 743e19f58d5863..72f8a75778d168 100644 --- a/src/node_options.h +++ b/src/node_options.h @@ -111,7 +111,7 @@ class EnvironmentOptions : public Options { std::string dns_result_order; bool enable_source_maps = false; bool experimental_fetch = true; - bool experimental_global_customevent = false; + bool experimental_global_customevent = true; bool experimental_global_web_crypto = false; bool experimental_https_modules = false; std::string experimental_specifier_resolution; diff --git a/test/parallel/test-global-customevent-disabled.js b/test/parallel/test-global-customevent-disabled.js new file mode 100644 index 00000000000000..2e19a498a0c01d --- /dev/null +++ b/test/parallel/test-global-customevent-disabled.js @@ -0,0 +1,7 @@ +// Flags: --no-experimental-global-customevent +'use strict'; + +require('../common'); +const { strictEqual } = require('node:assert'); + +strictEqual(typeof CustomEvent, 'undefined'); diff --git a/test/parallel/test-global-customevent.js b/test/parallel/test-global-customevent.js index a113631a997bb9..cf21189b97643d 100644 --- a/test/parallel/test-global-customevent.js +++ b/test/parallel/test-global-customevent.js @@ -1,4 +1,4 @@ -// Flags: --experimental-global-customevent --expose-internals +// Flags: --expose-internals 'use strict'; require('../common'); diff --git a/test/parallel/test-repl-tab-complete.js b/test/parallel/test-repl-tab-complete.js index cc211d6da8aaef..06a55414d5beb5 100644 --- a/test/parallel/test-repl-tab-complete.js +++ b/test/parallel/test-repl-tab-complete.js @@ -405,7 +405,7 @@ putIn.run([ 'var custom = "test";', ]); testMe.complete('cus', common.mustCall(function(error, data) { - assert.deepStrictEqual(data, [['custom'], 'cus']); + assert.deepStrictEqual(data, [['CustomEvent', 'custom'], 'cus']); })); // Make sure tab completion doesn't crash REPL with half-baked proxy objects. diff --git a/test/wpt/test-events.js b/test/wpt/test-events.js index 428762b6642580..82bcf7c887c9b4 100644 --- a/test/wpt/test-events.js +++ b/test/wpt/test-events.js @@ -4,6 +4,4 @@ const { WPTRunner } = require('../common/wpt'); const runner = new WPTRunner('dom/events'); -runner.setFlags(['--experimental-global-customevent']); - runner.runJsTests();