aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2016-07-14 13:01:52 -0400
committerJosh Matthews <josh@joshmatthews.net>2016-07-14 13:27:38 -0400
commit0e4865ea1ada7294d89581704f047b521f985c69 (patch)
tree3380b254c3b3060f8c45a187e0e31407b0df6afc
parent2cab84614068c7c42eb4d354b288637c9fa00d5e (diff)
downloadservo-0e4865ea1ada7294d89581704f047b521f985c69.tar.gz
servo-0e4865ea1ada7294d89581704f047b521f985c69.zip
Allow wrapping worker runnables in cancellable runnables.
-rw-r--r--components/script/dom/bindings/global.rs11
-rw-r--r--components/script/dom/workerglobalscope.rs7
2 files changed, 17 insertions, 1 deletions
diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs
index 1040e7b5965..6593fc36b8f 100644
--- a/components/script/dom/bindings/global.rs
+++ b/components/script/dom/bindings/global.rs
@@ -23,7 +23,7 @@ use net_traits::filemanager_thread::FileManagerThreadMsg;
use net_traits::{ResourceThreads, CoreResourceThread, RequestSource, IpcSend};
use profile_traits::{mem, time};
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort};
-use script_thread::{MainThreadScriptChan, ScriptThread};
+use script_thread::{MainThreadScriptChan, ScriptThread, RunnableWrapper};
use script_traits::{MsDuration, ScriptMsg as ConstellationMsg, TimerEventRequest};
use task_source::dom_manipulation::DOMManipulationTaskSource;
use timers::{OneshotTimerCallback, OneshotTimerHandle};
@@ -297,6 +297,15 @@ impl<'a> GlobalRef<'a> {
GlobalRef::Worker(ref worker) => worker.panic_chan(),
}
}
+
+ /// Returns a wrapper for runnables to ensure they are cancelled if the global
+ /// is being destroyed.
+ pub fn get_runnable_wrapper(&self) -> RunnableWrapper {
+ match *self {
+ GlobalRef::Window(ref window) => window.get_runnable_wrapper(),
+ GlobalRef::Worker(ref worker) => worker.get_runnable_wrapper(),
+ }
+ }
}
impl GlobalRoot {
diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs
index 2e1c983bfd4..b04663bbd08 100644
--- a/components/script/dom/workerglobalscope.rs
+++ b/components/script/dom/workerglobalscope.rs
@@ -29,6 +29,7 @@ use net_traits::{LoadContext, ResourceThreads, load_whole_resource};
use net_traits::{RequestSource, LoadOrigin, CustomResponseSender, IpcSend};
use profile_traits::{mem, time};
use script_runtime::{CommonScriptMsg, ScriptChan, ScriptPort, maybe_take_panic_result};
+use script_thread::RunnableWrapper;
use script_traits::ScriptMsg as ConstellationMsg;
use script_traits::{MsDuration, TimerEvent, TimerEventId, TimerEventRequest, TimerSource};
use std::cell::Cell;
@@ -268,6 +269,12 @@ impl WorkerGlobalScope {
pub fn panic_chan(&self) -> &IpcSender<PanicMsg> {
&self.panic_chan
}
+
+ pub fn get_runnable_wrapper(&self) -> RunnableWrapper {
+ RunnableWrapper {
+ cancelled: self.closing.clone(),
+ }
+ }
}
impl LoadOrigin for WorkerGlobalScope {