events: type check listeners

Make sure the argument passed is a string. Also use typeof === function
check instead of isArray().
This commit is contained in:
Trevor Norris authored and isaacs committed 2013-03-01 17:36:47 -08:00
1 parent 8ab346c98f
commit aba03ebb5a
1 file changed
+7 -4
+7 -4
View File
@@ -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) {