events: do not accept NaN in setMaxListeners

pull/37258/head
Fedor Indutny 2013-11-19 10:58:23 +04:00
parent 5885f464f0
commit fce0eb416b
2 changed files with 13 additions and 1 deletions

View File

@ -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;
};

View File

@ -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');