script: Migrate JobResult to GenericCallback (#39074)

Use the new GenericCallback abstraction for serviceworker job results.

Testing: Covered by service worker wpt tests

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
This commit is contained in:
Jonathan Schwender 2025-09-01 19:22:39 +02:00 committed by GitHub
parent fc30a26005
commit eece4c24b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 15 deletions

View file

@ -5,12 +5,11 @@
use std::default::Default; use std::default::Default;
use std::rc::Rc; use std::rc::Rc;
use base::generic_channel::GenericCallback;
use constellation_traits::{ use constellation_traits::{
Job, JobError, JobResult, JobResultValue, JobType, ScriptToConstellationMessage, Job, JobError, JobResult, JobResultValue, JobType, ScriptToConstellationMessage,
}; };
use dom_struct::dom_struct; use dom_struct::dom_struct;
use ipc_channel::ipc;
use ipc_channel::router::ROUTER;
use crate::dom::bindings::codegen::Bindings::ServiceWorkerContainerBinding::{ use crate::dom::bindings::codegen::Bindings::ServiceWorkerContainerBinding::{
RegistrationOptions, ServiceWorkerContainerMethods, RegistrationOptions, ServiceWorkerContainerMethods,
@ -155,15 +154,11 @@ impl ServiceWorkerContainerMethods<crate::DomTypeHolder> for ServiceWorkerContai
task_source: global.task_manager().dom_manipulation_task_source().into(), task_source: global.task_manager().dom_manipulation_task_source().into(),
}; };
let (job_result_sender, job_result_receiver) = ipc::channel().expect("ipc channel failure"); let result_handler = GenericCallback::new(move |message| match message {
ROUTER.add_typed_route(
job_result_receiver,
Box::new(move |message| match message {
Ok(msg) => handler.handle(msg), Ok(msg) => handler.handle(msg),
Err(err) => warn!("Error receiving a JobResult: {:?}", err), Err(err) => warn!("Error receiving a JobResult: {:?}", err),
}), })
); .expect("Failed to create callback");
let scope_things = let scope_things =
ServiceWorkerRegistration::create_scope_things(&global, script_url.clone()); ServiceWorkerRegistration::create_scope_things(&global, script_url.clone());
@ -173,7 +168,7 @@ impl ServiceWorkerContainerMethods<crate::DomTypeHolder> for ServiceWorkerContai
JobType::Register, JobType::Register,
scope, scope,
script_url, script_url,
job_result_sender, result_handler,
self.client.creation_url(), self.client.creation_url(),
Some(scope_things), Some(scope_things),
); );

View file

@ -8,7 +8,7 @@ use std::collections::HashMap;
use std::fmt; use std::fmt;
use base::Epoch; use base::Epoch;
use base::generic_channel::{GenericSender, SendResult}; use base::generic_channel::{GenericCallback, GenericSender, SendResult};
use base::id::{ use base::id::{
BroadcastChannelRouterId, BrowsingContextId, HistoryStateId, MessagePortId, BroadcastChannelRouterId, BrowsingContextId, HistoryStateId, MessagePortId,
MessagePortRouterId, PipelineId, ServiceWorkerId, ServiceWorkerRegistrationId, WebViewId, MessagePortRouterId, PipelineId, ServiceWorkerId, ServiceWorkerRegistrationId, WebViewId,
@ -290,7 +290,7 @@ pub struct Job {
/// <https://w3c.github.io/ServiceWorker/#dfn-job-script-url> /// <https://w3c.github.io/ServiceWorker/#dfn-job-script-url>
pub script_url: ServoUrl, pub script_url: ServoUrl,
/// <https://w3c.github.io/ServiceWorker/#dfn-job-client> /// <https://w3c.github.io/ServiceWorker/#dfn-job-client>
pub client: IpcSender<JobResult>, pub client: GenericCallback<JobResult>,
/// <https://w3c.github.io/ServiceWorker/#job-referrer> /// <https://w3c.github.io/ServiceWorker/#job-referrer>
pub referrer: ServoUrl, pub referrer: ServoUrl,
/// Various data needed to process job. /// Various data needed to process job.
@ -303,7 +303,7 @@ impl Job {
job_type: JobType, job_type: JobType,
scope_url: ServoUrl, scope_url: ServoUrl,
script_url: ServoUrl, script_url: ServoUrl,
client: IpcSender<JobResult>, client: GenericCallback<JobResult>,
referrer: ServoUrl, referrer: ServoUrl,
scope_things: Option<ScopeThings>, scope_things: Option<ScopeThings>,
) -> Job { ) -> Job {