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
Backport-PR-URL: #55264
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>
  • Loading branch information
aduh95 authored and marco-ippolito committed Nov 18, 2024
1 parent f25a5b6 commit 00a2fc7
Show file tree
Hide file tree
Showing 27 changed files with 50 additions and 45 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 errors = require('internal/errors');
Expand Down Expand Up @@ -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');
Expand Down
3 changes: 1 addition & 2 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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,
FunctionPrototypeBind,
uncurryThis,
Expand Down Expand Up @@ -96,6 +95,7 @@ const {
lazyDOMException,
promisify,
getLazy,
SymbolAsyncDispose,
} = require('internal/util');
const { EventEmitterMixin } = require('internal/event_target');
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 @@ -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.
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 @@ -17,8 +17,6 @@ const {
String,
StringPrototypeStartsWith,
Symbol,
SymbolAsyncDispose,
SymbolDispose,
globalThis,
} = primordials;

Expand All @@ -34,6 +32,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 @@ -28,7 +28,6 @@ const {
StringPrototypeStartsWith,
StringPrototypeTrim,
Symbol,
SymbolDispose,
SymbolAsyncIterator,
SafeStringIterator,
} = primordials;
Expand All @@ -46,7 +45,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 @@ -14,6 +14,7 @@ const {
const {
kEmptyObject,
once,
SymbolDispose,
} = require('internal/util');
const {
validateAbortSignal,
Expand All @@ -25,7 +26,6 @@ const {
const {
Promise,
PromisePrototypeThen,
SymbolDispose,
} = primordials;

const {
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
9 changes: 4 additions & 5 deletions lib/internal/test_runner/mock/mock_timers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
'use strict';

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

const {
ArrayPrototypeAt,
ArrayPrototypeForEach,
Expand All @@ -22,14 +18,17 @@ const {
Promise,
Symbol,
SymbolAsyncIterator,
SymbolDispose,
} = primordials;
const {
validateAbortSignal,
validateNumber,
validateStringArray,
} = require('internal/validators');

const {
emitExperimentalWarning,
SymbolDispose,
} = require('internal/util');
const {
AbortError,
codes: { ERR_INVALID_STATE, ERR_INVALID_ARG_VALUE },
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 @@ -22,7 +22,6 @@ const {
SafeSet,
SafePromiseAll,
SafePromiseRace,
SymbolDispose,
ObjectDefineProperty,
Symbol,
} = primordials;
Expand All @@ -49,6 +48,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 @@ -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,

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 @@ -21,7 +21,6 @@ const {
SafePromiseAll,
Symbol,
SymbolAsyncIterator,
SymbolDispose,
SymbolToStringTag,
TypedArrayPrototypeGetLength,
Uint8Array,
Expand Down Expand Up @@ -55,6 +54,7 @@ const {
kEmptyObject,
kEnumerableProperty,
SideEffectFreeRegExpPrototypeSymbolReplace,
SymbolDispose,
} = require('internal/util');

const {
Expand Down
10 changes: 7 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 @@ -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,
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
Loading

0 comments on commit 00a2fc7

Please sign in to comment.