@ -19,7 +19,6 @@
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var isArray = Array . isArray ;
var domain ;
var domain ;
exports . usingDomains = false ;
exports . usingDomains = false ;
@ -33,7 +32,7 @@ function EventEmitter() {
this . domain = domain . active ;
this . domain = domain . active ;
}
}
}
}
this . _ events = this . _ events || null ;
this . _ events = this . _ events || { } ;
this . _ maxListeners = this . _ maxListeners || defaultMaxListeners ;
this . _ maxListeners = this . _ maxListeners || defaultMaxListeners ;
}
}
exports . EventEmitter = EventEmitter ;
exports . EventEmitter = EventEmitter ;
@ -57,8 +56,9 @@ var PROCESS;
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' ) {
if ( ! this . _ events || ! this . _ events . error ||
if ( ! this . _ events . error ||
( isArray ( this . _ events . error ) && ! this . _ events . error . length ) ) {
( typeof this . _ events . error === 'object' &&
! this . _ events . error . length ) ) {
if ( this . domain ) {
if ( this . domain ) {
var er = arguments [ 1 ] ;
var er = arguments [ 1 ] ;
er . domainEmitter = this ;
er . domainEmitter = this ;
@ -77,7 +77,6 @@ EventEmitter.prototype.emit = function(type) {
}
}
}
}
if ( ! this . _ events ) return false ;
var handler = this . _ events [ type ] ;
var handler = this . _ events [ type ] ;
if ( ! handler ) return false ;
if ( ! handler ) return false ;
@ -111,7 +110,7 @@ EventEmitter.prototype.emit = function(type) {
}
}
return true ;
return true ;
} else if ( isArray ( handler ) ) {
} else if ( typeof handler === 'object' ) {
if ( this . domain ) {
if ( this . domain ) {
PROCESS = PROCESS || process ;
PROCESS = PROCESS || process ;
if ( this !== PROCESS ) {
if ( this !== PROCESS ) {
@ -153,7 +152,7 @@ EventEmitter.prototype.addListener = function(type, listener) {
if ( ! this . _ events [ type ] ) {
if ( ! this . _ events [ type ] ) {
// 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 ( typeof this . _ events [ type ] === 'object' ) {
// 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 ) ;
@ -165,7 +164,7 @@ EventEmitter.prototype.addListener = function(type, listener) {
}
}
// Check for listener leak
// Check for listener leak
if ( isArray ( this . _ events [ type ] ) && ! this . _ events [ type ] . warned ) {
if ( typeof this . _ events [ type ] === 'object' && ! this . _ events [ type ] . warned ) {
var m ;
var m ;
m = this . _ maxListeners ;
m = this . _ maxListeners ;
@ -219,11 +218,11 @@ EventEmitter.prototype.removeListener = function(type, listener) {
if ( list === listener ||
if ( list === listener ||
( typeof list . listener === 'function' && list . listener === listener ) ) {
( typeof list . listener === 'function' && list . listener === listener ) ) {
this . _ events [ type ] = null ;
this . _ events [ type ] = undefined ;
if ( this . _ events . removeListener )
if ( this . _ events . removeListener )
this . emit ( 'removeListener' , type , listener ) ;
this . emit ( 'removeListener' , type , listener ) ;
} else if ( isArray ( list ) ) {
} else if ( typeof list === 'object' ) {
for ( i = 0 ; i < length ; i ++ ) {
for ( i = 0 ; i < length ; i ++ ) {
if ( list [ i ] === listener ||
if ( list [ i ] === listener ||
( list [ i ] . listener && list [ i ] . listener === listener ) ) {
( list [ i ] . listener && list [ i ] . listener === listener ) ) {
@ -237,7 +236,7 @@ EventEmitter.prototype.removeListener = function(type, listener) {
if ( list . length === 1 ) {
if ( list . length === 1 ) {
list . length = 0 ;
list . length = 0 ;
this . _ events [ type ] = null ;
this . _ events [ type ] = undefined ;
} else {
} else {
list . splice ( position , 1 ) ;
list . splice ( position , 1 ) ;
}
}
@ -261,9 +260,9 @@ EventEmitter.prototype.removeAllListeners = function(type) {
// not listening for removeListener, no need to emit
// not listening for removeListener, no need to emit
if ( ! this . _ events . removeListener ) {
if ( ! this . _ events . removeListener ) {
if ( arguments . length === 0 )
if ( arguments . length === 0 )
this . _ events = null ;
this . _ events = { } ;
else if ( this . _ events [ type ] )
else if ( this . _ events [ type ] )
this . _ events [ type ] = null ;
this . _ events [ type ] = undefined ;
return this ;
return this ;
}
}
@ -274,7 +273,7 @@ EventEmitter.prototype.removeAllListeners = function(type) {
this . removeAllListeners ( key ) ;
this . removeAllListeners ( key ) ;
}
}
this . removeAllListeners ( 'removeListener' ) ;
this . removeAllListeners ( 'removeListener' ) ;
this . _ events = null ;
this . _ events = { } ;
return this ;
return this ;
}
}
@ -287,7 +286,7 @@ EventEmitter.prototype.removeAllListeners = function(type) {
while ( listeners . length )
while ( listeners . length )
this . removeListener ( type , listeners [ listeners . length - 1 ] ) ;
this . removeListener ( type , listeners [ listeners . length - 1 ] ) ;
}
}
this . _ events [ type ] = null ;
this . _ events [ type ] = undefined ;
return this ;
return this ;
} ;
} ;