From d5eb9a378e7ce357151b44f41f82e6ee3de1984a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Mon, 7 Oct 2024 11:47:44 +0200 Subject: [PATCH] lib: remove `Symbol[Async]Dispose` polyfills PR-URL: https://github.com/nodejs/node/pull/55276 Reviewed-By: Stephen Belanger Reviewed-By: Matteo Collina Reviewed-By: Moshe Atlow Reviewed-By: Luigi Pinca Reviewed-By: Yagiz Nizipli Reviewed-By: Chemi Atlow --- lib/_http_server.js | 2 +- lib/child_process.js | 2 +- lib/dgram.js | 4 ++- lib/events.js | 3 +- lib/https.js | 2 +- lib/inspector.js | 5 +--- lib/internal/child_process.js | 3 +- lib/internal/events/abort_listener.js | 2 +- lib/internal/fs/promises.js | 2 +- lib/internal/http2/core.js | 4 +-- lib/internal/process/pre_execution.js | 30 -------------------- lib/internal/readline/interface.js | 3 +- lib/internal/streams/add-abort-signal.js | 2 +- lib/internal/streams/end-of-stream.js | 2 +- lib/internal/streams/pipeline.js | 3 +- lib/internal/streams/readable.js | 4 +-- lib/internal/streams/writable.js | 4 +-- lib/internal/test_runner/mock/mock_timers.js | 2 +- lib/internal/test_runner/test.js | 2 +- lib/internal/util.js | 8 ------ lib/internal/webstreams/readablestream.js | 2 +- lib/net.js | 4 +-- lib/readline.js | 2 +- lib/readline/promises.js | 2 +- lib/timers.js | 2 +- typings/primordials.d.ts | 2 ++ 26 files changed, 33 insertions(+), 70 deletions(-) diff --git a/lib/_http_server.js b/lib/_http_server.js index 6a0bcd75513b5c..ba31f4534b2f68 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 51fc6fe995d3cf..c633866b962cfc 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 84b8708f701ed0..f29a5397688528 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 256dd580e159bd..07ffdebbb099e5 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 21b40275ecb691..ec68296ed518c4 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 b1d67b84fe04d6..b623d96b68c3f7 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 ab6872e4f89243..516015b9dd672a 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 2803fa585d29df..033cbf7b250fe0 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 a29c7d96c04263..5343cf3f170433 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 923db9ad1b5b1e..4dc4eaf547e238 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 0da8c50a6f888d..dfb672b49b4114 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 aaa1dea7a8cbcd..74b2b69083abe0 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 9d76fda29a6e48..2fa16d697c11b6 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 c234792bd33ed4..c44f99e993ad5b 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 4531cf06aa2277..dc3903fc8cd6ee 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 5a6fe1db000f5c..ac034d7d5548ea 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 b74b60882017f6..ac14b202b6639c 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 fa91c9759ecc15..a1e0043cafcf29 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 3a2a2b1383ff30..b777a1038ab49d 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 bf1622aa5305ce..4e74a4e569defd 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 7279ff3de4b28b..10179321c10366 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 604ba648754a2a..3ae75d7ece58dc 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 e3ae952648fcec..46e7f0cb628077 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 286222bfab9a61..ccd0745a33f941 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 a0e58810752035..5795da7b9aefc8 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 8e0dd1c521b2d9..da00d43f515286 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