From 60f1c9fb757cff720fddc8c247ba69ec83d80d72 Mon Sep 17 00:00:00 2001 From: Fabian Kromer Date: Tue, 23 Jun 2015 10:25:41 +0200 Subject: [PATCH] Do not assume that there is always a next occurrence when scheduling timeouts --- src/core/settimeout.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/settimeout.js b/src/core/settimeout.js index 329eea7..084c54e 100644 --- a/src/core/settimeout.js +++ b/src/core/settimeout.js @@ -22,8 +22,12 @@ later.setTimeout = function(fn, sched) { */ function scheduleTimeout() { var now = Date.now(), - next = s.next(2, now), - diff = next[0].getTime() - now; + next = s.next(2, now); + //make sure there actually is a next occurence before trying to call .getTime() on it + if(!next[0]){ + return; + } + var diff = next[0].getTime() - now; // minimum time to fire is one second, use next occurrence instead if(diff < 1000) { @@ -49,4 +53,4 @@ later.setTimeout = function(fn, sched) { }; -}; \ No newline at end of file +};