Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: use kEmptyObject as default value for options #46011

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/events.js
Expand Up @@ -1013,7 +1013,7 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
* }} [options]
* @returns {AsyncIterator}
*/
function on(emitter, event, options = {}) {
function on(emitter, event, options = kEmptyObject) {
// Parameters validation
const signal = options.signal;
validateAbortSignal(signal, 'options.signal');
Expand Down
7 changes: 5 additions & 2 deletions lib/internal/fs/watchers.js
Expand Up @@ -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,
Expand Down Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion lib/internal/http2/core.js
Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/internal/socketaddress.js
Expand Up @@ -26,6 +26,7 @@ const {

const {
customInspectSymbol: kInspect,
kEmptyObject,
} = require('internal/util');

const { inspect } = require('internal/util/inspect');
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion lib/net.js
Expand Up @@ -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,
Expand Down Expand Up @@ -1584,7 +1585,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 };
Expand Down