mirror of
https://github.com/nodejs/node.git
synced 2025-05-05 15:32:15 +00:00

Allows Symbol to be converted to String so it can be included in the error. Fixes: https://github.com/nodejs/node/issues/9003 PR-URL: https://github.com/nodejs/node/pull/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>
76 lines
2.1 KiB
JavaScript
76 lines
2.1 KiB
JavaScript
'use strict';
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const events = require('events');
|
|
|
|
var e = new events.EventEmitter();
|
|
|
|
// default
|
|
for (let i = 0; i < 10; i++) {
|
|
e.on('default', function() {});
|
|
}
|
|
assert.ok(!e._events['default'].hasOwnProperty('warned'));
|
|
e.on('default', function() {});
|
|
assert.ok(e._events['default'].warned);
|
|
|
|
// symbol
|
|
const symbol = Symbol('symbol');
|
|
e.setMaxListeners(1);
|
|
e.on(symbol, function() {});
|
|
assert.ok(!e._events[symbol].hasOwnProperty('warned'));
|
|
e.on(symbol, function() {});
|
|
assert.ok(e._events[symbol].hasOwnProperty('warned'));
|
|
|
|
// specific
|
|
e.setMaxListeners(5);
|
|
for (let i = 0; i < 5; i++) {
|
|
e.on('specific', function() {});
|
|
}
|
|
assert.ok(!e._events['specific'].hasOwnProperty('warned'));
|
|
e.on('specific', function() {});
|
|
assert.ok(e._events['specific'].warned);
|
|
|
|
// only one
|
|
e.setMaxListeners(1);
|
|
e.on('only one', function() {});
|
|
assert.ok(!e._events['only one'].hasOwnProperty('warned'));
|
|
e.on('only one', function() {});
|
|
assert.ok(e._events['only one'].hasOwnProperty('warned'));
|
|
|
|
// unlimited
|
|
e.setMaxListeners(0);
|
|
for (let i = 0; i < 1000; i++) {
|
|
e.on('unlimited', function() {});
|
|
}
|
|
assert.ok(!e._events['unlimited'].hasOwnProperty('warned'));
|
|
|
|
// process-wide
|
|
events.EventEmitter.defaultMaxListeners = 42;
|
|
e = new events.EventEmitter();
|
|
|
|
for (let i = 0; i < 42; ++i) {
|
|
e.on('fortytwo', function() {});
|
|
}
|
|
assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));
|
|
e.on('fortytwo', function() {});
|
|
assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));
|
|
delete e._events['fortytwo'].warned;
|
|
|
|
events.EventEmitter.defaultMaxListeners = 44;
|
|
e.on('fortytwo', function() {});
|
|
assert.ok(!e._events['fortytwo'].hasOwnProperty('warned'));
|
|
e.on('fortytwo', function() {});
|
|
assert.ok(e._events['fortytwo'].hasOwnProperty('warned'));
|
|
|
|
// but _maxListeners still has precedence over defaultMaxListeners
|
|
events.EventEmitter.defaultMaxListeners = 42;
|
|
e = new events.EventEmitter();
|
|
e.setMaxListeners(1);
|
|
e.on('uno', function() {});
|
|
assert.ok(!e._events['uno'].hasOwnProperty('warned'));
|
|
e.on('uno', function() {});
|
|
assert.ok(e._events['uno'].hasOwnProperty('warned'));
|
|
|
|
// chainable
|
|
assert.strictEqual(e, e.setMaxListeners(1));
|