diff options
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/bindings/global.rs | 11 | ||||
-rw-r--r-- | components/script/dom/filereader.rs | 2 | ||||
-rw-r--r-- | components/script/dom/globalscope.rs | 14 | ||||
-rw-r--r-- | components/script/task_source/mod.rs | 2 |
4 files changed, 16 insertions, 13 deletions
diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs index 3c2d0533ac7..2d984db4598 100644 --- a/components/script/dom/bindings/global.rs +++ b/components/script/dom/bindings/global.rs @@ -19,7 +19,7 @@ use js::glue::{IsWrapper, UnwrapObject}; use js::jsapi::{CurrentGlobalOrNull, GetGlobalForObjectCrossCompartment}; use js::jsapi::{JSContext, JSObject, JS_GetClass}; use script_runtime::{CommonScriptMsg, EnqueuedPromiseCallback, ScriptChan, ScriptPort}; -use script_thread::{RunnableWrapper, ScriptThread}; +use script_thread::ScriptThread; use task_source::file_reading::FileReadingTaskSource; /// A freely-copyable reference to a rooted global object. @@ -85,15 +85,6 @@ impl<'a> GlobalRef<'a> { } } - /// 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(), - } - } - /// Enqueue a promise callback for subsequent execution. pub fn enqueue_promise_job(&self, job: EnqueuedPromiseCallback) { match *self { diff --git a/components/script/dom/filereader.rs b/components/script/dom/filereader.rs index 4ba5af109be..ebfb5060a58 100644 --- a/components/script/dom/filereader.rs +++ b/components/script/dom/filereader.rs @@ -354,7 +354,7 @@ impl FileReader { let fr = Trusted::new(self); let gen_id = self.generation_id.get(); - let wrapper = self.global().r().get_runnable_wrapper(); + let wrapper = self.global_scope().get_runnable_wrapper(); let task_source = self.global().r().file_reading_task_source(); spawn_named("file reader async operation".to_owned(), move || { 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 { diff --git a/components/script/task_source/mod.rs b/components/script/task_source/mod.rs index cb607c57acb..bddc4f82173 100644 --- a/components/script/task_source/mod.rs +++ b/components/script/task_source/mod.rs @@ -19,6 +19,6 @@ pub trait TaskSource { -> Result<(), ()> where T: Runnable + Send + 'static; fn queue<T: Runnable + Send + 'static>(&self, msg: Box<T>, global: GlobalRef) -> Result<(), ()> { - self.queue_with_wrapper(msg, &global.get_runnable_wrapper()) + self.queue_with_wrapper(msg, &global.as_global_scope().get_runnable_wrapper()) } } |