summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBert Belder <bertbelder@gmail.com>2013-12-12 14:59:40 -0800
committerBert Belder <bertbelder@gmail.com>2013-12-20 12:47:24 -0800
commit54da818e4bec4e5a0a1928441ec6fc90b4903ba0 (patch)
tree499c3af3d6ea24741a20bc842960fb53c73158c3 /lib
parentf030d8426aa3241ad180c385f15134548579e7ce (diff)
downloadnodejs-54da818e4bec4e5a0a1928441ec6fc90b4903ba0.tar.gz
nodejs-54da818e4bec4e5a0a1928441ec6fc90b4903ba0.tar.bz2
nodejs-54da818e4bec4e5a0a1928441ec6fc90b4903ba0.zip
events: move EE c'tor guts to EventEmitter.init
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 #6693
Diffstat (limited to 'lib')
-rw-r--r--lib/events.js23
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/events.js b/lib/events.js
index b1d5c512a..eff953f49 100644
--- a/lib/events.js
+++ b/lib/events.js
@@ -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;
@@ -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.