Skip to content

Commit

Permalink
lib: move Symbol[Async]Dispose polyfills to internal/util
Browse files Browse the repository at this point in the history
PR-URL: #54853
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Chengzhong Wu <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Marco Ippolito <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
aduh95 authored Sep 10, 2024
1 parent 5de919b commit 7c58645
Show file tree
Hide file tree
Showing 27 changed files with 48 additions and 41 deletions.
2 changes: 1 addition & 1 deletion lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const {
ObjectSetPrototypeOf,
ReflectApply,
Symbol,
SymbolAsyncDispose,
SymbolFor,
} = primordials;

Expand Down Expand Up @@ -82,6 +81,7 @@ const {
const {
kEmptyObject,
promisify,
SymbolAsyncDispose,
} = require('internal/util');
const {
validateInteger,
Expand Down
2 changes: 1 addition & 1 deletion lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const {
StringPrototypeIncludes,
StringPrototypeSlice,
StringPrototypeToUpperCase,
SymbolDispose,
} = primordials;

const {
Expand All @@ -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(
Expand Down
4 changes: 1 addition & 3 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ const {
ObjectDefineProperty,
ObjectSetPrototypeOf,
ReflectApply,
SymbolAsyncDispose,
SymbolDispose,
} = primordials;

const {
Expand Down Expand Up @@ -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');
Expand Down
3 changes: 1 addition & 2 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ const {
ObjectSetPrototypeOf,
ReflectApply,
ReflectConstruct,
SymbolAsyncDispose,
} = primordials;

const {
assertCrypto,
kEmptyObject,
promisify,
SymbolAsyncDispose,
} = require('internal/util');
assertCrypto();

Expand Down
5 changes: 4 additions & 1 deletion lib/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ const {
JSONParse,
JSONStringify,
SafeMap,
SymbolDispose,
} = primordials;

const {
SymbolDispose,
} = require('internal/util');

const {
ERR_INSPECTOR_ALREADY_ACTIVATED,
ERR_INSPECTOR_ALREADY_CONNECTED,
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const {
ReflectApply,
StringPrototypeSlice,
Symbol,
SymbolDispose,
Uint8Array,
} = primordials;

Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/events/abort_listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const {
SymbolDispose,
} = primordials;
} = require('internal/util');
const {
validateAbortSignal,
validateFunction,
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/fs/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const {
SafeArrayIterator,
SafePromisePrototypeFinally,
Symbol,
SymbolAsyncDispose,
Uint8Array,
uncurryThis,
} = primordials;
Expand Down Expand Up @@ -100,6 +99,7 @@ const {
promisify,
isWindows,
isMacOS,
SymbolAsyncDispose,
} = require('internal/util');
const EventEmitter = require('events');
const { StringDecoder } = require('string_decoder');
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ const {
SafeMap,
SafeSet,
Symbol,
SymbolAsyncDispose,
SymbolDispose,
Uint32Array,
Uint8Array,
} = primordials;
Expand All @@ -30,6 +28,8 @@ const {
customInspectSymbol: kInspect,
kEmptyObject,
promisify,
SymbolAsyncDispose,
SymbolDispose,
} = require('internal/util');

assertCrypto();
Expand Down
5 changes: 0 additions & 5 deletions lib/internal/per_context/primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/process/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ const {
String,
StringPrototypeStartsWith,
Symbol,
SymbolAsyncDispose,
SymbolDispose,
globalThis,
} = primordials;

Expand All @@ -31,6 +29,8 @@ const {
defineReplaceableLazyAttribute,
setupCoverageHooks,
emitExperimentalWarning,
SymbolAsyncDispose,
SymbolDispose,
} = require('internal/util');

const {
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/readline/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const {
StringPrototypeTrim,
Symbol,
SymbolAsyncIterator,
SymbolDispose,
} = primordials;

const { codes: {
Expand All @@ -45,7 +44,7 @@ const {
validateString,
validateUint32,
} = require('internal/validators');
const { kEmptyObject } = require('internal/util');
const { SymbolDispose, kEmptyObject } = require('internal/util');
const {
inspect,
getStringWidth,
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/streams/add-abort-signal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const {
SymbolDispose,
} = primordials;
} = require('internal/util');

const {
AbortError,
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/streams/end-of-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
const {
Promise,
PromisePrototypeThen,
SymbolDispose,
} = primordials;

const {
Expand All @@ -19,6 +18,7 @@ const {
const {
kEmptyObject,
once,
SymbolDispose,
} = require('internal/util');
const {
validateAbortSignal,
Expand Down
3 changes: 1 addition & 2 deletions lib/internal/streams/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/streams/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const {
Promise,
SafeSet,
Symbol,
SymbolAsyncDispose,
SymbolAsyncIterator,
SymbolSpecies,
TypedArrayPrototypeSet,
Expand All @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion lib/internal/streams/writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const {
Promise,
StringPrototypeToLowerCase,
Symbol,
SymbolAsyncDispose,
SymbolHasInstance,
} = primordials;

Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/test_runner/mock/mock_timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const {
Promise,
Symbol,
SymbolAsyncIterator,
SymbolDispose,
globalThis,
} = primordials;

Expand All @@ -29,6 +28,7 @@ const {

const {
emitExperimentalWarning,
SymbolDispose,
} = require('internal/util');
const {
AbortError,
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const {
StringPrototypeStartsWith,
StringPrototypeTrim,
Symbol,
SymbolDispose,
} = primordials;
const { getCallerLocation } = internalBinding('util');
const { exitCodes: { kGenericUserError } } = internalBinding('errors');
Expand All @@ -52,6 +51,7 @@ const {
createDeferredPromise,
kEmptyObject,
once: runOnce,
SymbolDispose,
} = require('internal/util');
const { isPromise } = require('internal/util/types');
const {
Expand Down
8 changes: 8 additions & 0 deletions lib/internal/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
2 changes: 1 addition & 1 deletion lib/internal/webstreams/readablestream.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const {
SafePromiseAll,
Symbol,
SymbolAsyncIterator,
SymbolDispose,
SymbolToStringTag,
TypedArrayPrototypeGetLength,
Uint8Array,
Expand Down Expand Up @@ -54,6 +53,7 @@ const {
kEmptyObject,
kEnumerableProperty,
SideEffectFreeRegExpPrototypeSymbolReplace,
SymbolDispose,
} = require('internal/util');

const {
Expand Down
11 changes: 8 additions & 3 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ const {
ObjectDefineProperty,
ObjectSetPrototypeOf,
Symbol,
SymbolAsyncDispose,
SymbolDispose,
} = primordials;

const EventEmitter = require('events');
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const {
Promise,
PromiseReject,
StringPrototypeSlice,
SymbolDispose,
} = primordials;

const {
Expand All @@ -51,6 +50,7 @@ const {
const {
kEmptyObject,
promisify,
SymbolDispose,
} = require('internal/util');
const { validateAbortSignal } = require('internal/validators');

Expand Down
2 changes: 1 addition & 1 deletion lib/readline/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const {
Promise,
SymbolDispose,
} = primordials;

const {
Expand All @@ -22,6 +21,7 @@ const { validateAbortSignal } = require('internal/validators');

const {
kEmptyObject,
SymbolDispose,
} = require('internal/util');
let addAbortListener;

Expand Down
Loading

0 comments on commit 7c58645

Please sign in to comment.