Clean up of script timer code.

The code was split into the following two abstractions.
 - OneshotTimers can be used to schedule arbitrary oneshot timers, such
   as XHR-Timeouts.
 - JsTimers (`setTimeout` and `setInterval`) which use OneshotTimers to
   schedule individual callbacks.

With this change the implementation (of JsTimers in particular) is in
much closer alignment with the specification.
This commit is contained in:
benshu 2015-11-19 07:57:04 +01:00
parent 581aa1a14f
commit f2d4a7bbca
5 changed files with 371 additions and 277 deletions

View file

@ -23,7 +23,7 @@ use net_traits::ResourceThread;
use profile_traits::mem;
use script_thread::{CommonScriptMsg, ScriptChan, ScriptPort, ScriptThread};
use script_traits::{MsDuration, ScriptMsg as ConstellationMsg, TimerEventRequest};
use timers::{ScheduledCallback, TimerHandle};
use timers::{OneshotTimerCallback, OneshotTimerHandle};
use url::Url;
/// A freely-copyable reference to a rooted global object.
@ -224,9 +224,9 @@ impl<'a> GlobalRef<'a> {
/// Schedule the given `callback` to be invoked after at least `duration` milliseconds have
/// passed.
pub fn schedule_callback(&self,
callback: Box<ScheduledCallback>,
callback: OneshotTimerCallback,
duration: MsDuration)
-> TimerHandle {
-> OneshotTimerHandle {
match *self {
GlobalRef::Window(window) => window.schedule_callback(callback, duration),
GlobalRef::Worker(worker) => worker.schedule_callback(callback, duration),
@ -234,7 +234,7 @@ impl<'a> GlobalRef<'a> {
}
/// Unschedule a previously-scheduled callback.
pub fn unschedule_callback(&self, handle: TimerHandle) {
pub fn unschedule_callback(&self, handle: OneshotTimerHandle) {
match *self {
GlobalRef::Window(window) => window.unschedule_callback(handle),
GlobalRef::Worker(worker) => worker.unschedule_callback(handle),