mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
script: Use enum
s for event loop senders and receivers (#34896)
Previously, senders and receivers to different kinds of event loops (the main `ScriptThread`, different types of workers) used a rust `trait` mechanism to implement dynamic behavior. This led to having many unused implementations of this `trait`. This change moves to using an `enum` based approach for these senders and receivers and removes all of the dead code. In addition, to allowing for use of rust's dead code detection, it simplifies the code a great deal. All of these generic senders and receivers are moved to the `messaging.rs` file and given proper documentation. Finally, empty an `JSTraceable` implementation is made for all crossbeam `Sender<...>`s to avoid having to manually skip them everytime they are included in structs. The pre-existing empty `MallocSizeOf` implementation is used more thoroughly. Other unecessary wrappers around these senders and receivers are removed as well. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
82ac8d41d0
commit
77bc7f415d
18 changed files with 217 additions and 325 deletions
|
@ -7,7 +7,7 @@ use servo_url::ImmutableOrigin;
|
|||
|
||||
use crate::dom::bindings::refcounted::Trusted;
|
||||
use crate::dom::bindings::reflector::DomObject;
|
||||
use crate::script_runtime::CommonScriptMsg;
|
||||
use crate::messaging::CommonScriptMsg;
|
||||
|
||||
/// Messages used to control the worker event loops
|
||||
pub enum WorkerScriptMsg {
|
||||
|
|
|
@ -2,88 +2,19 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crossbeam_channel::{select, Receiver, Sender};
|
||||
use crossbeam_channel::{select, Receiver};
|
||||
use devtools_traits::DevtoolScriptControlMsg;
|
||||
|
||||
use crate::dom::abstractworker::WorkerScriptMsg;
|
||||
use crate::dom::bindings::conversions::DerivedFrom;
|
||||
use crate::dom::bindings::reflector::DomObject;
|
||||
use crate::dom::dedicatedworkerglobalscope::{AutoWorkerReset, DedicatedWorkerScriptMsg};
|
||||
use crate::dom::dedicatedworkerglobalscope::AutoWorkerReset;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::worker::TrustedWorkerAddress;
|
||||
use crate::dom::workerglobalscope::WorkerGlobalScope;
|
||||
use crate::realms::enter_realm;
|
||||
use crate::script_runtime::{CanGc, CommonScriptMsg, ScriptChan, ScriptPort};
|
||||
use crate::script_runtime::CanGc;
|
||||
use crate::task_queue::{QueuedTaskConversion, TaskQueue};
|
||||
|
||||
/// A ScriptChan that can be cloned freely and will silently send a TrustedWorkerAddress with
|
||||
/// common event loop messages. While this SendableWorkerScriptChan is alive, the associated
|
||||
/// Worker object will remain alive.
|
||||
#[derive(Clone, JSTraceable)]
|
||||
pub struct SendableWorkerScriptChan {
|
||||
#[no_trace]
|
||||
pub sender: Sender<DedicatedWorkerScriptMsg>,
|
||||
pub worker: TrustedWorkerAddress,
|
||||
}
|
||||
|
||||
impl ScriptChan for SendableWorkerScriptChan {
|
||||
fn send(&self, msg: CommonScriptMsg) -> Result<(), ()> {
|
||||
let msg = DedicatedWorkerScriptMsg::CommonWorker(
|
||||
self.worker.clone(),
|
||||
WorkerScriptMsg::Common(msg),
|
||||
);
|
||||
self.sender.send(msg).map_err(|_| ())
|
||||
}
|
||||
|
||||
fn as_boxed(&self) -> Box<dyn ScriptChan> {
|
||||
Box::new(SendableWorkerScriptChan {
|
||||
sender: self.sender.clone(),
|
||||
worker: self.worker.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// A ScriptChan that can be cloned freely and will silently send a TrustedWorkerAddress with
|
||||
/// worker event loop messages. While this SendableWorkerScriptChan is alive, the associated
|
||||
/// Worker object will remain alive.
|
||||
#[derive(Clone, JSTraceable)]
|
||||
pub struct WorkerThreadWorkerChan {
|
||||
#[no_trace]
|
||||
pub sender: Sender<DedicatedWorkerScriptMsg>,
|
||||
pub worker: TrustedWorkerAddress,
|
||||
}
|
||||
|
||||
impl ScriptChan for WorkerThreadWorkerChan {
|
||||
fn send(&self, msg: CommonScriptMsg) -> Result<(), ()> {
|
||||
let msg = DedicatedWorkerScriptMsg::CommonWorker(
|
||||
self.worker.clone(),
|
||||
WorkerScriptMsg::Common(msg),
|
||||
);
|
||||
self.sender.send(msg).map_err(|_| ())
|
||||
}
|
||||
|
||||
fn as_boxed(&self) -> Box<dyn ScriptChan> {
|
||||
Box::new(WorkerThreadWorkerChan {
|
||||
sender: self.sender.clone(),
|
||||
worker: self.worker.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ScriptPort for Receiver<DedicatedWorkerScriptMsg> {
|
||||
fn recv(&self) -> Result<CommonScriptMsg, ()> {
|
||||
let common_msg = match self.recv() {
|
||||
Ok(DedicatedWorkerScriptMsg::CommonWorker(_worker, common_msg)) => common_msg,
|
||||
Err(_) => return Err(()),
|
||||
Ok(DedicatedWorkerScriptMsg::WakeUp) => panic!("unexpected worker event message!"),
|
||||
};
|
||||
match common_msg {
|
||||
WorkerScriptMsg::Common(script_msg) => Ok(script_msg),
|
||||
WorkerScriptMsg::DOMMessage { .. } => panic!("unexpected worker event message!"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait WorkerEventLoopMethods {
|
||||
type WorkerMsg: QueuedTaskConversion + Send;
|
||||
type ControlMsg;
|
||||
|
|
|
@ -53,7 +53,10 @@ mod dummy {
|
|||
pub use self::dummy::LIVE_REFERENCES;
|
||||
|
||||
/// A pointer to a Rust DOM object that needs to be destroyed.
|
||||
struct TrustedReference(*const libc::c_void);
|
||||
#[derive(MallocSizeOf)]
|
||||
struct TrustedReference(
|
||||
#[ignore_malloc_size_of = "This is a shared reference."] *const libc::c_void,
|
||||
);
|
||||
unsafe impl Send for TrustedReference {}
|
||||
|
||||
impl TrustedReference {
|
||||
|
@ -158,10 +161,13 @@ impl TrustedPromise {
|
|||
/// DOM object is guaranteed to live at least as long as the last outstanding
|
||||
/// `Trusted<T>` instance.
|
||||
#[crown::unrooted_must_root_lint::allow_unrooted_interior]
|
||||
#[derive(MallocSizeOf)]
|
||||
pub struct Trusted<T: DomObject> {
|
||||
/// A pointer to the Rust DOM object of type T, but void to allow
|
||||
/// sending `Trusted<T>` between threads, regardless of T's sendability.
|
||||
#[conditional_malloc_size_of]
|
||||
refcount: Arc<TrustedReference>,
|
||||
#[ignore_malloc_size_of = "These are shared by all `Trusted` types."]
|
||||
owner_thread: *const LiveDOMReferences,
|
||||
phantom: PhantomData<T>,
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ use std::hash::{BuildHasher, Hash};
|
|||
use std::mem;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
use crossbeam_channel::Sender;
|
||||
use indexmap::IndexMap;
|
||||
/// A trait to allow tracing (only) DOM objects.
|
||||
pub use js::gc::Traceable as JSTraceable;
|
||||
|
@ -107,6 +108,10 @@ unsafe impl<T: JSTraceable> CustomTraceable for OnceCell<T> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl<T> CustomTraceable for Sender<T> {
|
||||
unsafe fn trace(&self, _: *mut JSTracer) {}
|
||||
}
|
||||
|
||||
/// Wrapper type for nop traceble
|
||||
///
|
||||
/// SAFETY: Inner type must not impl JSTraceable
|
||||
|
|
|
@ -27,9 +27,7 @@ use style::thread_state::{self, ThreadState};
|
|||
|
||||
use crate::devtools;
|
||||
use crate::dom::abstractworker::{SimpleWorkerErrorHandler, WorkerScriptMsg};
|
||||
use crate::dom::abstractworkerglobalscope::{
|
||||
run_worker_event_loop, SendableWorkerScriptChan, WorkerEventLoopMethods, WorkerThreadWorkerChan,
|
||||
};
|
||||
use crate::dom::abstractworkerglobalscope::{run_worker_event_loop, WorkerEventLoopMethods};
|
||||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::bindings::codegen::Bindings::DedicatedWorkerGlobalScopeBinding;
|
||||
use crate::dom::bindings::codegen::Bindings::DedicatedWorkerGlobalScopeBinding::DedicatedWorkerGlobalScopeMethods;
|
||||
|
@ -41,7 +39,7 @@ use crate::dom::bindings::reflector::DomObject;
|
|||
use crate::dom::bindings::root::{DomRoot, RootCollection, ThreadLocalStackRoots};
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::bindings::structuredclone;
|
||||
use crate::dom::bindings::trace::RootedTraceableBox;
|
||||
use crate::dom::bindings::trace::{CustomTraceable, RootedTraceableBox};
|
||||
use crate::dom::errorevent::ErrorEvent;
|
||||
use crate::dom::event::{Event, EventBubbles, EventCancelable, EventStatus};
|
||||
use crate::dom::eventtarget::EventTarget;
|
||||
|
@ -52,12 +50,10 @@ use crate::dom::webgpu::identityhub::IdentityHub;
|
|||
use crate::dom::worker::{TrustedWorkerAddress, Worker};
|
||||
use crate::dom::workerglobalscope::WorkerGlobalScope;
|
||||
use crate::fetch::load_whole_resource;
|
||||
use crate::messaging::{CommonScriptMsg, ScriptEventLoopReceiver, ScriptEventLoopSender};
|
||||
use crate::realms::{enter_realm, AlreadyInRealm, InRealm};
|
||||
use crate::script_runtime::ScriptThreadEventCategory::WorkerEvent;
|
||||
use crate::script_runtime::{
|
||||
CanGc, CommonScriptMsg, JSContext as SafeJSContext, Runtime, ScriptChan, ScriptPort,
|
||||
ThreadSafeJSContext,
|
||||
};
|
||||
use crate::script_runtime::{CanGc, JSContext as SafeJSContext, Runtime, ThreadSafeJSContext};
|
||||
use crate::task_queue::{QueuedTask, QueuedTaskConversion, TaskQueue};
|
||||
use crate::task_source::{SendableTaskSource, TaskSourceName};
|
||||
|
||||
|
@ -182,14 +178,12 @@ pub struct DedicatedWorkerGlobalScope {
|
|||
workerglobalscope: WorkerGlobalScope,
|
||||
#[ignore_malloc_size_of = "Defined in std"]
|
||||
task_queue: TaskQueue<DedicatedWorkerScriptMsg>,
|
||||
#[ignore_malloc_size_of = "Defined in std"]
|
||||
#[no_trace]
|
||||
own_sender: Sender<DedicatedWorkerScriptMsg>,
|
||||
#[ignore_malloc_size_of = "Trusted<T> has unclear ownership like Dom<T>"]
|
||||
worker: DomRefCell<Option<TrustedWorkerAddress>>,
|
||||
#[ignore_malloc_size_of = "Can't measure trait objects"]
|
||||
/// Sender to the parent thread.
|
||||
parent_sender: Box<dyn ScriptChan>,
|
||||
parent_event_loop_sender: ScriptEventLoopSender,
|
||||
#[ignore_malloc_size_of = "Arc"]
|
||||
#[no_trace]
|
||||
image_cache: Arc<dyn ImageCache>,
|
||||
|
@ -250,7 +244,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
worker_url: ServoUrl,
|
||||
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
|
||||
runtime: Runtime,
|
||||
parent_sender: Box<dyn ScriptChan + Send>,
|
||||
parent_event_loop_sender: ScriptEventLoopSender,
|
||||
own_sender: Sender<DedicatedWorkerScriptMsg>,
|
||||
receiver: Receiver<DedicatedWorkerScriptMsg>,
|
||||
closing: Arc<AtomicBool>,
|
||||
|
@ -273,7 +267,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
),
|
||||
task_queue: TaskQueue::new(receiver, own_sender.clone()),
|
||||
own_sender,
|
||||
parent_sender,
|
||||
parent_event_loop_sender,
|
||||
worker: DomRefCell::new(None),
|
||||
image_cache,
|
||||
browsing_context,
|
||||
|
@ -282,14 +276,14 @@ impl DedicatedWorkerGlobalScope {
|
|||
}
|
||||
|
||||
#[allow(unsafe_code, clippy::too_many_arguments)]
|
||||
pub fn new(
|
||||
pub(crate) fn new(
|
||||
init: WorkerGlobalScopeInit,
|
||||
worker_name: DOMString,
|
||||
worker_type: WorkerType,
|
||||
worker_url: ServoUrl,
|
||||
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
|
||||
runtime: Runtime,
|
||||
parent_sender: Box<dyn ScriptChan + Send>,
|
||||
parent_event_loop_sender: ScriptEventLoopSender,
|
||||
own_sender: Sender<DedicatedWorkerScriptMsg>,
|
||||
receiver: Receiver<DedicatedWorkerScriptMsg>,
|
||||
closing: Arc<AtomicBool>,
|
||||
|
@ -306,7 +300,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
worker_url,
|
||||
from_devtools_receiver,
|
||||
runtime,
|
||||
parent_sender,
|
||||
parent_event_loop_sender,
|
||||
own_sender,
|
||||
receiver,
|
||||
closing,
|
||||
|
@ -321,12 +315,12 @@ impl DedicatedWorkerGlobalScope {
|
|||
|
||||
/// <https://html.spec.whatwg.org/multipage/#run-a-worker>
|
||||
#[allow(unsafe_code, clippy::too_many_arguments)]
|
||||
pub fn run_worker_scope(
|
||||
pub(crate) fn run_worker_scope(
|
||||
mut init: WorkerGlobalScopeInit,
|
||||
worker_url: ServoUrl,
|
||||
from_devtools_receiver: IpcReceiver<DevtoolScriptControlMsg>,
|
||||
worker: TrustedWorkerAddress,
|
||||
parent_sender: Box<dyn ScriptChan + Send>,
|
||||
parent_event_loop_sender: ScriptEventLoopSender,
|
||||
own_sender: Sender<DedicatedWorkerScriptMsg>,
|
||||
receiver: Receiver<DedicatedWorkerScriptMsg>,
|
||||
worker_load_origin: WorkerScriptLoadOrigin,
|
||||
|
@ -379,10 +373,10 @@ impl DedicatedWorkerGlobalScope {
|
|||
|
||||
let runtime = unsafe {
|
||||
let task_source = SendableTaskSource {
|
||||
sender: Box::new(WorkerThreadWorkerChan {
|
||||
sender: ScriptEventLoopSender::DedicatedWorker {
|
||||
sender: own_sender.clone(),
|
||||
worker: worker.clone(),
|
||||
}),
|
||||
main_thread_worker: worker.clone(),
|
||||
},
|
||||
pipeline_id,
|
||||
name: TaskSourceName::Networking,
|
||||
canceller: Default::default(),
|
||||
|
@ -417,7 +411,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
worker_url,
|
||||
devtools_mpsc_port,
|
||||
runtime,
|
||||
parent_sender.as_boxed(),
|
||||
parent_event_loop_sender.clone(),
|
||||
own_sender,
|
||||
receiver,
|
||||
closing,
|
||||
|
@ -442,7 +436,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
) {
|
||||
Err(_) => {
|
||||
println!("error loading script {}", serialized_worker_url);
|
||||
parent_sender
|
||||
parent_event_loop_sender
|
||||
.send(CommonScriptMsg::Task(
|
||||
WorkerEvent,
|
||||
Box::new(SimpleWorkerErrorHandler::new(worker)),
|
||||
|
@ -491,7 +485,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
}
|
||||
},
|
||||
reporter_name,
|
||||
parent_sender,
|
||||
parent_event_loop_sender,
|
||||
CommonScriptMsg::CollectReports,
|
||||
);
|
||||
|
||||
|
@ -526,21 +520,23 @@ impl DedicatedWorkerGlobalScope {
|
|||
self.image_cache.clone()
|
||||
}
|
||||
|
||||
pub(crate) fn event_loop_sender(&self) -> Option<Box<dyn ScriptChan + Send>> {
|
||||
let worker = self.worker.borrow().clone()?;
|
||||
Some(Box::new(WorkerThreadWorkerChan {
|
||||
pub(crate) fn event_loop_sender(&self) -> Option<ScriptEventLoopSender> {
|
||||
Some(ScriptEventLoopSender::DedicatedWorker {
|
||||
sender: self.own_sender.clone(),
|
||||
worker,
|
||||
}))
|
||||
main_thread_worker: self.worker.borrow().clone()?,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn new_script_pair(&self) -> (Box<dyn ScriptChan + Send>, Box<dyn ScriptPort + Send>) {
|
||||
let (tx, rx) = unbounded();
|
||||
let chan = Box::new(SendableWorkerScriptChan {
|
||||
sender: tx,
|
||||
worker: self.worker.borrow().as_ref().unwrap().clone(),
|
||||
});
|
||||
(chan, Box::new(rx))
|
||||
pub(crate) fn new_script_pair(&self) -> (ScriptEventLoopSender, ScriptEventLoopReceiver) {
|
||||
let (sender, receiver) = unbounded();
|
||||
let main_thread_worker = self.worker.borrow().as_ref().unwrap().clone();
|
||||
(
|
||||
ScriptEventLoopSender::DedicatedWorker {
|
||||
sender,
|
||||
main_thread_worker,
|
||||
},
|
||||
ScriptEventLoopReceiver::DedicatedWorker(receiver),
|
||||
)
|
||||
}
|
||||
|
||||
fn handle_script_event(&self, msg: WorkerScriptMsg, can_gc: CanGc) {
|
||||
|
@ -626,7 +622,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
global.report_an_error(error_info, HandleValue::null(), CanGc::note());
|
||||
}
|
||||
}));
|
||||
self.parent_sender
|
||||
self.parent_event_loop_sender
|
||||
.send(CommonScriptMsg::Task(
|
||||
WorkerEvent,
|
||||
task,
|
||||
|
@ -650,7 +646,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
let task = Box::new(task!(post_worker_message: move || {
|
||||
Worker::handle_message(worker, data, CanGc::note());
|
||||
}));
|
||||
self.parent_sender
|
||||
self.parent_event_loop_sender
|
||||
.send(CommonScriptMsg::Task(
|
||||
WorkerEvent,
|
||||
task,
|
||||
|
|
|
@ -184,10 +184,10 @@ use crate::dom::windowproxy::WindowProxy;
|
|||
use crate::dom::xpathevaluator::XPathEvaluator;
|
||||
use crate::fetch::FetchCanceller;
|
||||
use crate::iframe_collection::IFrameCollection;
|
||||
use crate::messaging::MainThreadScriptMsg;
|
||||
use crate::messaging::{CommonScriptMsg, MainThreadScriptMsg};
|
||||
use crate::network_listener::{NetworkListener, PreInvoke};
|
||||
use crate::realms::{enter_realm, AlreadyInRealm, InRealm};
|
||||
use crate::script_runtime::{CanGc, CommonScriptMsg, ScriptThreadEventCategory};
|
||||
use crate::script_runtime::{CanGc, ScriptThreadEventCategory};
|
||||
use crate::script_thread::{with_script_thread, ScriptThread};
|
||||
use crate::stylesheet_set::StylesheetSetRef;
|
||||
use crate::task::TaskBox;
|
||||
|
|
|
@ -128,13 +128,12 @@ use crate::dom::webgpu::identityhub::IdentityHub;
|
|||
use crate::dom::window::Window;
|
||||
use crate::dom::workerglobalscope::WorkerGlobalScope;
|
||||
use crate::dom::workletglobalscope::WorkletGlobalScope;
|
||||
use crate::messaging::{CommonScriptMsg, ScriptEventLoopReceiver, ScriptEventLoopSender};
|
||||
use crate::microtask::{Microtask, MicrotaskQueue, UserMicrotask};
|
||||
use crate::network_listener::{NetworkListener, PreInvoke};
|
||||
use crate::realms::{enter_realm, AlreadyInRealm, InRealm};
|
||||
use crate::script_module::{DynamicModuleList, ModuleScript, ModuleTree, ScriptFetchOptions};
|
||||
use crate::script_runtime::{
|
||||
CanGc, CommonScriptMsg, JSContext as SafeJSContext, ScriptChan, ScriptPort, ThreadSafeJSContext,
|
||||
};
|
||||
use crate::script_runtime::{CanGc, JSContext as SafeJSContext, ThreadSafeJSContext};
|
||||
use crate::script_thread::{with_script_thread, ScriptThread};
|
||||
use crate::security_manager::CSPViolationReporter;
|
||||
use crate::task_manager::TaskManager;
|
||||
|
@ -2480,7 +2479,7 @@ impl GlobalScope {
|
|||
/// A sender to the event loop of this global scope. This either sends to the Worker event loop
|
||||
/// or the ScriptThread event loop in the case of a `Window`. This can be `None` for dedicated
|
||||
/// workers that are not currently handling a message.
|
||||
pub(crate) fn event_loop_sender(&self) -> Option<Box<dyn ScriptChan + Send>> {
|
||||
pub(crate) fn event_loop_sender(&self) -> Option<ScriptEventLoopSender> {
|
||||
if let Some(window) = self.downcast::<Window>() {
|
||||
Some(window.event_loop_sender())
|
||||
} else if let Some(dedicated) = self.downcast::<DedicatedWorkerGlobalScope>() {
|
||||
|
@ -2825,7 +2824,7 @@ impl GlobalScope {
|
|||
/// 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<dyn ScriptChan + Send>, Box<dyn ScriptPort + Send>) {
|
||||
pub(crate) fn new_script_pair(&self) -> (ScriptEventLoopSender, ScriptEventLoopReceiver) {
|
||||
if let Some(window) = self.downcast::<Window>() {
|
||||
return window.new_script_pair();
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ use crate::dom::bindings::inheritance::Castable;
|
|||
use crate::dom::bindings::root::{DomRoot, RootCollection, ThreadLocalStackRoots};
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::bindings::structuredclone;
|
||||
use crate::dom::bindings::trace::CustomTraceable;
|
||||
use crate::dom::dedicatedworkerglobalscope::AutoWorkerReset;
|
||||
use crate::dom::event::Event;
|
||||
use crate::dom::eventtarget::EventTarget;
|
||||
|
@ -44,10 +45,9 @@ use crate::dom::webgpu::identityhub::IdentityHub;
|
|||
use crate::dom::worker::TrustedWorkerAddress;
|
||||
use crate::dom::workerglobalscope::WorkerGlobalScope;
|
||||
use crate::fetch::load_whole_resource;
|
||||
use crate::messaging::{CommonScriptMsg, ScriptEventLoopSender};
|
||||
use crate::realms::{enter_realm, AlreadyInRealm, InRealm};
|
||||
use crate::script_runtime::{
|
||||
CanGc, CommonScriptMsg, JSContext as SafeJSContext, Runtime, ScriptChan, ThreadSafeJSContext,
|
||||
};
|
||||
use crate::script_runtime::{CanGc, JSContext as SafeJSContext, Runtime, ThreadSafeJSContext};
|
||||
use crate::task_queue::{QueuedTask, QueuedTaskConversion, TaskQueue};
|
||||
use crate::task_source::TaskSourceName;
|
||||
|
||||
|
@ -128,28 +128,6 @@ pub enum MixedMessage {
|
|||
Timer,
|
||||
}
|
||||
|
||||
#[derive(Clone, JSTraceable)]
|
||||
pub struct ServiceWorkerChan {
|
||||
#[no_trace]
|
||||
pub sender: Sender<ServiceWorkerScriptMsg>,
|
||||
}
|
||||
|
||||
impl ScriptChan for ServiceWorkerChan {
|
||||
fn send(&self, msg: CommonScriptMsg) -> Result<(), ()> {
|
||||
self.sender
|
||||
.send(ServiceWorkerScriptMsg::CommonWorker(
|
||||
WorkerScriptMsg::Common(msg),
|
||||
))
|
||||
.map_err(|_| ())
|
||||
}
|
||||
|
||||
fn as_boxed(&self) -> Box<dyn ScriptChan> {
|
||||
Box::new(ServiceWorkerChan {
|
||||
sender: self.sender.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[dom_struct]
|
||||
pub struct ServiceWorkerGlobalScope {
|
||||
workerglobalscope: WorkerGlobalScope,
|
||||
|
@ -158,8 +136,6 @@ pub struct ServiceWorkerGlobalScope {
|
|||
#[no_trace]
|
||||
task_queue: TaskQueue<ServiceWorkerScriptMsg>,
|
||||
|
||||
#[ignore_malloc_size_of = "Defined in std"]
|
||||
#[no_trace]
|
||||
own_sender: Sender<ServiceWorkerScriptMsg>,
|
||||
|
||||
/// A port on which a single "time-out" message can be received,
|
||||
|
@ -485,10 +461,8 @@ impl ServiceWorkerGlobalScope {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn event_loop_sender(&self) -> Box<dyn ScriptChan + Send> {
|
||||
Box::new(ServiceWorkerChan {
|
||||
sender: self.own_sender.clone(),
|
||||
})
|
||||
pub(crate) fn event_loop_sender(&self) -> ScriptEventLoopSender {
|
||||
ScriptEventLoopSender::ServiceWorker(self.own_sender.clone())
|
||||
}
|
||||
|
||||
fn dispatch_activate(&self, can_gc: CanGc) {
|
||||
|
|
|
@ -112,7 +112,7 @@ use crate::dom::bindings::reflector::DomObject;
|
|||
use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom};
|
||||
use crate::dom::bindings::str::{DOMString, USVString};
|
||||
use crate::dom::bindings::structuredclone;
|
||||
use crate::dom::bindings::trace::{JSTraceable, RootedTraceableBox};
|
||||
use crate::dom::bindings::trace::{CustomTraceable, JSTraceable, RootedTraceableBox};
|
||||
use crate::dom::bindings::utils::GlobalStaticData;
|
||||
use crate::dom::bindings::weakref::DOMTracker;
|
||||
use crate::dom::bluetooth::BluetoothExtraPermissionData;
|
||||
|
@ -149,11 +149,11 @@ use crate::dom::worklet::Worklet;
|
|||
use crate::dom::workletglobalscope::WorkletGlobalScopeType;
|
||||
use crate::layout_image::fetch_image_for_layout;
|
||||
use crate::messaging::{
|
||||
ImageCacheMsg, MainThreadScriptChan, MainThreadScriptMsg, SendableMainThreadScriptChan,
|
||||
ImageCacheMsg, MainThreadScriptMsg, ScriptEventLoopReceiver, ScriptEventLoopSender,
|
||||
};
|
||||
use crate::microtask::MicrotaskQueue;
|
||||
use crate::realms::{enter_realm, InRealm};
|
||||
use crate::script_runtime::{CanGc, JSContext, Runtime, ScriptChan, ScriptPort};
|
||||
use crate::script_runtime::{CanGc, JSContext, Runtime};
|
||||
use crate::script_thread::ScriptThread;
|
||||
use crate::timers::{IsInterval, TimerCallback};
|
||||
use crate::unminify::unminified_path;
|
||||
|
@ -202,8 +202,7 @@ impl LayoutBlocker {
|
|||
#[dom_struct]
|
||||
pub struct Window {
|
||||
globalscope: GlobalScope,
|
||||
#[ignore_malloc_size_of = "trait objects are hard"]
|
||||
script_chan: MainThreadScriptChan,
|
||||
script_chan: Sender<MainThreadScriptMsg>,
|
||||
#[no_trace]
|
||||
#[ignore_malloc_size_of = "TODO: Add MallocSizeOf support to layout"]
|
||||
layout: RefCell<Box<dyn Layout>>,
|
||||
|
@ -216,7 +215,6 @@ pub struct Window {
|
|||
#[ignore_malloc_size_of = "Arc"]
|
||||
#[no_trace]
|
||||
image_cache: Arc<dyn ImageCache>,
|
||||
#[ignore_malloc_size_of = "channels are hard"]
|
||||
#[no_trace]
|
||||
image_cache_chan: Sender<ImageCacheMsg>,
|
||||
window_proxy: MutNullableDom<WindowProxy>,
|
||||
|
@ -452,16 +450,23 @@ impl Window {
|
|||
}
|
||||
|
||||
pub(crate) fn main_thread_script_chan(&self) -> &Sender<MainThreadScriptMsg> {
|
||||
&self.script_chan.0
|
||||
&self.script_chan
|
||||
}
|
||||
|
||||
pub fn parent_info(&self) -> Option<PipelineId> {
|
||||
self.parent_info
|
||||
}
|
||||
|
||||
pub fn new_script_pair(&self) -> (Box<dyn ScriptChan + Send>, Box<dyn ScriptPort + Send>) {
|
||||
let (tx, rx) = unbounded();
|
||||
(Box::new(SendableMainThreadScriptChan(tx)), Box::new(rx))
|
||||
pub(crate) fn new_script_pair(&self) -> (ScriptEventLoopSender, ScriptEventLoopReceiver) {
|
||||
let (sender, receiver) = unbounded();
|
||||
(
|
||||
ScriptEventLoopSender::MainThread(sender),
|
||||
ScriptEventLoopReceiver::MainThread(receiver),
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn event_loop_sender(&self) -> ScriptEventLoopSender {
|
||||
ScriptEventLoopSender::MainThread(self.script_chan.clone())
|
||||
}
|
||||
|
||||
pub fn image_cache(&self) -> Arc<dyn ImageCache> {
|
||||
|
@ -2677,7 +2682,7 @@ impl Window {
|
|||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn new(
|
||||
runtime: Rc<Runtime>,
|
||||
script_chan: MainThreadScriptChan,
|
||||
script_chan: Sender<MainThreadScriptMsg>,
|
||||
layout: Box<dyn Layout>,
|
||||
font_context: Arc<FontContext>,
|
||||
image_cache_chan: Sender<ImageCacheMsg>,
|
||||
|
@ -2803,10 +2808,6 @@ impl Window {
|
|||
unsafe { WindowBinding::Wrap(JSContext::from_ptr(runtime.cx()), win) }
|
||||
}
|
||||
|
||||
pub(crate) fn event_loop_sender(&self) -> Box<dyn ScriptChan + Send> {
|
||||
Box::new(self.script_chan.clone())
|
||||
}
|
||||
|
||||
pub(crate) fn pipeline_id(&self) -> PipelineId {
|
||||
self.as_global_scope().pipeline_id()
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ use crate::dom::bindings::reflector::{reflect_dom_object_with_proto, DomObject};
|
|||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::str::USVString;
|
||||
use crate::dom::bindings::structuredclone;
|
||||
use crate::dom::bindings::trace::RootedTraceableBox;
|
||||
use crate::dom::bindings::trace::{CustomTraceable, RootedTraceableBox};
|
||||
use crate::dom::dedicatedworkerglobalscope::{
|
||||
DedicatedWorkerGlobalScope, DedicatedWorkerScriptMsg,
|
||||
};
|
||||
|
@ -47,8 +47,6 @@ pub type TrustedWorkerAddress = Trusted<Worker>;
|
|||
#[dom_struct]
|
||||
pub struct Worker {
|
||||
eventtarget: EventTarget,
|
||||
#[ignore_malloc_size_of = "Defined in std"]
|
||||
#[no_trace]
|
||||
/// Sender to the Receiver associated with the DedicatedWorkerGlobalScope
|
||||
/// this Worker created.
|
||||
sender: Sender<DedicatedWorkerScriptMsg>,
|
||||
|
|
|
@ -56,8 +56,9 @@ use crate::dom::window::{base64_atob, base64_btoa};
|
|||
use crate::dom::workerlocation::WorkerLocation;
|
||||
use crate::dom::workernavigator::WorkerNavigator;
|
||||
use crate::fetch;
|
||||
use crate::messaging::{CommonScriptMsg, ScriptEventLoopReceiver, ScriptEventLoopSender};
|
||||
use crate::realms::{enter_realm, InRealm};
|
||||
use crate::script_runtime::{CanGc, CommonScriptMsg, JSContext, Runtime, ScriptChan, ScriptPort};
|
||||
use crate::script_runtime::{CanGc, JSContext, Runtime};
|
||||
use crate::task::TaskCanceller;
|
||||
use crate::timers::{IsInterval, TimerCallback};
|
||||
|
||||
|
@ -491,7 +492,7 @@ impl WorkerGlobalScope {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn new_script_pair(&self) -> (Box<dyn ScriptChan + Send>, Box<dyn ScriptPort + Send>) {
|
||||
pub(crate) fn new_script_pair(&self) -> (ScriptEventLoopSender, ScriptEventLoopReceiver) {
|
||||
let dedicated = self.downcast::<DedicatedWorkerGlobalScope>();
|
||||
if let Some(dedicated) = dedicated {
|
||||
dedicated.new_script_pair()
|
||||
|
|
|
@ -49,9 +49,9 @@ use crate::dom::workletglobalscope::{
|
|||
WorkletGlobalScope, WorkletGlobalScopeInit, WorkletGlobalScopeType, WorkletTask,
|
||||
};
|
||||
use crate::fetch::load_whole_resource;
|
||||
use crate::messaging::MainThreadScriptMsg;
|
||||
use crate::messaging::{CommonScriptMsg, MainThreadScriptMsg};
|
||||
use crate::realms::InRealm;
|
||||
use crate::script_runtime::{CanGc, CommonScriptMsg, Runtime, ScriptThreadEventCategory};
|
||||
use crate::script_runtime::{CanGc, Runtime, ScriptThreadEventCategory};
|
||||
use crate::script_thread::ScriptThread;
|
||||
use crate::task::TaskBox;
|
||||
use crate::task_source::TaskSourceName;
|
||||
|
@ -768,7 +768,6 @@ impl WorkletThread {
|
|||
#[derive(Clone, JSTraceable, MallocSizeOf)]
|
||||
pub struct WorkletExecutor {
|
||||
worklet_id: WorkletId,
|
||||
#[ignore_malloc_size_of = "channels are hard"]
|
||||
#[no_trace]
|
||||
primary_sender: Sender<WorkletData>,
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
|
|||
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::trace::CustomTraceable;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::paintworkletglobalscope::{PaintWorkletGlobalScope, PaintWorkletTask};
|
||||
use crate::dom::testworkletglobalscope::{TestWorkletGlobalScope, TestWorkletTask};
|
||||
|
@ -40,8 +41,6 @@ pub struct WorkletGlobalScope {
|
|||
#[no_trace]
|
||||
base_url: ServoUrl,
|
||||
/// Sender back to the script thread
|
||||
#[ignore_malloc_size_of = "channels are hard"]
|
||||
#[no_trace]
|
||||
to_script_thread_sender: Sender<MainThreadScriptMsg>,
|
||||
/// Worklet task executor
|
||||
executor: WorkletExecutor,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue