// 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;
};
// 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');