From 0f7620a416286ff2e53c13d2966290bc4c2f7d68 Mon Sep 17 00:00:00 2001 From: Gang Chen Date: Thu, 6 Jan 2022 07:10:12 +0800 Subject: [PATCH 1/2] domain: pass opts to `EventEmitter.init` --- lib/domain.js | 4 ++-- test/parallel/test-domain-ee.js | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/domain.js b/lib/domain.js index fcc8bb0a6dbc69..fbce94bad5fe28 100644 --- a/lib/domain.js +++ b/lib/domain.js @@ -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, @@ -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; diff --git a/test/parallel/test-domain-ee.js b/test/parallel/test-domain-ee.js index bc53f78445d7ac..a42ccff7181643 100644 --- a/test/parallel/test-domain-ee.js +++ b/test/parallel/test-domain-ee.js @@ -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); +} From c0bfa3415df69856df104e6fc64c12b3452f8c87 Mon Sep 17 00:00:00 2001 From: Gang Chen Date: Thu, 6 Jan 2022 22:22:45 +0800 Subject: [PATCH 2/2] add comments --- lib/events.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/events.js b/lib/events.js index 48a080d3460eed..f722b17aecae0d 100644 --- a/lib/events.js +++ b/lib/events.js @@ -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 ||