diff options
author | Ben Noordhuis <info@bnoordhuis.nl> | 2012-05-04 17:45:27 +0200 |
---|---|---|
committer | isaacs <i@izs.me> | 2013-04-19 16:21:37 -0700 |
commit | cf0fa96db84caf9c1e6e5d0cb6f303cf6a8025c9 (patch) | |
tree | c1c346030c2f24579818ec907c0938edae1fd38c /lib/events.js | |
parent | 2efb6cf0cfb4ef6ea87a7c16dfe1b8540fd19ea2 (diff) | |
download | android-node-v8-cf0fa96db84caf9c1e6e5d0cb6f303cf6a8025c9.tar.gz android-node-v8-cf0fa96db84caf9c1e6e5d0cb6f303cf6a8025c9.tar.bz2 android-node-v8-cf0fa96db84caf9c1e6e5d0cb6f303cf6a8025c9.zip |
events: add EventEmitter.defaultMaxListeners
Class property that controls the maximum number of listeners for all
instances of EventEmitter.
Fixes #3014.
Conflicts:
lib/events.js
Diffstat (limited to 'lib/events.js')
-rw-r--r-- | lib/events.js | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/events.js b/lib/events.js index 38422dab0f..ef9ff7426c 100644 --- a/lib/events.js +++ b/lib/events.js @@ -33,17 +33,18 @@ function EventEmitter() { } } this._events = this._events || {}; - this._maxListeners = this._maxListeners || defaultMaxListeners; + this._maxListeners = this._maxListeners || undefined; } exports.EventEmitter = EventEmitter; -// By default EventEmitters will print a warning if more than -// 10 listeners are added to it. This is a useful default which -// helps finding memory leaks. -// + +// By default EventEmitters will print a warning if more than 10 listeners are +// added to it. This is a useful default which helps finding memory leaks. +EventEmitter.defaultMaxListeners = 10; + + // Obviously not all Emitters should be limited to 10. This function allows // that to be increased. Set to zero for unlimited. -var defaultMaxListeners = 10; EventEmitter.prototype.setMaxListeners = function(n) { if (typeof n !== 'number' || n < 0) throw TypeError('n must be a positive number'); @@ -150,7 +151,13 @@ EventEmitter.prototype.addListener = function(type, listener) { // Check for listener leak if (typeof this._events[type] === 'object' && !this._events[type].warned) { - m = this._maxListeners; + var m; + if (this._maxListeners !== undefined) { + m = this._maxListeners; + } else { + m = EventEmitter.defaultMaxListeners; + } + if (m && m > 0 && this._events[type].length > m) { this._events[type].warned = true; console.error('(node) warning: possible EventEmitter memory ' + |