summaryrefslogtreecommitdiff
path: root/lib/events.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/events.js')
-rw-r--r--lib/events.js16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/events.js b/lib/events.js
index c2b604f892..e0af38066a 100644
--- a/lib/events.js
+++ b/lib/events.js
@@ -45,6 +45,8 @@ EventEmitter.prototype.setMaxListeners = function(n) {
this._maxListeners = n;
};
+// non-global reference, for speed.
+var PROCESS;
EventEmitter.prototype.emit = function() {
var type = arguments[0];
@@ -77,7 +79,10 @@ EventEmitter.prototype.emit = function() {
if (typeof handler == 'function') {
if (this.domain) {
- this.domain.enter();
+ PROCESS = PROCESS || process;
+ if (this !== PROCESS) {
+ this.domain.enter();
+ }
}
switch (arguments.length) {
// fast cases
@@ -97,14 +102,17 @@ EventEmitter.prototype.emit = function() {
for (var i = 1; i < l; i++) args[i - 1] = arguments[i];
handler.apply(this, args);
}
- if (this.domain) {
+ if (this.domain && this !== PROCESS) {
this.domain.exit();
}
return true;
} else if (isArray(handler)) {
if (this.domain) {
- this.domain.enter();
+ PROCESS = PROCESS || process;
+ if (this !== PROCESS) {
+ this.domain.enter();
+ }
}
var l = arguments.length;
var args = new Array(l - 1);
@@ -114,7 +122,7 @@ EventEmitter.prototype.emit = function() {
for (var i = 0, l = listeners.length; i < l; i++) {
listeners[i].apply(this, args);
}
- if (this.domain) {
+ if (this.domain && this !== PROCESS) {
this.domain.exit();
}
return true;