lib: use `kEmptyObject` as default value for options · nodejs/node@28f9089 · GitHub
Skip to content

Commit 28f9089

Browse files
deokjinkimRafaelGSS
authored andcommitted
lib: use kEmptyObject as default value for options
`kEmptyObject` is more suitable than {} if options don't need mutation. PR-URL: #46011 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 71bf513 commit 28f9089

5 files changed

Lines changed: 13 additions & 7 deletions

File tree

lib/events.js

Lines changed: 3 additions & 2 deletions

lib/internal/fs/watchers.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ const {
1414
ERR_INVALID_ARG_VALUE,
1515
},
1616
} = require('internal/errors');
17-
const { createDeferredPromise } = require('internal/util');
17+
const {
18+
createDeferredPromise,
19+
kEmptyObject,
20+
} = require('internal/util');
1821

1922
const {
2023
kFsStatsFieldsNumber,
@@ -296,7 +299,7 @@ ObjectDefineProperty(FSEvent.prototype, 'owner', {
296299
set(v) { return this[owner_symbol] = v; }
297300
});
298301

299-
async function* watch(filename, options = {}) {
302+
async function* watch(filename, options = kEmptyObject) {
300303
const path = toNamespacedPath(getValidatedPath(filename));
301304
validateObject(options, 'options');
302305

lib/internal/http2/core.js

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const {
2626

2727
const {
2828
customInspectSymbol: kInspect,
29+
kEmptyObject,
2930
} = require('internal/util');
3031

3132
const { inspect } = require('internal/util/inspect');
@@ -44,7 +45,7 @@ class SocketAddress extends JSTransferable {
4445
return value?.[kHandle] !== undefined;
4546
}
4647

47-
constructor(options = {}) {
48+
constructor(options = kEmptyObject) {
4849
super();
4950
validateObject(options, 'options');
5051
let { family = 'ipv4' } = options;

lib/net.js

Lines changed: 2 additions & 1 deletion

0 commit comments

Comments
 (0)