Browse Source

events: type check listeners

Make sure the argument passed is a string. Also use typeof === function
check instead of isArray().
v0.9.12-release
Trevor Norris 12 years ago
committed by isaacs
parent
commit
aba03ebb5a
  1. 11
      lib/events.js

11
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) {

Loading…
Cancel
Save