Skip to content

Commit

Permalink
events: make memory leak warning name more verbose
Browse files Browse the repository at this point in the history
Switch from a generic `Warning` to the more specific
`MaxListenersExceededWarning`.

Ref: nodejs#8298
  • Loading branch information
addaleax committed Aug 30, 2016
1 parent 932c824 commit a6b6114
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/api/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-event-emitter-max-listeners-warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit a6b6114

Please sign in to comment.