diff options
author | Trevor Riles <trevor.riles@code42.com> | 2014-11-21 15:10:27 -0600 |
---|---|---|
committer | Trevor Riles <trevor.riles@code42.com> | 2014-11-21 15:10:27 -0600 |
commit | 89f19499136ea6b83cf79e729d90d055568886e5 (patch) | |
tree | bbc58f0e42a2821e0e4c9bd090690d5a9b308a5b /components/script/timers.rs | |
parent | b4c3aec383b2b1cd19ab6267775f9fb3735aa977 (diff) | |
download | servo-89f19499136ea6b83cf79e729d90d055568886e5.tar.gz servo-89f19499136ea6b83cf79e729d90d055568886e5.zip |
Use an enum to set set_timeout_or_interval's is_interval field. Fixes #4059
Diffstat (limited to 'components/script/timers.rs')
-rw-r--r-- | components/script/timers.rs | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/components/script/timers.rs b/components/script/timers.rs index 988bb427978..8d802731487 100644 --- a/components/script/timers.rs +++ b/components/script/timers.rs @@ -66,6 +66,14 @@ impl Drop for TimerManager { } } +// Enum allowing more descriptive values for the is_interval field +#[jstraceable] +#[deriving(PartialEq, Clone)] +pub enum IsInterval { + Interval, + NonInterval, +} + // Holder for the various JS values associated with setTimeout // (ie. function value to invoke and all arguments to pass // to the function when calling it) @@ -74,7 +82,7 @@ impl Drop for TimerManager { #[privatize] #[deriving(Clone)] struct TimerData { - is_interval: bool, + is_interval: IsInterval, funval: Function, args: Vec<JSVal> } @@ -91,7 +99,7 @@ impl TimerManager { callback: Function, arguments: Vec<JSVal>, timeout: i32, - is_interval: bool, + is_interval: IsInterval, source: TimerSource, script_chan: ScriptChan) -> i32 { @@ -104,15 +112,15 @@ impl TimerManager { let tm = Timer::new().unwrap(); let (cancel_chan, cancel_port) = channel(); let spawn_name = match source { - FromWindow(_) if is_interval => "Window:SetInterval", - FromWorker if is_interval => "Worker:SetInterval", + FromWindow(_) if is_interval == IsInterval::Interval => "Window:SetInterval", + FromWorker if is_interval == IsInterval::Interval => "Worker:SetInterval", FromWindow(_) => "Window:SetTimeout", FromWorker => "Worker:SetTimeout", }; spawn_named(spawn_name, proc() { let mut tm = tm; let duration = Duration::milliseconds(timeout as i64); - let timeout_port = if is_interval { + let timeout_port = if is_interval == IsInterval::Interval { tm.periodic(duration) } else { tm.oneshot(duration) @@ -131,7 +139,7 @@ impl TimerManager { timeout_port.recv(); let ScriptChan(ref chan) = script_chan; chan.send(FireTimerMsg(source, TimerId(handle))); - if !is_interval { + if is_interval == IsInterval::NonInterval { break; } } else if id == cancel_handle.id() { @@ -171,7 +179,7 @@ impl TimerManager { // TODO: Must handle rooting of funval and args when movable GC is turned on let _ = data.funval.Call_(this, data.args, ReportExceptions); - if !data.is_interval { + if data.is_interval == IsInterval::NonInterval { self.active_timers.borrow_mut().remove(&timer_id); } } |