mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
script: Refactor channels in ScriptThread
into receivers and senders (#34776)
Create two new data structures in the `script` crate to hold senders and receiver: - `ScriptThreadSenders`: holds all outgoing channels from the `ScriptThread` including a channel to the `ScriptThread` itself. The ultimate goal with this is to reduce duplication by giving a boxed version of this this to `Window`s. - `ScriptThradReceivers`: holds all incoming channels to the `ScriptThread`. This isn't cloenable like the senders. This is used to abstract away `recv()` and `try_recv()` methods used to make the `ScriptThread` event loop easier to read. In addition: - The many duplicated `ScriptThread` self-senders for the `TaskManager` have been removed and, in general, a lot of boilerplate is removed as well. - Visibilty of all methods affected by this change is changed to `pub(crate)` in order to take advantage of dead code detection. Some dead code produced from macros is removed. - Some conversion code is refactord into implementations of the `From` trait. - The names of channels uses a standard "sender" and "receiver" naming as well as trying to be descriptive of where they go in `ScriptThread` as well as `InitialScriptState` Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
1e95712772
commit
5f927a2c28
30 changed files with 732 additions and 902 deletions
|
@ -22,7 +22,7 @@ pub struct DOMManipulationTaskSource(pub Box<dyn ScriptChan + Send>, #[no_trace]
|
|||
|
||||
impl Clone for DOMManipulationTaskSource {
|
||||
fn clone(&self) -> DOMManipulationTaskSource {
|
||||
DOMManipulationTaskSource(self.0.clone(), self.1)
|
||||
DOMManipulationTaskSource(self.0.as_boxed(), self.1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ pub struct FileReadingTaskSource(
|
|||
|
||||
impl Clone for FileReadingTaskSource {
|
||||
fn clone(&self) -> FileReadingTaskSource {
|
||||
FileReadingTaskSource(self.0.clone(), self.1)
|
||||
FileReadingTaskSource(self.0.as_boxed(), self.1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ pub struct GamepadTaskSource(
|
|||
|
||||
impl Clone for GamepadTaskSource {
|
||||
fn clone(&self) -> GamepadTaskSource {
|
||||
GamepadTaskSource(self.0.clone(), self.1)
|
||||
GamepadTaskSource(self.0.as_boxed(), self.1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
use base::id::PipelineId;
|
||||
use crossbeam_channel::Sender;
|
||||
|
||||
use crate::messaging::MainThreadScriptMsg;
|
||||
use crate::script_runtime::{CommonScriptMsg, ScriptThreadEventCategory};
|
||||
use crate::script_thread::MainThreadScriptMsg;
|
||||
use crate::task::{TaskCanceller, TaskOnce};
|
||||
use crate::task_source::{TaskSource, TaskSourceName};
|
||||
|
||||
#[derive(Clone, JSTraceable)]
|
||||
pub struct HistoryTraversalTaskSource(
|
||||
pub(crate) struct HistoryTraversalTaskSource(
|
||||
#[no_trace] pub Sender<MainThreadScriptMsg>,
|
||||
#[no_trace] pub PipelineId,
|
||||
);
|
||||
|
|
|
@ -14,13 +14,13 @@ use crate::dom::bindings::refcounted::Trusted;
|
|||
use crate::dom::event::SimpleEventTask;
|
||||
use crate::dom::eventtarget::EventTarget;
|
||||
use crate::dom::window::Window;
|
||||
use crate::messaging::MainThreadScriptMsg;
|
||||
use crate::script_runtime::{CommonScriptMsg, ScriptThreadEventCategory};
|
||||
use crate::script_thread::MainThreadScriptMsg;
|
||||
use crate::task::{TaskCanceller, TaskOnce};
|
||||
use crate::task_source::{TaskSource, TaskSourceName};
|
||||
|
||||
#[derive(Clone, JSTraceable)]
|
||||
pub struct MediaElementTaskSource(
|
||||
pub(crate) struct MediaElementTaskSource(
|
||||
#[no_trace] pub Sender<MainThreadScriptMsg>,
|
||||
#[no_trace] pub PipelineId,
|
||||
);
|
||||
|
|
|
@ -16,7 +16,7 @@ pub struct NetworkingTaskSource(
|
|||
|
||||
impl Clone for NetworkingTaskSource {
|
||||
fn clone(&self) -> NetworkingTaskSource {
|
||||
NetworkingTaskSource(self.0.clone(), self.1)
|
||||
NetworkingTaskSource(self.0.as_boxed(), self.1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ pub struct PerformanceTimelineTaskSource(
|
|||
|
||||
impl Clone for PerformanceTimelineTaskSource {
|
||||
fn clone(&self) -> PerformanceTimelineTaskSource {
|
||||
PerformanceTimelineTaskSource(self.0.clone(), self.1)
|
||||
PerformanceTimelineTaskSource(self.0.as_boxed(), self.1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ pub struct PortMessageQueue(
|
|||
|
||||
impl Clone for PortMessageQueue {
|
||||
fn clone(&self) -> PortMessageQueue {
|
||||
PortMessageQueue(self.0.clone(), self.1)
|
||||
PortMessageQueue(self.0.as_boxed(), self.1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ pub struct RemoteEventTaskSource(
|
|||
|
||||
impl Clone for RemoteEventTaskSource {
|
||||
fn clone(&self) -> RemoteEventTaskSource {
|
||||
RemoteEventTaskSource(self.0.clone(), self.1)
|
||||
RemoteEventTaskSource(self.0.as_boxed(), self.1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ pub struct RenderingTaskSource(pub Box<dyn ScriptChan + Send>, #[no_trace] pub P
|
|||
|
||||
impl Clone for RenderingTaskSource {
|
||||
fn clone(&self) -> RenderingTaskSource {
|
||||
RenderingTaskSource(self.0.clone(), self.1)
|
||||
RenderingTaskSource(self.0.as_boxed(), self.1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ pub struct TimerTaskSource(
|
|||
|
||||
impl Clone for TimerTaskSource {
|
||||
fn clone(&self) -> TimerTaskSource {
|
||||
TimerTaskSource(self.0.clone(), self.1)
|
||||
TimerTaskSource(self.0.as_boxed(), self.1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,8 +14,8 @@ use crate::dom::bindings::refcounted::Trusted;
|
|||
use crate::dom::event::{EventBubbles, EventCancelable, EventTask};
|
||||
use crate::dom::eventtarget::EventTarget;
|
||||
use crate::dom::window::Window;
|
||||
use crate::messaging::MainThreadScriptMsg;
|
||||
use crate::script_runtime::{CommonScriptMsg, ScriptThreadEventCategory};
|
||||
use crate::script_thread::MainThreadScriptMsg;
|
||||
use crate::task::{TaskCanceller, TaskOnce};
|
||||
use crate::task_source::{TaskSource, TaskSourceName};
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ pub struct WebsocketTaskSource(
|
|||
|
||||
impl Clone for WebsocketTaskSource {
|
||||
fn clone(&self) -> WebsocketTaskSource {
|
||||
WebsocketTaskSource(self.0.clone(), self.1)
|
||||
WebsocketTaskSource(self.0.as_boxed(), self.1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue