diff --git a/lib/_http_server.js b/lib/_http_server.js index 6a0bcd75513..ba31f4534b2 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -29,6 +29,7 @@ const { ObjectSetPrototypeOf, ReflectApply, Symbol, + SymbolAsyncDispose, SymbolFor, } = primordials; @@ -81,7 +82,6 @@ const { const { kEmptyObject, promisify, - SymbolAsyncDispose, } = require('internal/util'); const { validateInteger, diff --git a/lib/child_process.js b/lib/child_process.js index 51fc6fe995d..c633866b962 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -42,6 +42,7 @@ const { StringPrototypeIncludes, StringPrototypeSlice, StringPrototypeToUpperCase, + SymbolDispose, } = primordials; const { @@ -50,7 +51,6 @@ const { getSystemErrorName, kEmptyObject, promisify, - SymbolDispose, } = require('internal/util'); const { isArrayBufferView } = require('internal/util/types'); let debug = require('internal/util/debuglog').debuglog( diff --git a/lib/dgram.js b/lib/dgram.js index 84b8708f701..f29a5397688 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -30,6 +30,8 @@ const { ObjectDefineProperty, ObjectSetPrototypeOf, ReflectApply, + SymbolAsyncDispose, + SymbolDispose, } = primordials; const { @@ -61,7 +63,7 @@ const { validatePort, } = require('internal/validators'); const { Buffer } = require('buffer'); -const { deprecate, guessHandleType, promisify, SymbolAsyncDispose, SymbolDispose } = require('internal/util'); +const { deprecate, guessHandleType, promisify } = require('internal/util'); const { isArrayBufferView } = require('internal/util/types'); const EventEmitter = require('events'); const { addAbortListener } = require('internal/events/abort_listener'); diff --git a/lib/events.js b/lib/events.js index 256dd580e15..07ffdebbb09 100644 --- a/lib/events.js +++ b/lib/events.js @@ -47,11 +47,12 @@ const { StringPrototypeSplit, Symbol, SymbolAsyncIterator, + SymbolDispose, SymbolFor, } = primordials; const kRejection = SymbolFor('nodejs.rejection'); -const { SymbolDispose, kEmptyObject, spliceOne } = require('internal/util'); +const { kEmptyObject, spliceOne } = require('internal/util'); const { inspect, diff --git a/lib/https.js b/lib/https.js index 21b40275ecb..ec68296ed51 100644 --- a/lib/https.js +++ b/lib/https.js @@ -33,13 +33,13 @@ const { ObjectSetPrototypeOf, ReflectApply, ReflectConstruct, + SymbolAsyncDispose, } = primordials; const { assertCrypto, kEmptyObject, promisify, - SymbolAsyncDispose, } = require('internal/util'); assertCrypto(); diff --git a/lib/inspector.js b/lib/inspector.js index b1d67b84fe0..b623d96b68c 100644 --- a/lib/inspector.js +++ b/lib/inspector.js @@ -4,11 +4,8 @@ const { JSONParse, JSONStringify, SafeMap, -} = primordials; - -const { SymbolDispose, -} = require('internal/util'); +} = primordials; const { ERR_INSPECTOR_ALREADY_ACTIVATED, diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index ab6872e4f89..516015b9dd6 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -12,6 +12,7 @@ const { ReflectApply, StringPrototypeSlice, Symbol, + SymbolDispose, Uint8Array, } = primordials; @@ -55,7 +56,7 @@ const { TTY } = internalBinding('tty_wrap'); const { UDP } = internalBinding('udp_wrap'); const SocketList = require('internal/socket_list'); const { owner_symbol } = require('internal/async_hooks').symbols; -const { convertToValidSignal, deprecate, SymbolDispose } = require('internal/util'); +const { convertToValidSignal, deprecate } = require('internal/util'); const { isArrayBufferView } = require('internal/util/types'); const spawn_sync = internalBinding('spawn_sync'); const { kStateSymbol } = require('internal/dgram'); diff --git a/lib/internal/events/abort_listener.js b/lib/internal/events/abort_listener.js index 2803fa585d2..033cbf7b250 100644 --- a/lib/internal/events/abort_listener.js +++ b/lib/internal/events/abort_listener.js @@ -2,7 +2,7 @@ const { SymbolDispose, -} = require('internal/util'); +} = primordials; const { validateAbortSignal, validateFunction, diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index a29c7d96c04..5343cf3f170 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -15,6 +15,7 @@ const { SafeArrayIterator, SafePromisePrototypeFinally, Symbol, + SymbolAsyncDispose, Uint8Array, uncurryThis, } = primordials; @@ -99,7 +100,6 @@ const { promisify, isWindows, isMacOS, - SymbolAsyncDispose, } = require('internal/util'); const EventEmitter = require('events'); const { StringDecoder } = require('string_decoder'); diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 923db9ad1b5..4dc4eaf547e 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -19,6 +19,8 @@ const { SafeMap, SafeSet, Symbol, + SymbolAsyncDispose, + SymbolDispose, Uint32Array, Uint8Array, } = primordials; @@ -28,8 +30,6 @@ const { customInspectSymbol: kInspect, kEmptyObject, promisify, - SymbolAsyncDispose, - SymbolDispose, } = require('internal/util'); assertCrypto(); diff --git a/lib/internal/process/pre_execution.js b/lib/internal/process/pre_execution.js index 0da8c50a6f8..dfb672b49b4 100644 --- a/lib/internal/process/pre_execution.js +++ b/lib/internal/process/pre_execution.js @@ -14,7 +14,6 @@ const { ObjectFreeze, String, StringPrototypeStartsWith, - Symbol, globalThis, } = primordials; @@ -29,8 +28,6 @@ const { defineReplaceableLazyAttribute, setupCoverageHooks, emitExperimentalWarning, - SymbolAsyncDispose, - SymbolDispose, deprecate, } = require('internal/util'); @@ -121,8 +118,6 @@ function prepareExecution(options) { require('internal/dns/utils').initializeDns(); - setupSymbolDisposePolyfill(); - if (isMainThread) { assert(internalBinding('worker').isMainThread); // Worker threads will get the manifest in the message handler. @@ -157,31 +152,6 @@ function prepareExecution(options) { return mainEntry; } -function setupSymbolDisposePolyfill() { - // TODO(MoLow): Remove this polyfill once Symbol.dispose and Symbol.asyncDispose are available in V8. - // eslint-disable-next-line node-core/prefer-primordials - if (typeof Symbol.dispose !== 'symbol') { - ObjectDefineProperty(Symbol, 'dispose', { - __proto__: null, - configurable: false, - enumerable: false, - value: SymbolDispose, - writable: false, - }); - } - - // eslint-disable-next-line node-core/prefer-primordials - if (typeof Symbol.asyncDispose !== 'symbol') { - ObjectDefineProperty(Symbol, 'asyncDispose', { - __proto__: null, - configurable: false, - enumerable: false, - value: SymbolAsyncDispose, - writable: false, - }); - } -} - function setupUserModules(forceDefaultLoader = false) { initializeCJSLoader(); initializeESMLoader(forceDefaultLoader); diff --git a/lib/internal/readline/interface.js b/lib/internal/readline/interface.js index aaa1dea7a8c..74b2b69083a 100644 --- a/lib/internal/readline/interface.js +++ b/lib/internal/readline/interface.js @@ -30,6 +30,7 @@ const { StringPrototypeTrim, Symbol, SymbolAsyncIterator, + SymbolDispose, } = primordials; const { codes: { @@ -44,7 +45,7 @@ const { validateString, validateUint32, } = require('internal/validators'); -const { SymbolDispose, kEmptyObject } = require('internal/util'); +const { kEmptyObject } = require('internal/util'); const { inspect, getStringWidth, diff --git a/lib/internal/streams/add-abort-signal.js b/lib/internal/streams/add-abort-signal.js index 9d76fda29a6..2fa16d697c1 100644 --- a/lib/internal/streams/add-abort-signal.js +++ b/lib/internal/streams/add-abort-signal.js @@ -2,7 +2,7 @@ const { SymbolDispose, -} = require('internal/util'); +} = primordials; const { AbortError, diff --git a/lib/internal/streams/end-of-stream.js b/lib/internal/streams/end-of-stream.js index c234792bd33..c44f99e993a 100644 --- a/lib/internal/streams/end-of-stream.js +++ b/lib/internal/streams/end-of-stream.js @@ -6,6 +6,7 @@ const { Promise, PromisePrototypeThen, + SymbolDispose, } = primordials; const { @@ -18,7 +19,6 @@ const { const { kEmptyObject, once, - SymbolDispose, } = require('internal/util'); const { validateAbortSignal, diff --git a/lib/internal/streams/pipeline.js b/lib/internal/streams/pipeline.js index 4531cf06aa2..dc3903fc8cd 100644 --- a/lib/internal/streams/pipeline.js +++ b/lib/internal/streams/pipeline.js @@ -7,10 +7,11 @@ const { ArrayIsArray, Promise, SymbolAsyncIterator, + SymbolDispose, } = primordials; const eos = require('internal/streams/end-of-stream'); -const { SymbolDispose, once } = require('internal/util'); +const { once } = require('internal/util'); const destroyImpl = require('internal/streams/destroy'); const Duplex = require('internal/streams/duplex'); const { diff --git a/lib/internal/streams/readable.js b/lib/internal/streams/readable.js index 5a6fe1db000..ac034d7d554 100644 --- a/lib/internal/streams/readable.js +++ b/lib/internal/streams/readable.js @@ -32,6 +32,7 @@ const { Promise, SafeSet, Symbol, + SymbolAsyncDispose, SymbolAsyncIterator, SymbolSpecies, TypedArrayPrototypeSet, @@ -43,9 +44,6 @@ Readable.ReadableState = ReadableState; const EE = require('events'); const { Stream, prependListener } = require('internal/streams/legacy'); const { Buffer } = require('buffer'); -const { - SymbolAsyncDispose, -} = require('internal/util'); const { addAbortSignal, diff --git a/lib/internal/streams/writable.js b/lib/internal/streams/writable.js index b74b6088201..ac14b202b66 100644 --- a/lib/internal/streams/writable.js +++ b/lib/internal/streams/writable.js @@ -35,6 +35,7 @@ const { Promise, StringPrototypeToLowerCase, Symbol, + SymbolAsyncDispose, SymbolHasInstance, } = primordials; @@ -46,9 +47,6 @@ const Stream = require('internal/streams/legacy').Stream; const { Buffer } = require('buffer'); const destroyImpl = require('internal/streams/destroy'); const eos = require('internal/streams/end-of-stream'); -const { - SymbolAsyncDispose, -} = require('internal/util'); const { addAbortSignal, diff --git a/lib/internal/test_runner/mock/mock_timers.js b/lib/internal/test_runner/mock/mock_timers.js index fa91c9759ec..a1e0043cafc 100644 --- a/lib/internal/test_runner/mock/mock_timers.js +++ b/lib/internal/test_runner/mock/mock_timers.js @@ -17,6 +17,7 @@ const { Promise, Symbol, SymbolAsyncIterator, + SymbolDispose, globalThis, } = primordials; @@ -28,7 +29,6 @@ const { const { emitExperimentalWarning, - SymbolDispose, } = require('internal/util'); const { AbortError, diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index 3a2a2b1383f..b777a1038ab 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -29,6 +29,7 @@ const { StringPrototypeStartsWith, StringPrototypeTrim, Symbol, + SymbolDispose, } = primordials; const { getCallerLocation } = internalBinding('util'); const { exitCodes: { kGenericUserError } } = internalBinding('errors'); @@ -55,7 +56,6 @@ const { createDeferredPromise, kEmptyObject, once: runOnce, - SymbolDispose, } = require('internal/util'); const { isPromise } = require('internal/util/types'); const { diff --git a/lib/internal/util.js b/lib/internal/util.js index bf1622aa530..4e74a4e569d 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -932,14 +932,6 @@ module.exports = { setupCoverageHooks, removeColors, - // Define Symbol.dispose and Symbol.asyncDispose - // Until these are defined by the environment. - // TODO(MoLow): Remove this polyfill once Symbol.dispose and Symbol.asyncDispose are available in primordials. - // eslint-disable-next-line node-core/prefer-primordials - SymbolDispose: Symbol.dispose || SymbolFor('nodejs.dispose'), - // eslint-disable-next-line node-core/prefer-primordials - SymbolAsyncDispose: Symbol.asyncDispose || SymbolFor('nodejs.asyncDispose'), - // Symbol used to customize promisify conversion customPromisifyArgs: kCustomPromisifyArgsSymbol, diff --git a/lib/internal/webstreams/readablestream.js b/lib/internal/webstreams/readablestream.js index 7279ff3de4b..10179321c10 100644 --- a/lib/internal/webstreams/readablestream.js +++ b/lib/internal/webstreams/readablestream.js @@ -22,6 +22,7 @@ const { SafePromiseAll, Symbol, SymbolAsyncIterator, + SymbolDispose, SymbolToStringTag, TypedArrayPrototypeGetLength, Uint8Array, @@ -54,7 +55,6 @@ const { kEmptyObject, kEnumerableProperty, SideEffectFreeRegExpPrototypeSymbolReplace, - SymbolDispose, } = require('internal/util'); const { diff --git a/lib/net.js b/lib/net.js index 604ba648754..3ae75d7ece5 100644 --- a/lib/net.js +++ b/lib/net.js @@ -36,6 +36,8 @@ const { ObjectDefineProperty, ObjectSetPrototypeOf, Symbol, + SymbolAsyncDispose, + SymbolDispose, } = primordials; const EventEmitter = require('events'); @@ -119,8 +121,6 @@ const { isWindows, kEmptyObject, promisify, - SymbolAsyncDispose, - SymbolDispose, } = require('internal/util'); const { validateAbortSignal, diff --git a/lib/readline.js b/lib/readline.js index e3ae952648f..46e7f0cb628 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -30,6 +30,7 @@ const { Promise, PromiseReject, StringPrototypeSlice, + SymbolDispose, } = primordials; const { @@ -50,7 +51,6 @@ const { const { kEmptyObject, promisify, - SymbolDispose, } = require('internal/util'); const { validateAbortSignal } = require('internal/validators'); diff --git a/lib/readline/promises.js b/lib/readline/promises.js index 286222bfab9..ccd0745a33f 100644 --- a/lib/readline/promises.js +++ b/lib/readline/promises.js @@ -2,6 +2,7 @@ const { Promise, + SymbolDispose, } = primordials; const { @@ -21,7 +22,6 @@ const { validateAbortSignal } = require('internal/validators'); const { kEmptyObject, - SymbolDispose, } = require('internal/util'); let addAbortListener; diff --git a/lib/timers.js b/lib/timers.js index a0e58810752..5795da7b9ae 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -26,6 +26,7 @@ const { MathTrunc, ObjectDefineProperties, ObjectDefineProperty, + SymbolDispose, SymbolToPrimitive, } = primordials; @@ -57,7 +58,6 @@ const { const { promisify: { custom: customPromisify }, deprecate, - SymbolDispose, } = require('internal/util'); let debug = require('internal/util/debuglog').debuglog('timer', (fn) => { debug = fn; diff --git a/typings/primordials.d.ts b/typings/primordials.d.ts index 8e0dd1c521b..da00d43f515 100644 --- a/typings/primordials.d.ts +++ b/typings/primordials.d.ts @@ -431,7 +431,9 @@ declare namespace primordials { export const SymbolPrototype: typeof Symbol.prototype export const SymbolFor: typeof Symbol.for export const SymbolKeyFor: typeof Symbol.keyFor + export const SymbolAsyncDispose: typeof Symbol.asyncDispose export const SymbolAsyncIterator: typeof Symbol.asyncIterator + export const SymbolDispose: typeof Symbol.dispose export const SymbolHasInstance: typeof Symbol.hasInstance export const SymbolIsConcatSpreadable: typeof Symbol.isConcatSpreadable export const SymbolIterator: typeof Symbol.iterator