From 51462f369b376615bc9d761dcaa5d822ea1ff8ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Girardi?= Date: Tue, 26 Aug 2014 12:01:49 -0400 Subject: [PATCH] Allow clearInterval to clear it's own interval As described in issue #655, the handler of an interval cannot successfully clear the same interval that generated it's invocation. Solve this issue by changing the order in which interval's handlers are called and then rescheduled to: first reschedule it and then call it. The actual order (call first then reschedule) produces that, during the execution of the interval's handler, the handler is not registered as a function to run after a timeout or interval ("scheduledFunctions"), because it was previously unregistered. Consequently, if the handler calls clearInterval, that function wont be able to find the handler and remove it completely. --- src/core/DelayedFunctionScheduler.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/DelayedFunctionScheduler.js b/src/core/DelayedFunctionScheduler.js index 8079c70e..adb93d1e 100644 --- a/src/core/DelayedFunctionScheduler.js +++ b/src/core/DelayedFunctionScheduler.js @@ -127,11 +127,12 @@ getJasmineRequireObj().DelayedFunctionScheduler = function() { for (var i = 0; i < funcsToRun.length; ++i) { var funcToRun = funcsToRun[i]; - funcToRun.funcToCall.apply(null, funcToRun.params || []); if (funcToRun.recurring) { reschedule(funcToRun); } + + funcToRun.funcToCall.apply(null, funcToRun.params || []); } } while (scheduledLookup.length > 0 && // checking first if we're out of time prevents setTimeout(0)