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:
parent
7e8d994e33
commit
983775d457
@ -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 event’s name and the number of attached
|
the event emitter instance, the event’s 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
|
||||||
|
@ -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;
|
||||||
|
@ -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');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user