Skip to content

Commit 9cf9046

Browse files
origranotaduh95
authored andcommitted
Revert "events: add hasEventListener util for validate"
This reverts commit bdb6d12. PR-URL: #56282 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Jason Zhang <[email protected]> Reviewed-By: Jake Yuesong Li <[email protected]>
1 parent a3f5ef2 commit 9cf9046

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

lib/events.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -287,12 +287,6 @@ ObjectDefineProperty(EventEmitter, 'defaultMaxListeners', {
287287
},
288288
});
289289

290-
function hasEventListener(self, type) {
291-
if (type === undefined)
292-
return self._events !== undefined;
293-
return self._events !== undefined && self._events[type] !== undefined;
294-
};
295-
296290
ObjectDefineProperties(EventEmitter, {
297291
kMaxEventTargetListeners: {
298292
__proto__: null,
@@ -686,11 +680,13 @@ EventEmitter.prototype.removeListener =
686680
function removeListener(type, listener) {
687681
checkListener(listener);
688682

689-
if (!hasEventListener(this, type))
683+
const events = this._events;
684+
if (events === undefined)
690685
return this;
691686

692-
const events = this._events;
693687
const list = events[type];
688+
if (list === undefined)
689+
return this;
694690

695691
if (list === listener || list.listener === listener) {
696692
this._eventsCount -= 1;
@@ -744,9 +740,9 @@ EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
744740
*/
745741
EventEmitter.prototype.removeAllListeners =
746742
function removeAllListeners(type) {
747-
if (!hasEventListener(this))
748-
return this;
749743
const events = this._events;
744+
if (events === undefined)
745+
return this;
750746

751747
// Not listening for removeListener, no need to emit
752748
if (events.removeListener === undefined) {
@@ -791,10 +787,14 @@ EventEmitter.prototype.removeAllListeners =
791787
};
792788

793789
function _listeners(target, type, unwrap) {
794-
if (!hasEventListener(target, type))
790+
const events = target._events;
791+
792+
if (events === undefined)
795793
return [];
796794

797-
const evlistener = target._events[type];
795+
const evlistener = events[type];
796+
if (evlistener === undefined)
797+
return [];
798798

799799
if (typeof evlistener === 'function')
800800
return unwrap ? [evlistener.listener || evlistener] : [evlistener];

0 commit comments

Comments
 (0)