diff --git a/components/script/timers.rs b/components/script/timers.rs index 4b8a2b6d272..7e164bbe5eb 100644 --- a/components/script/timers.rs +++ b/components/script/timers.rs @@ -23,7 +23,7 @@ use std::rc::Rc; use util::mem::HeapSizeOf; use util::str::DOMString; -#[derive(JSTraceable, PartialEq, Eq, Copy, Clone, HeapSizeOf, Hash, PartialOrd, Ord)] +#[derive(JSTraceable, PartialEq, Eq, Copy, Clone, HeapSizeOf, Hash, PartialOrd, Ord, Debug)] pub struct TimerHandle(i32); #[derive(JSTraceable, HeapSizeOf)] @@ -253,16 +253,22 @@ impl ActiveTimers { // Since the event id was the expected one, at least one timer should be due. assert!(base_time >= self.timers.borrow().last().unwrap().next_call); + // select timers to run to prevent firing timers + // that were installed during fire of another timer + let mut timers_to_run: Vec = Vec::new(); + loop { - let timer = { - let mut timers = self.timers.borrow_mut(); + let mut timers = self.timers.borrow_mut(); - if timers.is_empty() || timers.last().unwrap().next_call > base_time { - break; - } + if timers.is_empty() || timers.last().unwrap().next_call > base_time { + break; + } + + timers_to_run.push(timers.pop().unwrap()); + } + + for timer in timers_to_run { - timers.pop().unwrap() - }; let callback = timer.callback.clone(); // prep for step 6 in nested set_timeout_or_interval calls diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index e2b7aa33d2d..f65dfa849e2 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -5661,6 +5661,12 @@ "url": "/_mozilla/mozilla/textcontent.html" } ], + "mozilla/timer_eventInvalidation.html": [ + { + "path": "mozilla/timer_eventInvalidation.html", + "url": "/_mozilla/mozilla/timer_eventInvalidation.html" + } + ], "mozilla/title.html": [ { "path": "mozilla/title.html", diff --git a/tests/wpt/mozilla/tests/mozilla/timer_eventInvalidation.html b/tests/wpt/mozilla/tests/mozilla/timer_eventInvalidation.html new file mode 100644 index 00000000000..4a182a62f75 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/timer_eventInvalidation.html @@ -0,0 +1,21 @@ + + + + + + + + + diff --git a/tests/wpt/mozilla/tests/mozilla/timer_eventInvalidation_test.html b/tests/wpt/mozilla/tests/mozilla/timer_eventInvalidation_test.html new file mode 100644 index 00000000000..9656e578605 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/timer_eventInvalidation_test.html @@ -0,0 +1,14 @@ + + + + + + +