summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFedor Indutny <fedor.indutny@gmail.com>2013-11-19 10:58:23 +0400
committerFedor Indutny <fedor.indutny@gmail.com>2013-11-19 13:14:01 +0400
commitfce0eb416b47f205605fe3dde47550dec337c673 (patch)
tree50e909fe998cc2fa7e1ee77876264f439f310701
parent5885f464f0ad372efa7ef44a72df6d44acec3085 (diff)
downloadnode-fce0eb416b47f205605fe3dde47550dec337c673.tar.gz
events: do not accept NaN in setMaxListeners
-rw-r--r--lib/events.js2
-rw-r--r--test/simple/test-event-emitter-max-listeners.js12
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');