Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiviaMedeiros <livia@cirno.name>2022-05-21 12:51:52 +0300
committerAntoine du Hamel <duhamelantoine1995@gmail.com>2022-06-11 13:18:12 +0300
commit9220aca5b92e06f92eacff891678d83b18afc174 (patch)
tree309a71eaff5d66113e70efb9b62b07ba1df6c8c3
parentf3376f086bc979ccdf8f676df93dc48dcab5affa (diff)
events: use `kEmptyObject`
PR-URL: https://github.com/nodejs/node/pull/43159 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
-rw-r--r--lib/events.js5
-rw-r--r--lib/internal/event_target.js12
2 files changed, 12 insertions, 5 deletions
diff --git a/lib/events.js b/lib/events.js
index ad5ded2d0e9..603f3083ed2 100644
--- a/lib/events.js
+++ b/lib/events.js
@@ -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;
@@ -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)
diff --git a/lib/internal/event_target.js b/lib/internal/event_target.js
index d005e9edc08..651cf55d5f3 100644
--- a/lib/internal/event_target.js
+++ b/lib/internal/event_target.js
@@ -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');
@@ -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)
@@ -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))
@@ -869,7 +873,7 @@ function validateEventListenerOptions(options) {
return { capture: options };
if (options === null)
- return {};
+ return kEmptyObject;
validateObject(options, 'options', {
allowArray: true, allowFunction: true,
});