Skip to content

Commit fda2105

Browse files
LiviaMedeirosdanielleadams
authored andcommitted
events: use kEmptyObject
PR-URL: #43159 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent df0903c commit fda2105

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/events.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ const {
5252
SymbolAsyncIterator,
5353
} = primordials;
5454
const kRejection = SymbolFor('nodejs.rejection');
55+
56+
const { kEmptyObject } = require('internal/util');
57+
5558
const { inspect } = require('internal/util/inspect');
5659

5760
let spliceOne;
@@ -945,7 +948,7 @@ function getEventListeners(emitterOrTarget, type) {
945948
* @param {{ signal: AbortSignal; }} [options]
946949
* @returns {Promise}
947950
*/
948-
async function once(emitter, name, options = {}) {
951+
async function once(emitter, name, options = kEmptyObject) {
949952
const signal = options?.signal;
950953
validateAbortSignal(signal, 'options.signal');
951954
if (signal?.aborted)

lib/internal/event_target.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ const {
3535
} = require('internal/errors');
3636
const { validateObject, validateString } = require('internal/validators');
3737

38-
const { customInspectSymbol, kEnumerableProperty } = require('internal/util');
38+
const {
39+
customInspectSymbol,
40+
kEmptyObject,
41+
kEnumerableProperty,
42+
} = require('internal/util');
3943
const { inspect } = require('util');
4044

4145
const kIsEventTarget = SymbolFor('nodejs.event_target');
@@ -453,7 +457,7 @@ class EventTarget {
453457
* signal?: AbortSignal
454458
* }} [options]
455459
*/
456-
addEventListener(type, listener, options = {}) {
460+
addEventListener(type, listener, options = kEmptyObject) {
457461
if (!isEventTarget(this))
458462
throw new ERR_INVALID_THIS('EventTarget');
459463
if (arguments.length < 2)
@@ -540,7 +544,7 @@ class EventTarget {
540544
* capture?: boolean,
541545
* }} [options]
542546
*/
543-
removeEventListener(type, listener, options = {}) {
547+
removeEventListener(type, listener, options = kEmptyObject) {
544548
if (!isEventTarget(this))
545549
throw new ERR_INVALID_THIS('EventTarget');
546550
if (!shouldAddListener(listener))
@@ -869,7 +873,7 @@ function validateEventListenerOptions(options) {
869873
return { capture: options };
870874

871875
if (options === null)
872-
return {};
876+
return kEmptyObject;
873877
validateObject(options, 'options', {
874878
allowArray: true, allowFunction: true,
875879
});

0 commit comments

Comments
 (0)