diff options
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/bindings/global.rs | 12 | ||||
-rw-r--r-- | components/script/dom/globalscope.rs | 16 | ||||
-rw-r--r-- | components/script/dom/xmlhttprequest.rs | 2 |
3 files changed, 17 insertions, 13 deletions
diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs index d2b693dbf08..26d7c061503 100644 --- a/components/script/dom/bindings/global.rs +++ b/components/script/dom/bindings/global.rs @@ -18,7 +18,7 @@ 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, ScriptChan, ScriptPort}; +use script_runtime::CommonScriptMsg; use script_thread::ScriptThread; use task_source::file_reading::FileReadingTaskSource; @@ -66,16 +66,6 @@ impl<'a> GlobalRef<'a> { } } - /// Create a new sender/receiver pair that can be used to implement an on-demand - /// event loop. Used for implementing web APIs that require blocking semantics - /// without resorting to nested event loops. - pub fn new_script_pair(&self) -> (Box<ScriptChan + Send>, Box<ScriptPort + Send>) { - match *self { - GlobalRef::Window(ref window) => window.new_script_pair(), - GlobalRef::Worker(ref worker) => worker.new_script_pair(), - } - } - /// 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) { diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index cd8fca9a0e4..0b3b609d54b 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -26,7 +26,8 @@ use libc; use msg::constellation_msg::PipelineId; use net_traits::{CoreResourceThread, ResourceThreads, IpcSend}; use profile_traits::{mem, time}; -use script_runtime::{EnqueuedPromiseCallback, ScriptChan, maybe_take_panic_result}; +use script_runtime::{EnqueuedPromiseCallback, ScriptChan}; +use script_runtime::{ScriptPort, maybe_take_panic_result}; use script_thread::{MainThreadScriptChan, RunnableWrapper, ScriptThread}; use script_traits::{MsDuration, ScriptMsg as ConstellationMsg, TimerEvent}; use script_traits::{TimerEventId, TimerEventRequest, TimerSource}; @@ -431,6 +432,19 @@ impl GlobalScope { } unreachable!(); } + + /// Create a new sender/receiver pair that can be used to implement an on-demand + /// event loop. Used for implementing web APIs that require blocking semantics + /// without resorting to nested event loops. + pub fn new_script_pair(&self) -> (Box<ScriptChan + Send>, Box<ScriptPort + Send>) { + if let Some(window) = self.downcast::<Window>() { + return window.new_script_pair(); + } + if let Some(worker) = self.downcast::<WorkerGlobalScope>() { + return worker.new_script_pair(); + } + unreachable!(); + } } fn timestamp_in_ms(time: Timespec) -> u64 { diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index 7a586cfe6a1..e8254be3e70 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -1297,7 +1297,7 @@ impl XMLHttpRequest { let global_scope = global.as_global_scope(); let (script_chan, script_port) = if self.sync.get() { - let (tx, rx) = global.new_script_pair(); + let (tx, rx) = global_scope.new_script_pair(); (tx, Some(rx)) } else { (global_scope.networking_task_source(), None) |