mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Prevent moving CanGc values between threads/tasks (#33902)
* Make CanGc non-sendable, and add documentation. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Update CanGc usage to fix usages that were moved between threads/tasks. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
a58da5aa83
commit
b85093ad74
10 changed files with 69 additions and 89 deletions
|
@ -29,7 +29,7 @@ use crate::dom::serviceworkerglobalscope::{
|
|||
ServiceWorkerControlMsg, ServiceWorkerGlobalScope, ServiceWorkerScriptMsg,
|
||||
};
|
||||
use crate::dom::serviceworkerregistration::longest_prefix_match;
|
||||
use crate::script_runtime::{CanGc, ThreadSafeJSContext};
|
||||
use crate::script_runtime::ThreadSafeJSContext;
|
||||
|
||||
enum Message {
|
||||
FromResource(CustomResponseMediator),
|
||||
|
@ -250,12 +250,10 @@ impl ServiceWorkerManager {
|
|||
None
|
||||
}
|
||||
|
||||
fn handle_message(&mut self, can_gc: CanGc) {
|
||||
fn handle_message(&mut self) {
|
||||
while let Ok(message) = self.receive_message() {
|
||||
let should_continue = match message {
|
||||
Message::FromConstellation(msg) => {
|
||||
self.handle_message_from_constellation(*msg, can_gc)
|
||||
},
|
||||
Message::FromConstellation(msg) => self.handle_message_from_constellation(*msg),
|
||||
Message::FromResource(msg) => self.handle_message_from_resource(msg),
|
||||
};
|
||||
if !should_continue {
|
||||
|
@ -290,7 +288,7 @@ impl ServiceWorkerManager {
|
|||
}
|
||||
}
|
||||
|
||||
fn handle_message_from_constellation(&mut self, msg: ServiceWorkerMsg, can_gc: CanGc) -> bool {
|
||||
fn handle_message_from_constellation(&mut self, msg: ServiceWorkerMsg) -> bool {
|
||||
match msg {
|
||||
ServiceWorkerMsg::Timeout(_scope) => {
|
||||
// TODO: https://w3c.github.io/ServiceWorker/#terminate-service-worker
|
||||
|
@ -307,7 +305,7 @@ impl ServiceWorkerManager {
|
|||
self.handle_register_job(job);
|
||||
},
|
||||
JobType::Update => {
|
||||
self.handle_update_job(job, can_gc);
|
||||
self.handle_update_job(job);
|
||||
},
|
||||
JobType::Unregister => {
|
||||
// TODO: https://w3c.github.io/ServiceWorker/#unregister-algorithm
|
||||
|
@ -382,7 +380,7 @@ impl ServiceWorkerManager {
|
|||
}
|
||||
|
||||
/// <https://w3c.github.io/ServiceWorker/#update>
|
||||
fn handle_update_job(&mut self, job: Job, can_gc: CanGc) {
|
||||
fn handle_update_job(&mut self, job: Job) {
|
||||
// Step 1: Get registation
|
||||
if let Some(registration) = self.registrations.get_mut(&job.scope_url) {
|
||||
// Step 3.
|
||||
|
@ -405,12 +403,8 @@ impl ServiceWorkerManager {
|
|||
|
||||
// Very roughly steps 5 to 18.
|
||||
// TODO: implement all steps precisely.
|
||||
let (new_worker, join_handle, control_sender, context, closing) = update_serviceworker(
|
||||
self.own_sender.clone(),
|
||||
job.scope_url.clone(),
|
||||
scope_things,
|
||||
can_gc,
|
||||
);
|
||||
let (new_worker, join_handle, control_sender, context, closing) =
|
||||
update_serviceworker(self.own_sender.clone(), job.scope_url.clone(), scope_things);
|
||||
|
||||
// Since we've just started the worker thread, ensure we can shut it down later.
|
||||
registration.note_worker_thread(join_handle, control_sender, context, closing);
|
||||
|
@ -449,7 +443,6 @@ fn update_serviceworker(
|
|||
own_sender: IpcSender<ServiceWorkerMsg>,
|
||||
scope_url: ServoUrl,
|
||||
scope_things: ScopeThings,
|
||||
can_gc: CanGc,
|
||||
) -> (
|
||||
ServiceWorker,
|
||||
JoinHandle<()>,
|
||||
|
@ -475,7 +468,6 @@ fn update_serviceworker(
|
|||
control_receiver,
|
||||
context_sender,
|
||||
closing.clone(),
|
||||
can_gc,
|
||||
);
|
||||
|
||||
let context = context_receiver
|
||||
|
@ -512,7 +504,7 @@ impl ServiceWorkerManagerFactory for ServiceWorkerManager {
|
|||
resource_port,
|
||||
constellation_sender,
|
||||
)
|
||||
.handle_message(CanGc::note())
|
||||
.handle_message()
|
||||
};
|
||||
if thread::Builder::new()
|
||||
.name("SvcWorkerManager".to_owned())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue