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