Skip to content

Commit

Permalink
events: move EE c'tor guts to EventEmitter.init
Browse files Browse the repository at this point in the history
After landing 6ed861d it is no longer possible to reliably monkey-patch
the EventEmitter constructor. However there's valid use cases for that,
and makes for easier debugging. Therefore, move the guts of the
constructor to a separate function which is monkey-patchable.

Closes nodejs#6693
  • Loading branch information
piscisaureus committed Dec 20, 2013
1 parent f030d84 commit 54da818
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,7 @@ var domain;
var util = require('util');

function EventEmitter() {
this.domain = null;
if (EventEmitter.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 = this._events || {};
this._maxListeners = this._maxListeners || undefined;
EventEmitter.init.call(this);
}
module.exports = EventEmitter;

Expand All @@ -49,6 +40,18 @@ EventEmitter.prototype._maxListeners = undefined;
// added to it. This is a useful default which helps finding memory leaks.
EventEmitter.defaultMaxListeners = 10;

EventEmitter.init = function() {
this.domain = null;
if (EventEmitter.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 = this._events || {};
this._maxListeners = this._maxListeners || undefined;
};

// Obviously not all Emitters should be limited to 10. This function allows
// that to be increased. Set to zero for unlimited.
Expand Down

0 comments on commit 54da818

Please sign in to comment.