Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
lib: use kEmptyObject as default value for options
`kEmptyObject` is more suitable than {} if options don't
need mutation.
  • Loading branch information
deokjinkim committed Dec 29, 2022
commit 0ee6cae60ace291ca18079de598f9ced96d9160f
2 changes: 1 addition & 1 deletion lib/events.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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