mirror of https://github.com/lukechilds/node.git
Browse Source
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>v6.x
Anna Henningsen
8 years ago
committed by
Jeremiah Senkpiel
3 changed files with 37 additions and 1 deletions
@ -0,0 +1,21 @@ |
|||
// 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() {}); |
Loading…
Reference in new issue