Skip to content

Commit

Permalink
events: use kEmptyObject
Browse files Browse the repository at this point in the history
PR-URL: #43159
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
  • Loading branch information
LiviaMedeiros authored and danielleadams committed Jun 13, 2022
1 parent df0903c commit fda2105
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 @@ -945,7 +948,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 @@ -453,7 +457,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 @@ -540,7 +544,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 @@ -869,7 +873,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 fda2105

Please sign in to comment.