diff options
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/bindings/global.rs | 10 | ||||
-rw-r--r-- | components/script/dom/filereader.rs | 7 | ||||
-rw-r--r-- | components/script/dom/globalscope.rs | 13 |
3 files changed, 17 insertions, 13 deletions
diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs index 051a28439bd..e62573b5a9a 100644 --- a/components/script/dom/bindings/global.rs +++ b/components/script/dom/bindings/global.rs @@ -18,7 +18,6 @@ use js::{JSCLASS_IS_DOMJSCLASS, JSCLASS_IS_GLOBAL}; use js::glue::{IsWrapper, UnwrapObject}; use js::jsapi::{CurrentGlobalOrNull, GetGlobalForObjectCrossCompartment}; use js::jsapi::{JSContext, JSObject, JS_GetClass}; -use task_source::file_reading::FileReadingTaskSource; /// A freely-copyable reference to a rooted global object. #[derive(Copy, Clone)] @@ -54,15 +53,6 @@ impl<'a> GlobalRef<'a> { GlobalRef::Worker(ref worker) => worker.get_cx(), } } - - /// `ScriptChan` used to send messages to the event loop of this global's - /// thread. - pub fn file_reading_task_source(&self) -> FileReadingTaskSource { - match *self { - GlobalRef::Window(ref window) => window.file_reading_task_source(), - GlobalRef::Worker(ref worker) => worker.file_reading_task_source(), - } - } } impl<'a> Reflectable for GlobalRef<'a> { diff --git a/components/script/dom/filereader.rs b/components/script/dom/filereader.rs index ebfb5060a58..2872aa2d325 100644 --- a/components/script/dom/filereader.rs +++ b/components/script/dom/filereader.rs @@ -333,8 +333,9 @@ impl FileReader { return Err(Error::InvalidState); } // Step 2 + let global = self.global_scope(); if blob.IsClosed() { - let exception = DOMException::new(&self.global_scope(), DOMErrorName::InvalidStateError); + let exception = DOMException::new(&global, DOMErrorName::InvalidStateError); self.error.set(Some(&exception)); self.dispatch_progress_event(atom!("error"), 0, None); @@ -354,8 +355,8 @@ impl FileReader { let fr = Trusted::new(self); let gen_id = self.generation_id.get(); - let wrapper = self.global_scope().get_runnable_wrapper(); - let task_source = self.global().r().file_reading_task_source(); + let wrapper = global.get_runnable_wrapper(); + let task_source = global.file_reading_task_source(); spawn_named("file reader async operation".to_owned(), move || { perform_annotated_read_operation(gen_id, load_data, blob_contents, fr, task_source, wrapper) diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index fd5046c64c6..553393e3195 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -36,6 +36,7 @@ use std::collections::HashMap; use std::collections::hash_map::Entry; use std::ffi::CString; use std::panic; +use task_source::file_reading::FileReadingTaskSource; use time::{Timespec, get_time}; use timers::{IsInterval, OneshotTimerCallback, OneshotTimerHandle}; use timers::{OneshotTimers, TimerCallback}; @@ -457,6 +458,18 @@ impl GlobalScope { } unreachable!(); } + + /// Channel to send messages to the file reading task source of + /// this of this global scope. + pub fn file_reading_task_source(&self) -> FileReadingTaskSource { + if let Some(window) = self.downcast::<Window>() { + return window.file_reading_task_source(); + } + if let Some(worker) = self.downcast::<WorkerGlobalScope>() { + return worker.file_reading_task_source(); + } + unreachable!(); + } } fn timestamp_in_ms(time: Timespec) -> u64 { |