events: do not accept NaN in setMaxListeners
This commit is contained in:
parent
5885f464f0
commit
fce0eb416b
@ -45,7 +45,7 @@ exports.EventEmitter = EventEmitter;
|
|||||||
// that to be increased. Set to zero for unlimited.
|
// that to be increased. Set to zero for unlimited.
|
||||||
var defaultMaxListeners = 10;
|
var defaultMaxListeners = 10;
|
||||||
EventEmitter.prototype.setMaxListeners = function(n) {
|
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');
|
throw TypeError('n must be a positive number');
|
||||||
this._maxListeners = n;
|
this._maxListeners = n;
|
||||||
};
|
};
|
||||||
|
@ -38,4 +38,16 @@ e.on('maxListeners', function() {
|
|||||||
// Should not corrupt the 'maxListeners' queue.
|
// Should not corrupt the 'maxListeners' queue.
|
||||||
e.setMaxListeners(42);
|
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');
|
e.emit('maxListeners');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user