mirror of
https://github.com/servo/servo.git
synced 2025-06-20 15:18:58 +01:00
Add support for clearTimeout.
This commit is contained in:
parent
5be084a3b6
commit
29a75daa66
3 changed files with 22 additions and 5 deletions
|
@ -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);*/
|
||||
|
|
|
@ -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 {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -561,6 +561,10 @@ impl ScriptTask {
|
|||
fn handle_fire_timer_msg(&mut self, id: PipelineId, timer_data: ~TimerData) {
|
||||
let page = self.page_tree.find(id).expect("ScriptTask: received fire timer msg for a
|
||||
pipeline ID not associated with this script task. This is a bug.").page;
|
||||
let window = page.frame.expect("ScriptTask: Expect a timeout to have a document").window;
|
||||
if !window.active_timers.contains(&timer_data.handle) {
|
||||
return;
|
||||
}
|
||||
unsafe {
|
||||
let this_value = if timer_data.args.len() > 0 {
|
||||
RUST_JSVAL_TO_OBJECT(timer_data.args[0])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue