diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs index 26d7c061503..051a28439bd 100644 --- a/components/script/dom/bindings/global.rs +++ b/components/script/dom/bindings/global.rs @@ -18,8 +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 script_runtime::CommonScriptMsg; -use script_thread::ScriptThread; use task_source::file_reading::FileReadingTaskSource; /// A freely-copyable reference to a rooted global object. @@ -65,15 +63,6 @@ impl<'a> GlobalRef<'a> { GlobalRef::Worker(ref worker) => worker.file_reading_task_source(), } } - - /// Process a single event as if it were the next event in the thread queue for - /// this global. - pub fn process_event(&self, msg: CommonScriptMsg) { - match *self { - GlobalRef::Window(_) => ScriptThread::process_event(msg), - GlobalRef::Worker(ref worker) => worker.process_event(msg), - } - } } impl<'a> Reflectable for GlobalRef<'a> { diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index 0b3b609d54b..fd5046c64c6 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -26,7 +26,7 @@ use libc; use msg::constellation_msg::PipelineId; use net_traits::{CoreResourceThread, ResourceThreads, IpcSend}; use profile_traits::{mem, time}; -use script_runtime::{EnqueuedPromiseCallback, ScriptChan}; +use script_runtime::{CommonScriptMsg, EnqueuedPromiseCallback, ScriptChan}; use script_runtime::{ScriptPort, maybe_take_panic_result}; use script_thread::{MainThreadScriptChan, RunnableWrapper, ScriptThread}; use script_traits::{MsDuration, ScriptMsg as ConstellationMsg, TimerEvent}; @@ -445,6 +445,18 @@ impl GlobalScope { } unreachable!(); } + + /// Process a single event as if it were the next event + /// in the thread queue for this global scope. + pub fn process_event(&self, msg: CommonScriptMsg) { + if self.is::() { + return ScriptThread::process_event(msg); + } + if let Some(worker) = self.downcast::() { + return worker.process_event(msg); + } + unreachable!(); + } } fn timestamp_in_ms(time: Timespec) -> u64 { diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index e8254be3e70..4429ec71380 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -1309,7 +1309,7 @@ impl XMLHttpRequest { if let Some(script_port) = script_port { loop { - global.process_event(script_port.recv().unwrap()); + global_scope.process_event(script_port.recv().unwrap()); let context = context.lock().unwrap(); let sync_status = context.sync_status.borrow(); if let Some(ref status) = *sync_status {