GeezerVison is showing github.com — events: expose CustomEvent on global with CLI flag · nodejs/node@dfc4832
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: .eslintrc.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -321,6 +321,7 @@ module.exports = { | 321 | 321 | ByteLengthQueuingStrategy: 'readable', | 322 | 322 | CompressionStream: 'readable', | 323 | 323 | CountQueuingStrategy: 'readable', | | 324 | + CustomEvent: 'readable', | 324 | 325 | Crypto: 'readable', | 325 | 326 | CryptoKey: 'readable', | 326 | 327 | DecompressionStream: 'readable', | |
Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -280,6 +280,14 @@ effort to report stack traces relative to the original source file. | 280 | 280 | Overriding `Error.prepareStackTrace` prevents `--enable-source-maps` from | 281 | 281 | modifying the stack trace. | 282 | 282 |
| | 283 | +### `--experimental-global-customevent` | | 284 | + | | 285 | +<!-- YAML | | 286 | +added: REPLACEME | | 287 | +--> | | 288 | + | | 289 | +Expose the [CustomEvent Web API][] on the global scope. | | 290 | + | 283 | 291 | ### `--experimental-global-webcrypto` | 284 | 292 |
| 285 | 293 | <!-- YAML | @@ -1640,6 +1648,7 @@ Node.js options that are allowed are: | 1640 | 1648 | * `--enable-fips` | 1641 | 1649 | * `--enable-source-maps` | 1642 | 1650 | * `--experimental-abortcontroller` | | 1651 | +* `--experimental-global-customevent` | 1643 | 1652 | * `--experimental-global-webcrypto` | 1644 | 1653 | * `--experimental-import-meta-resolve` | 1645 | 1654 | * `--experimental-json-modules` | @@ -2064,6 +2073,7 @@ done | 2064 | 2073 | [#42511]: https://github.com/nodejs/node/issues/42511 | 2065 | 2074 | [Chrome DevTools Protocol]: https://chromedevtools.github.io/devtools-protocol/ | 2066 | 2075 | [CommonJS]: modules.md | | 2076 | +[CustomEvent Web API]: https://dom.spec.whatwg.org/#customevent | 2067 | 2077 | [ECMAScript module loader]: esm.md#loaders | 2068 | 2078 | [Fetch API]: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API | 2069 | 2079 | [Modules loaders]: packages.md#modules-loaders | |
Collapse file 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 number | Diff line number | Diff line change |
|---|
@@ -374,6 +374,19 @@ A browser-compatible implementation of {CryptoKey}. This global is available | 374 | 374 | only if the Node.js binary was compiled with including support for the | 375 | 375 | `node:crypto` module. | 376 | 376 |
| | 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 | + | 377 | 390 | ## Class: `DecompressionStream` | 378 | 391 |
| 379 | 392 | <!-- YAML | @@ -834,12 +847,14 @@ added: v18.0.0 | 834 | 847 | A browser-compatible implementation of [`WritableStreamDefaultWriter`][]. | 835 | 848 |
| 836 | 849 | [Web Crypto API]: webcrypto.md | | 850 | +[`--experimental-global-customevent`]: cli.md#--experimental-global-customevent | 837 | 851 | [`--experimental-global-webcrypto`]: cli.md#--experimental-global-webcrypto | 838 | 852 | [`--no-experimental-fetch`]: cli.md#--no-experimental-fetch | 839 | 853 | [`AbortController`]: https://developer.mozilla.org/en-US/docs/Web/API/AbortController | 840 | 854 | [`ByteLengthQueuingStrategy`]: webstreams.md#class-bytelengthqueuingstrategy | 841 | 855 | [`CompressionStream`]: webstreams.md#class-compressionstream | 842 | 856 | [`CountQueuingStrategy`]: webstreams.md#class-countqueuingstrategy | | 857 | +[`CustomEvent` Web API]: https://dom.spec.whatwg.org/#customevent | 843 | 858 | [`DOMException`]: https://developer.mozilla.org/en-US/docs/Web/API/DOMException | 844 | 859 | [`DecompressionStream`]: webstreams.md#class-decompressionstream | 845 | 860 | [`EventTarget` and `Event` API]: events.md#eventtarget-and-event-api | |
Collapse file Copy file name to clipboardExpand all lines: doc/node.1 +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -139,6 +139,9 @@ Requires Node.js to be built with | 139 | 139 | .It Fl -enable-source-maps | 140 | 140 | Enable Source Map V3 support for stack traces. | 141 | 141 | . | | 142 | +.It Fl -experimental-global-customevent | | 143 | +Expose the CustomEvent on the global scope. | | 144 | +. | 142 | 145 | .It Fl -experimental-global-webcrypto | 143 | 146 | Expose the Web Crypto API on the global scope. | 144 | 147 | . | |
Collapse file Copy file name to clipboardExpand all lines: lib/.eslintrc.yaml +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 49 | 49 | message: Use `const { CompressionStream } = require('internal/webstreams/compression')` instead of the global. | 50 | 50 | - name: CountQueuingStrategy | 51 | 51 | 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. | 52 | 54 | - name: DecompressionStream | 53 | 55 | message: Use `const { DecompressionStream } = require('internal/webstreams/compression')` instead of the global. | 54 | 56 | - name: DOMException | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/bootstrap/pre_execution.js +13Lines changed: 13 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -44,6 +44,7 @@ function prepareMainThreadExecution(expandArgv1 = false, | 44 | 44 | setupWarningHandler(); | 45 | 45 | setupFetch(); | 46 | 46 | setupWebCrypto(); | | 47 | + setupCustomEvent(); | 47 | 48 |
| 48 | 49 | // Resolve the coverage directory to an absolute path, and | 49 | 50 | // overwrite process.env so that the original path gets passed | @@ -249,6 +250,17 @@ function setupWebCrypto() { | 249 | 250 | } | 250 | 251 | } | 251 | 252 |
| | 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 | + | 252 | 264 | // Setup User-facing NODE_V8_COVERAGE environment variable that writes | 253 | 265 | // ScriptCoverage to a specified file. | 254 | 266 | function setupCoverageHooks(dir) { | @@ -567,6 +579,7 @@ module.exports = { | 567 | 579 | setupWarningHandler, | 568 | 580 | setupFetch, | 569 | 581 | setupWebCrypto, | | 582 | + setupCustomEvent, | 570 | 583 | setupDebugEnv, | 571 | 584 | setupPerfHooks, | 572 | 585 | prepareMainThreadExecution, | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/main/worker_thread.js +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -19,6 +19,7 @@ const { | 19 | 19 | setupWarningHandler, | 20 | 20 | setupFetch, | 21 | 21 | setupWebCrypto, | | 22 | + setupCustomEvent, | 22 | 23 | setupDebugEnv, | 23 | 24 | setupPerfHooks, | 24 | 25 | initializeDeprecations, | @@ -71,6 +72,7 @@ setupDebugEnv(); | 71 | 72 | setupWarningHandler(); | 72 | 73 | setupFetch(); | 73 | 74 | setupWebCrypto(); | | 75 | +setupCustomEvent(); | 74 | 76 | initializeSourceMapsHandlers(); | 75 | 77 |
| 76 | 78 | // Since worker threads cannot switch cwd, we do not need to | |
Collapse file Copy file name to clipboardExpand all lines: src/node_options.cc +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -339,6 +339,10 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | 339 | 339 | &EnvironmentOptions::experimental_fetch, | 340 | 340 | kAllowedInEnvironment, | 341 | 341 | true); | | 342 | + AddOption("--experimental-global-customevent", | | 343 | + "expose experimental CustomEvent on the global scope", | | 344 | + &EnvironmentOptions::experimental_global_customevent, | | 345 | + kAllowedInEnvironment); | 342 | 346 | AddOption("--experimental-global-webcrypto", | 343 | 347 | "expose experimental Web Crypto API on the global scope", | 344 | 348 | &EnvironmentOptions::experimental_global_web_crypto, | |
Collapse file Copy file name to clipboardExpand all lines: src/node_options.h +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -108,6 +108,7 @@ class EnvironmentOptions : public Options { | 108 | 108 | std::string dns_result_order; | 109 | 109 | bool enable_source_maps = false; | 110 | 110 | bool experimental_fetch = true; | | 111 | + bool experimental_global_customevent = false; | 111 | 112 | bool experimental_global_web_crypto = false; | 112 | 113 | bool experimental_https_modules = false; | 113 | 114 | std::string experimental_specifier_resolution; | |
Collapse file Copy file name to clipboardExpand all lines: test/common/index.js +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -315,6 +315,9 @@ if (hasCrypto && global.crypto) { | 315 | 315 | knownGlobals.push(global.CryptoKey); | 316 | 316 | knownGlobals.push(global.SubtleCrypto); | 317 | 317 | } | | 318 | +if (global.CustomEvent) { | | 319 | + knownGlobals.push(global.CustomEvent); | | 320 | +} | 318 | 321 | if (global.ReadableStream) { | 319 | 322 | knownGlobals.push( | 320 | 323 | global.ReadableStream, | |
|