diff options
author | Fedor Indutny <fedor.indutny@gmail.com> | 2013-11-19 10:58:23 +0400 |
---|---|---|
committer | Fedor Indutny <fedor.indutny@gmail.com> | 2013-11-19 13:14:01 +0400 |
commit | fce0eb416b47f205605fe3dde47550dec337c673 (patch) | |
tree | 50e909fe998cc2fa7e1ee77876264f439f310701 | |
parent | 5885f464f0ad372efa7ef44a72df6d44acec3085 (diff) | |
download | node-fce0eb416b47f205605fe3dde47550dec337c673.tar.gz |
events: do not accept NaN in setMaxListeners
-rw-r--r-- | lib/events.js | 2 | ||||
-rw-r--r-- | test/simple/test-event-emitter-max-listeners.js | 12 |
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/events.js b/lib/events.js index 8c02a558e..f43df093d 100644 --- a/lib/events.js +++ b/lib/events.js @@ -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; }; diff --git a/test/simple/test-event-emitter-max-listeners.js b/test/simple/test-event-emitter-max-listeners.js index 3dea94bcc..dfc3e1352 100644 --- a/test/simple/test-event-emitter-max-listeners.js +++ b/test/simple/test-event-emitter-max-listeners.js @@ -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'); |