From a3859c07263fae4d2367352af8775492d3e578b5 Mon Sep 17 00:00:00 2001 From: benshu Date: Sat, 24 Oct 2015 11:27:59 +0200 Subject: [PATCH] Fixed panic in ActiveTimers.set_timeout_or_interval. --- components/script/timers.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/components/script/timers.rs b/components/script/timers.rs index 6c982cb1ad4..3b09572e2bc 100644 --- a/components/script/timers.rs +++ b/components/script/timers.rs @@ -139,8 +139,6 @@ impl ActiveTimers { is_interval: IsInterval, source: TimerSource) -> i32 { - assert!(self.suspended_since.get().is_none()); - // step 3 let TimerHandle(new_handle) = self.next_timer_handle.get(); self.next_timer_handle.set(TimerHandle(new_handle + 1)); @@ -283,7 +281,10 @@ impl ActiveTimers { } fn schedule_timer_call(&self) { - assert!(self.suspended_since.get().is_none()); + if self.suspended_since.get().is_some() { + // The timer will be scheduled when the pipeline is thawed. + return; + } let timers = self.timers.borrow(); @@ -318,7 +319,12 @@ impl ActiveTimers { } fn base_time(&self) -> MsDuration { - precise_time_ms() - self.suspension_offset.get() + let offset = self.suspension_offset.get(); + + match self.suspended_since.get() { + Some(time) => time - offset, + None => precise_time_ms() - offset, + } } // see step 7 of https://html.spec.whatwg.org/multipage/#timer-initialisation-steps