diff options
author | bors-servo <release+servo@mozilla.com> | 2014-03-31 19:07:50 -0400 |
---|---|---|
committer | bors-servo <release+servo@mozilla.com> | 2014-03-31 19:07:50 -0400 |
commit | 3eac31394cb509ce7e4fa61a3543f6ec22c8bde4 (patch) | |
tree | 821f6ad653b1e2229bffcfa4a8bf3b53ad95d4f8 /src | |
parent | 83c2d923975e753830238bea175cc674839452d3 (diff) | |
parent | 1a8a3cc271080b573507cd9ea4ec6c1866a4af99 (diff) | |
download | servo-3eac31394cb509ce7e4fa61a3543f6ec22c8bde4.tar.gz servo-3eac31394cb509ce7e4fa61a3543f6ec22c8bde4.zip |
auto merge of #2002 : mrobinson/servo/issue-1477, r=jdm
A HashMap allows easily looking up a timer and canceling it in
Window.ClearTimeout.
Fixes #1477.
Diffstat (limited to 'src')
-rw-r--r-- | src/components/script/dom/window.rs | 20 | ||||
-rw-r--r-- | src/components/script/script_task.rs | 8 |
2 files changed, 16 insertions, 12 deletions
diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs index 18a7fd73059..9aaebee3303 100644 --- a/src/components/script/dom/window.rs +++ b/src/components/script/dom/window.rs @@ -25,7 +25,7 @@ use js::jsval::JSVal; use js::jsval::{NullValue, ObjectValue}; use js::JSPROP_ENUMERATE; -use collections::hashmap::HashSet; +use collections::hashmap::HashMap; use std::cast; use std::cmp; use std::comm::Chan; @@ -79,7 +79,7 @@ pub struct Window { location: Option<JS<Location>>, navigator: Option<JS<Navigator>>, image_cache_task: ImageCacheTask, - active_timers: ~HashSet<TimerHandle>, + active_timers: ~HashMap<i32, TimerHandle>, next_timer_handle: i32, priv extra: Untraceable } @@ -116,8 +116,8 @@ impl Window { impl Drop for Window { fn drop(&mut self) { self.extra.timer_chan.send(TimerMessageClose); - for handle in self.active_timers.iter() { - handle.cancel(); + for timer_handle in self.active_timers.values() { + timer_handle.cancel(); } } } @@ -254,14 +254,16 @@ impl Window { })); } }); - self.active_timers.insert(TimerHandle { handle: handle, cancel_chan: Some(cancel_chan) }); + self.active_timers.insert(handle, TimerHandle { handle: handle, cancel_chan: Some(cancel_chan) }); handle } pub fn ClearTimeout(&mut self, handle: i32) { - // FIXME(#1477): active_timers should be a HashMap and this should - // cancel the removed timer. - self.active_timers.remove(&TimerHandle { handle: handle, cancel_chan: None }); + let timer_handle = self.active_timers.pop(&handle); + match timer_handle { + Some(handle) => handle.cancel(), + None => { } + } } pub fn damage_and_reflow(&self, damage: DocumentDamageLevel) { @@ -310,7 +312,7 @@ impl Window { location: None, navigator: None, image_cache_task: image_cache_task, - active_timers: ~HashSet::new(), + active_timers: ~HashMap::new(), next_timer_handle: 0 }; diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index bbac828cf59..22a03a7b680 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -16,7 +16,7 @@ use dom::event::Event; use dom::uievent::UIEvent; use dom::eventtarget::EventTarget; use dom::node::{Node, NodeHelpers}; -use dom::window::{TimerData, TimerHandle, Window}; +use dom::window::{TimerData, Window}; use dom::windowproxy::WindowProxy; use html::hubbub_html_parser::HtmlParserResult; use html::hubbub_html_parser::{HtmlDiscoveredStyle, HtmlDiscoveredIFrame, HtmlDiscoveredScript}; @@ -645,10 +645,12 @@ impl ScriptTask { pipeline ID not associated with this script task. This is a bug.").page(); let frame = page.frame(); let mut window = frame.get().get_ref().window.clone(); - if !window.get().active_timers.contains(&TimerHandle { handle: timer_data.handle, cancel_chan: None }) { + + let timer_handle = window.get_mut().active_timers.pop(&timer_data.handle); + if timer_handle.is_none() { return; } - window.get_mut().active_timers.remove(&TimerHandle { handle: timer_data.handle, cancel_chan: None }); + let js_info = page.js_info(); let this_value = if timer_data.args.len() > 0 { fail!("NYI") |