-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
events,test: fix TypeError in EventEmitter warning
Allows Symbol to be converted to String so it can be included in the error. Conflicts: lib/events.js Fixes: #9003 Backport-PR-URL: #12459 PR-URL: #9021 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
- Loading branch information
1 parent
4180204
commit e760a1b
Showing
5 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
test/parallel/test-event-emitter-max-listeners-warning-for-null.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 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, null); | ||
assert.ok(warning.message.includes('2 null listeners added.')); | ||
})); | ||
|
||
e.on(null, function() {}); | ||
e.on(null, function() {}); |
24 changes: 24 additions & 0 deletions
24
test/parallel/test-event-emitter-max-listeners-warning-for-symbol.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// 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 symbol = Symbol('symbol'); | ||
|
||
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, symbol); | ||
assert.ok(warning.message.includes('2 Symbol(symbol) listeners added.')); | ||
})); | ||
|
||
e.on(symbol, function() {}); | ||
e.on(symbol, function() {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters