Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fda2105

Browse filesBrowse files
LiviaMedeirosdanielleadams
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 df0903c commit fda2105
Copy full SHA for fda2105

File tree

Expand file treeCollapse file tree

2 files changed

+12
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-5
lines changed
Open diff view settings
Collapse file

‎lib/events.js‎

Copy file name to clipboardExpand all lines: lib/events.js
+4-1Lines 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;
@@ -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)
Collapse file

‎lib/internal/event_target.js‎

Copy file name to clipboardExpand all lines: lib/internal/event_target.js
+8-4Lines 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');
@@ -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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.