Skip to content

Commit cab08ea

Browse files
committed
lib: use kEmptyObject as default value for options
`kEmptyObject` is more suitable than {} if options don't need mutation.
1 parent 4830a6c commit cab08ea

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

lib/events.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
10131013
* }} [options]
10141014
* @returns {AsyncIterator}
10151015
*/
1016-
function on(emitter, event, options = {}) {
1016+
function on(emitter, event, options = kEmptyObject) {
10171017
// Parameters validation
10181018
const signal = options.signal;
10191019
validateAbortSignal(signal, 'options.signal');

lib/internal/fs/watchers.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ const {
3737

3838
const { toNamespacedPath } = require('path');
3939

40+
const { kEmptyObject } = require('internal/util');
41+
4042
const {
4143
validateAbortSignal,
4244
validateBoolean,
@@ -296,7 +298,7 @@ ObjectDefineProperty(FSEvent.prototype, 'owner', {
296298
set(v) { return this[owner_symbol] = v; }
297299
});
298300

299-
async function* watch(filename, options = {}) {
301+
async function* watch(filename, options = kEmptyObject) {
300302
const path = toNamespacedPath(getValidatedPath(filename));
301303
validateObject(options, 'options');
302304

lib/internal/http2/core.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3326,7 +3326,7 @@ function createSecureServer(options, handler) {
33263326
function createServer(options, handler) {
33273327
if (typeof options === 'function') {
33283328
handler = options;
3329-
options = {};
3329+
options = kEmptyObject;
33303330
}
33313331
return new Http2Server(options, handler);
33323332
}

lib/internal/socketaddress.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const {
1111
AF_INET6,
1212
} = internalBinding('block_list');
1313

14+
const { kEmptyObject } = require('internal/util');
15+
1416
const {
1517
validateObject,
1618
validateString,
@@ -44,7 +46,7 @@ class SocketAddress extends JSTransferable {
4446
return value?.[kHandle] !== undefined;
4547
}
4648

47-
constructor(options = {}) {
49+
constructor(options = kEmptyObject) {
4850
super();
4951
validateObject(options, 'options');
5052
let { family = 'ipv4' } = options;

lib/net.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ const {
108108
} = require('internal/errors');
109109
const { isUint8Array } = require('internal/util/types');
110110
const { queueMicrotask } = require('internal/process/task_queues');
111+
const { kEmptyObject } = require('internal/util');
111112
const {
112113
validateAbortSignal,
113114
validateBoolean,
@@ -1584,7 +1585,7 @@ function Server(options, connectionListener) {
15841585

15851586
if (typeof options === 'function') {
15861587
connectionListener = options;
1587-
options = {};
1588+
options = kEmptyObject;
15881589
this.on('connection', connectionListener);
15891590
} else if (options == null || typeof options === 'object') {
15901591
options = { ...options };

0 commit comments

Comments
 (0)