aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorTrevor Riles <trevor.riles@code42.com>2014-11-21 15:10:27 -0600
committerTrevor Riles <trevor.riles@code42.com>2014-11-21 15:10:27 -0600
commit89f19499136ea6b83cf79e729d90d055568886e5 (patch)
treebbc58f0e42a2821e0e4c9bd090690d5a9b308a5b /components/script
parentb4c3aec383b2b1cd19ab6267775f9fb3735aa977 (diff)
downloadservo-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')
-rw-r--r--components/script/dom/window.rs6
-rw-r--r--components/script/dom/workerglobalscope.rs6
-rw-r--r--components/script/timers.rs22
3 files changed, 21 insertions, 13 deletions
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index da6b788db72..eb41466d31c 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -25,7 +25,7 @@ use page::Page;
use script_task::{ExitWindowMsg, ScriptChan, TriggerLoadMsg, TriggerFragmentMsg};
use script_task::FromWindow;
use script_traits::ScriptControlChan;
-use timers::{TimerId, TimerManager};
+use timers::{Interval, NonInterval, TimerId, TimerManager};
use servo_msg::compositor_msg::ScriptListener;
use servo_msg::constellation_msg::LoadData;
@@ -228,7 +228,7 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
self.timers.set_timeout_or_interval(callback,
args,
timeout,
- false, // is_interval
+ NonInterval, // is_interval
FromWindow(self.page.id.clone()),
self.script_chan.clone())
}
@@ -241,7 +241,7 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
self.timers.set_timeout_or_interval(callback,
args,
timeout,
- true, // is_interval
+ Interval, // is_interval
FromWindow(self.page.id.clone()),
self.script_chan.clone())
}
diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs
index 4b490da8674..1409699fbbf 100644
--- a/components/script/dom/workerglobalscope.rs
+++ b/components/script/dom/workerglobalscope.rs
@@ -14,7 +14,7 @@ use dom::workerlocation::WorkerLocation;
use dom::workernavigator::WorkerNavigator;
use dom::window::{base64_atob, base64_btoa};
use script_task::{ScriptChan, FromWorker};
-use timers::{TimerId, TimerManager};
+use timers::{Interval, NonInterval, TimerId, TimerManager};
use servo_net::resource_task::{ResourceTask, load_whole_resource};
use servo_util::str::DOMString;
@@ -160,7 +160,7 @@ impl<'a> WorkerGlobalScopeMethods for JSRef<'a, WorkerGlobalScope> {
self.timers.set_timeout_or_interval(callback,
args,
timeout,
- false, // is_interval
+ NonInterval, // is_interval
FromWorker,
self.script_chan.clone())
}
@@ -173,7 +173,7 @@ impl<'a> WorkerGlobalScopeMethods for JSRef<'a, WorkerGlobalScope> {
self.timers.set_timeout_or_interval(callback,
args,
timeout,
- true, // is_interval
+ Interval, // is_interval
FromWorker,
self.script_chan.clone())
}
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);
}
}