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>
This commit is contained in:
Anna Henningsen 2016-08-30 19:15:34 +02:00
parent 7e8d994e33
commit 983775d457
No known key found for this signature in database
GPG Key ID: D8B9F5AEAE84E4CF
3 changed files with 3 additions and 2 deletions

View File

@ -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 have the additional `emitter`, `type` and `count` properties, referring to
the event emitter instance, the events name and the number of attached the event emitter instance, the events name and the number of attached
listeners, respectively. listeners, respectively.
Its `name` property is set to `'MaxListenersExceededWarning'`.
### emitter.addListener(eventName, listener) ### emitter.addListener(eventName, listener)
<!-- YAML <!-- YAML

View File

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

View File

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