Skip to content

Commit

Permalink
domain: pass opts to EventEmitter.init
Browse files Browse the repository at this point in the history
PR-URL: nodejs#41414
Fixes: nodejs#41391
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Yongsheng Zhang <[email protected]>
Reviewed-By: Anatoli Papirovski <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
  • Loading branch information
MoonBall authored and Linkgoron committed Jan 31, 2022
1 parent d69637c commit 212b1fd
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 212b1fd

Please sign in to comment.