Skip to content

Commit a7eaf39

Browse files
LiviaMedeirostargos
authored andcommitted
events: use kEmptyObject
PR-URL: #43159 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 02cf57b commit a7eaf39

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/events.js

Lines changed: 4 additions & 1 deletion
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;
@@ -938,7 +941,7 @@ function getEventListeners(emitterOrTarget, type) {
938941
* @param {{ signal: AbortSignal; }} [options]
939942
* @returns {Promise}
940943
*/
941-
async function once(emitter, name, options = {}) {
944+
async function once(emitter, name, options = kEmptyObject) {
942945
const signal = options?.signal;
943946
validateAbortSignal(signal, 'options.signal');
944947
if (signal?.aborted)

lib/internal/event_target.js

Lines changed: 8 additions & 4 deletions
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');
@@ -455,7 +459,7 @@ class EventTarget {
455459
* signal?: AbortSignal
456460
* }} [options]
457461
*/
458-
addEventListener(type, listener, options = {}) {
462+
addEventListener(type, listener, options = kEmptyObject) {
459463
if (!isEventTarget(this))
460464
throw new ERR_INVALID_THIS('EventTarget');
461465
if (arguments.length < 2)
@@ -542,7 +546,7 @@ class EventTarget {
542546
* capture?: boolean,
543547
* }} [options]
544548
*/
545-
removeEventListener(type, listener, options = {}) {
549+
removeEventListener(type, listener, options = kEmptyObject) {
546550
if (!isEventTarget(this))
547551
throw new ERR_INVALID_THIS('EventTarget');
548552
if (!shouldAddListener(listener))
@@ -870,7 +874,7 @@ function validateEventListenerOptions(options) {
870874
return { capture: options };
871875

872876
if (options === null)
873-
return {};
877+
return kEmptyObject;
874878
validateObject(options, 'options', {
875879
allowArray: true, allowFunction: true,
876880
});

0 commit comments

Comments
 (0)