diff --git a/lib/events.js b/lib/events.js index 3deb155479187f..438c8f8306246a 100644 --- a/lib/events.js +++ b/lib/events.js @@ -31,6 +31,10 @@ const { ERR_UNHANDLED_ERROR } = require('internal/errors').codes; +const { + inspect +} = require('internal/util/inspect'); + function EventEmitter() { EventEmitter.init.call(this); } @@ -253,8 +257,8 @@ function _addListener(target, type, listener, prepend) { // eslint-disable-next-line no-restricted-syntax const w = new Error('Possible EventEmitter memory leak detected. ' + `${existing.length} ${String(type)} listeners ` + - 'added. Use emitter.setMaxListeners() to ' + - 'increase limit'); + `added to ${inspect(target, { depth: -1 })}. Use ` + + 'emitter.setMaxListeners() to increase limit'); w.name = 'MaxListenersExceededWarning'; w.emitter = target; w.type = type; diff --git a/test/parallel/test-event-emitter-max-listeners-warning-for-null.js b/test/parallel/test-event-emitter-max-listeners-warning-for-null.js index 2929e1c709328f..40b5f798cbadb0 100644 --- a/test/parallel/test-event-emitter-max-listeners-warning-for-null.js +++ b/test/parallel/test-event-emitter-max-listeners-warning-for-null.js @@ -15,7 +15,8 @@ process.on('warning', common.mustCall((warning) => { assert.strictEqual(warning.emitter, e); assert.strictEqual(warning.count, 2); assert.strictEqual(warning.type, null); - assert.ok(warning.message.includes('2 null listeners added.')); + assert.ok(warning.message.includes( + '2 null listeners added to [EventEmitter].')); })); e.on(null, () => {}); diff --git a/test/parallel/test-event-emitter-max-listeners-warning-for-symbol.js b/test/parallel/test-event-emitter-max-listeners-warning-for-symbol.js index 51c31ba0cf2f31..c27b38c2523453 100644 --- a/test/parallel/test-event-emitter-max-listeners-warning-for-symbol.js +++ b/test/parallel/test-event-emitter-max-listeners-warning-for-symbol.js @@ -17,7 +17,8 @@ process.on('warning', common.mustCall((warning) => { assert.strictEqual(warning.emitter, e); assert.strictEqual(warning.count, 2); assert.strictEqual(warning.type, symbol); - assert.ok(warning.message.includes('2 Symbol(symbol) listeners added.')); + assert.ok(warning.message.includes( + '2 Symbol(symbol) listeners added to [EventEmitter].')); })); e.on(symbol, () => {}); diff --git a/test/parallel/test-event-emitter-max-listeners-warning.js b/test/parallel/test-event-emitter-max-listeners-warning.js index 0be7fc84bce17b..3d047766b38fd9 100644 --- a/test/parallel/test-event-emitter-max-listeners-warning.js +++ b/test/parallel/test-event-emitter-max-listeners-warning.js @@ -6,7 +6,14 @@ const common = require('../common'); const events = require('events'); const assert = require('assert'); -const e = new events.EventEmitter(); +class FakeInput extends events.EventEmitter { + resume() {} + pause() {} + write() {} + end() {} +} + +const e = new FakeInput(); e.setMaxListeners(1); process.on('warning', common.mustCall((warning) => { @@ -15,7 +22,8 @@ process.on('warning', common.mustCall((warning) => { assert.strictEqual(warning.emitter, e); assert.strictEqual(warning.count, 2); assert.strictEqual(warning.type, 'event-type'); - assert.ok(warning.message.includes('2 event-type listeners added.')); + assert.ok(warning.message.includes( + '2 event-type listeners added to [FakeInput].')); })); e.on('event-type', () => {});