Truly independent web browser
LibJS+LibWeb: Trace lists of values only through GcRefCells
Shannon Booth49afda72a937
diff --git a/Libraries/LibJS/Rust/src/gc/root.rs b/Libraries/LibJS/Rust/src/gc/root.rsindex 2f6364360cb..a7b0af367d4 100644--- a/Libraries/LibJS/Rust/src/gc/root.rs+++ b/Libraries/LibJS/Rust/src/gc/root.rs@@ -8,6 +8,7 @@use core::cell::{OnceCell, RefCell};+use super::gc_ref_cell::GcRefCell;use super::visitor::{Trace, Visitor};use crate::interpreter::vm::Vm;@@ -80,14 +81,7 @@ impl<T: Trace + 'static> Drop for Root<'_, T> {/// element, so an empty one costs nothing.pub struct MarkedVec<'vm, T: Trace + Clone + 'static> {vm: &'vm Vm,- values: OnceCell<Root<'vm, RefCell<Vec<T>>>>,-}--// SAFETY: Forwards to the values; the borrow is never held across anything that collects.-unsafe impl<T: Trace> Trace for RefCell<Vec<T>> {- fn trace(&self, visitor: &mut Visitor) {- self.borrow().trace(visitor);- }+ values: OnceCell<Root<'vm, GcRefCell<Vec<T>>>>,}impl<'vm, T: Trace + Clone + 'static> MarkedVec<'vm, T> {@@ -106,9 +100,9 @@ impl<'vm, T: Trace + Clone + 'static> MarkedVec<'vm, T> {list}- fn rooted_values(&self) -> &RefCell<Vec<T>> {+ fn rooted_values(&self) -> &GcRefCell<Vec<T>> {self.values- .get_or_init(|| Root::new(self.vm, RefCell::new(Vec::new())))+ .get_or_init(|| Root::new(self.vm, GcRefCell::new(Vec::new()))).get()}diff --git a/Libraries/LibJS/Rust/src/interpreter/vm.rs b/Libraries/LibJS/Rust/src/interpreter/vm.rsindex 302516e8a4a..695d618dc44 100644--- a/Libraries/LibJS/Rust/src/interpreter/vm.rs+++ b/Libraries/LibJS/Rust/src/interpreter/vm.rs@@ -566,7 +566,7 @@ pub struct Vm {weak_containers: RefCell<Vec<WeakContainer>>,/// The finalization registries whose targets died in the collection in progress, which are handed to/// HostEnqueueFinalizationRegistryCleanupJob once it is over.- finalization_registries_with_dead_cells: RefCell<Vec<Gc<FinalizationRegistry>>>,+ finalization_registries_with_dead_cells: GcRefCell<Vec<Gc<FinalizationRegistry>>>,host_resize_array_buffer: Cell<HostResizeArrayBuffer>,host_grow_shared_array_buffer: Cell<HostGrowSharedArrayBuffer>,host_load_imported_module: Cell<HostLoadImportedModule>,@@ -712,7 +712,7 @@ impl Vm {job_queues: OnceCell::new(),run_executable_depth: Cell::new(0),weak_containers: RefCell::new(Vec::new()),- finalization_registries_with_dead_cells: RefCell::new(Vec::new()),+ finalization_registries_with_dead_cells: GcRefCell::new(Vec::new()),host_resize_array_buffer: Cell::new(default_host_resize_array_buffer),host_grow_shared_array_buffer: Cell::new(default_host_grow_shared_array_buffer),host_load_imported_module: Cell::new(Vm::load_imported_module),diff --git a/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/context.rs b/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/context.rsindex d1ff90f9593..ccbe9611a27 100644--- a/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/context.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/context.rs@@ -18,7 +18,7 @@ use libcompositing_rust::display_list::canvas_2d_recorder::{AlphaType, ColorSpacuse libcompositing_rust::display_list::commands::{Canvas2DShadow, CanvasId};use libgfx_rust::path::Path;use libgfx_rust::{AffineTransform, Color, CompositingAndBlendingOperator, FloatRect, IntRect, IntSize, WindingRule};-use libjs_rust::api::{ForeignCellSlot, Gc, Realm, Trace, Visitor, Vm};+use libjs_rust::api::{ForeignCellSlot, Gc, GcRefCell, Realm, Trace, Visitor, Vm};use super::canvas::{Canvas, FontMetricsSource, FontSelection, ResolvedFont, StyleValue, parse_color};use super::drawing_state::{CanvasColor, DrawingState, FillOrStrokeStyle};@@ -145,7 +145,7 @@ pub(crate) struct ContextState {#[gc(untraced)]context_lost: Cell<bool>,/// The drawing state stack, with the current drawing state last.- states: RefCell<Vec<DrawingState>>,+ states: GcRefCell<Vec<DrawingState>>,/// The current default path, in the coordinates of the current transformation matrix.#[gc(untraced)]path: RefCell<Path>,@@ -203,7 +203,7 @@ impl ContextState {size: Cell::new(parameters.size),origin_clean: Cell::new(true),context_lost: Cell::new(false),- states: RefCell::new(vec![DrawingState::default()]),+ states: GcRefCell::new(vec![DrawingState::default()]),path: RefCell::new(empty_path()),path_transform: Cell::new(AffineTransform::identity()),backing_storage: RefCell::new(None),diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/state.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/state.rsindex 65545d5a2fe..43d39757eee 100644--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/state.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/state.rs@@ -13,7 +13,7 @@ use core::marker::PhantomData;use core::ops::Deref;use ak::Utf16String;-use libjs_rust::api::{ForeignCellSlot, Gc, Realm, Trace, Visitor, Vm};+use libjs_rust::api::{ForeignCellSlot, Gc, GcRefCell, Realm, Trace, Visitor, Vm};use super::canvas::{Canvas, TexImageSourceFrame, TexImageSourceKind, read_tex_image_frame, read_tex_image_pixels, read_tex_image_source,@@ -173,7 +173,7 @@ pub(crate) struct ContextState {#[gc(untraced)]pub(crate) enabled_compressed_texture_formats: RefCell<Vec<u32>>,- pub(crate) enabled_extensions: RefCell<Vec<EnabledExtension>>,+ pub(crate) enabled_extensions: GcRefCell<Vec<EnabledExtension>>,#[gc(untraced)]pub(crate) enabled_empty_extensions: RefCell<Vec<EnabledEmptyExtension>>,@@ -234,7 +234,7 @@ impl ContextState {unpack_premultiply_alpha: Cell::new(false),unpack_colorspace_conversion: Cell::new(GL_BROWSER_DEFAULT_WEBGL),enabled_compressed_texture_formats: RefCell::new(Vec::new()),- enabled_extensions: RefCell::new(Vec::new()),+ enabled_extensions: GcRefCell::new(Vec::new()),enabled_empty_extensions: RefCell::new(Vec::new()),array_buffer_binding: Cell::new(None),element_array_buffer_binding: Cell::new(None),diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/web_gl_framebuffer.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/web_gl_framebuffer.rsindex 9c32092a7f1..502ef3b5864 100644--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/web_gl_framebuffer.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/web_gl_framebuffer.rs@@ -6,9 +6,7 @@//! https://registry.khronos.org/webgl/specs/latest/1.0/#5.5-use core::cell::RefCell;--use libjs_rust::api::{Gc, Realm, Trace, Vm};+use libjs_rust::api::{Gc, GcRefCell, Realm, Trace, Vm};use super::state::ContextState;use super::web_gl_object::WebGLObject;@@ -33,7 +31,7 @@ pub(crate) struct Attachment {#[gc(crate = libjs_rust)]pub(crate) struct WebGLFramebuffer {object: WebGLObject,- attachments: RefCell<Vec<Attachment>>,+ attachments: GcRefCell<Vec<Attachment>>,}impl Wrappable for WebGLFramebuffer {@@ -54,7 +52,7 @@ impl WebGLFramebuffer {vm,Self {object: WebGLObject::new(context, handle),- attachments: RefCell::new(Vec::new()),+ attachments: GcRefCell::new(Vec::new()),},)}