Skip to content

Commit

Permalink
fixup! fixup! event: simplify domain conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
Trott committed Mar 31, 2021
1 parent 77fd57d commit 8e77095
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,23 +335,21 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
} else if (!doError)
return false;

const domain = this.domain;

// If there is no 'error' event listener then throw.
if (doError) {
let er;
if (args.length > 0)
er = args[0];
if (domain) {
if (this.domain) {
if (!er) {
er = new ERR_UNHANDLED_ERROR();
}
if (typeof er === 'object') {
er.domainEmitter = this;
er.domain = domain;
er.domain = this.domain;
er.domainThrown = false;
}
domain.emit('error', er);
this.domain.emit('error', er);
} else if (er instanceof Error) {
try {
const capture = {};
Expand Down Expand Up @@ -389,8 +387,8 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
return false;

let needDomainExit = false;
if (domain && this !== process) {
domain.enter();
if (this.domain && this !== process) {
this.domain.enter();
needDomainExit = true;
}

Expand Down Expand Up @@ -421,7 +419,7 @@ EventEmitter.prototype.emit = function emit(type, ...args) {
}

if (needDomainExit)
domain.exit();
this.domain.exit();

return true;
};
Expand Down

0 comments on commit 8e77095

Please sign in to comment.