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) { EventEmitter.prototype.listeners = function(type) {
if (!this._events || !this._events[type]) return []; if (typeof type !== 'string')
if (!isArray(this._events[type])) { 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]];
} return this._events[type].slice();
return this._events[type].slice(0);
}; };
EventEmitter.listenerCount = function(emitter, type) { EventEmitter.listenerCount = function(emitter, type) {

Loading…
Cancel
Save