From 1435b146137a3014e61b410091fffa29dc98785b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominykas=20Blyz=CC=8Ce=CC=87?= Date: Thu, 10 Oct 2019 15:36:26 +0300 Subject: [PATCH] fix: restore the removed condition eslint was complaining that `timer` does not change in the while - but it was also serving as a guard. --- src/lolex-src.js | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/lolex-src.js b/src/lolex-src.js index 3209a140..9507e4b3 100644 --- a/src/lolex-src.js +++ b/src/lolex-src.js @@ -856,30 +856,32 @@ function withGlobal(_global) { function doTickInner() { // perform each timer in the requested range timer = firstTimerInRange(clock, tickFrom, tickTo); - while (tickFrom <= tickTo) { - if (clock.timers[timer.id]) { - tickFrom = timer.callAt; - clock.now = timer.callAt; - oldNow = clock.now; - try { - runJobs(clock); - callTimer(clock, timer); - } catch (e) { - firstException = firstException || e; - } + if (timer) { + while (tickFrom <= tickTo) { + if (clock.timers[timer.id]) { + tickFrom = timer.callAt; + clock.now = timer.callAt; + oldNow = clock.now; + try { + runJobs(clock); + callTimer(clock, timer); + } catch (e) { + firstException = firstException || e; + } + + if (isAsync) { + // finish up after native setImmediate callback to allow + // all native es6 promises to process their callbacks after + // each timer fires. + originalSetTimeout(nextPromiseTick); + return; + } - if (isAsync) { - // finish up after native setImmediate callback to allow - // all native es6 promises to process their callbacks after - // each timer fires. - originalSetTimeout(nextPromiseTick); - return; + compensationCheck(); } - compensationCheck(); + postTimerCall(); } - - postTimerCall(); } // perform process.nextTick()s again