Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

events: Make the EventEmitter class monomorphic

Always add domain, _events, and _maxListeners properties, even
if they are set to the default values at first.
  • Loading branch information
isaacs committed Oct 25, 2012
1 parent 4b8629d commit 57db16c8456784fce8d3d1c9f45f26c3557912fa
Showing with 4 additions and 5 deletions.
  1. +4 −5 lib/events.js
@@ -23,13 +23,16 @@ var isArray = Array.isArray;
var domain;

function EventEmitter() {
this.domain = null;
if (exports.usingDomains) {
// if there is an active domain, then attach to it.
domain = domain || require('domain');
if (domain.active && !(this instanceof domain.Domain)) {
this.domain = domain.active;
}
}
this._events = null;
this._maxListeners = defaultMaxListeners;
}
exports.EventEmitter = EventEmitter;

@@ -161,11 +164,7 @@ EventEmitter.prototype.addListener = function(type, listener) {
// Check for listener leak
if (isArray(this._events[type]) && !this._events[type].warned) {
var m;
if (this._maxListeners !== undefined) {
m = this._maxListeners;
} else {
m = defaultMaxListeners;
}
m = this._maxListeners;

if (m && m > 0 && this._events[type].length > m) {
this._events[type].warned = true;

0 comments on commit 57db16c

Please sign in to comment.
You can’t perform that action at this time.