| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3f90481 commit 0ce0abf
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -257,8 +257,9 @@ function _addListener(target, type, listener, prepend) { | |||
| 257 | 257 | if (m && m > 0 && existing.length > m) { | |
| 258 | 258 | existing.warned = true; | |
| 259 | 259 | const w = new Error('Possible EventEmitter memory leak detected. ' + | |
| 260 | - `${existing.length} ${type} listeners added. ` + | ||
| 261 | - 'Use emitter.setMaxListeners() to increase limit'); | ||
| 260 | + `${existing.length} ${String(type)} listeners ` + | ||
| 261 | + 'added. Use emitter.setMaxListeners() to ' + | ||
| 262 | + 'increase limit'); | ||
| 262 | 263 | w.name = 'MaxListenersExceededWarning'; | |
| 263 | 264 | w.emitter = target; | |
| 264 | 265 | w.type = type; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,7 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | require('../common'); | |
| 3 | - var assert = require('assert'); | ||
| 4 | - var events = require('events'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const events = require('events'); | ||
| 5 | 5 | ||
| 6 | 6 | var e = new events.EventEmitter(); | |
| 7 | 7 | ||
@@ -13,6 +13,14 @@ assert.ok(!e._events['default'].hasOwnProperty('warned')); | |||
| 13 | 13 | e.on('default', function() {}); | |
| 14 | 14 | assert.ok(e._events['default'].warned); | |
| 15 | 15 | ||
| 16 | + // symbol | ||
| 17 | + const symbol = Symbol('symbol'); | ||
| 18 | + e.setMaxListeners(1); | ||
| 19 | + e.on(symbol, function() {}); | ||
| 20 | + assert.ok(!e._events[symbol].hasOwnProperty('warned')); | ||
| 21 | + e.on(symbol, function() {}); | ||
| 22 | + assert.ok(e._events[symbol].hasOwnProperty('warned')); | ||
| 23 | + | ||
| 16 | 24 | // specific | |
| 17 | 25 | e.setMaxListeners(5); | |
| 18 | 26 | for (let i = 0; i < 5; i++) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,22 @@ | |||
| 1 | + // Flags: --no-warnings | ||
| 2 | + // The flag suppresses stderr output but the warning event will still emit | ||
| 3 | + 'use strict'; | ||
| 4 | + | ||
| 5 | + const common = require('../common'); | ||
| 6 | + const events = require('events'); | ||
| 7 | + const assert = require('assert'); | ||
| 8 | + | ||
| 9 | + const e = new events.EventEmitter(); | ||
| 10 | + e.setMaxListeners(1); | ||
| 11 | + | ||
| 12 | + process.on('warning', common.mustCall((warning) => { | ||
| 13 | + assert.ok(warning instanceof Error); | ||
| 14 | + assert.strictEqual(warning.name, 'MaxListenersExceededWarning'); | ||
| 15 | + assert.strictEqual(warning.emitter, e); | ||
| 16 | + assert.strictEqual(warning.count, 2); | ||
| 17 | + assert.strictEqual(warning.type, null); | ||
| 18 | + assert.ok(warning.message.includes('2 null listeners added.')); | ||
| 19 | + })); | ||
| 20 | + | ||
| 21 | + e.on(null, function() {}); | ||
| 22 | + e.on(null, function() {}); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,24 @@ | |||
| 1 | + // Flags: --no-warnings | ||
| 2 | + // The flag suppresses stderr output but the warning event will still emit | ||
| 3 | + 'use strict'; | ||
| 4 | + | ||
| 5 | + const common = require('../common'); | ||
| 6 | + const events = require('events'); | ||
| 7 | + const assert = require('assert'); | ||
| 8 | + | ||
| 9 | + const symbol = Symbol('symbol'); | ||
| 10 | + | ||
| 11 | + const e = new events.EventEmitter(); | ||
| 12 | + e.setMaxListeners(1); | ||
| 13 | + | ||
| 14 | + process.on('warning', common.mustCall((warning) => { | ||
| 15 | + assert.ok(warning instanceof Error); | ||
| 16 | + assert.strictEqual(warning.name, 'MaxListenersExceededWarning'); | ||
| 17 | + assert.strictEqual(warning.emitter, e); | ||
| 18 | + assert.strictEqual(warning.count, 2); | ||
| 19 | + assert.strictEqual(warning.type, symbol); | ||
| 20 | + assert.ok(warning.message.includes('2 Symbol(symbol) listeners added.')); | ||
| 21 | + })); | ||
| 22 | + | ||
| 23 | + e.on(symbol, function() {}); | ||
| 24 | + e.on(symbol, function() {}); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,6 +15,7 @@ process.on('warning', common.mustCall((warning) => { | |||
| 15 | 15 | assert.strictEqual(warning.emitter, e); | |
| 16 | 16 | assert.strictEqual(warning.count, 2); | |
| 17 | 17 | assert.strictEqual(warning.type, 'event-type'); | |
| 18 | + assert.ok(warning.message.includes('2 event-type listeners added.')); | ||
| 18 | 19 | })); | |
| 19 | 20 | ||
| 20 | 21 | e.on('event-type', function() {}); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments