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 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 || 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); +}