|
|
@ -1,11 +1,12 @@ |
|
|
|
exports.EventEmitter = process.EventEmitter; |
|
|
|
|
|
|
|
var isArray = Array.isArray; |
|
|
|
|
|
|
|
process.EventEmitter.prototype.emit = function (type) { |
|
|
|
// If there is no 'error' event listener then throw.
|
|
|
|
if (type === 'error') { |
|
|
|
if (!this._events || !this._events.error || |
|
|
|
(this._events.error instanceof Array && !this._events.error.length)) |
|
|
|
(isArray(this._events.error) && !this._events.error.length)) |
|
|
|
{ |
|
|
|
if (arguments[1] instanceof Error) { |
|
|
|
throw arguments[1]; |
|
|
@ -33,7 +34,7 @@ process.EventEmitter.prototype.emit = function (type) { |
|
|
|
} |
|
|
|
return true; |
|
|
|
|
|
|
|
} else if (this._events[type] instanceof Array) { |
|
|
|
} else if (isArray(this._events[type])) { |
|
|
|
var args = Array.prototype.slice.call(arguments, 1); |
|
|
|
|
|
|
|
|
|
|
@ -64,7 +65,7 @@ process.EventEmitter.prototype.addListener = function (type, listener) { |
|
|
|
if (!this._events[type]) { |
|
|
|
// Optimize the case of one listener. Don't need the extra array object.
|
|
|
|
this._events[type] = listener; |
|
|
|
} else if (this._events[type] instanceof Array) { |
|
|
|
} else if (isArray(this._events[type])) { |
|
|
|
// If we've already got an array, just append.
|
|
|
|
this._events[type].push(listener); |
|
|
|
} else { |
|
|
@ -87,7 +88,7 @@ process.EventEmitter.prototype.removeListener = function (type, listener) { |
|
|
|
|
|
|
|
var list = this._events[type]; |
|
|
|
|
|
|
|
if (list instanceof Array) { |
|
|
|
if (isArray(list)) { |
|
|
|
var i = list.indexOf(listener); |
|
|
|
if (i < 0) return this; |
|
|
|
list.splice(i, 1); |
|
|
@ -109,7 +110,7 @@ process.EventEmitter.prototype.removeAllListeners = function (type) { |
|
|
|
process.EventEmitter.prototype.listeners = function (type) { |
|
|
|
if (!this._events) this._events = {}; |
|
|
|
if (!this._events[type]) this._events[type] = []; |
|
|
|
if (!(this._events[type] instanceof Array)) { |
|
|
|
if (!isArray(this._events[type])) { |
|
|
|
this._events[type] = [this._events[type]]; |
|
|
|
} |
|
|
|
return this._events[type]; |
|
|
|