From 40ff0b5af5b793a77330432377e0edffa213d6f9 Mon Sep 17 00:00:00 2001 From: Gang Chen <13298548+MoonBall@users.noreply.github.com> Date: Wed, 19 Jan 2022 19:26:38 +0800 Subject: [PATCH] domain: pass opts to `EventEmitter.init` PR-URL: https://github.com/nodejs/node/pull/41414 Fixes: https://github.com/nodejs/node/issues/41391 Reviewed-By: Colin Ihrig Reviewed-By: Yongsheng Zhang Reviewed-By: Anatoli Papirovski Reviewed-By: Antoine du Hamel --- lib/domain.js | 4 ++-- lib/events.js | 2 ++ test/parallel/test-domain-ee.js | 8 ++++++++ 3 files changed, 12 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/lib/events.js b/lib/events.js index fa78697920c3e4..3b992f39bf7990 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 || 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); +}