diff options
Diffstat (limited to 'components/script/dom/globalscope.rs')
-rw-r--r-- | components/script/dom/globalscope.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index 96528a80164..159b934f8ae 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -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 { |