lib: move Symbol[Async]Dispose polyfills to internal/util

PR-URL: https://github.com/nodejs/node/pull/54853
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Antoine du Hamel 2024-09-10 23:24:56 +02:00 committed by GitHub
parent 5de919b652
commit 7c58645aca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
27 changed files with 48 additions and 41 deletions

View File

@ -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,

View File

@ -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(

View File

@ -30,8 +30,6 @@ const {
ObjectDefineProperty,
ObjectSetPrototypeOf,
ReflectApply,
SymbolAsyncDispose,
SymbolDispose,
} = primordials;
const {
@ -63,7 +61,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');

View File

@ -47,12 +47,11 @@ const {
StringPrototypeSplit,
Symbol,
SymbolAsyncIterator,
SymbolDispose,
SymbolFor,
} = primordials;
const kRejection = SymbolFor('nodejs.rejection');
const { kEmptyObject } = require('internal/util');
const { SymbolDispose, kEmptyObject } = require('internal/util');
const {
inspect,

View File

@ -33,13 +33,13 @@ const {
ObjectSetPrototypeOf,
ReflectApply,
ReflectConstruct,
SymbolAsyncDispose,
} = primordials;
const {
assertCrypto,
kEmptyObject,
promisify,
SymbolAsyncDispose,
} = require('internal/util');
assertCrypto();

View File

@ -4,9 +4,12 @@ const {
JSONParse,
JSONStringify,
SafeMap,
SymbolDispose,
} = primordials;
const {
SymbolDispose,
} = require('internal/util');
const {
ERR_INSPECTOR_ALREADY_ACTIVATED,
ERR_INSPECTOR_ALREADY_CONNECTED,

View File

@ -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');

View File

@ -2,7 +2,7 @@
const {
SymbolDispose,
} = primordials;
} = require('internal/util');
const {
validateAbortSignal,
validateFunction,

View File

@ -15,7 +15,6 @@ const {
SafeArrayIterator,
SafePromisePrototypeFinally,
Symbol,
SymbolAsyncDispose,
Uint8Array,
uncurryThis,
} = primordials;
@ -100,6 +99,7 @@ const {
promisify,
isWindows,
isMacOS,
SymbolAsyncDispose,
} = require('internal/util');
const EventEmitter = require('events');
const { StringDecoder } = require('string_decoder');

View File

@ -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();

View File

@ -229,11 +229,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.

View File

@ -15,8 +15,6 @@ const {
String,
StringPrototypeStartsWith,
Symbol,
SymbolAsyncDispose,
SymbolDispose,
globalThis,
} = primordials;
@ -31,6 +29,8 @@ const {
defineReplaceableLazyAttribute,
setupCoverageHooks,
emitExperimentalWarning,
SymbolAsyncDispose,
SymbolDispose,
} = require('internal/util');
const {

View File

@ -30,7 +30,6 @@ const {
StringPrototypeTrim,
Symbol,
SymbolAsyncIterator,
SymbolDispose,
} = primordials;
const { codes: {
@ -45,7 +44,7 @@ const {
validateString,
validateUint32,
} = require('internal/validators');
const { kEmptyObject } = require('internal/util');
const { SymbolDispose, kEmptyObject } = require('internal/util');
const {
inspect,
getStringWidth,

View File

@ -2,7 +2,7 @@
const {
SymbolDispose,
} = primordials;
} = require('internal/util');
const {
AbortError,

View File

@ -6,7 +6,6 @@
const {
Promise,
PromisePrototypeThen,
SymbolDispose,
} = primordials;
const {
@ -19,6 +18,7 @@ const {
const {
kEmptyObject,
once,
SymbolDispose,
} = require('internal/util');
const {
validateAbortSignal,

View File

@ -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 {

View File

@ -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,

View File

@ -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,

View File

@ -17,7 +17,6 @@ const {
Promise,
Symbol,
SymbolAsyncIterator,
SymbolDispose,
globalThis,
} = primordials;
@ -29,6 +28,7 @@ const {
const {
emitExperimentalWarning,
SymbolDispose,
} = require('internal/util');
const {
AbortError,

View File

@ -26,7 +26,6 @@ const {
StringPrototypeStartsWith,
StringPrototypeTrim,
Symbol,
SymbolDispose,
} = primordials;
const { getCallerLocation } = internalBinding('util');
const { exitCodes: { kGenericUserError } } = internalBinding('errors');
@ -52,6 +51,7 @@ const {
createDeferredPromise,
kEmptyObject,
once: runOnce,
SymbolDispose,
} = require('internal/util');
const { isPromise } = require('internal/util/types');
const {

View File

@ -936,6 +936,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,

View File

@ -20,7 +20,6 @@ const {
SafePromiseAll,
Symbol,
SymbolAsyncIterator,
SymbolDispose,
SymbolToStringTag,
TypedArrayPrototypeGetLength,
Uint8Array,
@ -54,6 +53,7 @@ const {
kEmptyObject,
kEnumerableProperty,
SideEffectFreeRegExpPrototypeSymbolReplace,
SymbolDispose,
} = require('internal/util');
const {

View File

@ -36,8 +36,6 @@ const {
ObjectDefineProperty,
ObjectSetPrototypeOf,
Symbol,
SymbolAsyncDispose,
SymbolDispose,
} = primordials;
const EventEmitter = require('events');
@ -116,7 +114,14 @@ const {
} = require('internal/errors');
const { isUint8Array } = require('internal/util/types');
const { queueMicrotask } = require('internal/process/task_queues');
const { kEmptyObject, guessHandleType, promisify, isWindows } = require('internal/util');
const {
guessHandleType,
isWindows,
kEmptyObject,
promisify,
SymbolAsyncDispose,
SymbolDispose,
} = require('internal/util');
const {
validateAbortSignal,
validateBoolean,

View File

@ -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');

View File

@ -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;

View File

@ -26,7 +26,6 @@ const {
MathTrunc,
ObjectDefineProperties,
ObjectDefineProperty,
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;

View File

@ -429,8 +429,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