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 BethGriggs committed Jan 24, 2022
1 parent e8062bf commit 74bd312
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
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
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
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 74bd312

Please sign in to comment.