diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2015-01-20 19:30:50 +0100 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2015-01-20 23:25:57 +0100 |
commit | ee9cd004d8a211871439fc77c0696b79c5d0e52d (patch) | |
tree | b7af0b11de5b56d31aeafe93174483fad480994d /lib/events.js | |
parent | 77d68070dafe56b5593ad92759a57c64de6b4cf1 (diff) | |
download | android-node-v8-ee9cd004d8a211871439fc77c0696b79c5d0e52d.tar.gz android-node-v8-ee9cd004d8a211871439fc77c0696b79c5d0e52d.tar.bz2 android-node-v8-ee9cd004d8a211871439fc77c0696b79c5d0e52d.zip |
lib: fix TypeError with EventEmitter#on() abuse
Commit 2931348 added EventEmitter#getMaxListeners() but introduced a
regression when people abuse EventEmitter.prototype.on.call() to call
EventEmitter#on() on a non-EE object. Add a workaround for that.
Fixes: https://github.com/iojs/io.js/issues/523
PR-URL: https://github.com/iojs/io.js/pull/527
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'lib/events.js')
-rw-r--r-- | lib/events.js | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/events.js b/lib/events.js index 2f3215a411..3bc532e06f 100644 --- a/lib/events.js +++ b/lib/events.js @@ -46,11 +46,14 @@ EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) { return this; }; -EventEmitter.prototype.getMaxListeners = function getMaxListeners() { - if (!util.isUndefined(this._maxListeners)) - return this._maxListeners; - else +function $getMaxListeners(that) { + if (util.isUndefined(that._maxListeners)) return EventEmitter.defaultMaxListeners; + return that._maxListeners; +} + +EventEmitter.prototype.getMaxListeners = function getMaxListeners() { + return $getMaxListeners(this); }; EventEmitter.prototype.emit = function emit(type) { @@ -151,7 +154,7 @@ EventEmitter.prototype.addListener = function addListener(type, listener) { // Check for listener leak if (util.isObject(this._events[type]) && !this._events[type].warned) { - var m = this.getMaxListeners(); + var m = $getMaxListeners(this); if (m && m > 0 && this._events[type].length > m) { this._events[type].warned = true; console.error('(node) warning: possible EventEmitter memory ' + |