Browse Source

events: make memory leak warning name more verbose

Switch from a generic `Warning` to the more specific
`MaxListenersExceededWarning`.

Ref: https://github.com/nodejs/node/pull/8298
PR-URL: https://github.com/nodejs/node/pull/8341
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
v7.x
Anna Henningsen 8 years ago
parent
commit
983775d457
No known key found for this signature in database GPG Key ID: D8B9F5AEAE84E4CF
  1. 1
      doc/api/events.md
  2. 2
      lib/events.js
  3. 2
      test/parallel/test-event-emitter-max-listeners-warning.js

1
doc/api/events.md

@ -285,6 +285,7 @@ The emitted warning can be inspected with [`process.on('warning')`][] and will
have the additional `emitter`, `type` and `count` properties, referring to
the event emitter instance, the event’s name and the number of attached
listeners, respectively.
Its `name` property is set to `'MaxListenersExceededWarning'`.
### emitter.addListener(eventName, listener)
<!-- YAML

2
lib/events.js

@ -259,7 +259,7 @@ function _addListener(target, type, listener, prepend) {
const w = new Error('Possible EventEmitter memory leak detected. ' +
`${existing.length} ${type} listeners added. ` +
'Use emitter.setMaxListeners() to increase limit');
w.name = 'Warning';
w.name = 'MaxListenersExceededWarning';
w.emitter = target;
w.type = type;
w.count = existing.length;

2
test/parallel/test-event-emitter-max-listeners-warning.js

@ -11,7 +11,7 @@ e.setMaxListeners(1);
process.on('warning', common.mustCall((warning) => {
assert.ok(warning instanceof Error);
assert.strictEqual(warning.name, 'Warning');
assert.strictEqual(warning.name, 'MaxListenersExceededWarning');
assert.strictEqual(warning.emitter, e);
assert.strictEqual(warning.count, 2);
assert.strictEqual(warning.type, 'event-type');

Loading…
Cancel
Save