Skip to content

Commit 4553d82

Browse files
committed
Throw an exception when timeout too large.
closes mochajs#1644
1 parent 17cec5b commit 4553d82

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/runnable.js

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Runnable.prototype.__proto__ = EventEmitter.prototype;
6565
Runnable.prototype.timeout = function(ms){
6666
if (0 == arguments.length) return this._timeout;
6767
if (ms === 0) this._enableTimeouts = false;
68+
if (ms > Math.pow(2, 31)) throw new RangeError('Interval too large, must be less than 2^31');
6869
if ('string' == typeof ms) ms = milliseconds(ms);
6970
debug('timeout %d', ms);
7071
this._timeout = ms;

test/runnable.js

+7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ describe('Runnable(title, fn)', function(){
4040
})
4141
})
4242

43+
describe('#timeout(ms) when ms>2^31', function(){
44+
it('should throw an error', function () {
45+
var run = new Runnable;
46+
run.timeout.bind(run, 1e10).should.throw(/Interval too large/);
47+
});
48+
});
49+
4350
describe('#enableTimeouts(enabled)', function(){
4451
it('should set enabled', function(){
4552
var run = new Runnable;

0 commit comments

Comments
 (0)