|
@ -1,7 +1,18 @@ |
|
|
var EventEmitter = exports.EventEmitter = process.EventEmitter; |
|
|
var EventEmitter = exports.EventEmitter = process.EventEmitter; |
|
|
|
|
|
|
|
|
var isArray = Array.isArray; |
|
|
var isArray = Array.isArray; |
|
|
|
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
//
|
|
|
|
|
|
// 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) { |
|
|
|
|
|
this._events.maxListeners = n; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EventEmitter.prototype.emit = function(type) { |
|
|
EventEmitter.prototype.emit = function(type) { |
|
|
// If there is no 'error' event listener then throw.
|
|
|
// If there is no 'error' event listener then throw.
|
|
|
if (type === 'error') { |
|
|
if (type === 'error') { |
|
@ -71,6 +82,26 @@ EventEmitter.prototype.addListener = function(type, listener) { |
|
|
// Optimize the case of one listener. Don't need the extra array object.
|
|
|
// Optimize the case of one listener. Don't need the extra array object.
|
|
|
this._events[type] = listener; |
|
|
this._events[type] = listener; |
|
|
} else if (isArray(this._events[type])) { |
|
|
} else if (isArray(this._events[type])) { |
|
|
|
|
|
|
|
|
|
|
|
// Check for listener leak
|
|
|
|
|
|
if (!this._events[type].warned) { |
|
|
|
|
|
var m; |
|
|
|
|
|
if (this._events.maxListeners !== undefined) { |
|
|
|
|
|
m = this._events.maxListeners; |
|
|
|
|
|
} else { |
|
|
|
|
|
m = defaultMaxListeners; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (m && m > 0 && this._events[type].length > m) { |
|
|
|
|
|
this._events[type].warned = true; |
|
|
|
|
|
console.error('(node) warning: possible EventEmitter memory ' + |
|
|
|
|
|
'leak detected. %d listeners added. ' + |
|
|
|
|
|
'Use emitter.setMaxListeners() to increase limit.', |
|
|
|
|
|
this._events[type].length); |
|
|
|
|
|
console.trace(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// If we've already got an array, just append.
|
|
|
// If we've already got an array, just append.
|
|
|
this._events[type].push(listener); |
|
|
this._events[type].push(listener); |
|
|
} else { |
|
|
} else { |
|
|