aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/globalscope.rs
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2016-10-04 15:36:20 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2016-10-06 21:35:51 +0200
commit514819f37a12c79c0398863c2ef817c9a4337f56 (patch)
tree563259529244275a3003508c0d72bf7ae4c24197 /components/script/dom/globalscope.rs
parentca8c6fb0724a364bdd11742a9c9611557595a6f7 (diff)
downloadservo-514819f37a12c79c0398863c2ef817c9a4337f56.tar.gz
servo-514819f37a12c79c0398863c2ef817c9a4337f56.zip
Introduce GlobalScope::get_runnable_wrapper
Diffstat (limited to 'components/script/dom/globalscope.rs')
-rw-r--r--components/script/dom/globalscope.rs14
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 {