mirror of
https://github.com/servo/servo.git
synced 2025-07-23 23:33:43 +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 profile_traits::time;
|
||||||
use script_runtime::{CommonScriptMsg, EnqueuedPromiseCallback, ScriptChan};
|
use script_runtime::{CommonScriptMsg, EnqueuedPromiseCallback, ScriptChan};
|
||||||
use script_runtime::{ScriptPort, maybe_take_panic_result};
|
use script_runtime::{ScriptPort, maybe_take_panic_result};
|
||||||
use script_thread::{MainThreadScriptChan, RunnableWrapper, ScriptThread};
|
use script_thread::{RunnableWrapper, ScriptThread};
|
||||||
use script_traits::MsDuration;
|
use script_traits::MsDuration;
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::panic;
|
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
|
/// `ScriptChan` used to send messages to the event loop of this global's
|
||||||
/// thread.
|
/// thread.
|
||||||
pub fn networking_task_source(&self) -> Box<ScriptChan + Send> {
|
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 msg::constellation_msg::PipelineId;
|
||||||
use net_traits::{CoreResourceThread, ResourceThreads, IpcSend};
|
use net_traits::{CoreResourceThread, ResourceThreads, IpcSend};
|
||||||
use profile_traits::{mem, time};
|
use profile_traits::{mem, time};
|
||||||
|
use script_runtime::ScriptChan;
|
||||||
|
use script_thread::MainThreadScriptChan;
|
||||||
use script_traits::{ScriptMsg as ConstellationMsg, TimerEventRequest};
|
use script_traits::{ScriptMsg as ConstellationMsg, TimerEventRequest};
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
@ -257,6 +259,17 @@ impl GlobalScope {
|
||||||
pub fn core_resource_thread(&self) -> CoreResourceThread {
|
pub fn core_resource_thread(&self) -> CoreResourceThread {
|
||||||
self.resource_threads().sender()
|
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 {
|
fn timestamp_in_ms(time: Timespec) -> u64 {
|
||||||
|
|
|
@ -330,8 +330,10 @@ impl WebSocket {
|
||||||
address: address,
|
address: address,
|
||||||
};
|
};
|
||||||
|
|
||||||
let global = self.global();
|
self.global_scope()
|
||||||
global.r().script_chan().send(CommonScriptMsg::RunnableMsg(WebSocketEvent, task)).unwrap();
|
.script_chan()
|
||||||
|
.send(CommonScriptMsg::RunnableMsg(WebSocketEvent, task))
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(true)
|
Ok(true)
|
||||||
|
|
|
@ -109,7 +109,7 @@ impl Worker {
|
||||||
|
|
||||||
DedicatedWorkerGlobalScope::run_worker_scope(
|
DedicatedWorkerGlobalScope::run_worker_scope(
|
||||||
init, worker_url, devtools_receiver, worker.runtime.clone(), worker_ref,
|
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)
|
Ok(worker)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue