Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
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 57db16c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/events.js
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 57db16c

Please sign in to comment.