diff options
author | James Graham <james@hoppipolla.co.uk> | 2013-09-19 00:02:41 +0100 |
---|---|---|
committer | James Graham <james@hoppipolla.co.uk> | 2013-09-19 00:02:41 +0100 |
commit | 29a75daa66cf289cf973cec179edc342114ca726 (patch) | |
tree | 4602508dce075b3860aa46395ecfbd87b3616a23 /src/components/script/dom | |
parent | 5be084a3b6fe2557519d4cd8506efb6b026464d3 (diff) | |
download | servo-29a75daa66cf289cf973cec179edc342114ca726.tar.gz servo-29a75daa66cf289cf973cec179edc342114ca726.zip |
Add support for clearTimeout.
Diffstat (limited to 'src/components/script/dom')
-rw-r--r-- | src/components/script/dom/bindings/codegen/Window.webidl | 2 | ||||
-rw-r--r-- | src/components/script/dom/window.rs | 19 |
2 files changed, 17 insertions, 4 deletions
diff --git a/src/components/script/dom/bindings/codegen/Window.webidl b/src/components/script/dom/bindings/codegen/Window.webidl index 7b406f104c1..b85890676eb 100644 --- a/src/components/script/dom/bindings/codegen/Window.webidl +++ b/src/components/script/dom/bindings/codegen/Window.webidl @@ -63,8 +63,8 @@ interface WindowTimers { //long setTimeout(Function handler, optional long timeout, any... arguments); //XXXjdm No support for Function or variadic arguments yet long setTimeout(any handler, optional long timeout/*, any... arguments*/); - /*long setTimeout(DOMString handler, optional long timeout, any... arguments); void clearTimeout(long handle); + /*long setTimeout(DOMString handler, optional long timeout, any... arguments); long setInterval(Function handler, optional long timeout, any... arguments); long setInterval(DOMString handler, optional long timeout, any... arguments); void clearInterval(long handle);*/ diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs index ec2db1bf4ac..2eac2f46966 100644 --- a/src/components/script/dom/window.rs +++ b/src/components/script/dom/window.rs @@ -23,6 +23,7 @@ use std::cast; use std::cell::Cell; use std::comm; use std::comm::SharedChan; +use std::hashmap::HashSet; use std::io; use std::ptr; use std::int; @@ -45,6 +46,8 @@ pub struct Window { timer_chan: SharedChan<TimerControlMsg>, navigator: Option<@mut Navigator>, image_cache_task: ImageCacheTask, + active_timers: ~HashSet<i32>, + next_timer_handle: i32, } #[unsafe_destructor] @@ -58,6 +61,7 @@ impl Drop for Window { // (ie. function value to invoke and all arguments to pass // to the function when calling it) pub struct TimerData { + handle: i32, funval: JSVal, args: ~[JSVal], } @@ -148,8 +152,10 @@ impl BindingObject for Window { } impl Window { - pub fn SetTimeout(&self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32 { + pub fn SetTimeout(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32 { let timeout = int::max(0, timeout) as u64; + let handle = self.next_timer_handle; + self.next_timer_handle += 1; // Post a delayed message to the per-window timer task; it will dispatch it // to the relevant script handler that will deal with it. @@ -159,11 +165,17 @@ impl Window { let mut tm = tm.take(); tm.sleep(timeout); chan.send(TimerMessage_Fire(~TimerData { + handle: handle, funval: callback, args: ~[] })); } - return 0; //TODO return handle into list of active timers + self.active_timers.insert(handle); + handle + } + + pub fn ClearTimeout(&mut self, handle: i32) { + self.active_timers.remove(&handle); } pub fn content_changed(&self) { @@ -208,6 +220,8 @@ impl Window { }, navigator: None, image_cache_task: image_cache_task, + active_timers: ~HashSet::new(), + next_timer_handle: 0 }; unsafe { @@ -251,4 +265,3 @@ impl Traceable for Window { } } } - |