aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2016-10-04 00:35:16 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2016-10-06 21:35:48 +0200
commita7305b7fc4e4b9c70e9a5ef43f66a7b6be6731ec (patch)
tree40200177fa4731b3a87a8b9ea3324adf2b224958
parent71236e168ac9c1e85c370be09a5566ec299b7bb6 (diff)
downloadservo-a7305b7fc4e4b9c70e9a5ef43f66a7b6be6731ec.tar.gz
servo-a7305b7fc4e4b9c70e9a5ef43f66a7b6be6731ec.zip
Introduce GlobalScope::script_chan
-rw-r--r--components/script/dom/bindings/global.rs12
-rw-r--r--components/script/dom/globalscope.rs13
-rw-r--r--components/script/dom/websocket.rs6
-rw-r--r--components/script/dom/worker.rs2
4 files changed, 19 insertions, 14 deletions
diff --git a/components/script/dom/bindings/global.rs b/components/script/dom/bindings/global.rs
index ecca46a5a5e..67ed8766932 100644
--- a/components/script/dom/bindings/global.rs
+++ b/components/script/dom/bindings/global.rs
@@ -25,7 +25,7 @@ use libc;
use profile_traits::time;
use script_runtime::{CommonScriptMsg, EnqueuedPromiseCallback, ScriptChan};
use script_runtime::{ScriptPort, maybe_take_panic_result};
-use script_thread::{MainThreadScriptChan, RunnableWrapper, ScriptThread};
+use script_thread::{RunnableWrapper, ScriptThread};
use script_traits::MsDuration;
use std::ffi::CString;
use std::panic;
@@ -69,16 +69,6 @@ impl<'a> GlobalRef<'a> {
/// `ScriptChan` used to send messages to the event loop of this global's
/// thread.
- pub fn script_chan(&self) -> Box<ScriptChan + Send> {
- match *self {
- GlobalRef::Window(ref window) =>
- MainThreadScriptChan(window.main_thread_script_chan().clone()).clone(),
- GlobalRef::Worker(ref worker) => worker.script_chan(),
- }
- }
-
- /// `ScriptChan` used to send messages to the event loop of this global's
- /// thread.
pub fn networking_task_source(&self) -> Box<ScriptChan + Send> {
match *self {
GlobalRef::Window(ref window) => window.networking_task_source(),
diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs
index 71405239122..7e5f0407e36 100644
--- a/components/script/dom/globalscope.rs
+++ b/components/script/dom/globalscope.rs
@@ -23,6 +23,8 @@ use js::jsapi::{HandleValue, JS_GetContext, JS_GetObjectRuntime, JSContext};
use msg::constellation_msg::PipelineId;
use net_traits::{CoreResourceThread, ResourceThreads, IpcSend};
use profile_traits::{mem, time};
+use script_runtime::ScriptChan;
+use script_thread::MainThreadScriptChan;
use script_traits::{ScriptMsg as ConstellationMsg, TimerEventRequest};
use std::cell::Cell;
use std::collections::HashMap;
@@ -257,6 +259,17 @@ impl GlobalScope {
pub fn core_resource_thread(&self) -> CoreResourceThread {
self.resource_threads().sender()
}
+
+ /// `ScriptChan` to send messages to the event loop of this global scope.
+ pub fn script_chan(&self) -> Box<ScriptChan + Send> {
+ if let Some(window) = self.downcast::<Window>() {
+ return MainThreadScriptChan(window.main_thread_script_chan().clone()).clone();
+ }
+ if let Some(worker) = self.downcast::<WorkerGlobalScope>() {
+ return worker.script_chan();
+ }
+ unreachable!();
+ }
}
fn timestamp_in_ms(time: Timespec) -> u64 {
diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs
index aa2a61b6c38..ac1cf53b2ae 100644
--- a/components/script/dom/websocket.rs
+++ b/components/script/dom/websocket.rs
@@ -330,8 +330,10 @@ impl WebSocket {
address: address,
};
- let global = self.global();
- global.r().script_chan().send(CommonScriptMsg::RunnableMsg(WebSocketEvent, task)).unwrap();
+ self.global_scope()
+ .script_chan()
+ .send(CommonScriptMsg::RunnableMsg(WebSocketEvent, task))
+ .unwrap();
}
Ok(true)
diff --git a/components/script/dom/worker.rs b/components/script/dom/worker.rs
index 1ef6242720d..035aa83bdf9 100644
--- a/components/script/dom/worker.rs
+++ b/components/script/dom/worker.rs
@@ -109,7 +109,7 @@ impl Worker {
DedicatedWorkerGlobalScope::run_worker_scope(
init, worker_url, devtools_receiver, worker.runtime.clone(), worker_ref,
- global.script_chan(), sender, receiver, worker_load_origin, closing);
+ global_scope.script_chan(), sender, receiver, worker_load_origin, closing);
Ok(worker)
}