diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-01-08 08:48:54 -0700 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-01-08 08:48:54 -0700 |
commit | df6a7959df69bf98b397f088fc3cf1fad2cc0aaf (patch) | |
tree | fae7131eb701121982eab0b793730a4c17615ef3 /components/script/timers.rs | |
parent | 1d7148c79f9124779a910fd5291c5fa0543b2dae (diff) | |
parent | 5fe3a3e54f2d94c33ca84c54521aab4bd6b98c1e (diff) | |
download | servo-df6a7959df69bf98b397f088fc3cf1fad2cc0aaf.tar.gz servo-df6a7959df69bf98b397f088fc3cf1fad2cc0aaf.zip |
auto merge of #4069 : guillaumebort/servo/fix/3936, r=jdm
Diffstat (limited to 'components/script/timers.rs')
-rw-r--r-- | components/script/timers.rs | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/components/script/timers.rs b/components/script/timers.rs index f449fa81507..f453c7677c3 100644 --- a/components/script/timers.rs +++ b/components/script/timers.rs @@ -8,9 +8,12 @@ use dom::bindings::codegen::Bindings::FunctionBinding::Function; use dom::bindings::js::JSRef; use dom::bindings::utils::Reflectable; +use dom::window::ScriptHelpers; + use script_task::{ScriptChan, ScriptMsg, TimerSource}; use servo_util::task::spawn_named; +use servo_util::str::DOMString; use js::jsval::JSVal; @@ -36,6 +39,13 @@ struct TimerHandle { cancel_chan: Option<Sender<()>>, } +#[jstraceable] +#[deriving(Clone)] +pub enum TimerCallback { + StringTimerCallback(DOMString), + FunctionTimerCallback(Function) +} + impl Hash for TimerId { fn hash(&self, state: &mut sip::SipState) { let TimerId(id) = *self; @@ -83,7 +93,7 @@ pub enum IsInterval { #[deriving(Clone)] struct TimerData { is_interval: IsInterval, - funval: Function, + callback: TimerCallback, args: Vec<JSVal> } @@ -96,7 +106,7 @@ impl TimerManager { } pub fn set_timeout_or_interval(&self, - callback: Function, + callback: TimerCallback, arguments: Vec<JSVal>, timeout: i32, is_interval: IsInterval, @@ -152,7 +162,7 @@ impl TimerManager { cancel_chan: Some(cancel_chan), data: TimerData { is_interval: is_interval, - funval: callback, + callback: callback, args: arguments } }; @@ -164,7 +174,7 @@ impl TimerManager { let mut timer_handle = self.active_timers.borrow_mut().remove(&TimerId(handle)); match timer_handle { Some(ref mut handle) => handle.cancel(), - None => { } + None => {} } } @@ -176,7 +186,14 @@ impl TimerManager { }; // TODO: Must handle rooting of funval and args when movable GC is turned on - let _ = data.funval.Call_(this, data.args, ReportExceptions); + match data.callback { + TimerCallback::FunctionTimerCallback(function) => { + let _ = function.Call_(this, data.args, ReportExceptions); + } + TimerCallback::StringTimerCallback(code_str) => { + this.evaluate_js_on_global_with_result(code_str.as_slice()); + } + }; if data.is_interval == IsInterval::NonInterval { self.active_timers.borrow_mut().remove(&timer_id); |