Truly independent web browser
LibWeb: Borrow tables and overlays through StyleRecordView references
Andreas Klinga3516e3c1478
diff --git a/Libraries/LibWeb/Rust/src/css/host_shared.rs b/Libraries/LibWeb/Rust/src/css/host_shared.rsindex c1f6cfd435c..bb84bbf609a 100644--- a/Libraries/LibWeb/Rust/src/css/host_shared.rs+++ b/Libraries/LibWeb/Rust/src/css/host_shared.rs@@ -86,6 +86,11 @@ impl<T> HostShared<T> {Self(pointer)}+ /// The address of `value`, or null.+ pub(crate) fn from_option(value: Option<&T>) -> Self {+ Self(value.map_or(std::ptr::null(), std::ptr::from_ref))+ }+pub(crate) const fn as_ptr(self) -> *const T {self.0}diff --git a/Libraries/LibWeb/Rust/src/css/style/bridge.rs b/Libraries/LibWeb/Rust/src/css/style/bridge.rsindex 86435ce21b4..1773c34d775 100644--- a/Libraries/LibWeb/Rust/src/css/style/bridge.rs+++ b/Libraries/LibWeb/Rust/src/css/style/bridge.rs@@ -2398,8 +2398,8 @@ pub unsafe fn style_record_view(engine: &mut StyleEngine, style_record: u64) ->Some(view) => FfiStyleRecordView {payloads: SharedPayload::as_pointer_slice(view.payloads).as_ptr(),base_payloads: SharedPayload::as_pointer_slice(view.base_payloads).as_ptr(),- longhand_table: view.longhand_table.cast().as_ptr(),- animated_overlay: view.animated_overlay.cast().as_ptr(),+ longhand_table: HostShared::from_option(view.longhand_table).cast().as_ptr(),+ animated_overlay: HostShared::from_option(view.animated_overlay).cast().as_ptr(),payload_count: view.payloads.len(),pseudo_element_styles: view.pseudo_element_styles,counter_style_environment_identity: view.counter_style_environment_identity,diff --git a/Libraries/LibWeb/Rust/src/css/style/child_reactions.rs b/Libraries/LibWeb/Rust/src/css/style/child_reactions.rsindex cf12ab1a1c6..7754223eddc 100644--- a/Libraries/LibWeb/Rust/src/css/style/child_reactions.rs+++ b/Libraries/LibWeb/Rust/src/css/style/child_reactions.rs@@ -240,10 +240,7 @@ impl StyleEngine {) else {return u32::MAX;};- // SAFETY: Live records retain their immutable base tables throughout this borrow.- let (Some(old_table), Some(new_table)) = (unsafe { old.longhand_table.as_ref() }, unsafe {- new.longhand_table.as_ref()- }) else {+ let (Some(old_table), Some(new_table)) = (old.longhand_table, new.longhand_table) else {return u32::MAX;};groups | old_table.non_inherited_inheritance_changes(new_table)diff --git a/Libraries/LibWeb/Rust/src/css/style/computed.rs b/Libraries/LibWeb/Rust/src/css/style/computed.rsindex f658e73078a..53604381a64 100644--- a/Libraries/LibWeb/Rust/src/css/style/computed.rs+++ b/Libraries/LibWeb/Rust/src/css/style/computed.rs@@ -175,9 +175,9 @@ pub(crate) struct StyleRecordView<'a> {pub payloads: &'a [SharedPayload],pub base_payloads: &'a [SharedPayload],/// Always the base record's table: animation overlays store no table entries.- pub longhand_table: HostShared<ComputedLonghandTable>,+ pub longhand_table: Option<&'a ComputedLonghandTable>,pub longhand_values: &'a [SharedPayload],- pub animated_overlay: HostShared<crate::css::animated_overlay::AnimatedOverlay>,+ pub animated_overlay: Option<&'a crate::css::animated_overlay::AnimatedOverlay>,pub pseudo_element_styles: u64,pub counter_style_environment_identity: u64,pub animation_overlay_identity: u64,@@ -186,11 +186,9 @@ pub(crate) struct StyleRecordView<'a> {impl StyleRecordView<'_> {pub(crate) fn longhand_table_for_partial_drive(&self) -> ComputedLonghandTable {- let source = unsafe {- self.longhand_table- .as_ref()- .expect("a retained style record must carry a longhand table")- };+ let source = self+ .longhand_table+ .expect("a retained style record must carry a longhand table");ComputedLonghandTable::copied_for_partial_drive(source)}}@@ -3058,7 +3056,7 @@ impl ComputedGroupSets {/// Read dependencies from a retained record even if its original node has been restyled.pub(crate) fn record_current_color_dependencies(&self, record: FinalStyleRecordID) -> Option<(u32, [u64; 6])> {let view = self.style_record_view(record.raw())?;- let table = unsafe { view.longhand_table.as_ref()? };+ let table = view.longhand_table?;Some((Self::specified_value_dependency_mask(table, retained_value_depends_on_current_color),Self::specified_value_dependency_properties(table, retained_value_depends_on_current_color)?,@@ -3273,7 +3271,7 @@ impl ComputedGroupSets {|| self.assigned_style_record(node).and_then(|record| self.style_record_view(record.raw()))- .is_some_and(|view| !view.animated_overlay.is_null())+ .is_some_and(|view| view.animated_overlay.is_some())}pub(super) fn node_inherited_group_swap_eligible(&self, node: StyleNodeID) -> bool {@@ -3786,7 +3784,7 @@ impl ComputedGroupSets {style_record,self.sets[record.groups].payloads.as_ref(),0_u64,- HostShared::null(),+ None,None,)} else {@@ -3796,7 +3794,7 @@ impl ComputedGroupSets {overlay.base_style_record,overlay.payloads.as_ref(),overlay.source_identity,- HostShared::new(std::ptr::from_ref(overlay.animated_overlay.as_ref())),+ Some(overlay.animated_overlay.as_ref()),Some(overlay.dependency_flags),)};@@ -3812,7 +3810,9 @@ impl ComputedGroupSets {let retained_longhand_table = record.longhand_table.and_then(|identity| self.computed_longhand_tables.get_index(identity.0 as usize));- let longhand_table = retained_longhand_table.map_or(HostShared::null(), |table| table.table);+ // SAFETY: A retained table holds a reference to its table for as long as the table set+ // holds the entry, which the view borrows.+ let longhand_table = retained_longhand_table.and_then(|table| unsafe { table.table.as_ref() });let longhand_values = retained_longhand_table.map_or(&[][..], RetainedLonghandTable::value_view);Some(StyleRecordView {payloads,@@ -4119,7 +4119,7 @@ mod tests {assert!(publication.transferred.table);let view = sets.style_record_view(publication.style_record_identity.raw()).unwrap();assert_eq!(view.payloads, payloads.as_slice());- assert_eq!(view.longhand_table, table);+ assert_eq!(HostShared::from_option(view.longhand_table), table);// Interning took the caller's reference instead of retaining a second one, so each// component still has exactly one owner: the catalog.for (index, &payload) in payloads.iter().enumerate() {@@ -4190,7 +4190,7 @@ mod tests {assert!(!republished.transferred.table);let view = sets.style_record_view(republished.style_record_identity.raw()).unwrap();assert_eq!(view.payloads, payloads.as_slice());- assert_eq!(view.longhand_table, table);+ assert_eq!(HostShared::from_option(view.longhand_table), table);assert_eq!(longhand_table_owners(table.as_ptr()), 1);// The catalog kept the components it already held, so the caller releases its own.for (index, &payload) in equal_payloads.iter().enumerate() {diff --git a/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rs b/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rsindex 0bf1b7a5d24..c4a95770ee8 100644--- a/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rs+++ b/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rs@@ -1193,7 +1193,7 @@ impl RetainedState {) -> Option<RegisteredValueContext> {let view = self.computed_group_sets.style_record_view(record.raw())?;let length = self.record_length_resolution_context(&view)?;- let table = unsafe { view.longhand_table.as_ref() }?;+ let table = view.longhand_table?;Some(RegisteredValueContext {length,color_scheme: u8::try_from(table.effective_color_scheme())diff --git a/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs b/Libraries/LibWeb/Rust/src/css/style/engine_sample.rsindex 65b4b1cbb79..769e1ad1f69 100644--- a/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs+++ b/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs@@ -20,7 +20,7 @@ use crate::css::computed_value_types::{};use crate::css::computed_values::InheritedBoxValues;use crate::css::css_pixels::CssPixels;-use crate::css::host_shared::SharedPayload;+use crate::css::host_shared::{HostShared, SharedPayload};use crate::css::property_metadata::property_id as prop;use crate::css::style_compute::{FfiAnimationLengthContexts, FfiEffectiveColorSchemeInput, FfiFontMetrics, FfiHostAnimationSample,@@ -389,8 +389,7 @@ impl super::StyleEngine {}let view = self.computed_group_sets.style_record_view(record).ok_or(NeedsHost)?;- // SAFETY: The record holds its table and overlay, and the host's install pins the record.- let mut overlay = unsafe { view.animated_overlay.as_ref() }.cloned().unwrap_or_default();+ let mut overlay = view.animated_overlay.cloned().unwrap_or_default();for &property in ended_properties.iter().filter(|property| !composed_properties.contains(property))@@ -510,11 +509,12 @@ impl super::StyleEngine {overlay: &AnimatedOverlay,bounds: super::style_invalidation::SampleBounds,) -> Result<super::layout_style::DerivedStyleRecord, NeedsHost> {- let table = self- .computed_group_sets- .style_record_view(record)- .ok_or(NeedsHost)?- .longhand_table;+ let table = HostShared::from_option(+ self.computed_group_sets+ .style_record_view(record)+ .ok_or(NeedsHost)?+ .longhand_table,+ );// What the host adjusts after it samples, and an animated color scheme, are the host's to compose.let facts = self.computed_group_sets.adjustment_facts(node);if overlay.entries().iter().any(|entry| {@@ -597,11 +597,12 @@ impl super::StyleEngine {transform_reference_box: Option<crate::css::css_pixels::CssPixelRect>,timeline_samples: super::animations::AnimationTimelineSamples<'_>,) -> Result<crate::css::style_compute::FfiHostAnimationSampleResult, NeedsHost> {- let table = self- .computed_group_sets- .style_record_view(record)- .ok_or(NeedsHost)?- .longhand_table;+ let table = HostShared::from_option(+ self.computed_group_sets+ .style_record_view(record)+ .ok_or(NeedsHost)?+ .longhand_table,+ );// A keyframe substitutes against the custom properties of the element and of its parent, as the host's// sample does, from the stores the engine holds for their environments throughout the sample.let inheritance_parent = self.tree.inheritance_parent(node);diff --git a/Libraries/LibWeb/Rust/src/css/style/hover_lane.rs b/Libraries/LibWeb/Rust/src/css/style/hover_lane.rsindex ec8c40f6bee..1947ecac6f6 100644--- a/Libraries/LibWeb/Rust/src/css/style/hover_lane.rs+++ b/Libraries/LibWeb/Rust/src/css/style/hover_lane.rs@@ -245,11 +245,10 @@ impl StyleEngine {/// Those of `properties` that a box with the style record `record` takes from its parent rather than declares, or/// none where the engine holds no such record.pub(crate) fn properties_inherited_by_record(&self, record: u64, properties: &[u16]) -> Option<SmallVec<[u16; 8]>> {- // SAFETY: A record's longhand table lives as long as the record, which the engine holds while it views it.let table = self.computed_group_sets.style_record_view(record)- .and_then(|view| unsafe { view.longhand_table.as_ref() })?;+ .and_then(|view| view.longhand_table)?;Some(properties.iter()@@ -782,8 +781,7 @@ impl StyleEngine {else {continue;};- // SAFETY: A live record's table lives as long as the record.- let Some(table) = (unsafe { view.longhand_table.as_ref() }) else {+ let Some(table) = view.longhand_table else {continue;};let inherits: SmallVec<[u16; 2]> = inheriteddiff --git a/Libraries/LibWeb/Rust/src/css/style/inputs.rs b/Libraries/LibWeb/Rust/src/css/style/inputs.rsindex 996ae07be12..66ec029e102 100644--- a/Libraries/LibWeb/Rust/src/css/style/inputs.rs+++ b/Libraries/LibWeb/Rust/src/css/style/inputs.rs@@ -997,8 +997,7 @@ impl RetainedState {) -> Option<&crate::css::computed_longhand_table::ComputedLonghandTable> {let style_record = computed::FinalStyleRecordID::from_raw(raw_style_record)?;let view = self.computed_group_sets.style_record_view(style_record.raw())?;- // SAFETY: The record is live, and shares its table for as long as it is.- unsafe { view.longhand_table.as_ref() }+ view.longhand_table}pub(super) fn published_style_record_view(diff --git a/Libraries/LibWeb/Rust/src/css/style/layout_style.rs b/Libraries/LibWeb/Rust/src/css/style/layout_style.rsindex 3ad25cf8009..1a0b1e288bc 100644--- a/Libraries/LibWeb/Rust/src/css/style/layout_style.rs+++ b/Libraries/LibWeb/Rust/src/css/style/layout_style.rs@@ -117,7 +117,7 @@ impl LayoutStyle {.expect("layout styles have every computed group");let mut style = Self {payloads,- longhand_table: view.longhand_table,+ longhand_table: HostShared::from_option(view.longhand_table),changed: false,};for (index, payload) in style.payloads.iter().copied().enumerate() {diff --git a/Libraries/LibWeb/Rust/src/css/style/publication.rs b/Libraries/LibWeb/Rust/src/css/style/publication.rsindex a310fcd95b5..0ae502227b8 100644--- a/Libraries/LibWeb/Rust/src/css/style/publication.rs+++ b/Libraries/LibWeb/Rust/src/css/style/publication.rs@@ -742,8 +742,7 @@ impl RetainedState {// needs their unadjusted values rebuilt before the host composes it again.|| (composes_animations&& self.computed_group_sets.style_record_view(old_style_record.raw()).is_some_and(|view| {- // SAFETY: The installed record keeps its overlay live.- unsafe { view.animated_overlay.as_ref() }.is_some_and(|overlay| {+ view.animated_overlay.is_some_and(|overlay| {overlay.entries().iter().any(|entry| {entry.post_compute_adjustment|| !property_computes_in_remaining_phase(entry.property)@@ -2089,7 +2088,7 @@ impl RetainedState {pub(super) fn record_declares_animations(&self, record: u64) -> bool {self.computed_group_sets.style_record_view(record)- .and_then(|view| unsafe { view.longhand_table.as_ref() })+ .and_then(|view| view.longhand_table).is_some_and(crate::css::style_compute::table_declares_css_animations)}@@ -2158,7 +2157,7 @@ impl RetainedState {pub(super) fn record_holds_an_animation_overlay(&self, record: computed::FinalStyleRecordID) -> bool {self.computed_group_sets.style_record_view(record.raw())- .is_none_or(|view| !view.animated_overlay.is_null())+ .is_none_or(|view| view.animated_overlay.is_some())}/// Whether a record's transition declarations name a longhand a change of which starts a@@ -2166,7 +2165,7 @@ impl RetainedState {pub(super) fn record_declares_transitions(&self, record: computed::FinalStyleRecordID) -> bool {self.computed_group_sets.style_record_view(record.raw())- .and_then(|view| unsafe { view.longhand_table.as_ref() })+ .and_then(|view| view.longhand_table).is_some_and(crate::css::style_compute::has_active_transition_properties)}@@ -2763,7 +2762,7 @@ impl RetainedState {state: CascadeStateID,) -> Option<ColdRecordParent> {let view = self.computed_group_sets.style_record_view(parent_record.raw())?;- if !view.animated_overlay.is_null() {+ if view.animated_overlay.is_some() {return None;}let dependency_flags = view.dependency_flags;@@ -2791,7 +2790,7 @@ impl RetainedState {while let Some(current) = ancestor {let record = self.computed_group_sets.assigned_style_record(current)?;let view = self.computed_group_sets.style_record_view(record.raw())?;- let table = unsafe { view.longhand_table.as_ref() }?;+ let table = view.longhand_table?;let display = crate::css::style_compute::effective_display(table, None);// C++ styles the children of a display:none element on demand, past the engine's// view of the parent, so no first record is computed under one.diff --git a/Libraries/LibWeb/Rust/src/css/style/publication/demand.rs b/Libraries/LibWeb/Rust/src/css/style/publication/demand.rsindex 7ade946df47..e314cc94052 100644--- a/Libraries/LibWeb/Rust/src/css/style/publication/demand.rs+++ b/Libraries/LibWeb/Rust/src/css/style/publication/demand.rs@@ -451,7 +451,7 @@ impl StyleEngine {.retained.computed_group_sets.style_record_view(element.raw())- .and_then(|view| unsafe { view.longhand_table.as_ref() })+ .and_then(|view| view.longhand_table).is_some_and(|table| table.display_is_list_item());// A highlight pseudo-element without rules of its own inherits its ancestor's.let generated = kinds_with_rules & (1 << kind) != 0diff --git a/Libraries/LibWeb/Rust/src/css/style/publication/drive.rs b/Libraries/LibWeb/Rust/src/css/style/publication/drive.rsindex 2c04d06c13a..4d78a909e08 100644--- a/Libraries/LibWeb/Rust/src/css/style/publication/drive.rs+++ b/Libraries/LibWeb/Rust/src/css/style/publication/drive.rs@@ -227,7 +227,7 @@ impl RetainedState {views[index].1.as_ref()- .and_then(|view| unsafe { view.longhand_table.as_ref() })+ .and_then(|view| view.longhand_table).map_or(std::ptr::null(), ComputedLonghandTable::raw_cascaded_font_size)};let default_size = CssPixels::from_integer(13).raw_value();@@ -396,15 +396,14 @@ impl RetainedState {debug_assert!(false, "the record being driven again has a view");return Ok(PartialDrive::DriverInputMoved);};- if !view.animated_overlay.is_null() {+ if view.animated_overlay.is_some() {self.counters.bump(Counter::EngineComputedRecordBailRecordOverlay);return Err(Unanswered::Refused);}// A record holding no table has no slots to copy the unselected properties from, and one// under display:none may have kept values its moved ancestors no longer pass on: the caller// drives either in full.- let Some(old_table) =- (unsafe { view.longhand_table.as_ref() }).filter(|_| view.dependency_flags & IN_DISPLAY_NONE_SUBTREE == 0)+ let Some(old_table) = (view.longhand_table).filter(|_| view.dependency_flags & IN_DISPLAY_NONE_SUBTREE == 0)else {return Ok(PartialDrive::DriverInputMoved);};@@ -420,9 +419,11 @@ impl RetainedState {return Err(Unanswered::Refused);};// A child inherits what the parent's animations sampled over its record.- Some(parent_snapshot_for_style_record(self, record.raw(), unsafe {- view.animated_overlay.as_ref()- }))+ Some(parent_snapshot_for_style_record(+ self,+ record.raw(),+ view.animated_overlay,+ ))}};let font = unsafe {@@ -606,9 +607,9 @@ impl RetainedState {while let Some(current) = ancestor&& let Some(record) = self.computed_group_sets.assigned_style_record(current)&& let Some(view) = self.computed_group_sets.style_record_view(record.raw())- && let Some(table) = unsafe { view.longhand_table.as_ref() }+ && let Some(table) = view.longhand_table{- let display = effective_display(table, unsafe { view.animated_overlay.as_ref() });+ let display = effective_display(table, view.animated_overlay);if !display.is_contents() {parent_display = Some(display);break;@@ -734,12 +735,12 @@ impl RetainedState {});let old_table = match &old_view {Some(view) => {- if !view.animated_overlay.is_null() {+ if view.animated_overlay.is_some() {self.counters.bump(Counter::EngineComputedRecordBailRecordOverlay);return Err(Unanswered::Refused);}// A record holding no table is driven from a fresh one, like a first record.- unsafe { view.longhand_table.as_ref() }+ view.longhand_table}None => None,};@@ -791,14 +792,14 @@ impl RetainedState {};let snapshot = match &parent_view {Some(parent_view) => {- let Some(parent_table) = (unsafe { parent_view.longhand_table.as_ref() }) else {+ let Some(parent_table) = parent_view.longhand_table else {debug_assert!(false, "an assigned parent record has a longhand table");self.counters.bump(Counter::EngineComputedRecordBailRecordParent);return Err(Unanswered::Refused);};Some(crate::css::style_compute::ParentSnapshot::new(parent_table,- unsafe { parent_view.animated_overlay.as_ref() },+ parent_view.animated_overlay,parent_font_metrics_depend_on_viewport_metrics,))}@@ -811,10 +812,10 @@ impl RetainedState {.retained_highlight_inheritance_parent_style_record(target.node(), target.pseudo_kind()).and_then(|record| self.computed_group_sets.style_record_view(record.raw())).and_then(|view| {- let table = unsafe { view.longhand_table.as_ref() }?;+ let table = view.longhand_table?;Some(crate::css::style_compute::ParentSnapshot::new(table,- unsafe { view.animated_overlay.as_ref() },+ view.animated_overlay,view.dependency_flags & (1 << 1) != 0,))});diff --git a/Libraries/LibWeb/Rust/src/css/style/publication/pseudo.rs b/Libraries/LibWeb/Rust/src/css/style/publication/pseudo.rsindex 466cd79986a..93917a03bb2 100644--- a/Libraries/LibWeb/Rust/src/css/style/publication/pseudo.rs+++ b/Libraries/LibWeb/Rust/src/css/style/publication/pseudo.rs@@ -77,7 +77,7 @@ impl RetainedState {.into_iter().filter_map(|kind| self.computed_group_sets.pseudo_style_record(node, kind)).filter_map(|record| self.computed_group_sets.style_record_view(record.raw()))- .filter_map(|view| unsafe { view.longhand_table.as_ref() })+ .filter_map(|view| view.longhand_table).any(|table| table.display_is_list_item());if !marker_is_live {required &= !(1_u64 << MARKER);@@ -178,7 +178,7 @@ impl RetainedState {let display_is_list_item = |engine: &Self, record: computed::FinalStyleRecordID| -> bool {let view = engine.computed_group_sets.style_record_view(record.raw());debug_assert!(view.is_some(), "an installed record has a view");- view.and_then(|view| unsafe { view.longhand_table.as_ref() })+ view.and_then(|view| view.longhand_table).is_none_or(|table| table.display_is_list_item())};let new_is_list_item = display_is_list_item(self, new_element_record);@@ -236,9 +236,7 @@ impl RetainedState {let Some(new_view) = self.computed_group_sets.style_record_view(new_element_record.raw()) else {return false;};- let (Some(old_table), Some(new_table)) = (unsafe { old_view.longhand_table.as_ref() }, unsafe {- new_view.longhand_table.as_ref()- }) else {+ let (Some(old_table), Some(new_table)) = (old_view.longhand_table, new_view.longhand_table) else {return false;};let old_display = crate::css::style_compute::effective_display(old_table, None);diff --git a/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs b/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rsindex 82acb81d25e..986c0e91c61 100644--- a/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs+++ b/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs@@ -645,8 +645,8 @@ fn property_invalidation(property: u16, old: ComputedValuesView<'_>, new: Computfn effective_value<'a>(view: &super::computed::StyleRecordView<'a>, property: u16) -> &'a StyleValueData {let index = usize::from(property - FIRST_LONGHAND_PROPERTY_ID);- let table = unsafe { view.longhand_table.deref() };- if let Some(entry) = unsafe { view.animated_overlay.as_ref() }.and_then(|overlay| overlay.get(property))+ let table = view.longhand_table.expect("a live record carries a longhand table");+ if let Some(entry) = view.animated_overlay.and_then(|overlay| overlay.get(property))&& overlay_wins(entry, table.is_important(property)){return entry.value();@@ -726,9 +726,10 @@ impl RetainedState {.style_record_view(old_style_record).unwrap_or_else(|| panic!("old style record {old_style_record:#x} is not live"));assert_eq!(payloads.len(), old_record.payloads.len());- // SAFETY: A live record's table lives as long as the record.- let table = unsafe { old_record.longhand_table.deref() };- let old_overlay = unsafe { old_record.animated_overlay.as_ref() };+ let table = old_record+ .longhand_table+ .expect("a live record carries a longhand table");+ let old_overlay = old_record.animated_overlay;let new_overlay = unsafe { animated_overlay.as_ref() };let old_values = ComputedValuesView::new(SharedPayload::as_pointer_slice(old_record.payloads));let new_values = ComputedValuesView::new(SharedPayload::as_pointer_slice(payloads));@@ -901,8 +902,12 @@ impl RetainedState {.unwrap_or_else(|| panic!("new style record {new_style_record:#x} is not live"));let old_values = ComputedValuesView::new(SharedPayload::as_pointer_slice(old_record.payloads));let new_values = ComputedValuesView::new(SharedPayload::as_pointer_slice(new_record.payloads));- let old_table = unsafe { old_record.longhand_table.deref() };- let new_table = unsafe { new_record.longhand_table.deref() };+ let old_table = old_record+ .longhand_table+ .expect("a live record carries a longhand table");+ let new_table = new_record+ .longhand_table+ .expect("a live record carries a longhand table");let all_groups_equal = old_record.payloads.iter()@@ -912,8 +917,8 @@ impl RetainedState {let can_skip = all_groups_equal&& std::ptr::eq(old_table, new_table)&& font_lists_equal- && old_record.animated_overlay.is_null()- && new_record.animated_overlay.is_null();+ && old_record.animated_overlay.is_none()+ && new_record.animated_overlay.is_none();let mut result = StyleInvalidation::default();if !font_lists_equal|| ((old_values.continue_() != crate::css::css_enums::continue_value::AUTO@@ -994,8 +999,8 @@ impl RetainedState {}result.merge(invalidation);}- let old_overlay = unsafe { old_record.animated_overlay.cast::<AnimatedOverlay>().as_ref() };- let new_overlay = unsafe { new_record.animated_overlay.cast::<AnimatedOverlay>().as_ref() };+ let old_overlay = old_record.animated_overlay;+ let new_overlay = new_record.animated_overlay;if old_overlay.is_some() || new_overlay.is_some() {for (index, effective_changed) in effective_changed.into_iter().enumerate() {if effective_changed {diff --git a/Libraries/LibWeb/Rust/src/css/style/transition_baselines.rs b/Libraries/LibWeb/Rust/src/css/style/transition_baselines.rsindex ed24f666fd9..05408b146e7 100644--- a/Libraries/LibWeb/Rust/src/css/style/transition_baselines.rs+++ b/Libraries/LibWeb/Rust/src/css/style/transition_baselines.rs@@ -129,8 +129,8 @@ impl RetainedState {while let Some(current) = ancestor {let record = self.computed_group_sets.assigned_style_record(current)?;let view = self.computed_group_sets.style_record_view(record.raw())?;- let ancestor_table = unsafe { view.longhand_table.as_ref() }?;- if let Some(entry) = unsafe { view.animated_overlay.as_ref() }.and_then(|overlay| overlay.get(property)) {+ let ancestor_table = view.longhand_table?;+ if let Some(entry) = view.animated_overlay.and_then(|overlay| overlay.get(property)) {if !entry.result_of_transition {return Some(InheritedAnimatedValue::Animation(entry));}diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rsindex 8359e0d5e7b..0856c0b6110 100644--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs@@ -3078,15 +3078,13 @@ pub(crate) fn parent_snapshot_for_style_record<'a>(let view = style_engine.style_record_view(style_record).expect("the inheritance parent style record must remain live during computation");- let table = unsafe {- view.longhand_table- .as_ref()- .expect("the inheritance parent style record must carry a longhand table")- };+ let table = view+ .longhand_table+ .expect("the inheritance parent style record must carry a longhand table");ParentSnapshot {table,inherited_value_overlay: animated_overlay,- stored_animated_overlay: unsafe { view.animated_overlay.as_ref() },+ stored_animated_overlay: view.animated_overlay,font_metrics_depend_on_viewport_metrics: view.dependency_flags & (1 << 1) != 0,highlight_colors_authored: view.dependency_flags & HIGHLIGHT_COLORS_AUTHORED != 0,highlight_color_is_current_color: view.dependency_flags & HIGHLIGHT_COLOR_IS_CURRENT_COLOR != 0,@@ -4790,7 +4788,7 @@ fn settled_animation_plan(record: u64,) -> Option<(smallvec::SmallVec<[FfiComputedAnimation; 1]>, bool)> {let view = style_engine.style_record_view(record)?;- let table = unsafe { view.longhand_table.as_ref() }?;+ let table = view.longhand_table?;let declaration_scope = style_engine.animation_name_declaration_scope_of(node, pseudo_kind)?;let existing_animations = style_engine.element_css_defined_animations(node, animation_slot(pseudo_kind));let element_tree_scope = style_engine.tree().tree_scope(node);diff --git a/Libraries/LibWeb/Rust/src/css/transition.rs b/Libraries/LibWeb/Rust/src/css/transition.rsindex 2b5bd246d76..a945268904e 100644--- a/Libraries/LibWeb/Rust/src/css/transition.rs+++ b/Libraries/LibWeb/Rust/src/css/transition.rs@@ -370,8 +370,7 @@ pub(crate) fn records_compute_differently() -> bool {let value = |record| {let view = engine.style_record_view(record)?;- // SAFETY: A live record's table lives as long as the record.- let table = unsafe { view.longhand_table.as_ref() }?;+ let table = view.longhand_table?;Some(table.get(property_id)?.pointer())};match (value(first), value(second)) {@@ -461,10 +460,9 @@ impl TransitionDecision {reference_box: Option<crate::css::css_pixels::CssPixelRect>,existing: &[FfiExistingTransition],) -> Vec<FfiTransitionAction> {- // SAFETY: A live record's table lives as long as the record.let Some(after_table) = engine.style_record_view(self.after)- .and_then(|after| unsafe { after.longhand_table.as_ref() })+ .and_then(|after| after.longhand_table)else {debug_assert!(false, "the records of a transition step carry longhand tables");return Vec::new();@@ -507,15 +505,12 @@ impl TransitionDecision {debug_assert!(false, "the records a transition step decides over remain live");return Vec::new();};- // SAFETY: A live record's table and overlay live as long as the record.- let (Some(before_table), before_overlay, Some(after_table), record_after_overlay) = (unsafe {- (- before.longhand_table.as_ref(),- before.animated_overlay.as_ref(),- after.longhand_table.as_ref(),- after.animated_overlay.as_ref(),- )- }) else {+ let (Some(before_table), before_overlay, Some(after_table), record_after_overlay) = (+ before.longhand_table,+ before.animated_overlay,+ after.longhand_table,+ after.animated_overlay,+ ) else {debug_assert!(false, "the records of a transition step carry longhand tables");return Vec::new();};@@ -787,12 +782,11 @@ impl RowTransitions {let after = row.new_style_record;let before_view = engine.style_record_view(before).ok_or("a record that is gone")?;let after_view = engine.style_record_view(after).ok_or("a record that is gone")?;- // SAFETY: A live record's table lives as long as the record.- let after_table = unsafe { after_view.longhand_table.as_ref() }.ok_or("a record without a table")?;+ let after_table = after_view.longhand_table.ok_or("a record without a table")?;if before_view.dependency_flags & crate::css::computed_longhand_table::IN_DISPLAY_NONE_SUBTREE != 0 {return Err("a style under display: none");}- if !after_view.animated_overlay.is_null() {+ if after_view.animated_overlay.is_some() {return Err("an animated record");}// A declaration whose delay and duration are each the single value 0s starts nothing, so it matters only to an