Introduce GlobalScope::get_runnable_wrapper

This commit is contained in:
Anthony Ramine 2016-10-04 15:36:20 +02:00
parent ca8c6fb072
commit 514819f37a
4 changed files with 16 additions and 13 deletions

View file

@ -27,7 +27,7 @@ use msg::constellation_msg::PipelineId;
use net_traits::{CoreResourceThread, ResourceThreads, IpcSend};
use profile_traits::{mem, time};
use script_runtime::{ScriptChan, maybe_take_panic_result};
use script_thread::MainThreadScriptChan;
use script_thread::{MainThreadScriptChan, RunnableWrapper};
use script_traits::{MsDuration, ScriptMsg as ConstellationMsg, TimerEvent};
use script_traits::{TimerEventId, TimerEventRequest, TimerSource};
use std::cell::Cell;
@ -396,6 +396,18 @@ impl GlobalScope {
}
unreachable!();
}
/// Returns a wrapper for runnables to ensure they are cancelled if
/// the global scope is being destroyed.
pub fn get_runnable_wrapper(&self) -> RunnableWrapper {
if let Some(window) = self.downcast::<Window>() {
return window.get_runnable_wrapper();
}
if let Some(worker) = self.downcast::<WorkerGlobalScope>() {
return worker.get_runnable_wrapper();
}
unreachable!();
}
}
fn timestamp_in_ms(time: Timespec) -> u64 {