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:
parent
8ab346c98f
commit
aba03ebb5a
@ -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…
x
Reference in New Issue
Block a user