diff --git a/lib/_http_server.js b/lib/_http_server.js index d1812a93598103..9e6e71e68005cd 100644 --- a/lib/_http_server.js +++ b/lib/_http_server.js @@ -29,7 +29,6 @@ const { ObjectSetPrototypeOf, ReflectApply, Symbol, - SymbolAsyncDispose, SymbolFor, } = primordials; @@ -82,6 +81,7 @@ const { const { kEmptyObject, promisify, + SymbolAsyncDispose, } = require('internal/util'); const { validateInteger, diff --git a/lib/child_process.js b/lib/child_process.js index 48870b35ad0f34..cc81cb373d59db 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -42,7 +42,6 @@ const { StringPrototypeIncludes, StringPrototypeSlice, StringPrototypeToUpperCase, - SymbolDispose, } = primordials; const { @@ -51,6 +50,7 @@ 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 d151cd6e5ed1df..d542e1c001f764 100644 --- a/lib/dgram.js +++ b/lib/dgram.js @@ -30,8 +30,6 @@ const { ObjectDefineProperty, ObjectSetPrototypeOf, ReflectApply, - SymbolAsyncDispose, - SymbolDispose, } = primordials; const errors = require('internal/errors'); @@ -60,7 +58,7 @@ const { validatePort, } = require('internal/validators'); const { Buffer } = require('buffer'); -const { deprecate, guessHandleType, promisify } = require('internal/util'); +const { deprecate, guessHandleType, promisify, SymbolAsyncDispose, SymbolDispose } = 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 3b2ad8f21e19b2..476571dc1f8eea 100644 --- a/lib/events.js +++ b/lib/events.js @@ -48,11 +48,10 @@ const { Symbol, SymbolFor, SymbolAsyncIterator, - SymbolDispose, } = primordials; const kRejection = SymbolFor('nodejs.rejection'); -const { kEmptyObject } = require('internal/util'); +const { SymbolDispose, kEmptyObject } = require('internal/util'); const { inspect, diff --git a/lib/https.js b/lib/https.js index ec68296ed518c4..21b40275ecb691 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 b623d96b68c3f7..b1d67b84fe04d6 100644 --- a/lib/inspector.js +++ b/lib/inspector.js @@ -4,9 +4,12 @@ const { JSONParse, JSONStringify, SafeMap, - SymbolDispose, } = primordials; +const { + SymbolDispose, +} = require('internal/util'); + const { ERR_INSPECTOR_ALREADY_ACTIVATED, ERR_INSPECTOR_ALREADY_CONNECTED, diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index 49edaba5b558e9..11cac3971d4ca6 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -12,7 +12,6 @@ const { ReflectApply, StringPrototypeSlice, Symbol, - SymbolDispose, Uint8Array, } = primordials; @@ -56,7 +55,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 } = require('internal/util'); +const { convertToValidSignal, deprecate, SymbolDispose } = 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 033cbf7b250fe0..2803fa585d29df 100644 --- a/lib/internal/events/abort_listener.js +++ b/lib/internal/events/abort_listener.js @@ -2,7 +2,7 @@ const { SymbolDispose, -} = primordials; +} = require('internal/util'); const { validateAbortSignal, validateFunction, diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index df5cfab361b114..8314cf29a850f5 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -15,7 +15,6 @@ const { SafeArrayIterator, SafePromisePrototypeFinally, Symbol, - SymbolAsyncDispose, Uint8Array, FunctionPrototypeBind, uncurryThis, @@ -96,6 +95,7 @@ const { lazyDOMException, promisify, getLazy, + SymbolAsyncDispose, } = require('internal/util'); const { EventEmitterMixin } = require('internal/event_target'); const { StringDecoder } = require('string_decoder'); diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 4b3ae479e90dcb..eb6a3c1d317d27 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -19,8 +19,6 @@ const { SafeMap, SafeSet, Symbol, - SymbolAsyncDispose, - SymbolDispose, Uint32Array, Uint8Array, } = primordials; @@ -30,6 +28,8 @@ const { customInspectSymbol: kInspect, kEmptyObject, promisify, + SymbolAsyncDispose, + SymbolDispose, } = require('internal/util'); assertCrypto(); diff --git a/lib/internal/per_context/primordials.js b/lib/internal/per_context/primordials.js index bba0343b064503..89c7903dd880bb 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -228,11 +228,6 @@ function copyPrototype(src, dest, prefix) { copyPrototype(original.prototype, primordials, `${name}Prototype`); }); -// 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 V8. -primordials.SymbolDispose ??= primordials.SymbolFor('nodejs.dispose'); -primordials.SymbolAsyncDispose ??= primordials.SymbolFor('nodejs.asyncDispose'); // Create copies of intrinsic objects that require a valid `this` to call // static methods. diff --git a/lib/internal/process/pre_execution.js b/lib/internal/process/pre_execution.js index ea7afd52fab1cf..a05d2846050c2f 100644 --- a/lib/internal/process/pre_execution.js +++ b/lib/internal/process/pre_execution.js @@ -17,8 +17,6 @@ const { String, StringPrototypeStartsWith, Symbol, - SymbolAsyncDispose, - SymbolDispose, globalThis, } = primordials; @@ -34,6 +32,8 @@ const { defineReplaceableLazyAttribute, setupCoverageHooks, emitExperimentalWarning, + SymbolAsyncDispose, + SymbolDispose, } = require('internal/util'); const { diff --git a/lib/internal/readline/interface.js b/lib/internal/readline/interface.js index 8ae051e4eadbeb..e1381b5341aaff 100644 --- a/lib/internal/readline/interface.js +++ b/lib/internal/readline/interface.js @@ -28,7 +28,6 @@ const { StringPrototypeStartsWith, StringPrototypeTrim, Symbol, - SymbolDispose, SymbolAsyncIterator, SafeStringIterator, } = primordials; @@ -46,7 +45,7 @@ const { validateString, validateUint32, } = require('internal/validators'); -const { kEmptyObject } = require('internal/util'); +const { SymbolDispose, 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 10e5545a28345b..821474f324bb5d 100644 --- a/lib/internal/streams/add-abort-signal.js +++ b/lib/internal/streams/add-abort-signal.js @@ -2,7 +2,7 @@ const { SymbolDispose, -} = primordials; +} = require('internal/util'); const { AbortError, diff --git a/lib/internal/streams/end-of-stream.js b/lib/internal/streams/end-of-stream.js index c1403f419c5ea5..70f884898f9740 100644 --- a/lib/internal/streams/end-of-stream.js +++ b/lib/internal/streams/end-of-stream.js @@ -14,6 +14,7 @@ const { const { kEmptyObject, once, + SymbolDispose, } = require('internal/util'); const { validateAbortSignal, @@ -25,7 +26,6 @@ const { const { Promise, PromisePrototypeThen, - SymbolDispose, } = primordials; const { diff --git a/lib/internal/streams/pipeline.js b/lib/internal/streams/pipeline.js index 4cf6b02766b6a8..098ae7462cb55c 100644 --- a/lib/internal/streams/pipeline.js +++ b/lib/internal/streams/pipeline.js @@ -7,11 +7,10 @@ const { ArrayIsArray, Promise, SymbolAsyncIterator, - SymbolDispose, } = primordials; const eos = require('internal/streams/end-of-stream'); -const { once } = require('internal/util'); +const { SymbolDispose, 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 b97c54bee3ed27..7f7c160f6919ae 100644 --- a/lib/internal/streams/readable.js +++ b/lib/internal/streams/readable.js @@ -32,7 +32,6 @@ const { Promise, SafeSet, Symbol, - SymbolAsyncDispose, SymbolAsyncIterator, SymbolSpecies, TypedArrayPrototypeSet, @@ -44,6 +43,9 @@ 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 103b9eaa72ffad..298fbe00c966bb 100644 --- a/lib/internal/streams/writable.js +++ b/lib/internal/streams/writable.js @@ -35,7 +35,6 @@ const { Promise, StringPrototypeToLowerCase, Symbol, - SymbolAsyncDispose, SymbolHasInstance, } = primordials; @@ -47,6 +46,9 @@ 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 1edef54bf3d91b..147de4efa5e6a0 100644 --- a/lib/internal/test_runner/mock/mock_timers.js +++ b/lib/internal/test_runner/mock/mock_timers.js @@ -1,9 +1,5 @@ 'use strict'; -const { - emitExperimentalWarning, -} = require('internal/util'); - const { ArrayPrototypeAt, ArrayPrototypeForEach, @@ -22,7 +18,6 @@ const { Promise, Symbol, SymbolAsyncIterator, - SymbolDispose, } = primordials; const { validateAbortSignal, @@ -30,6 +25,10 @@ const { validateStringArray, } = require('internal/validators'); +const { + emitExperimentalWarning, + SymbolDispose, +} = require('internal/util'); const { AbortError, codes: { ERR_INVALID_STATE, ERR_INVALID_ARG_VALUE }, diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index 8a171d099ee793..fb9643246b1f09 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -22,7 +22,6 @@ const { SafeSet, SafePromiseAll, SafePromiseRace, - SymbolDispose, ObjectDefineProperty, Symbol, } = primordials; @@ -49,6 +48,7 @@ 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 fdb3e92681129c..40e6f5e5090295 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -927,6 +927,14 @@ 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 3e169580d3df4a..99aabd3d56f4fd 100644 --- a/lib/internal/webstreams/readablestream.js +++ b/lib/internal/webstreams/readablestream.js @@ -21,7 +21,6 @@ const { SafePromiseAll, Symbol, SymbolAsyncIterator, - SymbolDispose, SymbolToStringTag, TypedArrayPrototypeGetLength, Uint8Array, @@ -55,6 +54,7 @@ const { kEmptyObject, kEnumerableProperty, SideEffectFreeRegExpPrototypeSymbolReplace, + SymbolDispose, } = require('internal/util'); const { diff --git a/lib/net.js b/lib/net.js index 6fe798e0f128c4..05239dacf3e6e0 100644 --- a/lib/net.js +++ b/lib/net.js @@ -36,8 +36,6 @@ const { ObjectDefineProperty, ObjectSetPrototypeOf, Symbol, - SymbolAsyncDispose, - SymbolDispose, } = primordials; const EventEmitter = require('events'); @@ -115,7 +113,13 @@ const { } = require('internal/errors'); const { isUint8Array } = require('internal/util/types'); const { queueMicrotask } = require('internal/process/task_queues'); -const { kEmptyObject, guessHandleType, promisify } = require('internal/util'); +const { + guessHandleType, + kEmptyObject, + promisify, + SymbolAsyncDispose, + SymbolDispose, +} = require('internal/util'); const { validateAbortSignal, validateBoolean, diff --git a/lib/readline.js b/lib/readline.js index 509c7022ee95cc..abc5b25d2e00e6 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -30,7 +30,6 @@ const { Promise, PromiseReject, StringPrototypeSlice, - SymbolDispose, } = primordials; const { @@ -51,6 +50,7 @@ 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 ccd0745a33f941..286222bfab9a61 100644 --- a/lib/readline/promises.js +++ b/lib/readline/promises.js @@ -2,7 +2,6 @@ const { Promise, - SymbolDispose, } = primordials; const { @@ -22,6 +21,7 @@ const { validateAbortSignal } = require('internal/validators'); const { kEmptyObject, + SymbolDispose, } = require('internal/util'); let addAbortListener; diff --git a/lib/timers.js b/lib/timers.js index d7bd32cc73c4ca..7ff4101bdbc3be 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -26,7 +26,6 @@ const { MathTrunc, ObjectDefineProperty, ObjectDefineProperties, - SymbolDispose, SymbolToPrimitive, } = primordials; @@ -58,6 +57,7 @@ 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 ce6ca86f3e633d..039b93f40beb4d 100644 --- a/typings/primordials.d.ts +++ b/typings/primordials.d.ts @@ -428,8 +428,6 @@ declare namespace primordials { export const SymbolFor: typeof Symbol.for export const SymbolKeyFor: typeof Symbol.keyFor export const SymbolAsyncIterator: typeof Symbol.asyncIterator - export const SymbolDispose: typeof Symbol.dispose - export const SymbolAsyncDispose: typeof Symbol.asyncDispose export const SymbolHasInstance: typeof Symbol.hasInstance export const SymbolIsConcatSpreadable: typeof Symbol.isConcatSpreadable export const SymbolIterator: typeof Symbol.iterator