From 5e914f263866f5f22a647e92060c1ed36e4d3300 Mon Sep 17 00:00:00 2001 From: LiviaMedeiros Date: Sat, 21 May 2022 02:02:15 +0800 Subject: [PATCH] deep-squash: rename nullObject to kEmptyObject --- lib/_tls_wrap.js | 6 ++--- lib/async_hooks.js | 4 +-- lib/child_process.js | 4 +-- lib/events.js | 4 +-- lib/fs.js | 18 ++++++------- lib/internal/blob.js | 4 +-- lib/internal/cluster/worker.js | 4 +-- lib/internal/crypto/keygen.js | 4 +-- lib/internal/crypto/random.js | 14 +++++------ lib/internal/crypto/x509.js | 4 +-- lib/internal/encoding.js | 10 ++++---- lib/internal/event_target.js | 8 +++--- lib/internal/fs/promises.js | 8 +++--- lib/internal/fs/streams.js | 6 ++--- lib/internal/fs/sync_write_stream.js | 4 +-- lib/internal/fs/utils.js | 4 +-- lib/internal/histogram.js | 4 +-- lib/internal/http2/core.js | 4 +-- lib/internal/perf/event_loop_delay.js | 4 +-- lib/internal/perf/observe.js | 4 +-- lib/internal/perf/timerify.js | 4 +-- lib/internal/perf/usertiming.js | 6 ++--- lib/internal/promise_hooks.js | 4 +-- lib/internal/readline/interface.js | 4 +-- lib/internal/streams/end-of-stream.js | 6 ++--- lib/internal/test_runner/test.js | 4 +-- lib/internal/tls/secure-context.js | 4 +-- lib/internal/tls/secure-pair.js | 4 +-- lib/internal/util.js | 4 +-- lib/internal/vm/module.js | 8 +++--- lib/internal/webstreams/adapters.js | 10 ++++---- lib/internal/webstreams/encoding.js | 4 +-- lib/internal/webstreams/readablestream.js | 12 ++++----- lib/internal/worker.js | 4 +-- lib/internal/worker/io.js | 4 +-- lib/readline.js | 8 +++--- lib/readline/promises.js | 4 +-- lib/timers/promises.js | 8 +++--- lib/vm.js | 12 ++++----- lib/wasi.js | 4 +-- test/parallel/test-internal-util-objects.js | 28 ++++++++++----------- 41 files changed, 134 insertions(+), 134 deletions(-) diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index a330bad962f488..99642a5b5feb65 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -41,7 +41,7 @@ const { const { assertCrypto, deprecate, - nullObject, + kEmptyObject, } = require('internal/util'); assertCrypto(); @@ -1182,9 +1182,9 @@ function Server(options, listener) { if (typeof options === 'function') { listener = options; - options = nullObject; + options = kEmptyObject; } else if (options == null || typeof options === 'object') { - options = options ?? nullObject; + options = options ?? kEmptyObject; } else { throw new ERR_INVALID_ARG_TYPE('options', 'Object', options); } diff --git a/lib/async_hooks.js b/lib/async_hooks.js index d1ef5e622679f8..52ef6e9f92ae53 100644 --- a/lib/async_hooks.js +++ b/lib/async_hooks.js @@ -20,7 +20,7 @@ const { ERR_ASYNC_TYPE, ERR_INVALID_ASYNC_ID } = require('internal/errors').codes; -const { nullObject } = require('internal/util'); +const { kEmptyObject } = require('internal/util'); const { validateFunction, validateString, @@ -157,7 +157,7 @@ function createHook(fns) { const destroyedSymbol = Symbol('destroyed'); class AsyncResource { - constructor(type, opts = nullObject) { + constructor(type, opts = kEmptyObject) { validateString(type, 'type'); let triggerAsyncId = opts; diff --git a/lib/child_process.js b/lib/child_process.js index e5350a7e2c76d3..26014fd5f45e39 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -46,7 +46,7 @@ const { convertToValidSignal, createDeferredPromise, getSystemErrorName, - nullObject, + kEmptyObject, promisify, } = require('internal/util'); const { isArrayBufferView } = require('internal/util/types'); @@ -509,7 +509,7 @@ function normalizeSpawnArguments(file, args, options) { } if (options === undefined) - options = nullObject; + options = kEmptyObject; else validateObject(options, 'options'); diff --git a/lib/events.js b/lib/events.js index 3b5a53ca8b0d09..ce29aab6552266 100644 --- a/lib/events.js +++ b/lib/events.js @@ -53,7 +53,7 @@ const { } = primordials; const kRejection = SymbolFor('nodejs.rejection'); -const { nullObject } = require('internal/util'); +const { kEmptyObject } = require('internal/util'); const { inspect } = require('internal/util/inspect'); @@ -941,7 +941,7 @@ function getEventListeners(emitterOrTarget, type) { * @param {{ signal: AbortSignal; }} [options] * @returns {Promise} */ -async function once(emitter, name, options = nullObject) { +async function once(emitter, name, options = kEmptyObject) { const signal = options?.signal; validateAbortSignal(signal, 'options.signal'); if (signal?.aborted) diff --git a/lib/fs.js b/lib/fs.js index 5badf49fb892cd..76163d440bd7e9 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -86,7 +86,7 @@ const { toPathIfFileURL } = require('internal/url'); const { customPromisifyArgs, deprecate, - nullObject, + kEmptyObject, promisify, } = require('internal/util'); const { @@ -627,7 +627,7 @@ function read(fd, buffer, offsetOrOptions, length, position, callback) { if (!isArrayBufferView(buffer)) { // This is fs.read(fd, params, callback) params = buffer; - ({ buffer = Buffer.alloc(16384) } = params ?? nullObject); + ({ buffer = Buffer.alloc(16384) } = params ?? kEmptyObject); } callback = offsetOrOptions; } else { @@ -640,7 +640,7 @@ function read(fd, buffer, offsetOrOptions, length, position, callback) { offset = 0, length = buffer.byteLength - offset, position = null, - } = params ?? nullObject); + } = params ?? kEmptyObject); } validateBuffer(buffer); @@ -705,7 +705,7 @@ function readSync(fd, buffer, offset, length, position) { if (arguments.length <= 3) { // Assume fs.readSync(fd, buffer, options) - const options = offset || nullObject; + const options = offset || kEmptyObject; ({ offset = 0, @@ -833,7 +833,7 @@ function write(fd, buffer, offsetOrOptions, length, position, callback) { offset = 0, length = buffer.byteLength - offset, position = null, - } = offsetOrOptions ?? nullObject); + } = offsetOrOptions ?? kEmptyObject); } if (offset == null || typeof offset === 'function') { @@ -903,7 +903,7 @@ function writeSync(fd, buffer, offsetOrOptions, length, position) { offset = 0, length = buffer.byteLength - offset, position = null, - } = offsetOrOptions ?? nullObject); + } = offsetOrOptions ?? kEmptyObject); } if (position === undefined) position = null; @@ -1461,7 +1461,7 @@ function readdirSync(path, options) { function fstat(fd, options = { bigint: false }, callback) { if (typeof options === 'function') { callback = options; - options = nullObject; + options = kEmptyObject; } fd = getValidatedFd(fd); callback = makeStatsCallback(callback); @@ -1485,7 +1485,7 @@ function fstat(fd, options = { bigint: false }, callback) { function lstat(path, options = { bigint: false }, callback) { if (typeof options === 'function') { callback = options; - options = nullObject; + options = kEmptyObject; } callback = makeStatsCallback(callback); path = getValidatedPath(path); @@ -1508,7 +1508,7 @@ function lstat(path, options = { bigint: false }, callback) { function stat(path, options = { bigint: false }, callback) { if (typeof options === 'function') { callback = options; - options = nullObject; + options = kEmptyObject; } callback = makeStatsCallback(callback); path = getValidatedPath(path); diff --git a/lib/internal/blob.js b/lib/internal/blob.js index bbe2548cdba112..79b402f43cb4dd 100644 --- a/lib/internal/blob.js +++ b/lib/internal/blob.js @@ -44,7 +44,7 @@ const { const { createDeferredPromise, customInspectSymbol: kInspect, - nullObject, + kEmptyObject, } = require('internal/util'); const { inspect } = require('internal/util/inspect'); @@ -135,7 +135,7 @@ class Blob { * }} [options] * @constructs {Blob} */ - constructor(sources = [], options = nullObject) { + constructor(sources = [], options = kEmptyObject) { if (sources === null || typeof sources[SymbolIterator] !== 'function' || typeof sources === 'string') { diff --git a/lib/internal/cluster/worker.js b/lib/internal/cluster/worker.js index 999042d20fad05..d5dfef4387175f 100644 --- a/lib/internal/cluster/worker.js +++ b/lib/internal/cluster/worker.js @@ -7,7 +7,7 @@ const { const EventEmitter = require('events'); -const { nullObject } = require('internal/util'); +const { kEmptyObject } = require('internal/util'); module.exports = Worker; @@ -19,7 +19,7 @@ function Worker(options) { ReflectApply(EventEmitter, this, []); if (options === null || typeof options !== 'object') - options = nullObject; + options = kEmptyObject; this.exitedAfterDisconnect = undefined; diff --git a/lib/internal/crypto/keygen.js b/lib/internal/crypto/keygen.js index d59cf3d7c476a0..113f6b61a41c81 100644 --- a/lib/internal/crypto/keygen.js +++ b/lib/internal/crypto/keygen.js @@ -40,7 +40,7 @@ const { const { customPromisifyArgs, - nullObject, + kEmptyObject, } = require('internal/util'); const { @@ -121,7 +121,7 @@ function handleError(ret) { }; } -function parseKeyEncoding(keyType, options = nullObject) { +function parseKeyEncoding(keyType, options = kEmptyObject) { const { publicKeyEncoding, privateKeyEncoding } = options; let publicFormat, publicType; diff --git a/lib/internal/crypto/random.js b/lib/internal/crypto/random.js index 56803afb05f0c8..c00f344890ec89 100644 --- a/lib/internal/crypto/random.js +++ b/lib/internal/crypto/random.js @@ -27,7 +27,7 @@ const { const { lazyDOMException, - nullObject, + kEmptyObject, } = require('internal/util'); const { Buffer, kMaxLength } = require('buffer'); @@ -400,7 +400,7 @@ function randomUUID(options) { validateObject(options, 'options'); const { disableEntropyCache = false, - } = options || nullObject; + } = options || kEmptyObject; validateBoolean(disableEntropyCache, 'options.disableEntropyCache'); @@ -465,7 +465,7 @@ function generatePrime(size, options, callback) { validateInt32(size, 'size', 1); if (typeof options === 'function') { callback = options; - options = nullObject; + options = kEmptyObject; } validateFunction(callback, 'callback'); @@ -483,7 +483,7 @@ function generatePrime(size, options, callback) { job.run(); } -function generatePrimeSync(size, options = nullObject) { +function generatePrimeSync(size, options = kEmptyObject) { validateInt32(size, 'size', 1); const job = createRandomPrimeJob(kCryptoJobSync, size, options); @@ -507,7 +507,7 @@ function unsignedBigIntToBuffer(bigint, name) { return Buffer.from(padded, 'hex'); } -function checkPrime(candidate, options = nullObject, callback) { +function checkPrime(candidate, options = kEmptyObject, callback) { if (typeof candidate === 'bigint') candidate = unsignedBigIntToBuffer(candidate, 'candidate'); if (!isAnyArrayBuffer(candidate) && !isArrayBufferView(candidate)) { @@ -525,7 +525,7 @@ function checkPrime(candidate, options = nullObject, callback) { } if (typeof options === 'function') { callback = options; - options = nullObject; + options = kEmptyObject; } validateFunction(callback, 'callback'); validateObject(options, 'options'); @@ -540,7 +540,7 @@ function checkPrime(candidate, options = nullObject, callback) { job.run(); } -function checkPrimeSync(candidate, options = nullObject) { +function checkPrimeSync(candidate, options = kEmptyObject) { if (typeof candidate === 'bigint') candidate = unsignedBigIntToBuffer(candidate, 'candidate'); if (!isAnyArrayBuffer(candidate) && !isArrayBufferView(candidate)) { diff --git a/lib/internal/crypto/x509.js b/lib/internal/crypto/x509.js index 176c90d7a95997..d08893d959f73a 100644 --- a/lib/internal/crypto/x509.js +++ b/lib/internal/crypto/x509.js @@ -23,7 +23,7 @@ const { const { customInspectSymbol: kInspect, - nullObject, + kEmptyObject, } = require('internal/util'); const { @@ -65,7 +65,7 @@ function isX509Certificate(value) { return value[kInternalState] !== undefined; } -function getFlags(options = nullObject) { +function getFlags(options = kEmptyObject) { validateObject(options, 'options'); const { subject = 'default', // Can be 'default', 'always', or 'never' diff --git a/lib/internal/encoding.js b/lib/internal/encoding.js index c4ee5075d1f85a..2df9c622a209a0 100644 --- a/lib/internal/encoding.js +++ b/lib/internal/encoding.js @@ -32,7 +32,7 @@ const { getConstructorOf, customInspectSymbol: inspect, kEnumerableProperty, - nullObject, + kEmptyObject, } = require('internal/util'); const { @@ -378,7 +378,7 @@ function makeTextDecoderICU() { } = internalBinding('icu'); class TextDecoder { - constructor(encoding = 'utf-8', options = nullObject) { + constructor(encoding = 'utf-8', options = kEmptyObject) { encoding = `${encoding}`; validateObject(options, 'options', { nullable: true, @@ -407,7 +407,7 @@ function makeTextDecoderICU() { } - decode(input = empty, options = nullObject) { + decode(input = empty, options = kEmptyObject) { validateDecoder(this); if (isAnyArrayBuffer(input)) { input = lazyBuffer().from(input); @@ -452,7 +452,7 @@ function makeTextDecoderJS() { } class TextDecoder { - constructor(encoding = 'utf-8', options = nullObject) { + constructor(encoding = 'utf-8', options = kEmptyObject) { encoding = `${encoding}`; validateObject(options, 'options', { nullable: true, @@ -480,7 +480,7 @@ function makeTextDecoderJS() { this[kBOMSeen] = false; } - decode(input = empty, options = nullObject) { + decode(input = empty, options = kEmptyObject) { validateDecoder(this); if (isAnyArrayBuffer(input)) { input = lazyBuffer().from(input); diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js index 1d6fe90886586d..308aa0662eda06 100644 --- a/lib/internal/event_target.js +++ b/lib/internal/event_target.js @@ -38,7 +38,7 @@ const { validateObject, validateString } = require('internal/validators'); const { customInspectSymbol, kEnumerableProperty, - nullObject, + kEmptyObject, } = require('internal/util'); const { inspect } = require('util'); @@ -455,7 +455,7 @@ class EventTarget { * signal?: AbortSignal * }} [options] */ - addEventListener(type, listener, options = nullObject) { + addEventListener(type, listener, options = kEmptyObject) { if (!isEventTarget(this)) throw new ERR_INVALID_THIS('EventTarget'); if (arguments.length < 2) @@ -542,7 +542,7 @@ class EventTarget { * capture?: boolean, * }} [options] */ - removeEventListener(type, listener, options = nullObject) { + removeEventListener(type, listener, options = kEmptyObject) { if (!isEventTarget(this)) throw new ERR_INVALID_THIS('EventTarget'); if (!shouldAddListener(listener)) @@ -870,7 +870,7 @@ function validateEventListenerOptions(options) { return { capture: options }; if (options === null) - return nullObject; + return kEmptyObject; validateObject(options, 'options', { allowArray: true, allowFunction: true, }); diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index 4068cfdff23722..d5659c2b8695dc 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -80,7 +80,7 @@ const { const pathModule = require('path'); const { lazyDOMException, - nullObject, + kEmptyObject, promisify, } = require('internal/util'); const { EventEmitterMixin } = require('internal/event_target'); @@ -520,7 +520,7 @@ async function read(handle, bufferOrParams, offset, length, position) { offset = 0, length = buffer.byteLength - offset, position = null, - } = bufferOrParams ?? nullObject); + } = bufferOrParams ?? kEmptyObject); validateBuffer(buffer); } @@ -583,7 +583,7 @@ async function write(handle, buffer, offsetOrOptions, length, position) { offset = 0, length = buffer.byteLength - offset, position = null, - } = offsetOrOptions ?? nullObject); + } = offsetOrOptions ?? kEmptyObject); } if (offset == null) { @@ -679,7 +679,7 @@ async function mkdir(path, options) { const { recursive = false, mode = 0o777 - } = options || nullObject; + } = options || kEmptyObject; path = getValidatedPath(path); validateBoolean(recursive, 'options.recursive'); diff --git a/lib/internal/fs/streams.js b/lib/internal/fs/streams.js index 1b95d303a7d072..5952d133569bce 100644 --- a/lib/internal/fs/streams.js +++ b/lib/internal/fs/streams.js @@ -18,7 +18,7 @@ const { } = require('internal/errors').codes; const { deprecate, - nullObject, + kEmptyObject, } = require('internal/util'); const { validateFunction, @@ -150,7 +150,7 @@ function ReadStream(path, options) { return new ReadStream(path, options); // A little bit bigger buffer and water marks by default - options = copyObject(getOptions(options, nullObject)); + options = copyObject(getOptions(options, kEmptyObject)); if (options.highWaterMark === undefined) options.highWaterMark = 64 * 1024; @@ -306,7 +306,7 @@ function WriteStream(path, options) { if (!(this instanceof WriteStream)) return new WriteStream(path, options); - options = copyObject(getOptions(options, nullObject)); + options = copyObject(getOptions(options, kEmptyObject)); // Only buffers are supported. options.decodeStrings = true; diff --git a/lib/internal/fs/sync_write_stream.js b/lib/internal/fs/sync_write_stream.js index d742a72064b4ed..8fa5c56aaffc62 100644 --- a/lib/internal/fs/sync_write_stream.js +++ b/lib/internal/fs/sync_write_stream.js @@ -4,7 +4,7 @@ const { ObjectSetPrototypeOf, ReflectApply, } = primordials; -const { nullObject } = require('internal/util'); +const { kEmptyObject } = require('internal/util'); const { Writable } = require('stream'); const { closeSync, writeSync } = require('fs'); @@ -12,7 +12,7 @@ const { closeSync, writeSync } = require('fs'); function SyncWriteStream(fd, options) { ReflectApply(Writable, this, [{ autoDestroy: true }]); - options = options || nullObject; + options = options || kEmptyObject; this.fd = fd; this.readable = false; diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index 7173d23f8aaa81..9280fcfef7018e 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -44,7 +44,7 @@ const { isBigUint64Array } = require('internal/util/types'); const { - nullObject, + kEmptyObject, once, } = require('internal/util'); const { toPathIfFileURL } = require('internal/url'); @@ -315,7 +315,7 @@ function getDirent(path, name, type, callback) { } } -function getOptions(options, defaultOptions = nullObject) { +function getOptions(options, defaultOptions = kEmptyObject) { if (options == null || typeof options === 'function') { return defaultOptions; } diff --git a/lib/internal/histogram.js b/lib/internal/histogram.js index 362ead7fc28144..ca540e555e0160 100644 --- a/lib/internal/histogram.js +++ b/lib/internal/histogram.js @@ -17,7 +17,7 @@ const { const { customInspectSymbol: kInspect, - nullObject, + kEmptyObject, } = require('internal/util'); const { inspect } = require('util'); @@ -353,7 +353,7 @@ internalRecordableHistogram.prototype[kDeserialize] = () => {}; * }} [options] * @returns {RecordableHistogram} */ -function createHistogram(options = nullObject) { +function createHistogram(options = kEmptyObject) { validateObject(options, 'options'); const { lowest = 1, diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 2bd60184aed8a7..5e07d8034e272b 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -37,7 +37,7 @@ const { const { assertCrypto, customInspectSymbol: kInspect, - nullObject, + kEmptyObject, promisify, } = require('internal/util'); @@ -3332,7 +3332,7 @@ function getPackedSettings(settings) { return binding.packSettings(); } -function getUnpackedSettings(buf, options = nullObject) { +function getUnpackedSettings(buf, options = kEmptyObject) { if (!isArrayBufferView(buf) || buf.length === undefined) { throw new ERR_INVALID_ARG_TYPE('buf', ['Buffer', 'TypedArray'], buf); diff --git a/lib/internal/perf/event_loop_delay.js b/lib/internal/perf/event_loop_delay.js index 3bf78a23d2ca8c..18d7967477e0e4 100644 --- a/lib/internal/perf/event_loop_delay.js +++ b/lib/internal/perf/event_loop_delay.js @@ -28,7 +28,7 @@ const { } = require('internal/histogram'); const { - nullObject, + kEmptyObject, } = require('internal/util'); const { @@ -73,7 +73,7 @@ class ELDHistogram extends Histogram { * }} [options] * @returns {ELDHistogram} */ -function monitorEventLoopDelay(options = nullObject) { +function monitorEventLoopDelay(options = kEmptyObject) { validateObject(options, 'options'); const { resolution = 10 } = options; diff --git a/lib/internal/perf/observe.js b/lib/internal/perf/observe.js index d7d692349558cb..1988ebd888bb38 100644 --- a/lib/internal/perf/observe.js +++ b/lib/internal/perf/observe.js @@ -55,7 +55,7 @@ const { customInspectSymbol: kInspect, deprecate, lazyDOMException, - nullObject, + kEmptyObject, } = require('internal/util'); const { @@ -211,7 +211,7 @@ class PerformanceObserver { this.#callback = callback; } - observe(options = nullObject) { + observe(options = kEmptyObject) { validateObject(options, 'options'); const { entryTypes, diff --git a/lib/internal/perf/timerify.js b/lib/internal/perf/timerify.js index 656c4261c310c9..0fe23dc8b5245b 100644 --- a/lib/internal/perf/timerify.js +++ b/lib/internal/perf/timerify.js @@ -35,7 +35,7 @@ const { } = require('internal/perf/observe'); const { - nullObject, + kEmptyObject, } = require('internal/util'); function processComplete(name, start, args, histogram) { @@ -56,7 +56,7 @@ function processComplete(name, start, args, histogram) { enqueue(entry); } -function timerify(fn, options = nullObject) { +function timerify(fn, options = kEmptyObject) { validateFunction(fn, 'fn'); validateObject(options, 'options'); diff --git a/lib/internal/perf/usertiming.js b/lib/internal/perf/usertiming.js index 6e76e9b38b79ec..b6fd5460c3ef66 100644 --- a/lib/internal/perf/usertiming.js +++ b/lib/internal/perf/usertiming.js @@ -29,7 +29,7 @@ const { const { structuredClone } = require('internal/structured_clone'); const { lazyDOMException, - nullObject, + kEmptyObject, } = require('internal/util'); const markTimings = new SafeMap(); @@ -64,7 +64,7 @@ class PerformanceMark extends InternalPerformanceEntry { name = `${name}`; if (nodeTimingReadOnlyAttributes.has(name)) throw new ERR_INVALID_ARG_VALUE('name', name); - options ??= nullObject; + options ??= kEmptyObject; validateObject(options, 'options'); const startTime = options.startTime ?? now(); validateNumber(startTime, 'startTime'); @@ -94,7 +94,7 @@ class PerformanceMeasure extends InternalPerformanceEntry { } } -function mark(name, options = nullObject) { +function mark(name, options = kEmptyObject) { const mark = new PerformanceMark(name, options); enqueue(mark); return mark; diff --git a/lib/internal/promise_hooks.js b/lib/internal/promise_hooks.js index 590230be8468d8..0938a86d06407b 100644 --- a/lib/internal/promise_hooks.js +++ b/lib/internal/promise_hooks.js @@ -11,7 +11,7 @@ const { const { setPromiseHooks } = internalBinding('async_wrap'); const { triggerUncaughtException } = internalBinding('errors'); -const { nullObject } = require('internal/util'); +const { kEmptyObject } = require('internal/util'); const { validatePlainFunction } = require('internal/validators'); const hooks = { @@ -102,7 +102,7 @@ const onBefore = makeUseHook('before'); const onAfter = makeUseHook('after'); const onSettled = makeUseHook('settled'); -function createHook({ init, before, after, settled } = nullObject) { +function createHook({ init, before, after, settled } = kEmptyObject) { const hooks = []; if (init) ArrayPrototypePush(hooks, onInit(init)); diff --git a/lib/internal/readline/interface.js b/lib/internal/readline/interface.js index 235d643eecf47d..457b67716c460f 100644 --- a/lib/internal/readline/interface.js +++ b/lib/internal/readline/interface.js @@ -48,7 +48,7 @@ const { validateString, validateUint32, } = require('internal/validators'); -const { nullObject } = require('internal/util'); +const { kEmptyObject } = require('internal/util'); const { inspect, getStringWidth, @@ -1054,7 +1054,7 @@ class Interface extends InterfaceConstructor { // Handle a write from the tty [kTtyWrite](s, key) { const previousKey = this[kPreviousKey]; - key = key || nullObject; + key = key || kEmptyObject; this[kPreviousKey] = key; if (!key.meta || key.name !== 'y') { diff --git a/lib/internal/streams/end-of-stream.js b/lib/internal/streams/end-of-stream.js index 408462b0423307..806280ebc1f1d2 100644 --- a/lib/internal/streams/end-of-stream.js +++ b/lib/internal/streams/end-of-stream.js @@ -12,7 +12,7 @@ const { ERR_STREAM_PREMATURE_CLOSE } = codes; const { - nullObject, + kEmptyObject, once, } = require('internal/util'); const { @@ -46,9 +46,9 @@ const nop = () => {}; function eos(stream, options, callback) { if (arguments.length === 2) { callback = options; - options = nullObject; + options = kEmptyObject; } else if (options == null) { - options = nullObject; + options = kEmptyObject; } else { validateObject(options, 'options'); } diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index aa7846b7798582..cac379b32582a4 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -17,7 +17,7 @@ const { getOptionValue } = require('internal/options'); const { TapStream } = require('internal/test_runner/tap_stream'); const { createDeferredPromise, - nullObject, + kEmptyObject, } = require('internal/util'); const { isPromise } = require('internal/util/types'); const { isUint32 } = require('internal/validators'); @@ -200,7 +200,7 @@ class Test extends AsyncResource { } if (options === null || typeof options !== 'object') { - options = nullObject; + options = kEmptyObject; } let parent = this; diff --git a/lib/internal/tls/secure-context.js b/lib/internal/tls/secure-context.js index 991b4f82a19847..152627b420a612 100644 --- a/lib/internal/tls/secure-context.js +++ b/lib/internal/tls/secure-context.js @@ -18,7 +18,7 @@ const { } = require('internal/errors'); const { - nullObject, + kEmptyObject, } = require('internal/util'); const { @@ -121,7 +121,7 @@ function processCiphers(ciphers, name) { return { cipherList, cipherSuites }; } -function configSecureContext(context, options = nullObject, name = 'options') { +function configSecureContext(context, options = kEmptyObject, name = 'options') { validateObject(options, name); const { diff --git a/lib/internal/tls/secure-pair.js b/lib/internal/tls/secure-pair.js index 086607eebcaca8..db999d90ccffd9 100644 --- a/lib/internal/tls/secure-pair.js +++ b/lib/internal/tls/secure-pair.js @@ -1,7 +1,7 @@ 'use strict'; const EventEmitter = require('events'); -const { nullObject } = require('internal/util'); +const { kEmptyObject } = require('internal/util'); const { Duplex } = require('stream'); const _tls_wrap = require('_tls_wrap'); const _tls_common = require('_tls_common'); @@ -58,7 +58,7 @@ class SecurePair extends EventEmitter { isServer = false, requestCert = !isServer, rejectUnauthorized = false, - options = nullObject) { + options = kEmptyObject) { super(); const { socket1, socket2 } = new DuplexPair(); diff --git a/lib/internal/util.js b/lib/internal/util.js index 59f21df5ade0ae..806eac7d70c2fe 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -501,7 +501,7 @@ const lazyDOMException = hideStackFrames((message, name) => { const kEnumerableProperty = ObjectCreate(null); kEnumerableProperty.enumerable = true; -const nullObject = ObjectFreeze(ObjectCreate(null)); +const kEmptyObject = ObjectFreeze(ObjectCreate(null)); module.exports = { assertCrypto, @@ -544,5 +544,5 @@ module.exports = { kVmBreakFirstLineSymbol: Symbol('kVmBreakFirstLineSymbol'), kEnumerableProperty, - nullObject, + kEmptyObject, }; diff --git a/lib/internal/vm/module.js b/lib/internal/vm/module.js index 80433cf4f53982..e47b7b59602773 100644 --- a/lib/internal/vm/module.js +++ b/lib/internal/vm/module.js @@ -27,7 +27,7 @@ const { customInspectSymbol, emitExperimentalWarning, getConstructorOf, - nullObject, + kEmptyObject, } = require('internal/util'); const { ERR_INVALID_ARG_TYPE, @@ -199,7 +199,7 @@ class Module { this[kWrap].instantiate(); } - async evaluate(options = nullObject) { + async evaluate(options = kEmptyObject) { if (this[kWrap] === undefined) { throw new ERR_VM_MODULE_NOT_MODULE(); } @@ -257,7 +257,7 @@ class SourceTextModule extends Module { #error = kNoError; #statusOverride; - constructor(sourceText, options = nullObject) { + constructor(sourceText, options = kEmptyObject) { validateString(sourceText, 'sourceText'); validateObject(options, 'options'); @@ -386,7 +386,7 @@ class SourceTextModule extends Module { } class SyntheticModule extends Module { - constructor(exportNames, evaluateCallback, options = nullObject) { + constructor(exportNames, evaluateCallback, options = kEmptyObject) { if (!ArrayIsArray(exportNames) || ArrayPrototypeSome(exportNames, (e) => typeof e !== 'string')) { throw new ERR_INVALID_ARG_TYPE('exportNames', diff --git a/lib/internal/webstreams/adapters.js b/lib/internal/webstreams/adapters.js index 9e4628d5f8c123..0fd571bfe11d19 100644 --- a/lib/internal/webstreams/adapters.js +++ b/lib/internal/webstreams/adapters.js @@ -55,7 +55,7 @@ const { const { createDeferredPromise, - nullObject, + kEmptyObject, } = require('internal/util'); const { @@ -199,7 +199,7 @@ function newWritableStreamFromStreamWritable(streamWritable) { * }} [options] * @returns {Writable} */ -function newStreamWritableFromWritableStream(writableStream, options = nullObject) { +function newStreamWritableFromWritableStream(writableStream, options = kEmptyObject) { if (!isWritableStream(writableStream)) { throw new ERR_INVALID_ARG_TYPE( 'writableStream', @@ -442,7 +442,7 @@ function newReadableStreamFromStreamReadable(streamReadable) { * }} [options] * @returns {Readable} */ -function newStreamReadableFromReadableStream(readableStream, options = nullObject) { +function newStreamReadableFromReadableStream(readableStream, options = kEmptyObject) { if (!isReadableStream(readableStream)) { throw new ERR_INVALID_ARG_TYPE( 'readableStream', @@ -586,7 +586,7 @@ function newReadableWritablePairFromDuplex(duplex) { * }} [options] * @returns {Duplex} */ -function newStreamDuplexFromReadableWritablePair(pair = nullObject, options = nullObject) { +function newStreamDuplexFromReadableWritablePair(pair = kEmptyObject, options = kEmptyObject) { validateObject(pair, 'pair'); const { readable: readableStream, @@ -877,7 +877,7 @@ function newWritableStreamFromStreamBase(streamBase, strategy) { * @param {QueuingStrategy} strategy * @returns {ReadableStream} */ -function newReadableStreamFromStreamBase(streamBase, strategy, options = nullObject) { +function newReadableStreamFromStreamBase(streamBase, strategy, options = kEmptyObject) { validateObject(streamBase, 'streamBase'); validateObject(options, 'options'); diff --git a/lib/internal/webstreams/encoding.js b/lib/internal/webstreams/encoding.js index 7552635ebf8203..de364207b92800 100644 --- a/lib/internal/webstreams/encoding.js +++ b/lib/internal/webstreams/encoding.js @@ -25,7 +25,7 @@ const { const { customInspectSymbol: kInspect, kEnumerableProperty, - nullObject, + kEmptyObject, } = require('internal/util'); const kHandle = Symbol('kHandle'); @@ -115,7 +115,7 @@ class TextDecoderStream { * ignoreBOM? : boolean, * }} [options] */ - constructor(encoding = 'utf-8', options = nullObject) { + constructor(encoding = 'utf-8', options = kEmptyObject) { this[kType] = 'TextDecoderStream'; this[kHandle] = new TextDecoder(encoding, options); this[kTransform] = new TransformStream({ diff --git a/lib/internal/webstreams/readablestream.js b/lib/internal/webstreams/readablestream.js index adad0bb91fe53a..cc1eecab02be8c 100644 --- a/lib/internal/webstreams/readablestream.js +++ b/lib/internal/webstreams/readablestream.js @@ -51,7 +51,7 @@ const { createDeferredPromise, customInspectSymbol: kInspect, kEnumerableProperty, - nullObject, + kEmptyObject, } = require('internal/util'); const { @@ -207,7 +207,7 @@ class ReadableStream { * @param {UnderlyingSource} [source] * @param {QueuingStrategy} [strategy] */ - constructor(source = {}, strategy = nullObject) { + constructor(source = {}, strategy = kEmptyObject) { if (source === null) throw new ERR_INVALID_ARG_VALUE('source', 'Object', source); this[kState] = { @@ -297,7 +297,7 @@ class ReadableStream { * }} [options] * @returns {ReadableStreamReader} */ - getReader(options = nullObject) { + getReader(options = kEmptyObject) { if (!isReadableStream(this)) throw new ERR_INVALID_THIS('ReadableStream'); validateObject(options, 'options', { nullable: true, allowFunction: true }); @@ -316,7 +316,7 @@ class ReadableStream { * @param {StreamPipeOptions} [options] * @returns {ReadableStream} */ - pipeThrough(transform, options = nullObject) { + pipeThrough(transform, options = kEmptyObject) { if (!isReadableStream(this)) throw new ERR_INVALID_THIS('ReadableStream'); const readable = transform?.readable; @@ -366,7 +366,7 @@ class ReadableStream { * @param {StreamPipeOptions} [options] * @returns {Promise} */ - pipeTo(destination, options = nullObject) { + pipeTo(destination, options = kEmptyObject) { try { if (!isReadableStream(this)) throw new ERR_INVALID_THIS('ReadableStream'); @@ -417,7 +417,7 @@ class ReadableStream { * }} [options] * @returns {AsyncIterable} */ - values(options = nullObject) { + values(options = kEmptyObject) { if (!isReadableStream(this)) throw new ERR_INVALID_THIS('ReadableStream'); validateObject(options, 'options'); diff --git a/lib/internal/worker.js b/lib/internal/worker.js index 82ff768999a0fa..0cede10ca4bf9b 100644 --- a/lib/internal/worker.js +++ b/lib/internal/worker.js @@ -55,7 +55,7 @@ const { } = workerIo; const { deserializeError } = require('internal/error_serdes'); const { fileURLToPath, isURLInstance, pathToFileURL } = require('internal/url'); -const { nullObject } = require('internal/util'); +const { kEmptyObject } = require('internal/util'); const { validateArray } = require('internal/validators'); const { @@ -119,7 +119,7 @@ function assignEnvironmentData(data) { } class Worker extends EventEmitter { - constructor(filename, options = nullObject) { + constructor(filename, options = kEmptyObject) { super(); debug(`[${threadId}] create new worker`, filename, options); if (options.execArgv) diff --git a/lib/internal/worker/io.js b/lib/internal/worker/io.js index 2bbf7aabdd08a1..fd4d1bdface6f7 100644 --- a/lib/internal/worker/io.js +++ b/lib/internal/worker/io.js @@ -20,7 +20,7 @@ const { const { kEnumerableProperty, - nullObject, + kEmptyObject, } = require('internal/util'); const { @@ -126,7 +126,7 @@ class MessageEvent extends Event { lastEventId = '', source = null, ports = [], - } = nullObject) { + } = kEmptyObject) { super(type); this[kData] = data; this[kOrigin] = `${origin}`; diff --git a/lib/readline.js b/lib/readline.js index 0990768bf92cbd..0da8a8fa2ccfa2 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -48,7 +48,7 @@ const { inspect, } = require('internal/util/inspect'); const { - nullObject, + kEmptyObject, promisify, } = require('internal/util'); const { validateAbortSignal } = require('internal/validators'); @@ -132,7 +132,7 @@ const superQuestion = _Interface.prototype.question; Interface.prototype.question = function(query, options, cb) { cb = typeof options === 'function' ? options : cb; if (options === null || typeof options !== 'object') { - options = nullObject; + options = kEmptyObject; } if (options.signal) { @@ -160,7 +160,7 @@ Interface.prototype.question = function(query, options, cb) { }; Interface.prototype.question[promisify.custom] = function(query, options) { if (options === null || typeof options !== 'object') { - options = nullObject; + options = kEmptyObject; } if (options.signal && options.signal.aborted) { @@ -434,7 +434,7 @@ Interface.prototype._moveCursor = _Interface.prototype[kMoveCursor]; Interface.prototype._ttyWrite = _Interface.prototype[kTtyWrite]; function _ttyWriteDumb(s, key) { - key = key || nullObject; + key = key || kEmptyObject; if (key.name === 'escape') return; diff --git a/lib/readline/promises.js b/lib/readline/promises.js index 0f723a453efff0..728a6253fd5e67 100644 --- a/lib/readline/promises.js +++ b/lib/readline/promises.js @@ -19,7 +19,7 @@ const { const { validateAbortSignal } = require('internal/validators'); const { - nullObject, + kEmptyObject, } = require('internal/util'); class Interface extends _Interface { @@ -27,7 +27,7 @@ class Interface extends _Interface { constructor(input, output, completer, terminal) { super(input, output, completer, terminal); } - question(query, options = nullObject) { + question(query, options = kEmptyObject) { return new Promise((resolve, reject) => { let cb = resolve; diff --git a/lib/timers/promises.js b/lib/timers/promises.js index b6a461fc5e32aa..7c8d364b1dde4f 100644 --- a/lib/timers/promises.js +++ b/lib/timers/promises.js @@ -36,7 +36,7 @@ const { } = require('internal/validators'); const { - nullObject, + kEmptyObject, } = require('internal/util'); const kScheduler = Symbol('kScheduler'); @@ -48,7 +48,7 @@ function cancelListenerHandler(clear, reject, signal) { } } -function setTimeout(after, value, options = nullObject) { +function setTimeout(after, value, options = kEmptyObject) { const args = value !== undefined ? [value] : value; if (options == null || typeof options !== 'object') { return PromiseReject( @@ -92,7 +92,7 @@ function setTimeout(after, value, options = nullObject) { () => signal.removeEventListener('abort', oncancel)) : ret; } -function setImmediate(value, options = nullObject) { +function setImmediate(value, options = kEmptyObject) { if (options == null || typeof options !== 'object') { return PromiseReject( new ERR_INVALID_ARG_TYPE( @@ -136,7 +136,7 @@ function setImmediate(value, options = nullObject) { () => signal.removeEventListener('abort', oncancel)) : ret; } -async function* setInterval(after, value, options = nullObject) { +async function* setInterval(after, value, options = kEmptyObject) { validateObject(options, 'options'); const { signal, ref = true } = options; validateAbortSignal(signal, 'options.signal'); diff --git a/lib/vm.js b/lib/vm.js index bd8a9d06b8b5d2..19e29a47219e43 100644 --- a/lib/vm.js +++ b/lib/vm.js @@ -59,12 +59,12 @@ const { const { kVmBreakFirstLineSymbol, emitExperimentalWarning, - nullObject, + kEmptyObject, } = require('internal/util'); const kParsingContext = Symbol('script parsing context'); class Script extends ContextifyScript { - constructor(code, options = nullObject) { + constructor(code, options = kEmptyObject) { code = `${code}`; if (typeof options === 'string') { options = { filename: options }; @@ -153,7 +153,7 @@ function validateContext(contextifiedObject) { } } -function getRunInContextArgs(options = nullObject) { +function getRunInContextArgs(options = kEmptyObject) { validateObject(options, 'options'); let timeout = options.timeout; @@ -213,7 +213,7 @@ function isContext(object) { } let defaultContextNameIndex = 1; -function createContext(contextObject = {}, options = nullObject) { +function createContext(contextObject = {}, options = kEmptyObject) { if (isContext(contextObject)) { return contextObject; } @@ -306,7 +306,7 @@ function runInThisContext(code, options) { return createScript(code, options).runInThisContext(options); } -function compileFunction(code, params, options = nullObject) { +function compileFunction(code, params, options = kEmptyObject) { validateString(code, 'code'); if (params !== undefined) { validateArray(params, 'params'); @@ -396,7 +396,7 @@ const measureMemoryExecutions = { eager: constants.measureMemory.execution.EAGER, }; -function measureMemory(options = nullObject) { +function measureMemory(options = kEmptyObject) { emitExperimentalWarning('vm.measureMemory'); validateObject(options, 'options'); const { mode = 'summary', execution = 'default' } = options; diff --git a/lib/wasi.js b/lib/wasi.js index c4bcaf10a69eee..7093953a00739a 100644 --- a/lib/wasi.js +++ b/lib/wasi.js @@ -15,7 +15,7 @@ const { } = require('internal/errors').codes; const { emitExperimentalWarning, - nullObject, + kEmptyObject, } = require('internal/util'); const { isArrayBuffer } = require('internal/util/types'); const { @@ -58,7 +58,7 @@ function setupInstance(self, instance) { } class WASI { - constructor(options = nullObject) { + constructor(options = kEmptyObject) { validateObject(options, 'options'); if (options.args !== undefined) diff --git a/test/parallel/test-internal-util-objects.js b/test/parallel/test-internal-util-objects.js index f64a76b13952b0..092deb9e09464b 100644 --- a/test/parallel/test-internal-util-objects.js +++ b/test/parallel/test-internal-util-objects.js @@ -7,7 +7,7 @@ require('../common'); const assert = require('assert'); const { kEnumerableProperty, - nullObject, + kEmptyObject, } = require('internal/util'); Object.prototype.blep = 'blop'; @@ -33,56 +33,56 @@ Object.prototype.blep = 'blop'; { assert.strictEqual( - nullObject.blep, + kEmptyObject.blep, undefined ); assert.strictEqual( - nullObject.prototype, + kEmptyObject.prototype, undefined ); assert.strictEqual( - Object.getPrototypeOf(nullObject), + Object.getPrototypeOf(kEmptyObject), null ); assert.strictEqual( - nullObject instanceof Object, + kEmptyObject instanceof Object, false ); assert.deepStrictEqual( - Object.getOwnPropertyDescriptors(nullObject), + Object.getOwnPropertyDescriptors(kEmptyObject), {} ); assert.deepStrictEqual( - Object.getOwnPropertyNames(nullObject), + Object.getOwnPropertyNames(kEmptyObject), [] ); assert.deepStrictEqual( - Object.getOwnPropertySymbols(nullObject), + Object.getOwnPropertySymbols(kEmptyObject), [] ); assert.strictEqual( - Object.isExtensible(nullObject), + Object.isExtensible(kEmptyObject), false ); assert.strictEqual( - Object.isSealed(nullObject), + Object.isSealed(kEmptyObject), true ); assert.strictEqual( - Object.isFrozen(nullObject), + Object.isFrozen(kEmptyObject), true ); assert.throws( - () => nullObject.foo = 'bar', + () => kEmptyObject.foo = 'bar', TypeError ); assert.throws( - () => Object.assign(nullObject, { foo: 'bar' }), + () => Object.assign(kEmptyObject, { foo: 'bar' }), TypeError ); assert.throws( - () => Object.defineProperty(nullObject, 'foo', {}), + () => Object.defineProperty(kEmptyObject, 'foo', {}), TypeError ); }