Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dfc4832

Browse filesBrowse files
daeyeondanielleadams
authored andcommitted
events: expose CustomEvent on global with CLI flag
Signed-off-by: Daeyeon Jeong daeyeon.dev@gmail.com PR-URL: #43885 Fixes: #40678 Refs: #43514 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Mestery <mestery@protonmail.com>
1 parent a96af37 commit dfc4832
Copy full SHA for dfc4832

File tree

Expand file treeCollapse file tree

13 files changed

+68
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

13 files changed

+68
-5
lines changed
Open diff view settings
Collapse file

‎.eslintrc.js‎

Copy file name to clipboardExpand all lines: .eslintrc.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ module.exports = {
321321
ByteLengthQueuingStrategy: 'readable',
322322
CompressionStream: 'readable',
323323
CountQueuingStrategy: 'readable',
324+
CustomEvent: 'readable',
324325
Crypto: 'readable',
325326
CryptoKey: 'readable',
326327
DecompressionStream: 'readable',
Collapse file

‎doc/api/cli.md‎

Copy file name to clipboardExpand all lines: doc/api/cli.md
+10Lines changed: 10 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,14 @@ effort to report stack traces relative to the original source file.
280280
Overriding `Error.prepareStackTrace` prevents `--enable-source-maps` from
281281
modifying the stack trace.
282282

283+
### `--experimental-global-customevent`
284+
285+
<!-- YAML
286+
added: REPLACEME
287+
-->
288+
289+
Expose the [CustomEvent Web API][] on the global scope.
290+
283291
### `--experimental-global-webcrypto`
284292

285293
<!-- YAML
@@ -1640,6 +1648,7 @@ Node.js options that are allowed are:
16401648
* `--enable-fips`
16411649
* `--enable-source-maps`
16421650
* `--experimental-abortcontroller`
1651+
* `--experimental-global-customevent`
16431652
* `--experimental-global-webcrypto`
16441653
* `--experimental-import-meta-resolve`
16451654
* `--experimental-json-modules`
@@ -2064,6 +2073,7 @@ done
20642073
[#42511]: https://github.com/nodejs/node/issues/42511
20652074
[Chrome DevTools Protocol]: https://chromedevtools.github.io/devtools-protocol/
20662075
[CommonJS]: modules.md
2076+
[CustomEvent Web API]: https://dom.spec.whatwg.org/#customevent
20672077
[ECMAScript module loader]: esm.md#loaders
20682078
[Fetch API]: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
20692079
[Modules loaders]: packages.md#modules-loaders
Collapse file

‎doc/api/globals.md‎

Copy file name to clipboardExpand all lines: doc/api/globals.md
+15Lines changed: 15 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,19 @@ A browser-compatible implementation of {CryptoKey}. This global is available
374374
only if the Node.js binary was compiled with including support for the
375375
`node:crypto` module.
376376

377+
## `CustomEvent`
378+
379+
<!-- YAML
380+
added: REPLACEME
381+
-->
382+
383+
> Stability: 1 - Experimental. Enable this API with the
384+
> [`--experimental-global-customevent`][] CLI flag.
385+
386+
<!-- type=global -->
387+
388+
A browser-compatible implementation of the [`CustomEvent` Web API][].
389+
377390
## Class: `DecompressionStream`
378391

379392
<!-- YAML
@@ -834,12 +847,14 @@ added: v18.0.0
834847
A browser-compatible implementation of [`WritableStreamDefaultWriter`][].
835848

836849
[Web Crypto API]: webcrypto.md
850+
[`--experimental-global-customevent`]: cli.md#--experimental-global-customevent
837851
[`--experimental-global-webcrypto`]: cli.md#--experimental-global-webcrypto
838852
[`--no-experimental-fetch`]: cli.md#--no-experimental-fetch
839853
[`AbortController`]: https://developer.mozilla.org/en-US/docs/Web/API/AbortController
840854
[`ByteLengthQueuingStrategy`]: webstreams.md#class-bytelengthqueuingstrategy
841855
[`CompressionStream`]: webstreams.md#class-compressionstream
842856
[`CountQueuingStrategy`]: webstreams.md#class-countqueuingstrategy
857+
[`CustomEvent` Web API]: https://dom.spec.whatwg.org/#customevent
843858
[`DOMException`]: https://developer.mozilla.org/en-US/docs/Web/API/DOMException
844859
[`DecompressionStream`]: webstreams.md#class-decompressionstream
845860
[`EventTarget` and `Event` API]: events.md#eventtarget-and-event-api
Collapse file

‎doc/node.1‎

Copy file name to clipboardExpand all lines: doc/node.1
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ Requires Node.js to be built with
139139
.It Fl -enable-source-maps
140140
Enable Source Map V3 support for stack traces.
141141
.
142+
.It Fl -experimental-global-customevent
143+
Expose the CustomEvent on the global scope.
144+
.
142145
.It Fl -experimental-global-webcrypto
143146
Expose the Web Crypto API on the global scope.
144147
.
Collapse file

‎lib/.eslintrc.yaml‎

Copy file name to clipboardExpand all lines: lib/.eslintrc.yaml
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ rules:
4949
message: Use `const { CompressionStream } = require('internal/webstreams/compression')` instead of the global.
5050
- name: CountQueuingStrategy
5151
message: Use `const { CountQueuingStrategy } = require('internal/webstreams/queuingstrategies')` instead of the global.
52+
- name: CustomEvent
53+
message: Use `const { CustomEvent } = require('internal/event_target');` instead of the global.
5254
- name: DecompressionStream
5355
message: Use `const { DecompressionStream } = require('internal/webstreams/compression')` instead of the global.
5456
- name: DOMException
Collapse file

‎lib/internal/bootstrap/pre_execution.js‎

Copy file name to clipboardExpand all lines: lib/internal/bootstrap/pre_execution.js
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ function prepareMainThreadExecution(expandArgv1 = false,
4444
setupWarningHandler();
4545
setupFetch();
4646
setupWebCrypto();
47+
setupCustomEvent();
4748

4849
// Resolve the coverage directory to an absolute path, and
4950
// overwrite process.env so that the original path gets passed
@@ -249,6 +250,17 @@ function setupWebCrypto() {
249250
}
250251
}
251252

253+
// TODO(daeyeon): move this to internal/bootstrap/browser when the CLI flag is
254+
// removed.
255+
function setupCustomEvent() {
256+
if (process.config.variables.node_no_browser_globals ||
257+
!getOptionValue('--experimental-global-customevent')) {
258+
return;
259+
}
260+
const { CustomEvent } = require('internal/event_target');
261+
exposeInterface(globalThis, 'CustomEvent', CustomEvent);
262+
}
263+
252264
// Setup User-facing NODE_V8_COVERAGE environment variable that writes
253265
// ScriptCoverage to a specified file.
254266
function setupCoverageHooks(dir) {
@@ -567,6 +579,7 @@ module.exports = {
567579
setupWarningHandler,
568580
setupFetch,
569581
setupWebCrypto,
582+
setupCustomEvent,
570583
setupDebugEnv,
571584
setupPerfHooks,
572585
prepareMainThreadExecution,
Collapse file

‎lib/internal/main/worker_thread.js‎

Copy file name to clipboardExpand all lines: lib/internal/main/worker_thread.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const {
1919
setupWarningHandler,
2020
setupFetch,
2121
setupWebCrypto,
22+
setupCustomEvent,
2223
setupDebugEnv,
2324
setupPerfHooks,
2425
initializeDeprecations,
@@ -71,6 +72,7 @@ setupDebugEnv();
7172
setupWarningHandler();
7273
setupFetch();
7374
setupWebCrypto();
75+
setupCustomEvent();
7476
initializeSourceMapsHandlers();
7577

7678
// Since worker threads cannot switch cwd, we do not need to
Collapse file

‎src/node_options.cc‎

Copy file name to clipboardExpand all lines: src/node_options.cc
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
339339
&EnvironmentOptions::experimental_fetch,
340340
kAllowedInEnvironment,
341341
true);
342+
AddOption("--experimental-global-customevent",
343+
"expose experimental CustomEvent on the global scope",
344+
&EnvironmentOptions::experimental_global_customevent,
345+
kAllowedInEnvironment);
342346
AddOption("--experimental-global-webcrypto",
343347
"expose experimental Web Crypto API on the global scope",
344348
&EnvironmentOptions::experimental_global_web_crypto,
Collapse file

‎src/node_options.h‎

Copy file name to clipboardExpand all lines: src/node_options.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class EnvironmentOptions : public Options {
108108
std::string dns_result_order;
109109
bool enable_source_maps = false;
110110
bool experimental_fetch = true;
111+
bool experimental_global_customevent = false;
111112
bool experimental_global_web_crypto = false;
112113
bool experimental_https_modules = false;
113114
std::string experimental_specifier_resolution;
Collapse file

‎test/common/index.js‎

Copy file name to clipboardExpand all lines: test/common/index.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ if (hasCrypto && global.crypto) {
315315
knownGlobals.push(global.CryptoKey);
316316
knownGlobals.push(global.SubtleCrypto);
317317
}
318+
if (global.CustomEvent) {
319+
knownGlobals.push(global.CustomEvent);
320+
}
318321
if (global.ReadableStream) {
319322
knownGlobals.push(
320323
global.ReadableStream,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.