Visitar URL original
lib: add lint rule to enforce use of `kEmptyObject` · nodejs/node@4fe2294 · GitHub
Skip to content

Commit 4fe2294

Browse files
committed
lib: add lint rule to enforce use of kEmptyObject
Signed-off-by: Antoine du Hamel <duhamelantoine1995@gmail.com> PR-URL: #63790 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 221ffa5 commit 4fe2294

20 files changed

Lines changed: 123 additions & 34 deletions

‎lib/diagnostics_channel.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const { triggerUncaughtException } = internalBinding('errors');
3535
// must always be accessed through the binding instead of cached.
3636
const dc_binding = internalBinding('diagnostics_channel');
3737

38-
const { WeakReference } = require('internal/util');
38+
const { WeakReference, kEmptyObject } = require('internal/util');
3939

4040
// Can't delete when weakref count reaches 0 as it could increment again.
4141
// Only GC can be used as a valid time to clean up the channels map.
@@ -343,7 +343,7 @@ class TracingChannel {
343343
return done;
344344
}
345345

346-
traceSync(fn, context = {}, thisArg, ...args) {
346+
traceSync(fn, context = { __proto__: null }, thisArg, ...args) {
347347
if (!this.hasSubscribers) {
348348
return ReflectApply(fn, thisArg, args);
349349
}
@@ -365,7 +365,7 @@ class TracingChannel {
365365
});
366366
}
367367

368-
tracePromise(fn, context = {}, thisArg, ...args) {
368+
tracePromise(fn, context = { __proto__: null }, thisArg, ...args) {
369369
if (!this.hasSubscribers) {
370370
return ReflectApply(fn, thisArg, args);
371371
}
@@ -407,7 +407,7 @@ class TracingChannel {
407407
});
408408
}
409409

410-
traceCallback(fn, position = -1, context = {}, thisArg, ...args) {
410+
traceCallback(fn, position = -1, context = kEmptyObject, thisArg, ...args) {
411411
if (!this.hasSubscribers) {
412412
return ReflectApply(fn, thisArg, args);
413413
}

‎lib/fs.js‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,7 +1647,7 @@ function readdirSync(path, options) {
16471647
* ) => any} [callback]
16481648
* @returns {void}
16491649
*/
1650-
function fstat(fd, options = { bigint: false }, callback) {
1650+
function fstat(fd, options = { __proto__: null, bigint: false }, callback) {
16511651
if (typeof options === 'function') {
16521652
callback = options;
16531653
options = kEmptyObject;
@@ -1670,7 +1670,7 @@ function fstat(fd, options = { bigint: false }, callback) {
16701670
* ) => any} callback
16711671
* @returns {void}
16721672
*/
1673-
function lstat(path, options = { bigint: false }, callback) {
1673+
function lstat(path, options = { __proto__: null, bigint: false }, callback) {
16741674
if (typeof options === 'function') {
16751675
callback = options;
16761676
options = kEmptyObject;
@@ -1698,7 +1698,7 @@ function lstat(path, options = { bigint: false }, callback) {
16981698
* ) => any} callback
16991699
* @returns {void}
17001700
*/
1701-
function stat(path, options = { bigint: false, throwIfNoEntry: true }, callback) {
1701+
function stat(path, options = { __proto__: null, bigint: false, throwIfNoEntry: true }, callback) {
17021702
if (typeof options === 'function') {
17031703
callback = options;
17041704
options = kEmptyObject;
@@ -1718,7 +1718,7 @@ function stat(path, options = { bigint: false, throwIfNoEntry: true }, callback)
17181718
binding.stat(getValidatedPath(path), options.bigint, req, options.throwIfNoEntry);
17191719
}
17201720

1721-
function statfs(path, options = { bigint: false }, callback) {
1721+
function statfs(path, options = { __proto__: null, bigint: false }, callback) {
17221722
if (typeof options === 'function') {
17231723
callback = options;
17241724
options = kEmptyObject;
@@ -1743,7 +1743,7 @@ function statfs(path, options = { bigint: false }, callback) {
17431743
* @param {{ bigint?: boolean; }} [options]
17441744
* @returns {Stats | undefined}
17451745
*/
1746-
function fstatSync(fd, options = { bigint: false }) {
1746+
function fstatSync(fd, options = { __proto__: null, bigint: false }) {
17471747
const stats = binding.fstat(fd, options.bigint, undefined, false);
17481748
if (stats === undefined) {
17491749
return;
@@ -1761,7 +1761,7 @@ function fstatSync(fd, options = { bigint: false }) {
17611761
* }} [options]
17621762
* @returns {Stats | undefined}
17631763
*/
1764-
function lstatSync(path, options = { bigint: false, throwIfNoEntry: true }) {
1764+
function lstatSync(path, options = { __proto__: null, bigint: false, throwIfNoEntry: true }) {
17651765
path = getValidatedPath(path);
17661766
if (permission.isEnabled() && !permission.has('fs.read', path)) {
17671767
const resource = BufferIsBuffer(path) ? BufferToString(path) : path;
@@ -1790,7 +1790,7 @@ function lstatSync(path, options = { bigint: false, throwIfNoEntry: true }) {
17901790
* }} [options]
17911791
* @returns {Stats}
17921792
*/
1793-
function statSync(path, options = { bigint: false, throwIfNoEntry: true }) {
1793+
function statSync(path, options = { __proto__: null, bigint: false, throwIfNoEntry: true }) {
17941794
const stats = binding.stat(
17951795
getValidatedPath(path),
17961796
options.bigint,
@@ -1803,7 +1803,7 @@ function statSync(path, options = { bigint: false, throwIfNoEntry: true }) {
18031803
return getStatsFromBinding(stats);
18041804
}
18051805

1806-
function statfsSync(path, options = { bigint: false }) {
1806+
function statfsSync(path, options = { __proto__: null, bigint: false }) {
18071807
const stats = binding.statfs(getValidatedPath(path), options.bigint);
18081808
return getStatFsFromBinding(stats);
18091809
}

‎lib/internal/async_local_storage/async_context_frame.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const AsyncContextFrame = require('internal/async_context_frame');
1313
const { AsyncResource } = require('async_hooks');
1414

1515
const RunScope = require('internal/async_local_storage/run_scope');
16+
const { kEmptyObject } = require('internal/util');
1617

1718
class AsyncLocalStorage {
1819
#defaultValue = undefined;
@@ -26,7 +27,7 @@ class AsyncLocalStorage {
2627
/**
2728
* @param {AsyncLocalStorageOptions} [options]
2829
*/
29-
constructor(options = {}) {
30+
constructor(options = kEmptyObject) {
3031
validateObject(options, 'options');
3132
this.#defaultValue = options.defaultValue;
3233

‎lib/internal/async_local_storage/async_hooks.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const {
2525
} = require('async_hooks');
2626

2727
const RunScope = require('internal/async_local_storage/run_scope');
28+
const { kEmptyObject } = require('internal/util');
2829

2930
const storageList = [];
3031

@@ -54,7 +55,7 @@ class AsyncLocalStorage {
5455
/**
5556
* @param {AsyncLocalStorageOptions} [options]
5657
*/
57-
constructor(options = {}) {
58+
constructor(options = kEmptyObject) {
5859
this.kResourceStore = Symbol('kResourceStore');
5960
this.enabled = false;
6061
validateObject(options, 'options');

‎lib/internal/blob.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ function createBlobReaderStream(reader) {
572572
// unbounded memory growth when the DataQueue has a large burst of data.
573573
const kMaxBatchChunks = 16;
574574

575-
async function* createBlobReaderIterable(reader, options = {}) {
575+
async function* createBlobReaderIterable(reader, options = kEmptyObject) {
576576
const { getReadError } = options;
577577
let wakeup = PromiseWithResolvers();
578578
let immediate;

‎lib/internal/fs/promises.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,7 +1723,7 @@ async function symlink(target, path, type) {
17231723
);
17241724
}
17251725

1726-
async function fstat(handle, options = { bigint: false }) {
1726+
async function fstat(handle, options = { __proto__: null, bigint: false }) {
17271727
const result = await PromisePrototypeThen(
17281728
binding.fstat(handle.fd, options.bigint, kUsePromises),
17291729
undefined,
@@ -1732,7 +1732,7 @@ async function fstat(handle, options = { bigint: false }) {
17321732
return getStatsFromBinding(result);
17331733
}
17341734

1735-
async function lstat(path, options = { bigint: false }) {
1735+
async function lstat(path, options = { __proto__: null, bigint: false }) {
17361736
path = getValidatedPath(path);
17371737
if (permission.isEnabled() && !permission.has('fs.read', path)) {
17381738
const resource = pathModule.toNamespacedPath(BufferIsBuffer(path) ? BufferToString(path) : path);
@@ -1746,7 +1746,7 @@ async function lstat(path, options = { bigint: false }) {
17461746
return getStatsFromBinding(result);
17471747
}
17481748

1749-
async function stat(path, options = { bigint: false, throwIfNoEntry: true }) {
1749+
async function stat(path, options = { __proto__: null, bigint: false, throwIfNoEntry: true }) {
17501750
const result = await PromisePrototypeThen(
17511751
binding.stat(getValidatedPath(path), options.bigint, kUsePromises, options.throwIfNoEntry),
17521752
undefined,
@@ -1759,7 +1759,7 @@ async function stat(path, options = { bigint: false, throwIfNoEntry: true }) {
17591759
return getStatsFromBinding(result);
17601760
}
17611761

1762-
async function statfs(path, options = { bigint: false }) {
1762+
async function statfs(path, options = { __proto__: null, bigint: false }) {
17631763
const result = await PromisePrototypeThen(
17641764
binding.statfs(getValidatedPath(path), options.bigint, kUsePromises),
17651765
undefined,

‎lib/internal/http2/core.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3816,7 +3816,7 @@ function getUnpackedSettings(buf, options = kEmptyObject) {
38163816
return settings;
38173817
}
38183818

3819-
function performServerHandshake(socket, options = {}) {
3819+
function performServerHandshake(socket, options = kEmptyObject) {
38203820
options = initializeOptions(options);
38213821
return new ServerHttp2Session(options, socket, undefined);
38223822
}

‎lib/internal/inspector/network_http.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const {
1919
} = require('internal/inspector/network');
2020
const { Network } = require('inspector');
2121
const EventEmitter = require('events');
22+
const { kEmptyObject } = require('internal/util');
2223

2324
const kRequestUrl = Symbol('kRequestUrl');
2425

@@ -36,7 +37,7 @@ function getRequestURL(request, host) {
3637
}
3738

3839
// Convert a Headers object (Map<string, number | string | string[]>) to a plain object (Map<string, string>)
39-
const convertHeaderObject = (headers = {}) => {
40+
const convertHeaderObject = (headers = kEmptyObject) => {
4041
// The 'host' header that contains the host and port of the URL.
4142
let host;
4243
let charset;

‎lib/internal/inspector/network_http2.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ const {
3030
} = internalBinding('http2').constants;
3131
const EventEmitter = require('events');
3232
const { Buffer } = require('buffer');
33+
const { kEmptyObject } = require('internal/util');
3334

3435
const kRequestUrl = Symbol('kRequestUrl');
3536

3637
// Convert a Headers object (Map<string, number | string | string[]>) to a plain object (Map<string, string>)
37-
function convertHeaderObject(headers = {}) {
38+
function convertHeaderObject(headers = kEmptyObject) {
3839
let scheme;
3940
let authority;
4041
let path;

‎lib/internal/modules/esm/hooks.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ class AsyncLoaderHooksOnLoaderHookWorker {
358358
* @param {object} context Metadata about the module
359359
* @returns {Promise<{ format: ModuleFormat, source: ModuleSource }>}
360360
*/
361-
async load(url, context = {}) {
361+
async load(url, context = kEmptyObject) {
362362
const chain = this.#chains.load;
363363
const meta = {
364364
chainFinished: null,

0 commit comments

Comments
 (0)