Skip to content

Commit

Permalink
events: use kEmptyObject
Browse files Browse the repository at this point in the history
PR-URL: nodejs/node#43159
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
LiviaMedeiros authored and guangwong committed Oct 10, 2022
1 parent 0b94ec8 commit 0a985b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ const {
SymbolAsyncIterator,
} = primordials;
const kRejection = SymbolFor('nodejs.rejection');

const { kEmptyObject } = require('internal/util');

const { inspect } = require('internal/util/inspect');

let spliceOne;
Expand Down Expand Up @@ -938,7 +941,7 @@ function getEventListeners(emitterOrTarget, type) {
* @param {{ signal: AbortSignal; }} [options]
* @returns {Promise}
*/
async function once(emitter, name, options = {}) {
async function once(emitter, name, options = kEmptyObject) {
const signal = options?.signal;
validateAbortSignal(signal, 'options.signal');
if (signal?.aborted)
Expand Down
12 changes: 8 additions & 4 deletions lib/internal/event_target.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ const {
} = require('internal/errors');
const { validateObject, validateString } = require('internal/validators');

const { customInspectSymbol, kEnumerableProperty } = require('internal/util');
const {
customInspectSymbol,
kEmptyObject,
kEnumerableProperty,
} = require('internal/util');
const { inspect } = require('util');

const kIsEventTarget = SymbolFor('nodejs.event_target');
Expand Down Expand Up @@ -455,7 +459,7 @@ class EventTarget {
* signal?: AbortSignal
* }} [options]
*/
addEventListener(type, listener, options = {}) {
addEventListener(type, listener, options = kEmptyObject) {
if (!isEventTarget(this))
throw new ERR_INVALID_THIS('EventTarget');
if (arguments.length < 2)
Expand Down Expand Up @@ -542,7 +546,7 @@ class EventTarget {
* capture?: boolean,
* }} [options]
*/
removeEventListener(type, listener, options = {}) {
removeEventListener(type, listener, options = kEmptyObject) {
if (!isEventTarget(this))
throw new ERR_INVALID_THIS('EventTarget');
if (!shouldAddListener(listener))
Expand Down Expand Up @@ -870,7 +874,7 @@ function validateEventListenerOptions(options) {
return { capture: options };

if (options === null)
return {};
return kEmptyObject;
validateObject(options, 'options', {
allowArray: true, allowFunction: true,
});
Expand Down

0 comments on commit 0a985b0

Please sign in to comment.