mirror of
https://github.com/nodejs/node.git
synced 2025-05-13 10:54:13 +00:00

This makes the famous `EventEmitter memory leak` warnings occurring when the listener count for a given event exceeds a specified number more programatically accessible, by giving them properties referring to the event emitter instance and the event itself. This can be useful for debugging the origins of such a warning when the stack itself doesn’t reveal enough information about the event emitter instance itself, e.g. when manual inspection of the already-registered listeners is expected to be useful. PR-URL: https://github.com/nodejs/node/pull/8298 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <Fishrock123@rocketmail.com>
22 lines
627 B
JavaScript
22 lines
627 B
JavaScript
// Flags: --no-warnings
|
|
// The flag suppresses stderr output but the warning event will still emit
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
const events = require('events');
|
|
const assert = require('assert');
|
|
|
|
const e = new events.EventEmitter();
|
|
e.setMaxListeners(1);
|
|
|
|
process.on('warning', common.mustCall((warning) => {
|
|
assert.ok(warning instanceof Error);
|
|
assert.strictEqual(warning.name, 'Warning');
|
|
assert.strictEqual(warning.emitter, e);
|
|
assert.strictEqual(warning.count, 2);
|
|
assert.strictEqual(warning.type, 'event-type');
|
|
}));
|
|
|
|
e.on('event-type', function() {});
|
|
e.on('event-type', function() {});
|