From aba03ebb5a76dd1452a3dce991f0165252976f9c Mon Sep 17 00:00:00 2001 From: Trevor Norris Date: Wed, 20 Feb 2013 15:33:24 -0800 Subject: [PATCH] events: type check listeners Make sure the argument passed is a string. Also use typeof === function check instead of isArray(). --- lib/events.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/events.js b/lib/events.js index d0bcc3b79a..280ef979ab 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) {