Skip to content

Commit

Permalink
domain: pass opts to EventEmitter.init
Browse files Browse the repository at this point in the history
PR-URL: #41414
Fixes: #41391
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
  • Loading branch information
MoonBall authored and danielleadams committed Feb 26, 2022
1 parent cafc4d5 commit 40ff0b5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/domain.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ Domain.prototype.bind = function(cb) {
EventEmitter.usingDomains = true;

const eventInit = EventEmitter.init;
EventEmitter.init = function() {
EventEmitter.init = function(opts) {
ObjectDefineProperty(this, 'domain', {
configurable: true,
enumerable: false,
Expand All @@ -457,7 +457,7 @@ EventEmitter.init = function() {
this.domain = exports.active;
}

return FunctionPrototypeCall(eventInit, this);
return FunctionPrototypeCall(eventInit, this, opts);
};

const eventEmit = EventEmitter.prototype.emit;
Expand Down
2 changes: 2 additions & 0 deletions lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ EventEmitter.setMaxListeners =
}
};

// If you're updating this function definition, please also update any
// re-definitions, such as the one in the Domain module (lib/domain.js).
EventEmitter.init = function(opts) {

if (this._events === undefined ||
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-domain-ee.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ d.on('error', common.mustCall((err) => {

d.add(e);
e.emit('error', new Error('foobar'));

{
// Ensure initial params pass to origin `EventEmitter.init` function
const e = new EventEmitter({ captureRejections: true });
const kCapture = Object.getOwnPropertySymbols(e)
.find((it) => it.description === 'kCapture');
assert.strictEqual(e[kCapture], true);
}

0 comments on commit 40ff0b5

Please sign in to comment.