mirror of
https://github.com/servo/servo.git
synced 2025-07-26 00:30:22 +01:00
Use an enum to set set_timeout_or_interval's is_interval field. Fixes #4059
This commit is contained in:
parent
b4c3aec383
commit
89f1949913
3 changed files with 21 additions and 13 deletions
|
@ -25,7 +25,7 @@ use page::Page;
|
||||||
use script_task::{ExitWindowMsg, ScriptChan, TriggerLoadMsg, TriggerFragmentMsg};
|
use script_task::{ExitWindowMsg, ScriptChan, TriggerLoadMsg, TriggerFragmentMsg};
|
||||||
use script_task::FromWindow;
|
use script_task::FromWindow;
|
||||||
use script_traits::ScriptControlChan;
|
use script_traits::ScriptControlChan;
|
||||||
use timers::{TimerId, TimerManager};
|
use timers::{Interval, NonInterval, TimerId, TimerManager};
|
||||||
|
|
||||||
use servo_msg::compositor_msg::ScriptListener;
|
use servo_msg::compositor_msg::ScriptListener;
|
||||||
use servo_msg::constellation_msg::LoadData;
|
use servo_msg::constellation_msg::LoadData;
|
||||||
|
@ -228,7 +228,7 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
|
||||||
self.timers.set_timeout_or_interval(callback,
|
self.timers.set_timeout_or_interval(callback,
|
||||||
args,
|
args,
|
||||||
timeout,
|
timeout,
|
||||||
false, // is_interval
|
NonInterval, // is_interval
|
||||||
FromWindow(self.page.id.clone()),
|
FromWindow(self.page.id.clone()),
|
||||||
self.script_chan.clone())
|
self.script_chan.clone())
|
||||||
}
|
}
|
||||||
|
@ -241,7 +241,7 @@ impl<'a> WindowMethods for JSRef<'a, Window> {
|
||||||
self.timers.set_timeout_or_interval(callback,
|
self.timers.set_timeout_or_interval(callback,
|
||||||
args,
|
args,
|
||||||
timeout,
|
timeout,
|
||||||
true, // is_interval
|
Interval, // is_interval
|
||||||
FromWindow(self.page.id.clone()),
|
FromWindow(self.page.id.clone()),
|
||||||
self.script_chan.clone())
|
self.script_chan.clone())
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ use dom::workerlocation::WorkerLocation;
|
||||||
use dom::workernavigator::WorkerNavigator;
|
use dom::workernavigator::WorkerNavigator;
|
||||||
use dom::window::{base64_atob, base64_btoa};
|
use dom::window::{base64_atob, base64_btoa};
|
||||||
use script_task::{ScriptChan, FromWorker};
|
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_net::resource_task::{ResourceTask, load_whole_resource};
|
||||||
use servo_util::str::DOMString;
|
use servo_util::str::DOMString;
|
||||||
|
@ -160,7 +160,7 @@ impl<'a> WorkerGlobalScopeMethods for JSRef<'a, WorkerGlobalScope> {
|
||||||
self.timers.set_timeout_or_interval(callback,
|
self.timers.set_timeout_or_interval(callback,
|
||||||
args,
|
args,
|
||||||
timeout,
|
timeout,
|
||||||
false, // is_interval
|
NonInterval, // is_interval
|
||||||
FromWorker,
|
FromWorker,
|
||||||
self.script_chan.clone())
|
self.script_chan.clone())
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ impl<'a> WorkerGlobalScopeMethods for JSRef<'a, WorkerGlobalScope> {
|
||||||
self.timers.set_timeout_or_interval(callback,
|
self.timers.set_timeout_or_interval(callback,
|
||||||
args,
|
args,
|
||||||
timeout,
|
timeout,
|
||||||
true, // is_interval
|
Interval, // is_interval
|
||||||
FromWorker,
|
FromWorker,
|
||||||
self.script_chan.clone())
|
self.script_chan.clone())
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
// Holder for the various JS values associated with setTimeout
|
||||||
// (ie. function value to invoke and all arguments to pass
|
// (ie. function value to invoke and all arguments to pass
|
||||||
// to the function when calling it)
|
// to the function when calling it)
|
||||||
|
@ -74,7 +82,7 @@ impl Drop for TimerManager {
|
||||||
#[privatize]
|
#[privatize]
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone)]
|
||||||
struct TimerData {
|
struct TimerData {
|
||||||
is_interval: bool,
|
is_interval: IsInterval,
|
||||||
funval: Function,
|
funval: Function,
|
||||||
args: Vec<JSVal>
|
args: Vec<JSVal>
|
||||||
}
|
}
|
||||||
|
@ -91,7 +99,7 @@ impl TimerManager {
|
||||||
callback: Function,
|
callback: Function,
|
||||||
arguments: Vec<JSVal>,
|
arguments: Vec<JSVal>,
|
||||||
timeout: i32,
|
timeout: i32,
|
||||||
is_interval: bool,
|
is_interval: IsInterval,
|
||||||
source: TimerSource,
|
source: TimerSource,
|
||||||
script_chan: ScriptChan)
|
script_chan: ScriptChan)
|
||||||
-> i32 {
|
-> i32 {
|
||||||
|
@ -104,15 +112,15 @@ impl TimerManager {
|
||||||
let tm = Timer::new().unwrap();
|
let tm = Timer::new().unwrap();
|
||||||
let (cancel_chan, cancel_port) = channel();
|
let (cancel_chan, cancel_port) = channel();
|
||||||
let spawn_name = match source {
|
let spawn_name = match source {
|
||||||
FromWindow(_) if is_interval => "Window:SetInterval",
|
FromWindow(_) if is_interval == IsInterval::Interval => "Window:SetInterval",
|
||||||
FromWorker if is_interval => "Worker:SetInterval",
|
FromWorker if is_interval == IsInterval::Interval => "Worker:SetInterval",
|
||||||
FromWindow(_) => "Window:SetTimeout",
|
FromWindow(_) => "Window:SetTimeout",
|
||||||
FromWorker => "Worker:SetTimeout",
|
FromWorker => "Worker:SetTimeout",
|
||||||
};
|
};
|
||||||
spawn_named(spawn_name, proc() {
|
spawn_named(spawn_name, proc() {
|
||||||
let mut tm = tm;
|
let mut tm = tm;
|
||||||
let duration = Duration::milliseconds(timeout as i64);
|
let duration = Duration::milliseconds(timeout as i64);
|
||||||
let timeout_port = if is_interval {
|
let timeout_port = if is_interval == IsInterval::Interval {
|
||||||
tm.periodic(duration)
|
tm.periodic(duration)
|
||||||
} else {
|
} else {
|
||||||
tm.oneshot(duration)
|
tm.oneshot(duration)
|
||||||
|
@ -131,7 +139,7 @@ impl TimerManager {
|
||||||
timeout_port.recv();
|
timeout_port.recv();
|
||||||
let ScriptChan(ref chan) = script_chan;
|
let ScriptChan(ref chan) = script_chan;
|
||||||
chan.send(FireTimerMsg(source, TimerId(handle)));
|
chan.send(FireTimerMsg(source, TimerId(handle)));
|
||||||
if !is_interval {
|
if is_interval == IsInterval::NonInterval {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else if id == cancel_handle.id() {
|
} 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
|
// TODO: Must handle rooting of funval and args when movable GC is turned on
|
||||||
let _ = data.funval.Call_(this, data.args, ReportExceptions);
|
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);
|
self.active_timers.borrow_mut().remove(&timer_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue