Truly independent web browser
LibWeb: Drop unsafe from host helpers that only take a DocumentHost
Andreas Kling67e228b419d8
diff --git a/Libraries/LibWeb/Rust/src/css/rule.rs b/Libraries/LibWeb/Rust/src/css/rule.rsindex 7f9497be0df..f45e9bc8a4a 100644--- a/Libraries/LibWeb/Rust/src/css/rule.rs+++ b/Libraries/LibWeb/Rust/src/css/rule.rs@@ -282,10 +282,10 @@ impl NativeRule {unreachable!()};let source = style.selectors();- unsafe { self.cached_matching_selectors(source, parent_kind, parents) }+ self.cached_matching_selectors(source, parent_kind, parents)}- unsafe fn cached_matching_selectors(+ fn cached_matching_selectors(&self,source: Arc<RustParsedSelectorList>,parent_kind: StyleNestingParent,@@ -344,10 +344,10 @@ impl NativeRule {} else {None};- Some(unsafe { self.cached_matching_selectors(source, parent_kind, parents) })+ Some(self.cached_matching_selectors(source, parent_kind, parents))}- pub(crate) unsafe fn scope_end_selectors(&self) -> Option<Rc<RustParsedSelectorList>> {+ pub(crate) fn scope_end_selectors(&self) -> Option<Rc<RustParsedSelectorList>> {let source = self.scope().end.as_ref()?;if let Some(cached) = self.scope_end_selectors.borrow().as_ref() {return Some(cached.clone());@@ -875,12 +875,9 @@ pub unsafe extern "C" fn rust_rule_scope_start_selectors(rule: &NativeRule) -> *.unwrap_or(std::ptr::null_mut())}-/// # Safety-/// Call for a scope rule or scoped import on the document thread. A non-null result-/// must be destroyed with `rust_parsed_selector_list_destroy`; null means the end is omitted.#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_rule_scope_end_selectors(rule: &NativeRule) -> *mut c_void {- unsafe { rule.scope_end_selectors() }+pub extern "C" fn rust_rule_scope_end_selectors(rule: &NativeRule) -> *mut c_void {+ rule.scope_end_selectors().map(|selectors| {Box::into_raw(Box::new(RustParsedSelectorList {selectors: selectors.selectors.clone(),diff --git a/Libraries/LibWeb/Rust/src/css/rule/compilation.rs b/Libraries/LibWeb/Rust/src/css/rule/compilation.rsindex 855a98a4b44..f7d75568152 100644--- a/Libraries/LibWeb/Rust/src/css/rule/compilation.rs+++ b/Libraries/LibWeb/Rust/src/css/rule/compilation.rs@@ -136,7 +136,7 @@ impl CompilationContext {});}if publication.is_some() {- context.selectors = unsafe { self.selectors.within(rule, matching, implicit_root) };+ context.selectors = self.selectors.within(rule, matching, implicit_root);}if let Some(container) = rule.container() {context.containers.push(std::sync::Arc::as_ptr(container));@@ -169,7 +169,7 @@ unsafe fn visit_rule(callbacks: &NativeCompilationCallbacks,publication: Option<&Publisher<'_>>,) {- let selectors = publication.and_then(|_| unsafe { context.selectors.matching_selectors(rule) });+ let selectors = publication.and_then(|_| context.selectors.matching_selectors(rule));let result = publication.map_or_else(NativeCompilationResult::default, |publication| {publication.compile(rule, sheet, context, selectors.as_ref())});@@ -378,7 +378,7 @@ pub unsafe extern "C" fn rust_style_sheet_replace_selectors(let mut pending = vec![(target, context)];let mut affected = Vec::new();while let Some((rule, context)) = pending.pop() {- let selectors = unsafe { context.selectors.matching_selectors(RuleRef::Materialized(&rule)) };+ let selectors = context.selectors.matching_selectors(RuleRef::Materialized(&rule));if has_compiled_children(RuleRef::Materialized(&rule))&& let Some(children) = &rule.children{@@ -1533,11 +1533,11 @@ mod tests {fn visit(rule: &NativeRule, inputs: &SelectorInputs, bound: &mut Vec<std::sync::Arc<RustParsedSelectorList>>) {// The traversal must supply nesting even when no parent owner can be consulted.*rule.parent.borrow_mut() = Default::default();- let selectors = unsafe { inputs.matching_selectors(RuleRef::Materialized(rule)) };+ let selectors = inputs.matching_selectors(RuleRef::Materialized(rule));if let Some(selectors) = &selectors {bound.push(selectors.clone());}- let nested = unsafe { inputs.within(RuleRef::Materialized(rule), selectors, u32::MAX) };+ let nested = inputs.within(RuleRef::Materialized(rule), selectors, u32::MAX);if let Some(children) = &rule.children {for child in children.materialized_rules().iter() {visit(child, &nested, bound);diff --git a/Libraries/LibWeb/Rust/src/css/rule/compilation/publication.rs b/Libraries/LibWeb/Rust/src/css/rule/compilation/publication.rsindex 810a1caab77..168532e685c 100644--- a/Libraries/LibWeb/Rust/src/css/rule/compilation/publication.rs+++ b/Libraries/LibWeb/Rust/src/css/rule/compilation/publication.rs@@ -58,11 +58,7 @@ impl Default for SelectorInputs {}impl SelectorInputs {- unsafe fn bind(- &self,- source: &RustParsedSelectorList,- parent_kind: StyleNestingParent,- ) -> Arc<RustParsedSelectorList> {+ fn bind(&self, source: &RustParsedSelectorList, parent_kind: StyleNestingParent) -> Arc<RustParsedSelectorList> {let empty: crate::css::selector::SelectorList = Box::new([]);let parents = if parent_kind == StyleNestingParent::Style {self.parents.as_ref().map_or(&empty, |parents| &parents.selectors)@@ -75,9 +71,9 @@ impl SelectorInputs {})}- pub(super) unsafe fn matching_selectors(&self, rule: RuleRef<'_>) -> Option<Arc<RustParsedSelectorList>> {+ pub(super) fn matching_selectors(&self, rule: RuleRef<'_>) -> Option<Arc<RustParsedSelectorList>> {match rule.rule_type() {- NativeRuleType::Style => Some(unsafe { self.bind(&rule.selectors().unwrap(), self.parent_kind) }),+ NativeRuleType::Style => Some(self.bind(&rule.selectors().unwrap(), self.parent_kind)),NativeRuleType::NestedDeclarations => {if let Some(parents) = &self.parents {return Some(parents.clone());@@ -91,7 +87,7 @@ impl SelectorInputs {}}- pub(super) unsafe fn within(+ pub(super) fn within(&self,rule: RuleRef<'_>,matching: Option<Arc<RustParsedSelectorList>>,@@ -100,7 +96,7 @@ impl SelectorInputs {let mut nested = self.clone();nested.immediate_parent_kind = StyleNestingParent::None;if rule.rule_type() == NativeRuleType::Style {- nested.parents = matching.or_else(|| unsafe { self.matching_selectors(rule) });+ nested.parents = matching.or_else(|| self.matching_selectors(rule));nested.parent_kind = StyleNestingParent::Style;nested.immediate_parent_kind = StyleNestingParent::Style;}@@ -110,10 +106,7 @@ impl SelectorInputs {} else {self.immediate_parent_kind};- let start = scope- .start- .as_ref()- .map(|start| unsafe { self.bind(start, parent_kind) });+ let start = scope.start.as_ref().map(|start| self.bind(start, parent_kind));let end = scope.end.as_ref().map(|end| RustParsedSelectorList {selectors: adapt_scope_end_selector_list(&end.selectors),});diff --git a/Libraries/LibWeb/Rust/src/css/style/bridge.rs b/Libraries/LibWeb/Rust/src/css/style/bridge.rsindex 1326bb6608e..473bca6bab1 100644--- a/Libraries/LibWeb/Rust/src/css/style/bridge.rs+++ b/Libraries/LibWeb/Rust/src/css/style/bridge.rs@@ -1228,7 +1228,7 @@ pub unsafe extern "C" fn style_engine_set_tree_scope_animation_keyframes(row,};// SAFETY: Guaranteed by the caller.- unsafe { super::engine_calls::queue(host, write) };+ super::engine_calls::queue(host, write);}/// Keeps the store behind an environment an element holds, and what a child inherits of it,@@ -1257,7 +1257,7 @@ pub unsafe extern "C" fn style_engine_note_custom_property_environment(inheritable_store: retain(inheritable_store),};// SAFETY: Guaranteed by the caller.- unsafe { super::engine_calls::queue(host, write) };+ super::engine_calls::queue(host, write);}/// [`style_engine_note_custom_property_environment`] on `engine`.@@ -1737,7 +1737,7 @@ pub unsafe extern "C" fn style_engine_set_element_inline_style_properties(let data = unsafe { block.cast::<DeclarationBlock>().as_ref() }.map(DeclarationBlock::data);let has_transitions = data.as_ref().is_some_and(|data| declares_transitions(&data.properties));// SAFETY: Guaranteed by the caller.- unsafe { super::engine_calls::queue(host, super::engine_calls::EngineWrite::InlineStyle { node, data }) };+ super::engine_calls::queue(host, super::engine_calls::EngineWrite::InlineStyle { node, data });has_transitions}@@ -1773,7 +1773,7 @@ pub unsafe extern "C" fn style_engine_set_element_presentational_hint_properties}let has_transitions = declares_transitions(&hints.properties);// SAFETY: Guaranteed by the caller.- unsafe {+ {super::engine_calls::queue(host,super::engine_calls::EngineWrite::PresentationalHints {diff --git a/Libraries/LibWeb/Rust/src/css/style/engine_calls.rs b/Libraries/LibWeb/Rust/src/css/style/engine_calls.rsindex b2eb6c735e2..c422f61fbe9 100644--- a/Libraries/LibWeb/Rust/src/css/style/engine_calls.rs+++ b/Libraries/LibWeb/Rust/src/css/style/engine_calls.rs@@ -349,11 +349,7 @@ fn element_parts(node: u32, names: &[u32], hosts: &[u32]) -> Option<(StyleNodeID}/// Queues `write` for the render state of `host`'s document.-///-/// # Safety-///-/// `host` must be a live document host, on the document's thread.-pub(super) unsafe fn queue(host: &DocumentHost, write: EngineWrite) {+pub(super) fn queue(host: &DocumentHost, write: EngineWrite) {host.queue_change(ArenaChange::Engine(write));}@@ -665,12 +661,8 @@ pub unsafe extern "C" fn style_engine_viewport_dependent_nodes(/// Has the engine keep the random base values of the keys that name the element whose style node `node` was, as the/// element loses it, in a slot the element holds, or answers null where no element has any.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn style_engine_park_element_random_base_values(host: &DocumentHost, node: u32) -> *const c_void {+pub extern "C" fn style_engine_park_element_random_base_values(host: &DocumentHost, node: u32) -> *const c_void {let Some(node) = StyleNodeID::from_raw(node) else {return std::ptr::null();};@@ -679,7 +671,7 @@ pub unsafe extern "C" fn style_engine_park_element_random_base_values(host: &Doc}let slot = ParkedBaseValues::default();// SAFETY: Guaranteed by the caller.- unsafe {+ {queue(host,EngineWrite::ParkRandomBaseValues {diff --git a/Libraries/LibWeb/Rust/src/css/style/tests.rs b/Libraries/LibWeb/Rust/src/css/style/tests.rsindex 57398f9260c..b19af2eb745 100644--- a/Libraries/LibWeb/Rust/src/css/style/tests.rs+++ b/Libraries/LibWeb/Rust/src/css/style/tests.rs@@ -130,7 +130,7 @@ fn native_scope_publication_outlives_the_rule_graph() {NativeRuleType::Scope | NativeRuleType::Import) {let start = unsafe { rule.scope_start_selectors() };- let end = unsafe { rule.scope_end_selectors() };+ let end = rule.scope_end_selectors();scope.push(start.as_deref(), end.as_deref(), nodes[0].raw());}let children = unsafe { rust_rule_children(&rule).as_ref() };diff --git a/Libraries/LibWeb/Rust/src/css/style_sheet.rs b/Libraries/LibWeb/Rust/src/css/style_sheet.rsindex 316f6f10766..ff447ec4690 100644--- a/Libraries/LibWeb/Rust/src/css/style_sheet.rs+++ b/Libraries/LibWeb/Rust/src/css/style_sheet.rs@@ -527,7 +527,7 @@ pub unsafe extern "C" fn rust_style_sheet_evaluate_media_queries(conditions.push((identity, holds));});// SAFETY: Guaranteed by the caller.- unsafe { write_rule_conditions(host, conditions) };+ write_rule_conditions(host, conditions);result}@@ -547,14 +547,11 @@ pub unsafe extern "C" fn rust_style_sheet_publish_conditions(conditions.push((identity, holds));});// SAFETY: Guaranteed by the caller.- unsafe { write_rule_conditions(host, conditions) };+ write_rule_conditions(host, conditions);}/// Writes whether the conditions of each rule hold, for the rules the engine has.-///-/// # Safety-/// `host` must be a live document host, on its document's thread.-unsafe fn write_rule_conditions(host: &crate::render_state::DocumentHost, conditions: Vec<(u64, bool)>) {+fn write_rule_conditions(host: &crate::render_state::DocumentHost, conditions: Vec<(u64, bool)>) {if conditions.is_empty() {return;}diff --git a/Libraries/LibWeb/Rust/src/layout/box_removal.rs b/Libraries/LibWeb/Rust/src/layout/box_removal.rsindex fc0f8a6b09e..e57431a19e0 100644--- a/Libraries/LibWeb/Rust/src/layout/box_removal.rs+++ b/Libraries/LibWeb/Rust/src/layout/box_removal.rs@@ -306,7 +306,7 @@ pub unsafe extern "C" fn render_state_can_detach_box_in_place(return false;};// SAFETY: Guaranteed by the caller.- unsafe {+ {super::shell_reads::read_arena(host, read, (parent, child, facts), |arena, (parent, child, facts)| {let (parent_row, child_row) = (arena.bound_row(parent), arena.bound_row(child));!parent_row.is_invalid()diff --git a/Libraries/LibWeb/Rust/src/layout/layout_changes.rs b/Libraries/LibWeb/Rust/src/layout/layout_changes.rsindex b5350313940..20bca46a932 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_changes.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_changes.rs@@ -435,25 +435,18 @@ pub(crate) fn write(wait: impl RenderWait, host: &DocumentHost, write: LayoutWri}/// Queues `change` for the render state of `host`'s document.-///-/// # Safety-///-/// `host` must come from `document_host_create` and not be destroyed yet, on the document's thread.-pub(crate) unsafe fn queue(host: &DocumentHost, change: LayoutChange) {+pub(crate) fn queue(host: &DocumentHost, change: LayoutChange) {host.queue_change(ArenaChange::Layout(change));}-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_set_needs_layout_update(+pub extern "C" fn render_state_set_needs_layout_update(host: &DocumentHost,node: NodeSlotId,propagate_through_ancestors: bool,) {// SAFETY: Guaranteed by the caller.- unsafe {+ {queue(host,LayoutChange::SetNeedsLayoutUpdate {@@ -485,34 +478,25 @@ pub unsafe extern "C" fn render_state_detach_remaining_rows_for_removal(host.queue_change(ArenaChange::DetachForRemoval(style_nodes.into()));}-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_set_needs_full_layout_tree_update(host: &DocumentHost) {+pub extern "C" fn render_state_set_needs_full_layout_tree_update(host: &DocumentHost) {// SAFETY: Guaranteed by the caller.- unsafe { queue(host, LayoutChange::SetNeedsFullLayoutTreeUpdate) };+ queue(host, LayoutChange::SetNeedsFullLayoutTreeUpdate);}-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_reset_cached_intrinsic_sizes_of_self_and_ancestors(+pub extern "C" fn render_state_reset_cached_intrinsic_sizes_of_self_and_ancestors(host: &DocumentHost,node: NodeSlotId,) {// SAFETY: Guaranteed by the caller.- unsafe { queue(host, LayoutChange::ResetCachedIntrinsicSizesOfSelfAndAncestors { node }) };+ queue(host, LayoutChange::ResetCachedIntrinsicSizesOfSelfAndAncestors { node });}-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_record_partial_relayout_escape(host: &DocumentHost) {+pub extern "C" fn render_state_record_partial_relayout_escape(host: &DocumentHost) {// SAFETY: Guaranteed by the caller.- unsafe { queue(host, LayoutChange::RecordPartialRelayoutEscape) };+ queue(host, LayoutChange::RecordPartialRelayoutEscape);}/// # Safety@@ -540,7 +524,7 @@ pub unsafe extern "C" fn render_state_style_node_changed(generated_for,};// SAFETY: Guaranteed by the caller.- unsafe { queue(host, change) };+ queue(host, change);if let Some(new) = new {host.write_marks(super::tree_update_marks::LayoutTreeUpdateMarkWrite::Clear(new));}@@ -570,31 +554,21 @@ pub unsafe extern "C" fn render_state_set_anchor_name_elements(elements: elements.iter().copied().filter_map(StyleNodeID::from_raw).collect(),};// SAFETY: Guaranteed by the caller.- unsafe { queue(host, change) };+ queue(host, change);}-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_set_element_scroll_offset(- host: &DocumentHost,- element: u32,- offset: FfiCssPixelPoint,-) {+pub extern "C" fn render_state_set_element_scroll_offset(host: &DocumentHost, element: u32, offset: FfiCssPixelPoint) {let Some(element) = StyleNodeID::from_raw(element) else {return;};let offset = offset.into();// SAFETY: Guaranteed by the caller.- unsafe { queue(host, LayoutChange::SetElementScrollOffset { element, offset }) };+ queue(host, LayoutChange::SetElementScrollOffset { element, offset });}-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_set_pseudo_element_scroll_offset(+pub extern "C" fn render_state_set_pseudo_element_scroll_offset(host: &DocumentHost,generator: u32,generated_for: u8,@@ -609,23 +583,16 @@ pub unsafe extern "C" fn render_state_set_pseudo_element_scroll_offset(offset: offset.into(),};// SAFETY: Guaranteed by the caller.- unsafe { queue(host, change) };+ queue(host, change);}-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_set_identity_in_focused_text_control(- host: &DocumentHost,- node: u32,- value: bool,-) {+pub extern "C" fn render_state_set_identity_in_focused_text_control(host: &DocumentHost, node: u32, value: bool) {let Some(node) = StyleNodeID::from_raw(node) else {return;};// SAFETY: Guaranteed by the caller.- unsafe { queue(host, LayoutChange::SetIdentityInFocusedTextControl { node, value }) };+ queue(host, LayoutChange::SetIdentityInFocusedTextControl { node, value });}/// Publishes what the SVG element `element` names parses to. A `<polyline>` or `<polygon>` passes its `points` list@@ -657,18 +624,14 @@ pub unsafe extern "C" fn render_state_set_svg_attribute_facts(points: points.into(),};// SAFETY: Guaranteed by the caller.- unsafe { queue(host, change) };+ queue(host, change);}/// Publishes only the resources a graphics element's style names, leaving what its attributes parse to alone. Style/// records are replaced far more often than an SVG attribute changes, and parsing every presentation attribute again/// to carry four names would make every style change pay for it.-///-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_set_svg_style_references(+pub extern "C" fn render_state_set_svg_style_references(host: &DocumentHost,element: u32,mask: u32,@@ -684,30 +647,19 @@ pub unsafe extern "C" fn render_state_set_svg_style_references(references: [mask, clip_path, fill, stroke],};// SAFETY: Guaranteed by the caller.- unsafe { queue(host, change) };+ queue(host, change);}-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_set_document_is_decoded_svg(host: &DocumentHost, is_decoded_svg: bool) {+pub extern "C" fn render_state_set_document_is_decoded_svg(host: &DocumentHost, is_decoded_svg: bool) {// SAFETY: Guaranteed by the caller.- unsafe { queue(host, LayoutChange::SetDocumentIsDecodedSvg(is_decoded_svg)) };+ queue(host, LayoutChange::SetDocumentIsDecodedSvg(is_decoded_svg));}-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_set_node_flag(- host: &DocumentHost,- node: NodeSlotId,- flag: NodeFlag,- value: bool,-) {+pub extern "C" fn render_state_set_node_flag(host: &DocumentHost, node: NodeSlotId, flag: NodeFlag, value: bool) {// SAFETY: Guaranteed by the caller.- unsafe { queue(host, LayoutChange::SetNodeFlag { node, flag, value }) };+ queue(host, LayoutChange::SetNodeFlag { node, flag, value });}/// # Safety@@ -724,25 +676,19 @@ pub unsafe extern "C" fn render_state_set_owned_image_natural_size(natural_size: natural_size.into(),};// SAFETY: Guaranteed by the caller.- unsafe { queue(host, change) };+ queue(host, change);}-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_invalidate_searchable_text(host: &DocumentHost) {+pub extern "C" fn render_state_invalidate_searchable_text(host: &DocumentHost) {// SAFETY: Guaranteed by the caller.- unsafe { queue(host, LayoutChange::InvalidateSearchableText) };+ queue(host, LayoutChange::InvalidateSearchableText);}-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_restamp_table_spans(host: &DocumentHost, node: NodeSlotId) {+pub extern "C" fn render_state_restamp_table_spans(host: &DocumentHost, node: NodeSlotId) {// SAFETY: Guaranteed by the caller.- unsafe { queue(host, LayoutChange::RestampTableSpans { node }) };+ queue(host, LayoutChange::RestampTableSpans { node });}#[cfg(test)]diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rsindex fb4496e708e..4f914910ca4 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs@@ -5565,12 +5565,8 @@ pub(crate) struct NodeAllocation {/// Whether the counter styles the generated content of the element `style_node` names, or of its/// pseudo-element `generated_for`, names now differ from the ones its box was built with.-///-/// # Safety-///-/// The arena must remain valid for the duration of the call.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_content_counter_styles_changed(+pub extern "C" fn render_state_content_counter_styles_changed(host: &DocumentHost,read: &crate::render_state::BegunRead,style_node: u32,@@ -5580,11 +5576,9 @@ pub unsafe extern "C" fn render_state_content_counter_styles_changed(return false;};// SAFETY: Guaranteed by the caller.- unsafe {- read_arena(host, read, owner, |arena, owner| {- super::generated_content::content_counter_styles_changed(arena, owner)- })- }+ read_arena(host, read, owner, |arena, owner| {+ super::generated_content::content_counter_styles_changed(arena, owner)+ })}fn counter_owner(style_node: u32, generated_for: u8) -> Option<super::counters::CounterOwner> {@@ -5607,14 +5601,14 @@ pub unsafe extern "C" fn style_resets_forward_list_item_counter(payloads: *const}#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_set_node_needs_compositor_animation_frame(+pub extern "C" fn render_state_set_node_needs_compositor_animation_frame(host: &DocumentHost,id: NodeSlotId,kind: super::node_data::CompositorAnimationFrameKind,value: bool,) {// SAFETY: Guaranteed by the caller.- unsafe {+ {queue(host,LayoutChange::SetNodeNeedsCompositorAnimationFrame { node: id, kind, value },@@ -5623,18 +5617,10 @@ pub unsafe extern "C" fn render_state_set_node_needs_compositor_animation_frame(}/// What the row is scrolled to, as the document published it.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_row_scroll_offset(- host: &DocumentHost,- slot: NodeSlotId,- out: &mut FfiCssPixelPoint,-) {+pub extern "C" fn render_state_row_scroll_offset(host: &DocumentHost, slot: NodeSlotId, out: &mut FfiCssPixelPoint) {// SAFETY: Guaranteed by the caller.- *out = unsafe {+ *out = {read_arena(host, node_read(), slot, |arena, slot| {arena.row_scroll_offset(slot).into()})@@ -5654,7 +5640,7 @@ pub unsafe extern "C" fn render_state_set_node_style(payloads: StylePayloadsRef::new(payloads.cast()),};// SAFETY: Guaranteed by the caller.- unsafe { queue(host, change) };+ queue(host, change);}/// Prepares `row` for leaving the layout tree. A detached box is read until its row is freed, so@@ -5701,12 +5687,8 @@ pub(crate) fn prepare_subtree_for_detach(host_calls: HostCalls<'_>, arena: &Layo/// bound to, or of the box of its pseudo-element `generated_for`, so that the box keeps its style/// readable once the node has left the document. The row is found by identity, so this makes no/// shell.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_pin_bound_box_style_record_for_detachment(+pub extern "C" fn render_state_pin_bound_box_style_record_for_detachment(host: &DocumentHost,style_node: u32,generated_for: u8,@@ -5715,7 +5697,7 @@ pub unsafe extern "C" fn render_state_pin_bound_box_style_record_for_detachment(return;};// SAFETY: Guaranteed by the caller.- unsafe {+ {queue(host,LayoutChange::PinBoundBoxStyleRecordForDetachment {@@ -5728,27 +5710,16 @@ pub unsafe extern "C" fn render_state_pin_bound_box_style_record_for_detachment(/// Pins the style record `record` for the host's readers of the row `slot`, until the host/// releases it or the row is freed.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread, and `slot` a live row.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_pin_node_style_record_for_host(- host: &DocumentHost,- slot: NodeSlotId,- record: u64,-) {+pub extern "C" fn render_state_pin_node_style_record_for_host(host: &DocumentHost, slot: NodeSlotId, record: u64) {// SAFETY: Guaranteed by the caller.- unsafe { queue(host, LayoutChange::PinNodeStyleRecordForHost { node: slot, record }) };+ queue(host, LayoutChange::PinNodeStyleRecordForHost { node: slot, record });}-/// # Safety-///-/// `host` must be a live document host, on its document's thread, and `slot` a live row.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_release_node_style_record_pin_for_host(host: &DocumentHost, slot: NodeSlotId) {+pub extern "C" fn render_state_release_node_style_record_pin_for_host(host: &DocumentHost, slot: NodeSlotId) {// SAFETY: Guaranteed by the caller.- unsafe { queue(host, LayoutChange::ReleaseNodeStyleRecordPinForHost { node: slot }) };+ queue(host, LayoutChange::ReleaseNodeStyleRecordPinForHost { node: slot });}#[unsafe(no_mangle)]@@ -5771,7 +5742,7 @@ pub unsafe extern "C" fn render_state_set_box_presence_host(callback: unsafe extern "C" fn(*mut c_void, u32, u8),) {// SAFETY: Guaranteed by the caller.- unsafe {+ {queue(host,LayoutChange::SetBoxPresenceHost(Some(BoxPresenceHost(context, callback))),@@ -5779,13 +5750,10 @@ pub unsafe extern "C" fn render_state_set_box_presence_host(}}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_clear_box_presence_host(host: &DocumentHost) {+pub extern "C" fn render_state_clear_box_presence_host(host: &DocumentHost) {// SAFETY: Guaranteed by the caller.- unsafe { queue(host, LayoutChange::SetBoxPresenceHost(None)) };+ queue(host, LayoutChange::SetBoxPresenceHost(None));}/// Forgets every callback the document registered with its host, as the document is finalized.@@ -5810,27 +5778,24 @@ pub unsafe extern "C" fn document_host_set_style_record_host_callbacks(}#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_layout_pass_is_running(host: &DocumentHost) -> bool {+pub extern "C" fn render_state_layout_pass_is_running(host: &DocumentHost) -> bool {// SAFETY: Guaranteed by the caller.- unsafe { read_arena(host, node_read(), (), |arena, ()| arena.layout_pass_is_running()) }+ read_arena(host, node_read(), (), |arena, ()| arena.layout_pass_is_running())}#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_needs_full_layout_tree_update(+pub extern "C" fn render_state_needs_full_layout_tree_update(host: &DocumentHost,read: &crate::render_state::BegunRead,) -> bool {// SAFETY: Guaranteed by the caller.- unsafe { read_arena(host, read, (), |arena, ()| arena.needs_full_layout_tree_update()) }+ read_arena(host, read, (), |arena, ()| arena.needs_full_layout_tree_update())}#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_layout_root(- host: &DocumentHost,- read: &crate::render_state::BegunRead,-) -> NodeSlotId {+pub extern "C" fn render_state_layout_root(host: &DocumentHost, read: &crate::render_state::BegunRead) -> NodeSlotId {// SAFETY: Guaranteed by the caller.- unsafe { read_arena(host, read, (), |arena, ()| arena.layout_root()) }+ read_arena(host, read, (), |arena, ()| arena.layout_root())}/// Whether the layout of `host`'s document is up to date, where the host knows it without asking and no frame bringsdiff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena/main_thread_entries.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena/main_thread_entries.rsindex e3c095f34f0..3c073d70126 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena/main_thread_entries.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena/main_thread_entries.rs@@ -50,7 +50,7 @@ mod tests {host.host_tables().attach_shell(child, shell);let read = host.read_for_test();// SAFETY: The host lives on this thread until the test host is dropped.- assert_eq!(unsafe { render_state_node_shell_if_live(host, read, child) }, shell);+ assert_eq!(render_state_node_shell_if_live(host, read, child), shell);let sibling = FfiDetachedBoxSibling {style_node: 0,@@ -72,7 +72,7 @@ mod tests {}// A recording can still name the removed image. Resolving it must apply the removal before answering.// SAFETY: As above; the entry point accepts a stale slot.- let resolved = unsafe { render_state_node_shell_if_live(host, read, child) };+ let resolved = render_state_node_shell_if_live(host, read, child);let shell_was_destroyed = !host.host_tables().shells.borrow().contains_key(&child);host.run(ScriptForcedRead::for_test(), true, |state| {state.arena_mut().free_subtree(parent)@@ -85,12 +85,8 @@ mod tests {/// The row's layout node, which the host's shell factory makes the first time it is asked for, or null for a row that/// is not live.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread. `id` may be invalid or stale.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_node_shell_if_live(+pub extern "C" fn render_state_node_shell_if_live(host: &DocumentHost,read: &crate::render_state::BegunRead,id: NodeSlotId,@@ -104,7 +100,7 @@ pub unsafe extern "C" fn render_state_node_shell_if_live(.map_or(std::ptr::null_mut(), |facts| host.host_tables().shell_of(facts));}// SAFETY: Guaranteed by the caller.- let facts = unsafe {+ let facts = {read_arena(host, read, id, |arena, id| {let kind = arena.node_kind_if_live(id)?;(kind != NodeKind::Unset).then_some(super::super::host_tables::ShellFacts { id, kind })diff --git a/Libraries/LibWeb/Rust/src/layout/node_facts.rs b/Libraries/LibWeb/Rust/src/layout/node_facts.rsindex 646faab90d0..bfa243074ea 100644--- a/Libraries/LibWeb/Rust/src/layout/node_facts.rs+++ b/Libraries/LibWeb/Rust/src/layout/node_facts.rs@@ -1451,11 +1451,9 @@ pub unsafe extern "C" fn render_state_take_changed_document_svg_root_natural_siznatural_size: *mut crate::painting::host::FfiNaturalSize,) -> bool {// SAFETY: Guaranteed by the caller.- let changed = unsafe {- super::shell_reads::read_arena(host, read, (), |arena, ()| {- arena.take_changed_document_svg_root_natural_size()- })- };+ let changed = super::shell_reads::read_arena(host, read, (), |arena, ()| {+ arena.take_changed_document_svg_root_natural_size()+ });let Some(changed) = changed else {return false;};diff --git a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rsindex f8a248982e8..0b88467ac14 100644--- a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs+++ b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs@@ -767,20 +767,15 @@ impl LayoutNodeArena {}}-/// # Safety-///-/// `host` must be a live document host, on its document's thread, and `node` must name a live row of its document.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_node_is_partial_relayout_boundary(+pub extern "C" fn render_state_node_is_partial_relayout_boundary(host: &crate::render_state::DocumentHost,node: NodeSlotId,) -> bool {// SAFETY: Guaranteed by the caller.- unsafe {- super::shell_reads::read_arena(host, node_read(), node, |arena, node| {- arena.node_is_partial_relayout_boundary(node)- })- }+ super::shell_reads::read_arena(host, node_read(), node, |arena, node| {+ arena.node_is_partial_relayout_boundary(node)+ })}/// The facts the host owns that take an update off the partial relayout path.diff --git a/Libraries/LibWeb/Rust/src/layout/shell_reads.rs b/Libraries/LibWeb/Rust/src/layout/shell_reads.rsindex 08df8534a3b..a05fb47675b 100644--- a/Libraries/LibWeb/Rust/src/layout/shell_reads.rs+++ b/Libraries/LibWeb/Rust/src/layout/shell_reads.rs@@ -26,11 +26,7 @@ crate::render_state::held_node_entries!();/// Answers `answer` from the render state of `host`'s document and `args`, as of every write the host made, spending/// `wait`.-///-/// # Safety-///-/// `host` must be a live document host on its document's thread.-pub(crate) unsafe fn read_arena<A, R>(+pub(crate) fn read_arena<A, R>(host: &DocumentHost,wait: impl RenderWait,args: A,@@ -40,53 +36,34 @@ pub(crate) unsafe fn read_arena<A, R>(}/// The rows of `host`'s document as of every write the host made, spending `wait`.-///-/// # Safety-///-/// `host` must be a live document host on its document's thread.-unsafe fn rows(host: &DocumentHost, wait: impl RenderWait) -> Rc<RowSnapshot> {+fn rows(host: &DocumentHost, wait: impl RenderWait) -> Rc<RowSnapshot> {host.fresh_rows(wait)}/// The style record each row of `host`'s document has, as of every write the host made, for a read of the row `id`,/// spending `wait`.-///-/// # Safety-///-/// As for [`rows`].-unsafe fn styles(host: &DocumentHost, id: NodeSlotId, wait: impl RenderWait) -> crate::layout::row_reads::RowStyles {+fn styles(host: &DocumentHost, id: NodeSlotId, wait: impl RenderWait) -> crate::layout::row_reads::RowStyles {host.row_styles_of(id, wait)}/// What each row of `host`'s document is, and the row each node is bound to, as of every write the host made, spending/// `wait`.-///-/// # Safety-///-/// As for [`rows`].-unsafe fn identities(host: &DocumentHost, wait: impl RenderWait) -> RowIdentities {+fn identities(host: &DocumentHost, wait: impl RenderWait) -> RowIdentities {host.row_identities(wait)}-/// # Safety-///-/// `host` must be a live document host, on its document's thread, and `id` the slot of a live row.#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_flags(host: &DocumentHost, id: NodeSlotId) -> u32 {+pub extern "C" fn layout_row_flags(host: &DocumentHost, id: NodeSlotId) -> u32 {// SAFETY: Guaranteed by the caller.- unsafe { rows(host, node_read()) }.flags(id)+ rows(host, node_read()).flags(id)}/// The row's flags that say what node it stands for (see [`super::node_data::NodeFlag::IDENTITY`]); every other flag/// reads as unset.-///-/// # Safety-///-/// As for [`layout_row_flags`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_identity_flags(host: &DocumentHost, id: NodeSlotId) -> u32 {+pub extern "C" fn layout_row_identity_flags(host: &DocumentHost, id: NodeSlotId) -> u32 {// SAFETY: Guaranteed by the caller.- unsafe { identities(host, node_read()) }.identity_flags(id)+ identities(host, node_read()).identity_flags(id)}/// The layout node of the row `id` links to, made if nothing has asked for it yet, or null.@@ -97,103 +74,70 @@ pub unsafe extern "C" fn layout_row_identity_flags(host: &DocumentHost, id: Node#[unsafe(no_mangle)]pub unsafe extern "C" fn layout_row_link_shell(host: &DocumentHost, id: NodeSlotId, link: FfiNodeLink) -> *mut c_void {// SAFETY: Guaranteed by the caller.- let linked = unsafe { rows(host, node_read()) }.link(id, link);+ let linked = rows(host, node_read()).link(id, link);// SAFETY: As above.unsafe { shell_of(host, node_read(), (!linked.is_invalid()).then_some(linked)) }}-/// # Safety-///-/// As for [`layout_row_flags`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_generated_for(host: &DocumentHost, id: NodeSlotId) -> u8 {+pub extern "C" fn layout_row_generated_for(host: &DocumentHost, id: NodeSlotId) -> u8 {// SAFETY: Guaranteed by the caller.- unsafe { identities(host, node_read()) }.generated_for(id)+ identities(host, node_read()).generated_for(id)}-/// # Safety-///-/// As for [`layout_row_flags`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_has_compositor_animation_frame(+pub extern "C" fn layout_row_has_compositor_animation_frame(host: &DocumentHost,id: NodeSlotId,kind: CompositorAnimationFrameKind,) -> bool {// SAFETY: Guaranteed by the caller.- unsafe { rows(host, node_read()) }.has_compositor_animation_frame(id, kind)+ rows(host, node_read()).has_compositor_animation_frame(id, kind)}/// The style node of the row, or 0 for a row that is gone or carries none.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_style_node(host: &DocumentHost, id: NodeSlotId) -> u32 {+pub extern "C" fn layout_row_style_node(host: &DocumentHost, id: NodeSlotId) -> u32 {// SAFETY: Guaranteed by the caller.- unsafe { identities(host, node_read()) }+ identities(host, node_read()).style_node(id).map_or(0, crate::css::style::tree::StyleNodeID::raw)}-/// # Safety-///-/// As for [`layout_row_flags`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_style_record(host: &DocumentHost, id: NodeSlotId) -> u64 {+pub extern "C" fn layout_row_style_record(host: &DocumentHost, id: NodeSlotId) -> u64 {// SAFETY: Guaranteed by the caller.- unsafe { styles(host, id, node_read()) }.style_record(id)+ styles(host, id, node_read()).style_record(id)}/// Whether the arena derived the style record of the row `id`, which only a job changes but for the layout node's own/// writes, and a job tells the layout node of.-///-/// # Safety-///-/// As for [`layout_row_flags`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_style_is_derived(host: &DocumentHost, id: NodeSlotId) -> bool {+pub extern "C" fn layout_row_style_is_derived(host: &DocumentHost, id: NodeSlotId) -> bool {// SAFETY: Guaranteed by the caller.- unsafe { styles(host, id, node_read()) }.style_is_derived(id)+ styles(host, id, node_read()).style_is_derived(id)}-/// # Safety-///-/// As for [`layout_row_flags`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_style_payloads(host: &DocumentHost, id: NodeSlotId) -> *const c_void {+pub extern "C" fn layout_row_style_payloads(host: &DocumentHost, id: NodeSlotId) -> *const c_void {// SAFETY: Guaranteed by the caller.- unsafe { styles(host, id, node_read()) }- .style_payloads(id)- .as_ptr()- .cast()+ styles(host, id, node_read()).style_payloads(id).as_ptr().cast()}-/// # Safety-///-/// As for [`layout_row_flags`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_is_atomic_inline(host: &DocumentHost, id: NodeSlotId) -> bool {+pub extern "C" fn layout_row_is_atomic_inline(host: &DocumentHost, id: NodeSlotId) -> bool {// SAFETY: Guaranteed by the caller.- unsafe { rows(host, node_read()) }.is_atomic_inline(id)+ rows(host, node_read()).is_atomic_inline(id)}-/// # Safety-///-/// As for [`layout_row_flags`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_is_fragmented_inline(host: &DocumentHost, id: NodeSlotId) -> bool {+pub extern "C" fn layout_row_is_fragmented_inline(host: &DocumentHost, id: NodeSlotId) -> bool {// SAFETY: Guaranteed by the caller.- unsafe { rows(host, node_read()) }.is_fragmented_inline(id)+ rows(host, node_read()).is_fragmented_inline(id)}/// Answers `read` from the rows of `host`'s document through the paint side's reads, for a layout node the host holds.-///-/// # Safety-///-/// As for [`rows`].-unsafe fn read_rows<R>(host: &DocumentHost, read: impl FnOnce(&PaintSource<'_>) -> R) -> R {+fn read_rows<R>(host: &DocumentHost, read: impl FnOnce(&PaintSource<'_>) -> R) -> R {host.read_rows(node_read(), false, read)}@@ -223,7 +167,7 @@ unsafe fn bound_shell() -> *mut c_void {let facts = {// SAFETY: Guaranteed by the caller.- let identities = unsafe { identities(host, wait) };+ let identities = identities(host, wait);bound(&identities).and_then(|id| identities.shell_facts(id))};let Some(facts) = facts else {@@ -266,7 +210,7 @@ pub unsafe extern "C" fn layout_row_bound_committed_content_size(return false;};// SAFETY: Guaranteed by the caller.- let Some(row) = unsafe { identities(host, read) }.bound_row(style_node) else {+ let Some(row) = identities(host, read).bound_row(style_node) else {return false;};host.read_rows(read, false, |rows| {@@ -321,14 +265,10 @@ pub extern "C" fn layout_row_read_of_held_node(host: &DocumentHost) -> *const Be/// Whether the row `id` is the one the element or text node with `style_node` is bound to, or, with no style node, the/// viewport row the document is bound to.-///-/// # Safety-///-/// As for [`layout_row_flags`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_is_bound_to(host: &DocumentHost, id: NodeSlotId, style_node: u32) -> bool {+pub extern "C" fn layout_row_is_bound_to(host: &DocumentHost, id: NodeSlotId, style_node: u32) -> bool {// SAFETY: Guaranteed by the caller.- let identities = unsafe { identities(host, node_read()) };+ let identities = identities(host, node_read());let bound = match StyleNodeID::from_raw(style_node) {Some(style_node) => identities.bound_row(style_node),None => identities.bound_viewport_row(),@@ -344,57 +284,42 @@ pub unsafe extern "C" fn layout_row_is_bound_to(host: &DocumentHost, id: NodeSlo#[unsafe(no_mangle)]pub unsafe extern "C" fn layout_row_containing_block_shell_if_live(host: &DocumentHost, id: NodeSlotId) -> *mut c_void {// SAFETY: Guaranteed by the caller.- let containing_block = unsafe { read_rows(host, |rows| rows.node_containing_block_if_live(id)) };+ let containing_block = read_rows(host, |rows| rows.node_containing_block_if_live(id));// SAFETY: As above.unsafe { shell_of(host, node_read(), containing_block) }}-/// # Safety-///-/// As for [`layout_row_bound_shell`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_establishes_an_absolute_positioning_containing_block(+pub extern "C" fn layout_row_establishes_an_absolute_positioning_containing_block(host: &DocumentHost,id: NodeSlotId,) -> bool {// SAFETY: Guaranteed by the caller.- unsafe {- read_rows(host, |rows| {- crate::painting::style_queries::establishes_positioning_containing_blocks(rows, id).0- })- }+ read_rows(host, |rows| {+ crate::painting::style_queries::establishes_positioning_containing_blocks(rows, id).0+ })}-/// # Safety-///-/// As for [`layout_row_bound_shell`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_establishes_a_fixed_positioning_containing_block(+pub extern "C" fn layout_row_establishes_a_fixed_positioning_containing_block(host: &DocumentHost,id: NodeSlotId,) -> bool {// SAFETY: Guaranteed by the caller.- unsafe {- read_rows(host, |rows| {- crate::painting::style_queries::establishes_positioning_containing_blocks(rows, id).1- })- }+ read_rows(host, |rows| {+ crate::painting::style_queries::establishes_positioning_containing_blocks(rows, id).1+ })}-/// # Safety-///-/// As for [`layout_row_bound_shell`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_any_ancestor_establishes_a_fixed_position_containing_block(+pub extern "C" fn layout_row_any_ancestor_establishes_a_fixed_position_containing_block(host: &DocumentHost,id: NodeSlotId,) -> bool {// SAFETY: Guaranteed by the caller.- unsafe {- read_rows(host, |rows| {- crate::painting::style_queries::any_ancestor_establishes_a_fixed_position_containing_block(rows, id)- })- }+ read_rows(host, |rows| {+ crate::painting::style_queries::any_ancestor_establishes_a_fixed_position_containing_block(rows, id)+ })}/// The layout node of the row whose paintable row `slot` is, or null when the row has none.@@ -409,62 +334,42 @@ pub unsafe extern "C" fn layout_row_paintable_layout_node_shell(slot: NodeSlotId,) -> *mut c_void {// SAFETY: Guaranteed by the caller.- let populated = unsafe { rows(host, read) }.paintable.paintable_row_is_populated(slot);+ let populated = rows(host, read).paintable.paintable_row_is_populated(slot);// SAFETY: As above.unsafe { shell_of(host, read, populated.then_some(slot)) }}-/// # Safety-///-/// As for [`layout_row_bound_shell`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_paintable_is_positioned(host: &DocumentHost, slot: NodeSlotId) -> bool {+pub extern "C" fn layout_row_paintable_is_positioned(host: &DocumentHost, slot: NodeSlotId) -> bool {// SAFETY: Guaranteed by the caller.- unsafe {- read_rows(host, |rows| {- rows.paintable_row_is_populated(slot) && crate::painting::style_queries::is_positioned(rows, slot)- })- }+ read_rows(host, |rows| {+ rows.paintable_row_is_populated(slot) && crate::painting::style_queries::is_positioned(rows, slot)+ })}-/// # Safety-///-/// As for [`layout_row_bound_shell`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_paintable_has_child_paintables(host: &DocumentHost, slot: NodeSlotId) -> bool {+pub extern "C" fn layout_row_paintable_has_child_paintables(host: &DocumentHost, slot: NodeSlotId) -> bool {// SAFETY: Guaranteed by the caller.- unsafe {- read_rows(host, |rows| {- crate::painting::paint_order::first_paint_child(rows, slot).is_some()- })- }+ read_rows(host, |rows| {+ crate::painting::paint_order::first_paint_child(rows, slot).is_some()+ })}-/// # Safety-///-/// As for [`layout_row_bound_shell`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_paintable_is_chrome_mirrored(host: &DocumentHost, slot: NodeSlotId) -> bool {+pub extern "C" fn layout_row_paintable_is_chrome_mirrored(host: &DocumentHost, slot: NodeSlotId) -> bool {// SAFETY: Guaranteed by the caller.- unsafe {- read_rows(host, |rows| {- crate::painting::chrome_geometry::is_chrome_mirrored(rows, slot)- })- }+ read_rows(host, |rows| {+ crate::painting::chrome_geometry::is_chrome_mirrored(rows, slot)+ })}-/// # Safety-///-/// As for [`layout_row_flags`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_has_css_transform(host: &DocumentHost, id: NodeSlotId) -> bool {+pub extern "C" fn layout_row_has_css_transform(host: &DocumentHost, id: NodeSlotId) -> bool {// SAFETY: Guaranteed by the caller.- unsafe {- read_rows(host, |rows| {- rows.node_style_if_live(id)- .is_some_and(|style| crate::painting::style_queries::has_css_transform(rows, id, style))- })- }+ read_rows(host, |rows| {+ rows.node_style_if_live(id)+ .is_some_and(|style| crate::painting::style_queries::has_css_transform(rows, id, style))+ })}/// The characters the generated text row `id` renders, as a raw `AK::Utf16String` representation for which the callerdiff --git a/Libraries/LibWeb/Rust/src/layout/trace.rs b/Libraries/LibWeb/Rust/src/layout/trace.rsindex fecab055aca..801cbf225fd 100644--- a/Libraries/LibWeb/Rust/src/layout/trace.rs+++ b/Libraries/LibWeb/Rust/src/layout/trace.rs@@ -203,8 +203,7 @@ pub(crate) fn name_layout_trace_owners(main_thread: &MainThread, read: &crate::rreturn;};// SAFETY: The host is live for the token's entry.- let owners =- unsafe { super::shell_reads::read_arena(host, read, (), |arena, ()| arena.layout_trace.unnamed_owners(arena)) };+ let owners = super::shell_reads::read_arena(host, read, (), |arena, ()| arena.layout_trace.unnamed_owners(arena));if owners.is_empty() {return;}@@ -220,7 +219,7 @@ pub(crate) fn name_layout_trace_owners(main_thread: &MainThread, read: &crate::r}).collect();// SAFETY: As above.- unsafe { super::layout_changes::queue(host, super::layout_changes::LayoutChange::NameLayoutTraceOwners(names)) };+ super::layout_changes::queue(host, super::layout_changes::LayoutChange::NameLayoutTraceOwners(names));}fn describe_node(@@ -247,15 +246,11 @@ impl LayoutNodeArena {}}-/// # Safety-///-/// `host` must be a live document host, on its document's thread. The callback must remain valid until tracing stops-/// and must synchronously describe the live row it is handed without mutating layout.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_begin_layout_trace(host: &DocumentHost, describe_node: DescribeNode) {+pub extern "C" fn render_state_begin_layout_trace(host: &DocumentHost, describe_node: DescribeNode) {host.host_tables().layout_trace_describe_node.set(Some(describe_node));// SAFETY: As above.- unsafe { super::layout_changes::queue(host, super::layout_changes::LayoutChange::BeginLayoutTrace) };+ super::layout_changes::queue(host, super::layout_changes::LayoutChange::BeginLayoutTrace);}/// # Safety@@ -270,7 +265,7 @@ pub unsafe extern "C" fn render_state_take_layout_trace(append_text: AppendText,) {// SAFETY: Guaranteed by the caller.- let text = unsafe { super::shell_reads::read_arena(host, read, (), |arena, ()| arena.layout_trace.take()) };+ let text = super::shell_reads::read_arena(host, read, (), |arena, ()| arena.layout_trace.take());unsafe { append_text(context, text.as_ptr(), text.len()) };}diff --git a/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rs b/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rsindex 976188e71c0..47515802089 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rs@@ -189,11 +189,7 @@ impl LayoutTreeUpdateMarkWrite {/// Answers `read` of the layout tree update marks of `host`'s document for the node `style_node` names, which the host/// holds (see [`DocumentHost::read_marks`]). An identity of 0 names no node, and `read` is not run for it.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.-unsafe fn read_marks<R: Default>(+fn read_marks<R: Default>(host: &DocumentHost,style_node: u32,read: fn(&LayoutTreeUpdateMarks, StyleNodeID) -> R,@@ -205,55 +201,35 @@ unsafe fn read_marks<R: Default>(}/// Makes `write` to the layout tree update marks of `host`'s document, which the host holds, answering what it answers.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.-unsafe fn write_marks(host: &DocumentHost, write: LayoutTreeUpdateMarkWrite) -> bool {+fn write_marks(host: &DocumentHost, write: LayoutTreeUpdateMarkWrite) -> bool {host.write_marks(write)}/// Whether the node `style_node` names holds a layout tree update mark of its own.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_needs_layout_tree_update(host: &DocumentHost, style_node: u32) -> bool {+pub extern "C" fn render_state_needs_layout_tree_update(host: &DocumentHost, style_node: u32) -> bool {// SAFETY: Guaranteed by the caller.- unsafe { read_marks(host, style_node, LayoutTreeUpdateMarks::needs) }+ read_marks(host, style_node, LayoutTreeUpdateMarks::needs)}/// Which narrower rebuilds the marks the node `style_node` names has collected still permit.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_layout_tree_update_reuse_reasons(host: &DocumentHost, style_node: u32) -> u8 {+pub extern "C" fn render_state_layout_tree_update_reuse_reasons(host: &DocumentHost, style_node: u32) -> u8 {// SAFETY: Guaranteed by the caller.- unsafe { read_marks(host, style_node, LayoutTreeUpdateMarks::reuse_reasons) }+ read_marks(host, style_node, LayoutTreeUpdateMarks::reuse_reasons)}/// Whether a flat-tree descendant of the node `style_node` names holds a layout tree update mark.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_child_needs_layout_tree_update(host: &DocumentHost, style_node: u32) -> bool {+pub extern "C" fn render_state_child_needs_layout_tree_update(host: &DocumentHost, style_node: u32) -> bool {// SAFETY: Guaranteed by the caller.- unsafe { read_marks(host, style_node, LayoutTreeUpdateMarks::child_needs) }+ read_marks(host, style_node, LayoutTreeUpdateMarks::child_needs)}/// Folds a layout tree update mark into the one the node `style_node` names holds, answering/// whether its own bit changed: the transition the mark site widens the rebuild from.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_merge_layout_tree_update_mark(+pub extern "C" fn render_state_merge_layout_tree_update_mark(host: &DocumentHost,style_node: u32,value: bool,@@ -263,17 +239,13 @@ pub unsafe extern "C" fn render_state_merge_layout_tree_update_mark(return false;};// SAFETY: Guaranteed by the caller.- unsafe { write_marks(host, LayoutTreeUpdateMarkWrite::Merge(style_node, value, reuse_reason)) }+ write_marks(host, LayoutTreeUpdateMarkWrite::Merge(style_node, value, reuse_reason))}/// Records whether a flat-tree descendant of the node `style_node` names holds a layout tree update/// mark, answering what was recorded before. The mark's ancestor walk stops where it was already.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_set_child_needs_layout_tree_update(+pub extern "C" fn render_state_set_child_needs_layout_tree_update(host: &DocumentHost,style_node: u32,value: bool,@@ -282,22 +254,18 @@ pub unsafe extern "C" fn render_state_set_child_needs_layout_tree_update(return false;};// SAFETY: Guaranteed by the caller.- unsafe { write_marks(host, LayoutTreeUpdateMarkWrite::SetChildNeeds(style_node, value)) }+ write_marks(host, LayoutTreeUpdateMarkWrite::SetChildNeeds(style_node, value))}/// Retires the layout tree update marks the node `style_node` names holds. An identity handed to a node holds none,/// whatever the node that held it before left behind.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_clear_layout_tree_update_marks(host: &DocumentHost, style_node: u32) {+pub extern "C" fn render_state_clear_layout_tree_update_marks(host: &DocumentHost, style_node: u32) {let Some(style_node) = StyleNodeID::from_raw(style_node) else {return;};// SAFETY: Guaranteed by the caller.- unsafe { write_marks(host, LayoutTreeUpdateMarkWrite::Clear(style_node)) };+ write_marks(host, LayoutTreeUpdateMarkWrite::Clear(style_node));}/// A layout tree update mark as the render owner applies it, which says what the reason the DOM made it for asks of the@@ -466,7 +434,7 @@ pub unsafe extern "C" fn render_state_apply_layout_tree_update_mark(use super::layout_changes::{LayoutChange, queue};let node = StyleNodeID::from_raw(style_node);// SAFETY: Guaranteed by the caller.- unsafe { queue(host, LayoutChange::ApplyLayoutTreeUpdateMark { node, mark }) };+ queue(host, LayoutChange::ApplyLayoutTreeUpdateMark { node, mark });}/// What the host marks on a box. A second mark on the box the last queued change marks merges into it, so a burst of@@ -732,7 +700,7 @@ unsafe fn queue_marks(host: &DocumentHost, target: MarkedBox, marks: FfiBoxMarksreturn;}// SAFETY: Guaranteed by the caller.- unsafe { super::layout_changes::queue(host, super::layout_changes::LayoutChange::MarkBox { target, marks }) };+ super::layout_changes::queue(host, super::layout_changes::LayoutChange::MarkBox { target, marks });}/// Marks the box bound to the node with `style_node`, or the document's for 0.diff --git a/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs b/Libraries/LibWeb/Rust/src/painting/display_list/dump.rsindex 87eba683904..a7ed11e95ee 100644--- a/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs+++ b/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs@@ -131,7 +131,7 @@ pub unsafe extern "C" fn painting_dump(let visual_context_tree = unsafe { libcompositing_rust::ffi::tree_from_handle(visual_context_tree) };let (_, command_runs) = unsafe { libcompositing_rust::display_list::storage::tape_of(display_list) };// SAFETY: Guaranteed by the caller.- let owners = unsafe {+ let owners = {crate::painting::ffi::read_arena(host, read, viewport, |arena, viewport| {let mut owners = VisualContextNodeOwners::collect(arena, viewport);for owners in [&mut owners.spatial, &mut owners.clip, &mut owners.effect] {diff --git a/Libraries/LibWeb/Rust/src/painting/ffi.rs b/Libraries/LibWeb/Rust/src/painting/ffi.rsindex e1a4e58965b..ecdc19aa6f6 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi.rs@@ -35,11 +35,7 @@ crate::render_state::held_node_entries!();/// Answers `answer` from the render state of `host`'s document and `args`, as of every change the host queued,/// spending `wait`: the host's painting, input, editing and devtools code reads what the render state laid out and/// painted.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.-pub(crate) unsafe fn read_arena<A, R>(+pub(crate) fn read_arena<A, R>(host: &DocumentHost,wait: impl RenderWait,args: A,@@ -119,23 +115,15 @@ pub unsafe extern "C" fn document_host_set_chrome_state_callback(/// Copies the row in `slot` to `row`, where it is populated. The host reads it from the rows it holds where they still/// read as the arena, and asks otherwise.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_paintable_row(- host: &DocumentHost,- slot: NodeSlotId,- row: &mut PaintableData,-) -> bool {+pub extern "C" fn render_state_paintable_row(host: &DocumentHost, slot: NodeSlotId, row: &mut PaintableData) -> bool {let known = host.read_known_rows(|rows, _| {rows.paintable.paintable_row_is_populated(slot).then(|| *rows.paintable.paintable_data(slot))});// SAFETY: Guaranteed by the caller.- let answer = known.unwrap_or_else(|| unsafe {+ let answer = known.unwrap_or_else(|| {read_arena(host, node_read(), slot, |arena, slot| {let paintable_rows = arena.paintable_rows();paintable_rows@@ -151,21 +139,15 @@ pub unsafe extern "C" fn render_state_paintable_row(}/// Whether the row in `slot` is populated, which the host answers without asking where it knows.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_has_paintable_row(host: &DocumentHost, slot: NodeSlotId) -> bool {+pub extern "C" fn render_state_has_paintable_row(host: &DocumentHost, slot: NodeSlotId) -> bool {if let Some(populated) = host.known_paintable_row_is_populated(slot) {return populated;}// SAFETY: Guaranteed by the caller.- unsafe {- read_arena(host, node_read(), slot, |arena, slot| {- arena.paintable_rows().paintable_row_is_populated(slot)- })- }+ read_arena(host, node_read(), slot, |arena, slot| {+ arena.paintable_rows().paintable_row_is_populated(slot)+ })}#[repr(C)]@@ -186,11 +168,8 @@ pub unsafe extern "C" fn document_host_set_geometry_host(host.host_tables().geometry_host.set(Some(callbacks));}-/// # Safety-///-/// `arena` must be a live arena used on the document thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_paintable_scrollable_overflow(+pub extern "C" fn render_state_paintable_scrollable_overflow(host: &DocumentHost,slot: NodeSlotId,out: &mut FfiOptionalOverflowData,@@ -205,7 +184,7 @@ pub unsafe extern "C" fn render_state_paintable_scrollable_overflow(return;}// SAFETY: Guaranteed by the caller.- *out = unsafe {+ *out = {read_arena(host, node_read(), slot, |arena, slot| {arena.measure_scrollable_overflow();FfiOptionalOverflowData::of(&arena.paintable_rows(), slot)@@ -241,17 +220,14 @@ pub struct FfiBoxModelMetrics {pub inset: crate::painting::paintable_data::FfiPixelBox,}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_paintable_svg_viewport_size(+pub extern "C" fn render_state_paintable_svg_viewport_size(host: &DocumentHost,slot: NodeSlotId,out: &mut FfiCssPixelSize,) {// SAFETY: Guaranteed by the caller.- *out = unsafe {+ *out = {read_arena(host, node_read(), slot, |arena, slot| {let paintable_rows = arena.paintable_rows();if !paintable_rows.paintable_row_is_populated(slot) {@@ -268,16 +244,13 @@ pub struct FfiOptionalAffineTransform {pub transform: svg_formatting_context::FfiAffineTransform,}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_paintable_svg_viewport_transform(+pub extern "C" fn render_state_paintable_svg_viewport_transform(host: &DocumentHost,slot: NodeSlotId,) -> FfiOptionalAffineTransform {// SAFETY: Guaranteed by the caller.- unsafe {+ {read_arena(host, node_read(), slot, |arena, slot| {let transform = if arena.paintable_row_is_populated(slot) {crate::painting::paintable_geometry::committed_svg_viewport_transform(arena, slot)@@ -294,17 +267,13 @@ pub unsafe extern "C" fn render_state_paintable_svg_viewport_transform(/// The transform an SVG element's box was laid out with: its own CSS transform reduced to 2D, with a <use> element's/// x/y translation multiplied in.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_paintable_svg_element_transform(+pub extern "C" fn render_state_paintable_svg_element_transform(host: &DocumentHost,slot: NodeSlotId,) -> svg_formatting_context::FfiAffineTransform {// SAFETY: Guaranteed by the caller.- unsafe {+ {read_arena(host, node_read(), slot, |arena, slot| {if !arena.paintable_row_is_populated(slot) {return svg_formatting_context::FfiAffineTransform::default();@@ -314,11 +283,8 @@ pub unsafe extern "C" fn render_state_paintable_svg_element_transform(}}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_paintable_transform_reference_box(+pub extern "C" fn render_state_paintable_transform_reference_box(host: &DocumentHost,slot: NodeSlotId,out: &mut FfiCssPixelRect,@@ -331,7 +297,7 @@ pub unsafe extern "C" fn render_state_paintable_transform_reference_box(return;}// SAFETY: Guaranteed by the caller.- *out = unsafe {+ *out = {read_arena(host, node_read(), slot, |arena, slot| {reference_box(&arena.paintable_rows(), slot)})@@ -349,16 +315,13 @@ pub(crate) fn committed_transform_reference_box(rows: &impl PaintRead, slot: Nod))}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_physical_overflow_directions(+pub extern "C" fn render_state_physical_overflow_directions(host: &DocumentHost,paintable: NodeSlotId,) -> FfiPhysicalOverflowDirections {// SAFETY: Guaranteed by the caller.- unsafe {+ {read_arena(host, node_read(), paintable, |arena, paintable| {let directions = if arena.paintable_row_is_populated(paintable) {crate::painting::scrollable_overflow::physical_overflow_directions(arena, paintable)@@ -373,24 +336,19 @@ pub unsafe extern "C" fn render_state_physical_overflow_directions(}}-/// # Safety-///-/// `arena` must be a live layout arena handle used on the document thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_background_color_can_be_compositor_animated(+pub extern "C" fn render_state_background_color_can_be_compositor_animated(host: &DocumentHost,slot: NodeSlotId,) -> bool {// SAFETY: Guaranteed by the caller.- unsafe {- read_arena(host, node_read(), slot, |arena, slot| {- crate::painting::record::paint::background_resolution::background_color_can_be_compositor_animated(- &arena.paintable_rows(),- slot,- crate::layout::viewport_propagation::root_background_source(arena),- )- })- }+ read_arena(host, node_read(), slot, |arena, slot| {+ crate::painting::record::paint::background_resolution::background_color_can_be_compositor_animated(+ &arena.paintable_rows(),+ slot,+ crate::layout::viewport_propagation::root_background_source(arena),+ )+ })}/// # Safety@@ -403,7 +361,7 @@ pub unsafe extern "C" fn render_state_paintable_visual_context_node_count(list: crate::painting::host::FfiVisualContextBoxNodeList,) -> usize {// SAFETY: Guaranteed by the caller.- unsafe {+ {read_arena(host, node_read(), (slot, list), |arena, (slot, list)| {use crate::painting::host::FfiVisualContextBoxNodeList;arena.with_paintable_visual_context_node_handles(slot, |handles| match list {@@ -427,7 +385,7 @@ pub unsafe extern "C" fn render_state_paintable_visual_context_copy_node_indicescapacity: usize,) {// SAFETY: Guaranteed by the caller.- let indices = unsafe {+ let indices = {read_arena(host, node_read(), (slot, list), |arena, (slot, list)| {use crate::painting::host::FfiVisualContextBoxNodeList;arena.with_paintable_visual_context_node_handles(slot, |handles| -> Vec<u32> {@@ -457,14 +415,10 @@ pub(super) fn apply_walk_assignments(/// The index of the sticky node the accumulated visual context tree holds for `paintable`, which/// is where the scroll state snapshot keeps its resolved sticky offset, or `u32::MAX` when the tree/// holds none.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_sticky_spatial_node_index(host: &DocumentHost, paintable: NodeSlotId) -> u32 {+pub extern "C" fn render_state_sticky_spatial_node_index(host: &DocumentHost, paintable: NodeSlotId) -> u32 {// SAFETY: Guaranteed by the caller.- unsafe {+ {read_arena(host, node_read(), paintable, |arena, paintable| {let paint_state = arena.paint_state().borrow();paint_state@@ -776,16 +730,13 @@ pub unsafe extern "C" fn ladybird_web_record_image_paint_display_list(}}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_paintable_computed_svg_path(+pub extern "C" fn render_state_paintable_computed_svg_path(host: &DocumentHost,paintable: NodeSlotId,) -> *const c_void {// SAFETY: Guaranteed by the caller.- unsafe {+ {read_arena(host, node_read(), paintable, |arena, paintable| {let paintable_rows = arena.paintable_rows();if !paintable_rows.paintable_row_is_populated(paintable) {@@ -805,17 +756,13 @@ pub struct FfiSvgTextCharacterCells {pub count: usize,}-/// # Safety-///-/// `host` must be a live document host, on its document's thread. The cells the result points at-/// belong to the committed fragment, so the caller reads them before the next commit.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_paintable_svg_text_character_cells(+pub extern "C" fn render_state_paintable_svg_text_character_cells(host: &DocumentHost,paintable: NodeSlotId,) -> FfiSvgTextCharacterCells {// SAFETY: Guaranteed by the caller.- unsafe {+ {read_arena(host, node_read(), paintable, |arena, paintable| {let none = FfiSvgTextCharacterCells {cells: std::ptr::null(),@@ -877,12 +824,8 @@ pub(crate) unsafe fn rect_to_viewport_transform_from_ffi(/// Whether a row has ever been given a style with `content-visibility: auto`, which is when a/// layout commit collects the boxes with it. The host knows without asking right after the round that committed it.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_may_have_auto_content_visibility(+pub extern "C" fn render_state_may_have_auto_content_visibility(host: &DocumentHost,read: &crate::render_state::BegunRead,) -> bool {@@ -890,7 +833,7 @@ pub unsafe extern "C" fn render_state_may_have_auto_content_visibility(return facts.may_have_auto_content_visibility;}// SAFETY: Guaranteed by the caller.- unsafe { read_arena(host, read, (), |arena, ()| arena.may_have_auto_content_visibility()) }+ read_arena(host, read, (), |arena, ()| arena.may_have_auto_content_visibility())}/// # Safety@@ -905,7 +848,7 @@ pub unsafe extern "C" fn render_state_collect_boxes_with_auto_content_visibilitypush_box: unsafe extern "C" fn(*mut c_void, NodeSlotId),) {// SAFETY: Guaranteed by the caller.- let boxes = unsafe {+ let boxes = {read_arena(host, read, root, |arena, root| {let mut boxes = Vec::new();crate::painting::content_visibility::for_each_box_with_auto_content_visibility(@@ -922,16 +865,13 @@ pub unsafe extern "C" fn render_state_collect_boxes_with_auto_content_visibility}}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_inline_paintable_has_content_pieces(+pub extern "C" fn render_state_inline_paintable_has_content_pieces(host: &DocumentHost,inline_paintable: NodeSlotId,) -> bool {// SAFETY: Guaranteed by the caller.- unsafe {+ {read_arena(host, node_read(), inline_paintable, |arena, inline_paintable| {let mut has_content = false;with_inline_pieces(&arena.paintable_rows(), inline_paintable, |piece, _| {@@ -953,17 +893,14 @@ pub struct FfiOptionalCssPixelPoint {pub y: CssPixels,}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_inline_paintable_first_piece_position(+pub extern "C" fn render_state_inline_paintable_first_piece_position(host: &DocumentHost,inline_paintable: NodeSlotId,out: &mut FfiOptionalCssPixelPoint,) {// SAFETY: Guaranteed by the caller.- *out = unsafe {+ *out = {read_arena(host, node_read(), inline_paintable, |arena, inline_paintable| {let mut result = FfiOptionalCssPixelPoint {has_value: false,@@ -1016,7 +953,7 @@ pub unsafe extern "C" fn render_state_text_visual_lines(push: unsafe extern "C" fn(*mut c_void, FfiVisualLine),) {// SAFETY: Guaranteed by the caller.- let lines = unsafe {+ let lines = {read_arena(host, node_read(), primary, |arena, primary| {let fragments = arena.text_fragments(primary);crate::painting::visual_lines::collect_visual_lines(&arena.paintable_rows(), fragments.as_slice())@@ -1056,17 +993,14 @@ fn has_rendered_text_matching(found}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_text_has_rendered_text_before(+pub extern "C" fn render_state_text_has_rendered_text_before(host: &DocumentHost,primary: NodeSlotId,offset: usize,) -> bool {// SAFETY: Guaranteed by the caller.- unsafe {+ {read_arena(host, node_read(), (primary, offset), |arena, (primary, offset)| {let fragments = arena.text_fragments(primary);let node_slots = fragments.as_slice();@@ -1077,17 +1011,14 @@ pub unsafe extern "C" fn render_state_text_has_rendered_text_before(}}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_text_has_rendered_text_after(+pub extern "C" fn render_state_text_has_rendered_text_after(host: &DocumentHost,primary: NodeSlotId,offset: usize,) -> bool {// SAFETY: Guaranteed by the caller.- unsafe {+ {read_arena(host, node_read(), (primary, offset), |arena, (primary, offset)| {let fragments = arena.text_fragments(primary);let node_slots = fragments.as_slice();@@ -1104,11 +1035,8 @@ pub struct FfiOptionalCssPixels {pub value: CssPixels,}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_visual_line_caret_inline_coordinate(+pub extern "C" fn render_state_visual_line_caret_inline_coordinate(host: &DocumentHost,owner_paintable: u32,line_index: u32,@@ -1117,7 +1045,7 @@ pub unsafe extern "C" fn render_state_visual_line_caret_inline_coordinate(out: &mut FfiOptionalCssPixels,) {// SAFETY: Guaranteed by the caller.- *out = unsafe {+ *out = {read_arena(host,node_read(),@@ -1145,11 +1073,8 @@ pub unsafe extern "C" fn render_state_visual_line_caret_inline_coordinate(};}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_visual_line_offset_closest_to_inline_coordinate(+pub extern "C" fn render_state_visual_line_offset_closest_to_inline_coordinate(host: &DocumentHost,owner_paintable: u32,line_index: u32,@@ -1158,7 +1083,7 @@ pub unsafe extern "C" fn render_state_visual_line_offset_closest_to_inline_coordfallback_offset: usize,) -> usize {// SAFETY: Guaranteed by the caller.- unsafe {+ {read_arena(host,node_read(),@@ -1198,7 +1123,7 @@ pub unsafe extern "C" fn render_state_paintable_grid_layout_json(consume: unsafe extern "C" fn(*mut c_void, *const u8, usize),) {// SAFETY: Guaranteed by the caller.- let data = unsafe {+ let data = {read_arena(host, node_read(), paintable, |arena, paintable| {if !arena.paintable_row_is_populated(paintable) {return None;@@ -1226,7 +1151,7 @@ pub unsafe extern "C" fn render_state_paintable_flex_layout_json(resolve_node_id: unsafe extern "C" fn(*const c_void, u32) -> i64,) {// SAFETY: Guaranteed by the caller.- let data = unsafe {+ let data = {read_arena(host, node_read(), paintable, |arena, paintable| {if !arena.paintable_row_is_populated(paintable) {return None;@@ -1244,17 +1169,14 @@ pub unsafe extern "C" fn render_state_paintable_flex_layout_json(}}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_paintable_used_grid_tracks(+pub extern "C" fn render_state_paintable_used_grid_tracks(host: &DocumentHost,paintable: NodeSlotId,columns: bool,) -> *const c_void {// SAFETY: Guaranteed by the caller.- unsafe {+ {read_arena(host,node_read(),@@ -1274,13 +1196,8 @@ pub unsafe extern "C" fn render_state_paintable_used_grid_tracks(}}-/// # Safety-///-/// `host` must be a live document host, on its document's thread. The-/// returned tree is retained; the caller owns one reference and releases it with-/// `visual_context_tree_release`.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_main_visual_context_tree_retain(+pub extern "C" fn render_state_main_visual_context_tree_retain(host: &DocumentHost,read: &crate::render_state::BegunRead,) -> *const c_void {@@ -1293,23 +1210,18 @@ pub unsafe extern "C" fn render_state_main_visual_context_tree_retain(return tree;}// SAFETY: Guaranteed by the caller.- unsafe {- read_arena(host, read, (), |arena, ()| {- retain(arena.paint_state().borrow().visual_context.tree.as_ref())- })- }+ read_arena(host, read, (), |arena, ()| {+ retain(arena.paint_state().borrow().visual_context.tree.as_ref())+ })}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_has_visual_context_tree(+pub extern "C" fn render_state_has_visual_context_tree(host: &DocumentHost,read: &crate::render_state::BegunRead,) -> bool {// SAFETY: Guaranteed by the caller.- unsafe {+ {read_arena(host, read, (), |arena, ()| {let paint_state = arena.paint_state().borrow();paint_state.visual_context.tree.is_some()@@ -1317,11 +1229,8 @@ pub unsafe extern "C" fn render_state_has_visual_context_tree(}}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_visual_context_tree_structural_epoch(+pub extern "C" fn render_state_visual_context_tree_structural_epoch(host: &DocumentHost,read: &crate::render_state::BegunRead,) -> u64 {@@ -1331,7 +1240,7 @@ pub unsafe extern "C" fn render_state_visual_context_tree_structural_epoch(.map_or(0, |tree| tree.structural_epoch)});// SAFETY: Guaranteed by the caller.- known.unwrap_or_else(|| unsafe {+ known.unwrap_or_else(|| {read_arena(host, read, (), |arena, ()| {let paint_state = arena.paint_state().borrow();paint_state.visual_context.structural_epoch()@@ -1339,16 +1248,13 @@ pub unsafe extern "C" fn render_state_visual_context_tree_structural_epoch(})}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_visual_context_tree_has_visual_animations(+pub extern "C" fn render_state_visual_context_tree_has_visual_animations(host: &DocumentHost,read: &crate::render_state::BegunRead,) -> bool {// SAFETY: Guaranteed by the caller.- unsafe {+ {read_arena(host, read, (), |arena, ()| {let paint_state = arena.paint_state().borrow();paint_state@@ -1444,7 +1350,7 @@ pub unsafe extern "C" fn compositor_animation_effect_build(let layout_node = request.layout_node();state.build(&request, &host, |kind| {// SAFETY: Guaranteed by the caller.- unsafe {+ {read_arena(document_host,node_read(),@@ -1597,16 +1503,12 @@ pub unsafe extern "C" fn layout_arena_paint_push_svg_filter_primitive(/// Notes that the SVG paint resources the document's rows enrolled may have changed, and answers whether any row/// enrolled one, which only then are synced again. A row a frame in flight enrolls is synced as it enrolls.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_note_svg_paint_resources_changed(host: &DocumentHost) -> bool {+pub extern "C" fn render_state_note_svg_paint_resources_changed(host: &DocumentHost) -> bool {let enrolled = host.svg_paint_resources_may_be_enrolled();if enrolled {// SAFETY: As above.- unsafe { queue(host, PaintChange::SvgPaintResourcesChanged) };+ queue(host, PaintChange::SvgPaintResourcesChanged);}enrolled}diff --git a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rsindex 3a89e95568a..1f47ac9cd6e 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs@@ -17,11 +17,7 @@ crate::stage::main_thread_ffi_entries!();/// Answers `read` from the rows of `host`'s document as of every write the host made, spending `wait`, with every/// row's overflow measured, as input and chrome read boxes: scroll limits, wheel targets, scrollbars and snap areas.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.-unsafe fn read_measured_rows<R>(+fn read_measured_rows<R>(host: &crate::render_state::DocumentHost,wait: impl crate::render_state::RenderWait,read: impl FnOnce(&crate::painting::paint_read::PaintSource<'_>) -> R,@@ -29,20 +25,15 @@ unsafe fn read_measured_rows<R>(host.read_rows(wait, true, read)}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_paintable_physical_resize_axes(+pub extern "C" fn layout_row_paintable_physical_resize_axes(host: &crate::render_state::DocumentHost,slot: NodeSlotId,) -> FfiPhysicalResizeAxes {// SAFETY: Guaranteed by the caller.- let axes = unsafe {- read_measured_rows(host, super::node_read(), |rows| {- crate::painting::chrome_geometry::physical_resize_axes(rows, slot)- })- };+ let axes = read_measured_rows(host, super::node_read(), |rows| {+ crate::painting::chrome_geometry::physical_resize_axes(rows, slot)+ });FfiPhysicalResizeAxes {horizontal: axes.horizontal,vertical: axes.vertical,@@ -65,19 +56,17 @@ pub unsafe extern "C" fn layout_row_paintable_compute_scrollbar_data(out: &mut FfiOptionalScrollbarData,) {// SAFETY: Guaranteed by the caller.- let data = unsafe {- read_measured_rows(host, super::node_read(), |rows| {- crate::painting::chrome_geometry::ChromeGeometry { arena: rows, metrics }.compute_scrollbar_data(- slot,- direction,- enlarged,- has_device_scroll_offset.then_some(crate::painting::chrome_geometry::ScrollbarScrollState {- device_scroll_offset,- device_pixels_per_css_pixel,- }),- )- })- };+ let data = read_measured_rows(host, super::node_read(), |rows| {+ crate::painting::chrome_geometry::ChromeGeometry { arena: rows, metrics }.compute_scrollbar_data(+ slot,+ direction,+ enlarged,+ has_device_scroll_offset.then_some(crate::painting::chrome_geometry::ScrollbarScrollState {+ device_scroll_offset,+ device_pixels_per_css_pixel,+ }),+ )+ });let Some(data) = data else {*out = FfiOptionalScrollbarData::default();return;@@ -93,17 +82,14 @@ pub unsafe extern "C" fn layout_row_paintable_compute_scrollbar_data(};}-/// # Safety-///-/// As for [`layout_row_paintable_physical_resize_axes`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_paintable_minimum_scroll_offset(+pub extern "C" fn layout_row_paintable_minimum_scroll_offset(host: &crate::render_state::DocumentHost,slot: NodeSlotId,out: &mut FfiCssPixelPoint,) {// SAFETY: Guaranteed by the caller.- *out = unsafe {+ *out = {read_measured_rows(host, super::node_read(), |rows| {crate::painting::chrome_geometry::minimum_scroll_offset(rows, slot)})@@ -111,17 +97,14 @@ pub unsafe extern "C" fn layout_row_paintable_minimum_scroll_offset(.into();}-/// # Safety-///-/// As for [`layout_row_paintable_physical_resize_axes`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_paintable_maximum_scroll_offset(+pub extern "C" fn layout_row_paintable_maximum_scroll_offset(host: &crate::render_state::DocumentHost,slot: NodeSlotId,out: &mut FfiCssPixelPoint,) {// SAFETY: Guaranteed by the caller.- *out = unsafe {+ *out = {read_measured_rows(host, super::node_read(), |rows| {crate::painting::chrome_geometry::maximum_scroll_offset(rows, slot)})@@ -129,20 +112,15 @@ pub unsafe extern "C" fn layout_row_paintable_maximum_scroll_offset(.into();}-/// # Safety-///-/// As for [`layout_row_paintable_physical_resize_axes`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_paintable_wheel_scrollable_axes(+pub extern "C" fn layout_row_paintable_wheel_scrollable_axes(host: &crate::render_state::DocumentHost,slot: NodeSlotId,) -> FfiPhysicalResizeAxes {// SAFETY: Guaranteed by the caller.- let axes = unsafe {- read_measured_rows(host, super::node_read(), |rows| {- crate::painting::chrome_geometry::wheel_scrollable_axes(rows, slot)- })- };+ let axes = read_measured_rows(host, super::node_read(), |rows| {+ crate::painting::chrome_geometry::wheel_scrollable_axes(rows, slot)+ });FfiPhysicalResizeAxes {horizontal: axes.horizontal,vertical: axes.vertical,@@ -159,11 +137,9 @@ pub unsafe extern "C" fn layout_row_snap_container_geometry(out_geometry: *mut crate::painting::host::FfiSnapContainerGeometry,) -> bool {// SAFETY: Guaranteed by the caller.- let geometry = unsafe {- read_measured_rows(host, super::node_read(), |rows| {- crate::painting::scroll_snap::snap_container_geometry(rows, snap_container)- })- };+ let geometry = read_measured_rows(host, super::node_read(), |rows| {+ crate::painting::scroll_snap::snap_container_geometry(rows, snap_container)+ });let Some(geometry) = geometry else {return false;};@@ -183,7 +159,7 @@ pub unsafe extern "C" fn layout_row_scroll_snapport_rect(out: &mut FfiCssPixelRect,) {// SAFETY: Guaranteed by the caller.- *out = unsafe {+ *out = {read_measured_rows(host, super::node_read(), |rows| {crate::painting::scroll_snap::scroll_snapport_rect(rows, snap_container, scrollport.into())})@@ -191,30 +167,21 @@ pub unsafe extern "C" fn layout_row_scroll_snapport_rect(.into();}-/// # Safety-///-/// As for [`layout_row_paintable_physical_resize_axes`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_scroll_snap_axes(+pub extern "C" fn layout_row_scroll_snap_axes(host: &crate::render_state::DocumentHost,snap_container: NodeSlotId,) -> crate::painting::host::FfiSnapAxes {// SAFETY: Guaranteed by the caller.- unsafe {- read_measured_rows(host, super::node_read(), |rows| {- crate::painting::scroll_snap::snap_axes_of_scroll_container(rows, snap_container)- })- }+ read_measured_rows(host, super::node_read(), |rows| {+ crate::painting::scroll_snap::snap_axes_of_scroll_container(rows, snap_container)+ })}/// The box a scroll brings the caret at `offset` in the text of `text` into view in, which it scrolls to `*offset_out`, or/// an invalid slot for none.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_scroll_target_for_text_position(+pub extern "C" fn render_state_scroll_target_for_text_position(host: &crate::render_state::DocumentHost,text: NodeSlotId,offset: usize,@@ -223,7 +190,7 @@ pub unsafe extern "C" fn render_state_scroll_target_for_text_position(offset_out: &mut FfiCssPixelPoint,) -> NodeSlotId {// SAFETY: Guaranteed by the caller.- let target = unsafe {+ let target = {read_arena(host,super::node_read(),@@ -247,18 +214,15 @@ pub unsafe extern "C" fn render_state_scroll_target_for_text_position(container}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_scrolling_box_for_scroll_step(+pub extern "C" fn render_state_scrolling_box_for_scroll_step(host: &crate::render_state::DocumentHost,target: NodeSlotId,viewport: NodeSlotId,delta: FfiCssPixelPoint,) -> NodeSlotId {// SAFETY: Guaranteed by the caller.- unsafe {+ {read_arena(host,super::node_read(),@@ -289,7 +253,7 @@ pub unsafe extern "C" fn render_state_for_each_wheel_scrollable_box_in_containinpush_scrollable_box: unsafe extern "C" fn(*mut c_void, NodeSlotId, f64, f64),) {// SAFETY: Guaranteed by the caller.- let boxes = unsafe {+ let boxes = {read_arena(host,super::node_read(),@@ -314,39 +278,31 @@ pub unsafe extern "C" fn render_state_for_each_wheel_scrollable_box_in_containin}}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_box_ending_scroll_chain(+pub extern "C" fn render_state_box_ending_scroll_chain(host: &crate::render_state::DocumentHost,start: NodeSlotId,delta_x: f64,delta_y: f64,) -> NodeSlotId {// SAFETY: Guaranteed by the caller.- unsafe {- read_arena(- host,- node_read(),- (start, delta_x, delta_y),- |arena, (start, delta_x, delta_y)| {- crate::painting::scroll_chain::box_ending_scroll_chain(&arena.paintable_rows(), start, delta_x, delta_y)- },- )- }+ read_arena(+ host,+ node_read(),+ (start, delta_x, delta_y),+ |arena, (start, delta_x, delta_y)| {+ crate::painting::scroll_chain::box_ending_scroll_chain(&arena.paintable_rows(), start, delta_x, delta_y)+ },+ )}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_first_wheel_scrollable_box_in_containing_block_chain(+pub extern "C" fn render_state_first_wheel_scrollable_box_in_containing_block_chain(host: &crate::render_state::DocumentHost,start: NodeSlotId,) -> NodeSlotId {// SAFETY: Guaranteed by the caller.- unsafe {+ {read_arena(host, node_read(), start, |arena, start| {arena.measure_scrollable_overflow();crate::painting::scroll_chain::first_wheel_scrollable_box_in_containing_block_chain(@@ -569,7 +525,7 @@ pub unsafe extern "C" fn render_state_for_each_snap_area(push_snap_area: unsafe extern "C" fn(*mut c_void, *const crate::painting::host::FfiSnapAreaGeometry),) {// SAFETY: Guaranteed by the caller.- let areas = unsafe {+ let areas = {read_arena(host, super::node_read(), snap_container, |arena, snap_container| {let mut areas = Vec::new();crate::painting::scroll_snap::for_each_snap_area(@@ -609,11 +565,9 @@ pub unsafe extern "C" fn render_state_publish_recording(crate::painting::record::publish::publish_recording(host, publication, &main_thread, &publish);}drop(recording);- let presented = unsafe {- read_arena(host, read, (), |arena, ()| {- crate::painting::ffi::FfiPresentedRecording::of_last_recording(arena)- })- };+ let presented = read_arena(host, read, (), |arena, ()| {+ crate::painting::ffi::FfiPresentedRecording::of_last_recording(arena)+ });// SAFETY: The caller provides writable storage for what it reads of the recording.unsafe { out.write(presented) };}@@ -634,11 +588,9 @@ pub unsafe extern "C" fn render_state_take_recording_trace(return false;};// SAFETY: As above.- let recording = unsafe {- read_arena(host, read, (), |arena, ()| {- arena.paint_state().borrow().last_recording.clone()- })- };+ let recording = read_arena(host, read, (), |arena, ()| {+ arena.paint_state().borrow().last_recording.clone()+ });let Some(recording) = recording else {return false;};@@ -675,7 +627,7 @@ pub unsafe extern "C" fn render_state_for_each_subtree_fragment_rect(consume: unsafe extern "C" fn(*mut c_void, NodeSlotId, FfiCssPixelRect),) {// SAFETY: Guaranteed by the caller.- let rects = unsafe {+ let rects = {read_arena(host, super::node_read(), root, |arena, root| {let paintable_rows = arena.paintable_rows();let mut rects = Vec::new();@@ -751,14 +703,12 @@ pub unsafe extern "C" fn render_state_record_display_list(// SAFETY: The host lends the input arrays and buffers for this call, and the inputs copy what they read of them.let inputs = unsafe { inputs.recording_inputs() };// SAFETY: Guaranteed by the caller.- let Some(frame) = (unsafe {- read_arena(- host,- read,- frame_inputs,- crate::painting::recording_slot::freeze_recording_frame,- )- }) else {+ let Some(frame) = read_arena(+ host,+ read,+ frame_inputs,+ crate::painting::recording_slot::freeze_recording_frame,+ ) else {host.recording().give_back_recorder(recorder);return FfiRecordingStart::NothingToRecord;};@@ -1141,22 +1091,16 @@ pub extern "C" fn layout_hit_test_list_generation(host: &crate::render_state::Do}/// The DOM node a hit on the paintable dispatches events to.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_paintable_event_dispatch_target(+pub extern "C" fn layout_paintable_event_dispatch_target(host: &crate::render_state::DocumentHost,read: &crate::render_state::BegunRead,slot: NodeSlotId,) -> crate::painting::host::FfiNodeIdentity {// SAFETY: Guaranteed by the caller.- unsafe {- read_measured_rows(host, read, |rows| {- crate::painting::hit_test::resolve::event_dispatch_target_of_paintable(rows, slot)- })- }+ read_measured_rows(host, read, |rows| {+ crate::painting::hit_test::resolve::event_dispatch_target_of_paintable(rows, slot)+ })}#[unsafe(no_mangle)]diff --git a/Libraries/LibWeb/Rust/src/painting/layout_tree_dump.rs b/Libraries/LibWeb/Rust/src/painting/layout_tree_dump.rsindex cd7f00e6f9d..32957d25e0f 100644--- a/Libraries/LibWeb/Rust/src/painting/layout_tree_dump.rs+++ b/Libraries/LibWeb/Rust/src/painting/layout_tree_dump.rs@@ -144,7 +144,7 @@ pub unsafe extern "C" fn render_state_dump_layout_tree(// SAFETY: Guaranteed by the entry point's contract.let main_thread = unsafe { main_thread(host) };// SAFETY: As above.- let plan = unsafe {+ let plan = {crate::painting::ffi::read_arena(host,node_read(),diff --git a/Libraries/LibWeb/Rust/src/painting/paint_changes.rs b/Libraries/LibWeb/Rust/src/painting/paint_changes.rsindex 20281b275a7..f1c17c2714c 100644--- a/Libraries/LibWeb/Rust/src/painting/paint_changes.rs+++ b/Libraries/LibWeb/Rust/src/painting/paint_changes.rs@@ -209,30 +209,20 @@ impl PaintChange {}/// Queues `change` for the render state of `host`'s document.-///-/// # Safety-///-/// `host` must come from `document_host_create` and not be destroyed yet, on the document's thread.-pub(crate) unsafe fn queue(host: &DocumentHost, change: PaintChange) {+pub(crate) fn queue(host: &DocumentHost, change: PaintChange) {host.queue_change(ArenaChange::Paint(change));}-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_set_viewport_scroll_offset(host: &DocumentHost, offset: FfiCssPixelPoint) {+pub extern "C" fn render_state_set_viewport_scroll_offset(host: &DocumentHost, offset: FfiCssPixelPoint) {// SAFETY: Guaranteed by the caller.- unsafe { queue(host, PaintChange::SetViewportScrollOffset(offset.into())) };+ queue(host, PaintChange::SetViewportScrollOffset(offset.into()));}-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_invalidate_scroll_state(host: &DocumentHost) {+pub extern "C" fn render_state_invalidate_scroll_state(host: &DocumentHost) {// SAFETY: Guaranteed by the caller.- unsafe { queue(host, PaintChange::InvalidateScrollState) };+ queue(host, PaintChange::InvalidateScrollState);}/// # Safety@@ -261,16 +251,13 @@ pub unsafe extern "C" fn render_state_apply_selection(end_offset,};// SAFETY: Guaranteed by the caller.- unsafe { queue(host, change) };+ queue(host, change);}-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_clear_selection(host: &DocumentHost, viewport: NodeSlotId) {+pub extern "C" fn render_state_clear_selection(host: &DocumentHost, viewport: NodeSlotId) {// SAFETY: Guaranteed by the caller.- unsafe { queue(host, PaintChange::ClearSelection { viewport }) };+ queue(host, PaintChange::ClearSelection { viewport });}/// # Safety@@ -305,28 +292,22 @@ pub unsafe extern "C" fn render_state_apply_search_text(entries,};// SAFETY: Guaranteed by the caller.- unsafe { queue(host, change) };+ queue(host, change);}-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_clear_search_text(host: &DocumentHost) {+pub extern "C" fn render_state_clear_search_text(host: &DocumentHost) {// Rows that show no search text have none to clear, which spares the write that would leave the rows the host// holds stale.if !host.host_tables().shows_search_text.replace(false) {return;}// SAFETY: Guaranteed by the caller.- unsafe { queue(host, PaintChange::ClearSearchText) };+ queue(host, PaintChange::ClearSearchText);}-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_sync_highlight_pseudo_styles(+pub extern "C" fn render_state_sync_highlight_pseudo_styles(host: &DocumentHost,element: u32,selection_style_record: u64,@@ -345,14 +326,11 @@ pub unsafe extern "C" fn render_state_sync_highlight_pseudo_styles(],};// SAFETY: Guaranteed by the caller.- unsafe { queue(host, change) };+ queue(host, change);}-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_set_scrollbar_enlarged(+pub extern "C" fn render_state_set_scrollbar_enlarged(host: &DocumentHost,node: NodeSlotId,direction: ScrollDirection,@@ -364,7 +342,7 @@ pub unsafe extern "C" fn render_state_set_scrollbar_enlarged(enlarged,};// SAFETY: Guaranteed by the caller.- unsafe { queue(host, change) };+ queue(host, change);}/// # Safety@@ -404,27 +382,20 @@ pub unsafe extern "C" fn render_state_set_layer_image_paint_facts(}drop(rows_with_facts);// SAFETY: Guaranteed by the caller.- unsafe { queue(host, PaintChange::SetLayerImagePaintFacts { node, entries }) };+ queue(host, PaintChange::SetLayerImagePaintFacts { node, entries });}-/// # Safety-///-/// `host` must be a live document host, on the document's thread.-unsafe fn queue_replaced_paint_facts(host: &DocumentHost, target: MarkedBox, facts: ReplacedPaintFacts) {+fn queue_replaced_paint_facts(host: &DocumentHost, target: MarkedBox, facts: ReplacedPaintFacts) {// SAFETY: Guaranteed by the caller.- unsafe { queue(host, PaintChange::SetReplacedPaintFacts { target, facts }) };+ queue(host, PaintChange::SetReplacedPaintFacts { target, facts });}/// Queues `facts`, read off the element with `element`, for the box bound to it, which the render state finds as it/// applies them: the element may change beside a frame in flight, which holds the boxes.-///-/// # Safety-///-/// `host` must be a live document host, on the document's thread.-unsafe fn queue_element_paint_facts(host: &DocumentHost, element: u32, facts: ReplacedPaintFacts) {+fn queue_element_paint_facts(host: &DocumentHost, element: u32, facts: ReplacedPaintFacts) {if let Some(element) = StyleNodeID::from_raw(element) {// SAFETY: Guaranteed by the caller.- unsafe { queue_replaced_paint_facts(host, MarkedBox::Node(Some(element)), facts) };+ queue_replaced_paint_facts(host, MarkedBox::Node(Some(element)), facts);}}@@ -438,7 +409,7 @@ pub unsafe extern "C" fn render_state_set_form_control_paint_facts(facts: FfiFormControlPaintFacts,) {// SAFETY: Guaranteed by the caller.- unsafe { queue_element_paint_facts(host, element, ReplacedPaintFacts::FormControl(facts)) };+ queue_element_paint_facts(host, element, ReplacedPaintFacts::FormControl(facts));}/// The canvas paints its surface's content of this size and generation now: where that changed, so does what its box@@ -454,7 +425,7 @@ pub unsafe extern "C" fn render_state_set_canvas_paint_facts(facts: FfiCanvasPaintFacts,) {// SAFETY: Guaranteed by the caller.- unsafe { queue_element_paint_facts(host, element, ReplacedPaintFacts::Canvas(facts)) };+ queue_element_paint_facts(host, element, ReplacedPaintFacts::Canvas(facts));}/// The navigable container paints the compositor context of its content, if it has one: where that changed, so does@@ -471,7 +442,7 @@ pub unsafe extern "C" fn render_state_set_navigable_container_paint_facts() {let facts = ReplacedPaintFacts::NavigableContainer(facts);// SAFETY: Guaranteed by the caller.- unsafe { queue_replaced_paint_facts(host, MarkedBox::Row(node), facts) };+ queue_replaced_paint_facts(host, MarkedBox::Row(node), facts);}/// The image box `node` shows the image of the provider its box holds: its own, or its element's.@@ -488,7 +459,7 @@ pub unsafe extern "C" fn render_state_set_replaced_image_paint_facts(// SAFETY: Guaranteed by the caller.let facts = unsafe { ImagePaintFacts::from_ffi(&facts) };// SAFETY: Guaranteed by the caller.- unsafe { queue_replaced_paint_facts(host, MarkedBox::Row(node), ReplacedPaintFacts::Image(facts)) };+ queue_replaced_paint_facts(host, MarkedBox::Row(node), ReplacedPaintFacts::Image(facts));}/// The image of the element with `element` is the one `facts` describes, which its box shows unless the box owns the@@ -506,7 +477,7 @@ pub unsafe extern "C" fn render_state_set_element_image_paint_facts(// SAFETY: Guaranteed by the caller.let facts = unsafe { ImagePaintFacts::from_ffi(&facts) };// SAFETY: Guaranteed by the caller.- unsafe { queue_element_paint_facts(host, element, ReplacedPaintFacts::Image(facts)) };+ queue_element_paint_facts(host, element, ReplacedPaintFacts::Image(facts));}/// # Safety@@ -522,7 +493,7 @@ pub unsafe extern "C" fn render_state_set_video_paint_facts(// SAFETY: Guaranteed by the caller.let facts = unsafe { VideoPaintFacts::from_ffi(&facts) };// SAFETY: Guaranteed by the caller.- unsafe { queue_element_paint_facts(host, element, ReplacedPaintFacts::Video(facts)) };+ queue_element_paint_facts(host, element, ReplacedPaintFacts::Video(facts));}/// Publishes the `<area>` elements of the image map the image `node` is associated with, in tree order. Publishing no@@ -557,16 +528,12 @@ pub unsafe extern "C" fn render_state_publish_image_map_areas(}).collect();// SAFETY: Guaranteed by the caller.- unsafe { queue(host, PaintChange::PublishImageMapAreas { node, areas }) };+ queue(host, PaintChange::PublishImageMapAreas { node, areas });}/// Notes a style change of `node` for its visual contexts: one that changes their structure, or only their values.-///-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_note_visual_context_style_change(+pub extern "C" fn render_state_note_visual_context_style_change(host: &DocumentHost,node: NodeSlotId,changes_structure: bool,@@ -577,35 +544,26 @@ pub unsafe extern "C" fn render_state_note_visual_context_style_change(VisualContextBoxDirtyKind::StyleValueChange};// SAFETY: Guaranteed by the caller.- unsafe { queue(host, PaintChange::NoteVisualContextBoxDirty { node, kind }) };+ queue(host, PaintChange::NoteVisualContextBoxDirty { node, kind });}-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_invalidate_all_paint_caches(host: &DocumentHost) {+pub extern "C" fn render_state_invalidate_all_paint_caches(host: &DocumentHost) {// SAFETY: Guaranteed by the caller.- unsafe { queue(host, PaintChange::InvalidateAllPaintCaches) };+ queue(host, PaintChange::InvalidateAllPaintCaches);}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_visual_context_request_full_rebuild(+pub extern "C" fn render_state_visual_context_request_full_rebuild(host: &DocumentHost,scope: crate::painting::visual_context::dirty::VisualContextUpdateScope,) {// SAFETY: Guaranteed by the caller.- unsafe { queue(host, PaintChange::RequestFullVisualContextRebuild(scope)) };+ queue(host, PaintChange::RequestFullVisualContextRebuild(scope));}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_set_recording_trace_enabled(host: &DocumentHost, enabled: bool) {+pub extern "C" fn render_state_set_recording_trace_enabled(host: &DocumentHost, enabled: bool) {// SAFETY: Guaranteed by the caller.- unsafe { queue(host, PaintChange::SetRecordingTraceEnabled(enabled)) };+ queue(host, PaintChange::SetRecordingTraceEnabled(enabled));}diff --git a/Libraries/LibWeb/Rust/src/painting/stacking_context/dump.rs b/Libraries/LibWeb/Rust/src/painting/stacking_context/dump.rsindex 7378b66ccb7..4f5711540a5 100644--- a/Libraries/LibWeb/Rust/src/painting/stacking_context/dump.rs+++ b/Libraries/LibWeb/Rust/src/painting/stacking_context/dump.rs@@ -57,7 +57,7 @@ pub unsafe extern "C" fn render_state_dump_stacking_context_tree(// SAFETY: Guaranteed by the caller.let main_thread = unsafe { main_thread(host) };// SAFETY: As above.- let lines = unsafe {+ let lines = {crate::painting::ffi::read_arena(host, read, viewport, |arena, viewport| {let mut lines = Vec::new();if arena.stacking_context_entries(viewport).is_some() {