diff --git a/lib/events.js b/lib/events.js index d0bcc3b79a6..280ef979ab4 100644 --- a/lib/events.js +++ b/lib/events.js @@ -288,11 +288,14 @@ EventEmitter.prototype.removeAllListeners = function(type) { }; EventEmitter.prototype.listeners = function(type) { - if (!this._events || !this._events[type]) return []; - if (!isArray(this._events[type])) { + if (typeof type !== 'string') + throw TypeError('event type must be a string'); + + if (!this._events || !this._events[type]) + return []; + if (typeof this._events[type] === 'function') return [this._events[type]]; - } - return this._events[type].slice(0); + return this._events[type].slice(); }; EventEmitter.listenerCount = function(emitter, type) {