From bf229cab32595f744b86b2b305b6570bbe23e99d Mon Sep 17 00:00:00 2001 From: Ilyas Shabi Date: Mon, 1 Jan 2024 13:24:07 +0100 Subject: [PATCH] stream: fix eventNames() to not return not defined events --- lib/events.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/events.js b/lib/events.js index 3ba2484ece938f..1352358e225c3e 100644 --- a/lib/events.js +++ b/lib/events.js @@ -888,7 +888,11 @@ function listenerCount(type, listener) { * @returns {any[]} */ EventEmitter.prototype.eventNames = function eventNames() { - return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : []; + const names = []; + for (const key of ReflectOwnKeys(this._events)) + this._events[key] !== undefined && names.push(key); + + return names; }; function arrayClone(arr) {