aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/abstractworkerglobalscope.rs8
-rw-r--r--components/script/dom/testbinding.rs6
-rw-r--r--components/script/dom/workerglobalscope.rs33
-rw-r--r--components/script/dom/worklet.rs3
-rw-r--r--components/script/dom/workletglobalscope.rs56
-rw-r--r--components/script/script_module.rs6
6 files changed, 55 insertions, 57 deletions
diff --git a/components/script/dom/abstractworkerglobalscope.rs b/components/script/dom/abstractworkerglobalscope.rs
index d87a5c20d96..2309c08d41d 100644
--- a/components/script/dom/abstractworkerglobalscope.rs
+++ b/components/script/dom/abstractworkerglobalscope.rs
@@ -110,9 +110,7 @@ pub fn run_worker_event_loop<T, WorkerMsg, Event>(
+ DomObject,
{
let scope = worker_scope.upcast::<WorkerGlobalScope>();
- let devtools_port = scope
- .from_devtools_sender()
- .map(|_| scope.from_devtools_receiver());
+ let devtools_receiver = scope.devtools_receiver();
let task_queue = worker_scope.task_queue();
let event = select! {
recv(worker_scope.control_receiver()) -> msg => T::from_control_msg(msg.unwrap()),
@@ -120,7 +118,7 @@ pub fn run_worker_event_loop<T, WorkerMsg, Event>(
task_queue.take_tasks(msg.unwrap());
T::from_worker_msg(task_queue.recv().unwrap())
},
- recv(devtools_port.unwrap_or(&crossbeam_channel::never())) -> msg =>
+ recv(devtools_receiver.unwrap_or(&crossbeam_channel::never())) -> msg =>
T::from_devtools_msg(msg.unwrap()),
};
let mut sequential = vec![];
@@ -134,7 +132,7 @@ pub fn run_worker_event_loop<T, WorkerMsg, Event>(
// Batch all events that are ready.
// The task queue will throttle non-priority tasks if necessary.
match task_queue.take_tasks_and_recv() {
- Err(_) => match devtools_port.map(|port| port.try_recv()) {
+ Err(_) => match devtools_receiver.map(|port| port.try_recv()) {
None => {},
Some(Err(_)) => break,
Some(Ok(ev)) => sequential.push(T::from_devtools_msg(ev)),
diff --git a/components/script/dom/testbinding.rs b/components/script/dom/testbinding.rs
index 0377fb6ed03..caf0ba1f24b 100644
--- a/components/script/dom/testbinding.rs
+++ b/components/script/dom/testbinding.rs
@@ -1017,8 +1017,8 @@ impl TestBindingMethods for TestBinding {
let global = self.global();
let handler = PromiseNativeHandler::new(
&global,
- resolve.map(SimpleHandler::new),
- reject.map(SimpleHandler::new),
+ resolve.map(SimpleHandler::new_boxed),
+ reject.map(SimpleHandler::new_boxed),
);
let p = Promise::new_in_current_realm(comp);
p.append_native_handler(&handler, comp);
@@ -1030,7 +1030,7 @@ impl TestBindingMethods for TestBinding {
handler: Rc<SimpleCallback>,
}
impl SimpleHandler {
- fn new(callback: Rc<SimpleCallback>) -> Box<dyn Callback> {
+ fn new_boxed(callback: Rc<SimpleCallback>) -> Box<dyn Callback> {
Box::new(SimpleHandler { handler: callback })
}
}
diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs
index 79d52a9ff99..f328e0a127c 100644
--- a/components/script/dom/workerglobalscope.rs
+++ b/components/script/dom/workerglobalscope.rs
@@ -114,15 +114,14 @@ pub struct WorkerGlobalScope {
#[ignore_malloc_size_of = "Defined in ipc-channel"]
#[no_trace]
- /// Optional `IpcSender` for sending the `DevtoolScriptControlMsg`
- /// to the server from within the worker
- from_devtools_sender: Option<IpcSender<DevtoolScriptControlMsg>>,
+ /// A `Sender` for sending messages to devtools. This is unused but is stored here to
+ /// keep the channel alive.
+ _devtools_sender: Option<IpcSender<DevtoolScriptControlMsg>>,
- #[ignore_malloc_size_of = "Defined in std"]
+ #[ignore_malloc_size_of = "Defined in crossbeam"]
#[no_trace]
- /// This `Receiver` will be ignored later if the corresponding
- /// `IpcSender` doesn't exist
- from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
+ /// A `Receiver` for receiving messages from devtools.
+ devtools_receiver: Option<Receiver<DevtoolScriptControlMsg>>,
#[no_trace]
navigation_start: CrossProcessInstant,
@@ -137,12 +136,18 @@ impl WorkerGlobalScope {
worker_type: WorkerType,
worker_url: ServoUrl,
runtime: Runtime,
- from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
+ devtools_receiver: Receiver<DevtoolScriptControlMsg>,
closing: Arc<AtomicBool>,
gpu_id_hub: Arc<IdentityHub>,
) -> Self {
// Install a pipeline-namespace in the current thread.
PipelineNamespace::auto_install();
+
+ let devtools_receiver = match init.from_devtools_sender {
+ Some(..) => Some(devtools_receiver),
+ None => None,
+ };
+
Self {
globalscope: GlobalScope::new_inherited(
init.pipeline_id,
@@ -168,8 +173,8 @@ impl WorkerGlobalScope {
runtime: DomRefCell::new(Some(runtime)),
location: Default::default(),
navigator: Default::default(),
- from_devtools_sender: init.from_devtools_sender,
- from_devtools_receiver,
+ devtools_receiver,
+ _devtools_sender: init.from_devtools_sender,
navigation_start: CrossProcessInstant::now(),
performance: Default::default(),
}
@@ -193,12 +198,8 @@ impl WorkerGlobalScope {
.prepare_for_new_child()
}
- pub fn from_devtools_sender(&self) -> Option<IpcSender<DevtoolScriptControlMsg>> {
- self.from_devtools_sender.clone()
- }
-
- pub fn from_devtools_receiver(&self) -> &Receiver<DevtoolScriptControlMsg> {
- &self.from_devtools_receiver
+ pub fn devtools_receiver(&self) -> Option<&Receiver<DevtoolScriptControlMsg>> {
+ self.devtools_receiver.as_ref()
}
#[allow(unsafe_code)]
diff --git a/components/script/dom/worklet.rs b/components/script/dom/worklet.rs
index 697bba659e7..d2ee1ef965c 100644
--- a/components/script/dom/worklet.rs
+++ b/components/script/dom/worklet.rs
@@ -611,7 +611,8 @@ impl WorkletThread {
hash_map::Entry::Vacant(entry) => {
debug!("Creating new worklet global scope.");
let executor = WorkletExecutor::new(worklet_id, self.primary_sender.clone());
- let result = global_type.new(
+ let result = WorkletGlobalScope::new(
+ global_type,
&self.runtime,
pipeline_id,
base_url,
diff --git a/components/script/dom/workletglobalscope.rs b/components/script/dom/workletglobalscope.rs
index cca5ecb3f1b..35adf0ac6e9 100644
--- a/components/script/dom/workletglobalscope.rs
+++ b/components/script/dom/workletglobalscope.rs
@@ -47,6 +47,33 @@ pub struct WorkletGlobalScope {
}
impl WorkletGlobalScope {
+ /// Create a new heap-allocated `WorkletGlobalScope`.
+ pub fn new(
+ scope_type: WorkletGlobalScopeType,
+ runtime: &Runtime,
+ pipeline_id: PipelineId,
+ base_url: ServoUrl,
+ executor: WorkletExecutor,
+ init: &WorkletGlobalScopeInit,
+ ) -> DomRoot<WorkletGlobalScope> {
+ match scope_type {
+ WorkletGlobalScopeType::Test => DomRoot::upcast(TestWorkletGlobalScope::new(
+ runtime,
+ pipeline_id,
+ base_url,
+ executor,
+ init,
+ )),
+ WorkletGlobalScopeType::Paint => DomRoot::upcast(PaintWorkletGlobalScope::new(
+ runtime,
+ pipeline_id,
+ base_url,
+ executor,
+ init,
+ )),
+ }
+ }
+
/// Create a new stack-allocated `WorkletGlobalScope`.
pub fn new_inherited(
pipeline_id: PipelineId,
@@ -178,35 +205,6 @@ pub enum WorkletGlobalScopeType {
Paint,
}
-impl WorkletGlobalScopeType {
- /// Create a new heap-allocated `WorkletGlobalScope`.
- pub fn new(
- &self,
- runtime: &Runtime,
- pipeline_id: PipelineId,
- base_url: ServoUrl,
- executor: WorkletExecutor,
- init: &WorkletGlobalScopeInit,
- ) -> DomRoot<WorkletGlobalScope> {
- match *self {
- WorkletGlobalScopeType::Test => DomRoot::upcast(TestWorkletGlobalScope::new(
- runtime,
- pipeline_id,
- base_url,
- executor,
- init,
- )),
- WorkletGlobalScopeType::Paint => DomRoot::upcast(PaintWorkletGlobalScope::new(
- runtime,
- pipeline_id,
- base_url,
- executor,
- init,
- )),
- }
- }
-}
-
/// A task which can be performed in the context of a worklet global.
pub enum WorkletTask {
Test(TestWorkletTask),
diff --git a/components/script/script_module.rs b/components/script/script_module.rs
index ba0d845cb14..89d9d3f0284 100644
--- a/components/script/script_module.rs
+++ b/components/script/script_module.rs
@@ -347,7 +347,7 @@ impl ModuleTree {
let handler = PromiseNativeHandler::new(
&owner.global(),
- Some(ModuleHandler::new(Box::new(
+ Some(ModuleHandler::new_boxed(Box::new(
task!(fetched_resolve: move || {
this.notify_owner_to_finish(identity, options);
}),
@@ -383,7 +383,7 @@ impl ModuleTree {
let handler = PromiseNativeHandler::new(
&owner.global(),
- Some(ModuleHandler::new(Box::new(
+ Some(ModuleHandler::new_boxed(Box::new(
task!(fetched_resolve: move || {
this.finish_dynamic_module(identity, module_id);
}),
@@ -858,7 +858,7 @@ struct ModuleHandler {
}
impl ModuleHandler {
- pub fn new(task: Box<dyn TaskBox>) -> Box<dyn Callback> {
+ pub fn new_boxed(task: Box<dyn TaskBox>) -> Box<dyn Callback> {
Box::new(Self {
task: DomRefCell::new(Some(task)),
})