mirror of https://github.com/nodejs/node.git
events: do not accept NaN in setMaxListeners
parent
5885f464f0
commit
fce0eb416b
|
@ -45,7 +45,7 @@ exports.EventEmitter = EventEmitter;
|
|||
// that to be increased. Set to zero for unlimited.
|
||||
var defaultMaxListeners = 10;
|
||||
EventEmitter.prototype.setMaxListeners = function(n) {
|
||||
if (typeof n !== 'number' || n < 0)
|
||||
if (typeof n !== 'number' || n < 0 || isNaN(n))
|
||||
throw TypeError('n must be a positive number');
|
||||
this._maxListeners = n;
|
||||
};
|
||||
|
|
|
@ -38,4 +38,16 @@ e.on('maxListeners', function() {
|
|||
// Should not corrupt the 'maxListeners' queue.
|
||||
e.setMaxListeners(42);
|
||||
|
||||
assert.throws(function() {
|
||||
e.setMaxListeners(NaN);
|
||||
});
|
||||
|
||||
assert.throws(function() {
|
||||
e.setMaxListeners(-1);
|
||||
});
|
||||
|
||||
assert.throws(function() {
|
||||
e.setMaxListeners("and even this");
|
||||
});
|
||||
|
||||
e.emit('maxListeners');
|
||||
|
|
Loading…
Reference in New Issue