eventemitter2
Advanced tools
Comparing version 2.1.2 to 2.1.3
@@ -24,7 +24,6 @@ /*! | ||
if (conf) { | ||
this._conf = conf; | ||
conf.delimiter && (this.delimiter = conf.delimiter); | ||
conf.maxListeners && (this._events.maxListeners = conf.maxListeners); | ||
this._events.maxListeners = conf.maxListeners !== undefined ? conf.maxListeners : defaultMaxListeners; | ||
conf.wildcard && (this.wildcard = conf.wildcard); | ||
@@ -36,5 +35,18 @@ conf.newListener && (this.newListener = conf.newListener); | ||
} | ||
} else { | ||
this._events.maxListeners = defaultMaxListeners; | ||
} | ||
} | ||
function logPossibleMemoryLeak(count) { | ||
console.error('(node) warning: possible EventEmitter memory ' + | ||
'leak detected. %d listeners added. ' + | ||
'Use emitter.setMaxListeners() to increase limit.', | ||
count); | ||
if (console.trace){ | ||
console.trace(); | ||
} | ||
} | ||
function EventEmitter(conf) { | ||
@@ -187,28 +199,16 @@ this._events = {}; | ||
} | ||
else if(typeof tree._listeners === 'function') { | ||
tree._listeners = [tree._listeners, listener]; | ||
} | ||
else if (isArray(tree._listeners)) { | ||
else { | ||
if (typeof tree._listeners === 'function') { | ||
tree._listeners = [tree._listeners]; | ||
} | ||
tree._listeners.push(listener); | ||
if (!tree._listeners.warned) { | ||
var m = defaultMaxListeners; | ||
if (typeof this._events.maxListeners !== 'undefined') { | ||
m = this._events.maxListeners; | ||
} | ||
if (m > 0 && tree._listeners.length > m) { | ||
tree._listeners.warned = true; | ||
console.error('(node) warning: possible EventEmitter memory ' + | ||
'leak detected. %d listeners added. ' + | ||
'Use emitter.setMaxListeners() to increase limit.', | ||
tree._listeners.length); | ||
if(console.trace){ | ||
console.trace(); | ||
} | ||
} | ||
if ( | ||
!tree._listeners.warned && | ||
this._events.maxListeners > 0 && | ||
tree._listeners.length > this._events.maxListeners | ||
) { | ||
tree._listeners.warned = true; | ||
logPossibleMemoryLeak(tree._listeners.length); | ||
} | ||
@@ -233,6 +233,8 @@ } | ||
EventEmitter.prototype.setMaxListeners = function(n) { | ||
this._events || init.call(this); | ||
this._events.maxListeners = n; | ||
if (!this._conf) this._conf = {}; | ||
this._conf.maxListeners = n; | ||
if (n !== undefined) { | ||
this._events || init.call(this); | ||
this._events.maxListeners = n; | ||
if (!this._conf) this._conf = {}; | ||
this._conf.maxListeners = n; | ||
} | ||
}; | ||
@@ -471,3 +473,2 @@ | ||
EventEmitter.prototype.on = function(type, listener) { | ||
if (typeof type === 'function') { | ||
@@ -487,3 +488,3 @@ this.onAny(type); | ||
if(this.wildcard) { | ||
if (this.wildcard) { | ||
growListenerTree.call(this, type, listener); | ||
@@ -497,7 +498,8 @@ return this; | ||
} | ||
else if(typeof this._events[type] === 'function') { | ||
// Adding the second element, need to change to array. | ||
this._events[type] = [this._events[type], listener]; | ||
} | ||
else if (isArray(this._events[type])) { | ||
else { | ||
if (typeof this._events[type] === 'function') { | ||
// Change to array. | ||
this._events[type] = [this._events[type]]; | ||
} | ||
// If we've already got an array, just append. | ||
@@ -507,23 +509,12 @@ this._events[type].push(listener); | ||
// Check for listener leak | ||
if (!this._events[type].warned) { | ||
var m = defaultMaxListeners; | ||
if (typeof this._events.maxListeners !== 'undefined') { | ||
m = this._events.maxListeners; | ||
} | ||
if (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); | ||
if(console.trace){ | ||
console.trace(); | ||
} | ||
} | ||
if ( | ||
!this._events[type].warned && | ||
this._events.maxListeners > 0 && | ||
this._events[type].length > this._events.maxListeners | ||
) { | ||
this._events[type].warned = true; | ||
logPossibleMemoryLeak(this._events[type].length); | ||
} | ||
} | ||
return this; | ||
@@ -533,3 +524,2 @@ }; | ||
EventEmitter.prototype.onAny = function(fn) { | ||
if (typeof fn !== 'function') { | ||
@@ -539,3 +529,3 @@ throw new Error('onAny only accepts instances of Function'); | ||
if(!this._all) { | ||
if (!this._all) { | ||
this._all = []; | ||
@@ -674,3 +664,3 @@ } | ||
if(this.wildcard) { | ||
if (this.wildcard) { | ||
var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); | ||
@@ -684,4 +674,3 @@ var leafs = searchListenerTree.call(this, null, ns, this.listenerTree, 0); | ||
} | ||
else { | ||
if (!this._events || !this._events[type]) return this; | ||
else if (this._events) { | ||
this._events[type] = null; | ||
@@ -693,3 +682,3 @@ } | ||
EventEmitter.prototype.listeners = function(type) { | ||
if(this.wildcard) { | ||
if (this.wildcard) { | ||
var handlers = []; | ||
@@ -696,0 +685,0 @@ var ns = typeof type === 'string' ? type.split(this.delimiter) : type.slice(); |
{ | ||
"name": "eventemitter2", | ||
"version": "2.1.2", | ||
"version": "2.1.3", | ||
"description": "A Node.js event emitter implementation with namespaces, wildcards, TTL and browser support.", | ||
@@ -5,0 +5,0 @@ "keywords": ["event", "events", "emitter", "eventemitter"], |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34218
674