Skip to content

Commit

Permalink
lib: remove Symbol[Async]Dispose polyfills
Browse files Browse the repository at this point in the history
PR-URL: #55276
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Moshe Atlow <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Chemi Atlow <[email protected]>
  • Loading branch information
targos authored Oct 7, 2024
1 parent 9a9409f commit d5eb9a3
Show file tree
Hide file tree
Showing 26 changed files with 33 additions and 70 deletions.
2 changes: 1 addition & 1 deletion lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const {
ObjectSetPrototypeOf,
ReflectApply,
Symbol,
SymbolAsyncDispose,
SymbolFor,
} = primordials;

Expand Down Expand Up @@ -81,7 +82,6 @@ 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,6 +42,7 @@ const {
StringPrototypeIncludes,
StringPrototypeSlice,
StringPrototypeToUpperCase,
SymbolDispose,
} = primordials;

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

const {
Expand Down Expand Up @@ -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');
Expand Down
3 changes: 2 additions & 1 deletion lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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: 1 addition & 4 deletions lib/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ const {
JSONParse,
JSONStringify,
SafeMap,
} = primordials;

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

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

Expand Down Expand Up @@ -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');
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,
} = require('internal/util');
} = primordials;
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,6 +15,7 @@ const {
SafeArrayIterator,
SafePromisePrototypeFinally,
Symbol,
SymbolAsyncDispose,
Uint8Array,
uncurryThis,
} = primordials;
Expand Down Expand Up @@ -99,7 +100,6 @@ 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,6 +19,8 @@ const {
SafeMap,
SafeSet,
Symbol,
SymbolAsyncDispose,
SymbolDispose,
Uint32Array,
Uint8Array,
} = primordials;
Expand All @@ -28,8 +30,6 @@ const {
customInspectSymbol: kInspect,
kEmptyObject,
promisify,
SymbolAsyncDispose,
SymbolDispose,
} = require('internal/util');

assertCrypto();
Expand Down
30 changes: 0 additions & 30 deletions lib/internal/process/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const {
ObjectFreeze,
String,
StringPrototypeStartsWith,
Symbol,
globalThis,
} = primordials;

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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/readline/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const {
StringPrototypeTrim,
Symbol,
SymbolAsyncIterator,
SymbolDispose,
} = primordials;

const { codes: {
Expand All @@ -44,7 +45,7 @@ const {
validateString,
validateUint32,
} = require('internal/validators');
const { SymbolDispose, kEmptyObject } = require('internal/util');
const { 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,
} = require('internal/util');
} = primordials;

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,6 +6,7 @@
const {
Promise,
PromisePrototypeThen,
SymbolDispose,
} = primordials;

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

Expand All @@ -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,
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,6 +17,7 @@ const {
Promise,
Symbol,
SymbolAsyncIterator,
SymbolDispose,
globalThis,
} = primordials;

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

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

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

const EventEmitter = require('events');
Expand Down Expand Up @@ -119,8 +121,6 @@ const {
isWindows,
kEmptyObject,
promisify,
SymbolAsyncDispose,
SymbolDispose,
} = require('internal/util');
const {
validateAbortSignal,
Expand Down
2 changes: 1 addition & 1 deletion lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const {
Promise,
PromiseReject,
StringPrototypeSlice,
SymbolDispose,
} = primordials;

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

Expand Down
Loading

0 comments on commit d5eb9a3

Please sign in to comment.