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

lib: expose global CloseEvent #53355

Merged
merged 1 commit into from
Jun 7, 2024
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
14 changes: 14 additions & 0 deletions doc/api/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,19 @@ added: v0.0.1

[`clearTimeout`][] is described in the [timers][] section.

## `CloseEvent`

<!-- YAML
added: REPLACEME
-->
KhafraDev marked this conversation as resolved.
Show resolved Hide resolved

<!-- type=global -->

The `CloseEvent` class. See [`CloseEvent`][] for more details.

A browser-compatible implementation of [`CloseEvent`][]. Disable this API
with the [`--no-experimental-websocket`][] CLI flag.

## Class: `CompressionStream`

<!-- YAML
Expand Down Expand Up @@ -1156,6 +1169,7 @@ A browser-compatible implementation of [`WritableStreamDefaultWriter`][].
[`--no-experimental-websocket`]: cli.md#--no-experimental-websocket
[`AbortController`]: https://developer.mozilla.org/en-US/docs/Web/API/AbortController
[`ByteLengthQueuingStrategy`]: webstreams.md#class-bytelengthqueuingstrategy
[`CloseEvent`]: https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/CloseEvent
[`CompressionStream`]: webstreams.md#class-compressionstream
[`CountQueuingStrategy`]: webstreams.md#class-countqueuingstrategy
[`CustomEvent` Web API]: https://dom.spec.whatwg.org/#customevent
Expand Down
4 changes: 4 additions & 0 deletions lib/eslint.config_partial.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export default [
name: 'ByteLengthQueuingStrategy',
message: "Use `const { ByteLengthQueuingStrategy } = require('internal/webstreams/queuingstrategies')` instead of the global.",
},
{
name: 'CloseEvent',
message: "Use `const { CloseEvent } = require('internal/deps/undici/undici');` instead of the global.",
},
{
name: 'CompressionStream',
message: "Use `const { CompressionStream } = require('internal/webstreams/compression')` instead of the global.",
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/bootstrap/web/exposed-window-or-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ ObjectDefineProperty(globalThis, 'fetch', {
// https://fetch.spec.whatwg.org/#request-class
// https://fetch.spec.whatwg.org/#response-class
exposeLazyInterfaces(globalThis, 'internal/deps/undici/undici', [
'FormData', 'Headers', 'Request', 'Response', 'MessageEvent',
'FormData', 'Headers', 'Request', 'Response', 'MessageEvent', 'CloseEvent',
]);

// https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events.org/
Expand Down
1 change: 1 addition & 0 deletions lib/internal/process/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ function setupWarningHandler() {
function setupWebsocket() {
if (getOptionValue('--no-experimental-websocket')) {
delete globalThis.WebSocket;
delete globalThis.CloseEvent;
}
}

Expand Down
1 change: 1 addition & 0 deletions test/common/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const webIdlExposedWindow = new Set([
'Response',
'WebSocket',
'EventSource',
'CloseEvent',
]);

const nodeGlobals = new Set([
Expand Down
1 change: 1 addition & 0 deletions test/eslint.config_partial.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default [
languageOptions: {
globals: {
...globals.node,
CloseEvent: true,
},
},
rules: {
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-websocket-disabled.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ require('../common');
const assert = require('assert');

assert.strictEqual(typeof WebSocket, 'undefined');
assert.strictEqual(typeof CloseEvent, 'undefined');
1 change: 1 addition & 0 deletions test/parallel/test-websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ require('../common');
const assert = require('assert');

assert.strictEqual(typeof WebSocket, 'function');
assert.strictEqual(typeof CloseEvent, 'function');