Comparing version 0.1.2 to 0.1.3
@@ -43,23 +43,77 @@ /** | ||
var onEvent = EventEmitter.prototype.on | ||
EventEmitter.prototype.on = EventEmitter.prototype.addListener = function (type, callback) { | ||
var newCallback | ||
EventEmitter.prototype.on = EventEmitter.prototype.addListener = function (type, listener) { | ||
var self = this | ||
, list | ||
, id | ||
, newCallback | ||
callback._wrappedCallback = callback._wrappedCallback || [] | ||
newCallback = wrap(callback, 'EventEmitter.on') | ||
if (newCallback !== callback) { | ||
callback._wrappedCallback.push(newCallback) | ||
self._hookListeners = self._hookListeners || {} | ||
id = listener._hookId = listener._hookId || ''+process.hrtime() | ||
self._hookListeners[id] = self._hookListeners[id] || {} | ||
if (!self._hookListeners[id][type]) { | ||
self._hookListeners[id][type] = [] | ||
self._hookListeners[id][type].callback = function() { | ||
var args = arguments | ||
, list = self._hookListeners[id][type] | ||
for (var i = 0, length = list.length; i < length; i++) { | ||
list[i].apply(self, args) | ||
} | ||
} | ||
} | ||
arguments[1] = newCallback | ||
return onEvent.apply(this, arguments) | ||
newCallback = wrap(listener, 'EventEmitter.on') | ||
if (newCallback !== listener) { | ||
self._hookListeners[id][type].push(newCallback) | ||
} | ||
return onEvent.call(this, type, self._hookListeners[id][type].callback) | ||
} | ||
var removeEvent = EventEmitter.prototype.removeListener | ||
EventEmitter.prototype.removeListener = function (type, callback) { | ||
if (callback && Array.isArray(callback._wrappedCallback) && callback._wrappedCallback.length) { | ||
arguments[1] = callback._wrappedCallback.pop() | ||
EventEmitter.prototype.removeListener = function (type, listener) { | ||
var empty = true | ||
, id = listener._hookId | ||
, list | ||
, hookListener | ||
, hookCallback | ||
if (this._hookListeners && | ||
this._hookListeners[id] && | ||
this._hookListeners[id][type]) { | ||
hookCallback = this._hookListeners[id][type].callback | ||
hookListener = this._hookListeners[id] | ||
list = hookListener[type] | ||
list.shift() | ||
if (!list.length) { | ||
delete hookListener[type] | ||
} | ||
for (var i in hookListener) { | ||
if (hookListener.hasOwnProperty(i)) { | ||
empty = false | ||
break; | ||
} | ||
} | ||
if (empty) { | ||
delete this._hookListeners[id] | ||
} | ||
listener = hookCallback | ||
} | ||
return removeEvent.apply(this, arguments) | ||
return removeEvent.call(this, type, listener) | ||
} | ||
var removeAll = EventEmitter.prototype.removeAllListeners | ||
EventEmitter.prototype.removeAllListeners = function (type) { | ||
for (var id in this._hookListeners) { | ||
if (this._hookListeners.hasOwnProperty(id)) { | ||
if (this._hookListeners[id][type]) { | ||
delete this._hookListeners[id][type] | ||
} | ||
} | ||
} | ||
return removeAll.call(this, type) | ||
} | ||
} | ||
// If we delete an EventEmitter, we have a memory leak | ||
var alreadyRequired | ||
console.log('there') |
{ | ||
"name": "trycatch", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "An asynchronous exception handler with long stack traces for node.js", | ||
@@ -5,0 +5,0 @@ "homepage": "http://github.com/CrabDude/trycatch", |
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
43986
617