Fix intermittent crashes in paint worklets (#30671)

Garbage collection means that the worklets might drop after the script
head has been cleaned up. The worklet now caches the thread pool in the
DOM object itself which should prevent it from needing to access script
thread TLS when being cleaned up. The value is stored as a OnceCell to
maintain the same lazy thread pool creation pattern as before.

Fixes #25838.
Fixes #25258.
This commit is contained in:
Martin Robinson 2023-11-02 15:55:50 +01:00 committed by GitHub
parent c2af95d2fc
commit f8ec3df495
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
76 changed files with 59 additions and 137 deletions

View file

@ -29,6 +29,7 @@
//! The `unsafe_no_jsmanaged_fields!()` macro adds an empty implementation of
//! `JSTraceable` to a datatype.
use std::cell::OnceCell;
use std::collections::hash_map::RandomState;
use std::collections::HashMap;
use std::fmt::Display;
@ -89,6 +90,12 @@ unsafe impl<T: CustomTraceable> CustomTraceable for DomRefCell<T> {
}
}
unsafe impl<T: JSTraceable> CustomTraceable for OnceCell<T> {
unsafe fn trace(&self, tracer: *mut JSTracer) {
self.get().map(|value| value.trace(tracer));
}
}
/// Wrapper type for nop traceble
///
/// SAFETY: Inner type must not impl JSTraceable