mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Introduce GlobalScope::script_chan
This commit is contained in:
parent
71236e168a
commit
a7305b7fc4
4 changed files with 19 additions and 14 deletions
|
@ -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;
|
||||
|
@ -67,16 +67,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> {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue