diff --git a/lib/events.js b/lib/events.js index 004112cd353db8..32805d7aa10767 100644 --- a/lib/events.js +++ b/lib/events.js @@ -1002,7 +1002,7 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) { * @param {{ signal: AbortSignal; }} [options] * @returns {AsyncIterator} */ -function on(emitter, event, options) { +function on(emitter, event, options = kEmptyObject) { const signal = options?.signal; validateAbortSignal(signal, 'options.signal'); if (signal?.aborted) diff --git a/lib/internal/fs/watchers.js b/lib/internal/fs/watchers.js index 7b820e70df1613..bc4555584ab1f9 100644 --- a/lib/internal/fs/watchers.js +++ b/lib/internal/fs/watchers.js @@ -14,7 +14,10 @@ const { ERR_INVALID_ARG_VALUE, }, } = require('internal/errors'); -const { createDeferredPromise } = require('internal/util'); +const { + createDeferredPromise, + kEmptyObject, +} = require('internal/util'); const { kFsStatsFieldsNumber, @@ -296,7 +299,7 @@ ObjectDefineProperty(FSEvent.prototype, 'owner', { set(v) { return this[owner_symbol] = v; } }); -async function* watch(filename, options = {}) { +async function* watch(filename, options = kEmptyObject) { const path = toNamespacedPath(getValidatedPath(filename)); validateObject(options, 'options'); diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index fd101022c9dad7..9503fbf891336e 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -3326,7 +3326,7 @@ function createSecureServer(options, handler) { function createServer(options, handler) { if (typeof options === 'function') { handler = options; - options = {}; + options = kEmptyObject; } return new Http2Server(options, handler); } diff --git a/lib/internal/socketaddress.js b/lib/internal/socketaddress.js index 506f397180e6a1..96554f5f28d874 100644 --- a/lib/internal/socketaddress.js +++ b/lib/internal/socketaddress.js @@ -26,6 +26,7 @@ const { const { customInspectSymbol: kInspect, + kEmptyObject, } = require('internal/util'); const { inspect } = require('internal/util/inspect'); @@ -44,7 +45,7 @@ class SocketAddress extends JSTransferable { return value?.[kHandle] !== undefined; } - constructor(options = {}) { + constructor(options = kEmptyObject) { super(); validateObject(options, 'options'); let { family = 'ipv4' } = options; diff --git a/lib/net.js b/lib/net.js index 33690d02e681de..db0c9878afc2a2 100644 --- a/lib/net.js +++ b/lib/net.js @@ -108,6 +108,7 @@ const { } = require('internal/errors'); const { isUint8Array } = require('internal/util/types'); const { queueMicrotask } = require('internal/process/task_queues'); +const { kEmptyObject } = require('internal/util'); const { validateAbortSignal, validateBoolean, @@ -1583,7 +1584,7 @@ function Server(options, connectionListener) { if (typeof options === 'function') { connectionListener = options; - options = {}; + options = kEmptyObject; this.on('connection', connectionListener); } else if (options == null || typeof options === 'object') { options = { ...options };