0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-27 22:16:50 +01:00
nodejs/test/common/globals.js
Khafra 6ed93b4d69
lib: expose global CloseEvent
This PR adds `CloseEvent` as a global, which can be disabled
via the --no-experimental-websocket flag.

```js
const ws = new WebSocket('...')

ws.addEventListener('close', (event) => {
  assert(event instanceof CloseEvent)
})

```

Fixes: https://github.com/nodejs/node/issues/50275
PR-URL: https://github.com/nodejs/node/pull/53355
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
2024-06-07 17:54:28 +00:00

147 lines
2.4 KiB
JavaScript

'use strict';
const intrinsics = new Set([
'Object',
'Function',
'Array',
'Number',
'parseFloat',
'parseInt',
'Infinity',
'NaN',
'undefined',
'Boolean',
'String',
'Symbol',
'Date',
'Promise',
'RegExp',
'Error',
'AggregateError',
'EvalError',
'RangeError',
'ReferenceError',
'SyntaxError',
'TypeError',
'URIError',
'globalThis',
'JSON',
'Math',
'Intl',
'ArrayBuffer',
'Uint8Array',
'Int8Array',
'Uint16Array',
'Int16Array',
'Uint32Array',
'Int32Array',
'Float32Array',
'Float64Array',
'Uint8ClampedArray',
'BigUint64Array',
'BigInt64Array',
'DataView',
'Map',
'BigInt',
'Set',
'WeakMap',
'WeakSet',
'Proxy',
'Reflect',
'ShadowRealm',
'FinalizationRegistry',
'WeakRef',
'decodeURI',
'decodeURIComponent',
'encodeURI',
'encodeURIComponent',
'escape',
'unescape',
'eval',
'isFinite',
'isNaN',
'SharedArrayBuffer',
'Atomics',
'WebAssembly',
'Iterator',
]);
if (global.gc) {
intrinsics.add('gc');
}
// v8 exposes console in the global scope.
intrinsics.add('console');
const webIdlExposedWildcard = new Set([
'DOMException',
'TextEncoder',
'TextDecoder',
'AbortController',
'AbortSignal',
'CustomEvent',
'EventTarget',
'Event',
'URL',
'URLSearchParams',
'ReadableStream',
'ReadableStreamDefaultReader',
'ReadableStreamBYOBReader',
'ReadableStreamBYOBRequest',
'ReadableByteStreamController',
'ReadableStreamDefaultController',
'TransformStream',
'TransformStreamDefaultController',
'WritableStream',
'WritableStreamDefaultWriter',
'WritableStreamDefaultController',
'ByteLengthQueuingStrategy',
'CountQueuingStrategy',
'TextEncoderStream',
'TextDecoderStream',
'CompressionStream',
'DecompressionStream',
]);
const webIdlExposedWindow = new Set([
'console',
'BroadcastChannel',
'queueMicrotask',
'structuredClone',
'MessageChannel',
'MessagePort',
'MessageEvent',
'clearInterval',
'clearTimeout',
'setInterval',
'setTimeout',
'atob',
'btoa',
'Blob',
'Performance',
'performance',
'fetch',
'FormData',
'Headers',
'Request',
'Response',
'WebSocket',
'EventSource',
'CloseEvent',
]);
const nodeGlobals = new Set([
'process',
'global',
'Buffer',
'clearImmediate',
'setImmediate',
]);
module.exports = {
intrinsics,
webIdlExposedWildcard,
webIdlExposedWindow,
nodeGlobals,
};