Skip to content

Truly independent web browser

LibWeb: Pass plain-value arrays through FFI as AK spans

Andreas Kling0e65443b67ed
diff --git a/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.cpp b/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.cpp
index b8a7c2fa253..a48f3de603c 100644
--- a/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.cpp
+++ b/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.cpp
@@ -91,7 +91,7 @@ NonnullRefPtr<ComputedStyleWorkingSet> ComputedStyleWorkingSet::create_with_base
ComputedValuesFFI::rust_computed_longhand_table_clear_seeded_state(working_set->m_computed_longhand_table);
auto importance = base.property_importance_bitmap();
auto inheritance = base.property_inheritance_bitmap();
- ComputedValuesFFI::rust_computed_longhand_table_load_flag_bitmaps(working_set->m_computed_longhand_table, importance.data(), importance.size(), inheritance.data(), inheritance.size());
+ ComputedValuesFFI::rust_computed_longhand_table_load_flag_bitmaps(working_set->m_computed_longhand_table, importance, inheritance);
for (auto const& entry : base.inheritance_dependent_specified_values())
ComputedValuesFFI::rust_computed_longhand_table_add_inheritance_dependent_value(working_set->m_computed_longhand_table, entry.property, entry.value);
working_set->set_display_before_box_type_transformation(base.display_before_box_type_transformation());
diff --git a/Libraries/LibWeb/CSS/StyleEngineBridge.cpp b/Libraries/LibWeb/CSS/StyleEngineBridge.cpp
index 2c1835f6c10..14d695c4493 100644
--- a/Libraries/LibWeb/CSS/StyleEngineBridge.cpp
+++ b/Libraries/LibWeb/CSS/StyleEngineBridge.cpp
@@ -67,9 +67,9 @@ void StyleEngine::mint_style_nodes(Span<StyleNodeID> nodes)
{
if (nodes.is_empty())
return;
- auto* raw_nodes = reinterpret_cast<u32*>(nodes.data());
- StyleEngineFFI::style_node_id_allocator_mint(m_style_node_ids, false, raw_nodes, nodes.size());
- StyleEngineFFI::style_engine_mint_style_nodes(m_render_document->host(), raw_nodes, nodes.size());
+ Span<u32> raw_nodes { reinterpret_cast<u32*>(nodes.data()), nodes.size() };
+ StyleEngineFFI::style_node_id_allocator_mint(m_style_node_ids, false, raw_nodes);
+ StyleEngineFFI::style_engine_mint_style_nodes(m_render_document->host(), raw_nodes);
// An element minted beside a style transaction that flew is unknown to it, whenever its arrival is recorded.
if (has_flown_style_transaction()) {
for (auto node : nodes)
@@ -81,9 +81,9 @@ void StyleEngine::mint_text_style_nodes(Span<StyleNodeID> nodes)
{
if (nodes.is_empty())
return;
- auto* raw_nodes = reinterpret_cast<u32*>(nodes.data());
- StyleEngineFFI::style_node_id_allocator_mint(m_style_node_ids, true, raw_nodes, nodes.size());
- StyleEngineFFI::style_engine_mint_style_nodes(m_render_document->host(), raw_nodes, nodes.size());
+ Span<u32> raw_nodes { reinterpret_cast<u32*>(nodes.data()), nodes.size() };
+ StyleEngineFFI::style_node_id_allocator_mint(m_style_node_ids, true, raw_nodes);
+ StyleEngineFFI::style_engine_mint_style_nodes(m_render_document->host(), raw_nodes);
}
HashTable<StyleNodeID> StyleEngine::take_deferred_element_initial_features()
diff --git a/Libraries/LibWeb/CSS/StyleEngineInput.cpp b/Libraries/LibWeb/CSS/StyleEngineInput.cpp
index 5d05d72cf5e..1b352359fd1 100644
--- a/Libraries/LibWeb/CSS/StyleEngineInput.cpp
+++ b/Libraries/LibWeb/CSS/StyleEngineInput.cpp
@@ -1857,7 +1857,7 @@ void record_element_animation_effect_descriptions(DOM::Element& element, u8 slot
versions.ensure_capacity(effects.size());
for (auto const& effect : effects)
versions.unchecked_append({ .identity = effect->animation_preparation_identity(), .generation = effect->animation_preparation_generation() });
- if (StyleEngineFFI::style_engine_describes_animation_effects(style_engine->host(), element.style_node_id().value(), slot, versions.data(), versions.size()))
+ if (StyleEngineFFI::style_engine_describes_animation_effects(style_engine->host(), element.style_node_id().value(), slot, versions.span()))
return;
Vector<StyleEngineFFI::FfiPublishedAnimationEffect> ffi_effects;
diff --git a/Libraries/LibWeb/CSS/StyleScope.cpp b/Libraries/LibWeb/CSS/StyleScope.cpp
index a4efe032a05..4ec1a986522 100644
--- a/Libraries/LibWeb/CSS/StyleScope.cpp
+++ b/Libraries/LibWeb/CSS/StyleScope.cpp
@@ -582,8 +582,8 @@ void StyleScope::publish_animation_keyframes()
return;
StyleEngineFFI::style_engine_set_tree_scope_animation_keyframes(
document().style_computer().style_engine().host(), style_engine_tree_scope().value(),
- bit_cast<FlatPtr>(as_if<DOM::ShadowRoot>(*m_node)), name_lengths.data(), name_units.data(), name_units.size(),
- keyframe_sets.data(), name_lengths.size());
+ bit_cast<FlatPtr>(as_if<DOM::ShadowRoot>(*m_node)), name_lengths.span(), name_units.span(),
+ keyframe_sets.span());
m_published_keyframe_sets = move(published);
}
diff --git a/Libraries/LibWeb/Compositor/RenderClock.cpp b/Libraries/LibWeb/Compositor/RenderClock.cpp
index 260627b7bb9..84d8211acc4 100644
--- a/Libraries/LibWeb/Compositor/RenderClock.cpp
+++ b/Libraries/LibWeb/Compositor/RenderClock.cpp
@@ -74,7 +74,7 @@ bool ClockTicksHandle::tick(i64 frame_time_nanoseconds, ReadonlySpan<Web::Compos
continue;
scrollers.append({ scroll_offset.scroll_node.node_id.value(), scroll_offset.offset.x().to_double(), scroll_offset.offset.y().to_double() });
}
- return Layout::RustFFI::clock_ticks_tick(m_ticks, frame_time_nanoseconds, scrollers.data(), scrollers.size());
+ return Layout::RustFFI::clock_ticks_tick(m_ticks, frame_time_nanoseconds, scrollers.span());
}
PointerAnswer ClockTicksHandle::pointer_moved(Optional<Gfx::FloatPoint> device_position, u32 buttons, bool scrolled_since_frame, u64 input_event_id) const
diff --git a/Libraries/LibWeb/DOM/AnchorNameMap.cpp b/Libraries/LibWeb/DOM/AnchorNameMap.cpp
index c2fbd405892..816245877d5 100644
--- a/Libraries/LibWeb/DOM/AnchorNameMap.cpp
+++ b/Libraries/LibWeb/DOM/AnchorNameMap.cpp
@@ -67,8 +67,7 @@ void AnchorNameMap::publish(Utf16FlyString const& name, Document& document, Opti
arena->host(),
scope_host.value_or(CSS::StyleNodeID {}).value(),
name.raw_identity(),
- style_nodes.data(),
- style_nodes.size());
+ style_nodes.span());
}
}
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index bf06174815e..a40ace352a5 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -10087,7 +10087,7 @@ void Document::publish_animation_keyframes_for_style_update()
m_animation_keyframes_published_generation = m_style_sheet_set_generation;
auto* host = style_computer().style_engine().host();
for (auto const& departed : m_departed_animation_keyframes)
- CSS::StyleEngineFFI::style_engine_set_tree_scope_animation_keyframes(host, departed.tree_scope.value(), departed.shadow_root_identity, nullptr, nullptr, 0, nullptr, 0);
+ CSS::StyleEngineFFI::style_engine_set_tree_scope_animation_keyframes(host, departed.tree_scope.value(), departed.shadow_root_identity, {}, {}, {});
m_departed_animation_keyframes.clear();
style_scope().build_rule_cache_if_needed();
for_each_shadow_root([](DOM::ShadowRoot& shadow_root) {
diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp
index d76f9b96af4..fb6f502a6c5 100644
--- a/Libraries/LibWeb/DOM/Node.cpp
+++ b/Libraries/LibWeb/DOM/Node.cpp
@@ -1559,7 +1559,7 @@ void Node::detach_remaining_layout_nodes_for_removal()
if (style_nodes.is_empty())
return;
// The detach is queued for the render state, and the host pays what it owes once the job that applies it is done.
- Layout::RustFFI::render_state_detach_remaining_rows_for_removal(arena->host(), style_nodes.data(), style_nodes.size());
+ Layout::RustFFI::render_state_detach_remaining_rows_for_removal(arena->host(), style_nodes.span());
}
GC::RootVector<GC::Ref<HTML::HTMLSlotElement>> Node::descendant_slots_before_removal(Node& parent_root)
diff --git a/Libraries/LibWeb/Layout/LayoutRustBridge.cpp b/Libraries/LibWeb/Layout/LayoutRustBridge.cpp
index 00a8e3d3d23..23f1da71d77 100644
--- a/Libraries/LibWeb/Layout/LayoutRustBridge.cpp
+++ b/Libraries/LibWeb/Layout/LayoutRustBridge.cpp
@@ -389,8 +389,7 @@ void publish_svg_attribute_facts(DOM::Element& element)
element.document().layout_node_arena().host(),
element.style_node_id().value(),
build_svg_attribute_facts(element),
- reinterpret_cast<RustFFI::FfiFloatPoint const*>(points.data()),
- points.size());
+ ReadonlySpan<RustFFI::FfiFloatPoint> { reinterpret_cast<RustFFI::FfiFloatPoint const*>(points.data()), points.size() });
}
// The unit of a published MathML length. Mirrors Rust `math_length_unit`.
diff --git a/Libraries/LibWeb/Layout/Node.cpp b/Libraries/LibWeb/Layout/Node.cpp
index 5ce4318c5a5..761e45d74f1 100644
--- a/Libraries/LibWeb/Layout/Node.cpp
+++ b/Libraries/LibWeb/Layout/Node.cpp
@@ -723,7 +723,7 @@ void Node::dom_node_style_node_changed(DOM::Node& dom_node, CSS::StyleNodeID old
generated_for.append(encode_generated_for(pseudo_element));
});
}
- RustFFI::render_state_style_node_changed(arena->host(), old_style_node.value(), new_style_node.value(), generated_for.data(), generated_for.size());
+ RustFFI::render_state_style_node_changed(arena->host(), old_style_node.value(), new_style_node.value(), generated_for.span());
// The arena tells a node about a change to its layout node through its StyleNodeID, so a node whose StyleNodeID
// changes is one it cannot name. Its box presence is committed again here instead. A node that had no StyleNodeID
// had no layout node either, and a fresh StyleNodeID has none bound yet, so it has nothing to commit.
diff --git a/Libraries/LibWeb/Painting/DocumentPaintState.cpp b/Libraries/LibWeb/Painting/DocumentPaintState.cpp
index d9dbe241112..7323f9ec812 100644
--- a/Libraries/LibWeb/Painting/DocumentPaintState.cpp
+++ b/Libraries/LibWeb/Painting/DocumentPaintState.cpp
@@ -250,7 +250,7 @@ void DocumentPaintState::recompute_selection_states(Layout::BegunRead const& rea
for_each_node_in_highlight_range(read, range, is_excluded_from_selection, [&](DOM::Node& node, SelectionState state) {
append_highlight_entry(read, entries, node, state);
});
- Layout::RustFFI::render_state_apply_selection(m_layout_node_arena->host(), viewport_row_slot(read, document), entries.data(), entries.size(), range.start_offset(), range.end_offset());
+ Layout::RustFFI::render_state_apply_selection(m_layout_node_arena->host(), viewport_row_slot(read, document), entries.span(), range.start_offset(), range.end_offset());
}
void DocumentPaintState::reset_search_text_states()
@@ -286,7 +286,7 @@ void DocumentPaintState::recompute_search_text_states(Layout::BegunRead const& r
}
if (active_match)
append_range(*active_match, true);
- Layout::RustFFI::render_state_apply_search_text(m_layout_node_arena->host(), viewport_row_slot(read, document), ranges.data(), ranges.size(), entries.data(), entries.size());
+ Layout::RustFFI::render_state_apply_search_text(m_layout_node_arena->host(), viewport_row_slot(read, document), ranges.span(), entries.span());
}
void DocumentPaintState::reset_spelling_error_states()
@@ -309,7 +309,7 @@ void DocumentPaintState::recompute_spelling_error_states(Layout::BegunRead const
});
}
});
- Layout::RustFFI::render_state_apply_spelling_errors(m_layout_node_arena->host(), viewport_row_slot(read, document), errors.data(), errors.size());
+ Layout::RustFFI::render_state_apply_spelling_errors(m_layout_node_arena->host(), viewport_row_slot(read, document), errors.span());
}
}
diff --git a/Libraries/LibWeb/Painting/PaintFacts.cpp b/Libraries/LibWeb/Painting/PaintFacts.cpp
index 9539174a60d..077f509948c 100644
--- a/Libraries/LibWeb/Painting/PaintFacts.cpp
+++ b/Libraries/LibWeb/Painting/PaintFacts.cpp
@@ -344,7 +344,7 @@ static void push_image_map_area_facts_onto(GC::Ptr<HTML::HTMLMapElement> map_ele
return TraversalDecision::Continue;
});
}
- Layout::RustFFI::render_state_publish_image_map_areas(layout_node.document_host(), Layout::Node::slot_id(&layout_node), areas.data(), areas.size(), coords.data(), coords.size());
+ Layout::RustFFI::render_state_publish_image_map_areas(layout_node.document_host(), Layout::Node::slot_id(&layout_node), areas.span(), coords.span());
}
// Which map an image is associated with is a hash-name reference resolved against the image's root, so any map or area
diff --git a/Libraries/LibWeb/Rust/build.rs b/Libraries/LibWeb/Rust/build.rs
index c5edf6ed49c..522765e52eb 100644
--- a/Libraries/LibWeb/Rust/build.rs
+++ b/Libraries/LibWeb/Rust/build.rs
@@ -2835,7 +2835,8 @@ fn main() -> Result<(), Box<dyn Error>> {
"FfiReplacedContentFacts".to_string(),
"FfiStylePayloads".to_string(),
"FfiUtf16View".to_string(),
- // Handed back through the layout header, which builds on this one.
+ // Lent and handed back through the layout header, which builds on this one.
+ "ArcRef".to_string(),
"OwnedArc".to_string(),
"OwnedBox".to_string(),
"NodeFlag".to_string(),
diff --git a/Libraries/LibWeb/Rust/src/css/computed_longhand_table.rs b/Libraries/LibWeb/Rust/src/css/computed_longhand_table.rs
index 8b9efb92cfa..a922cc29a0b 100644
--- a/Libraries/LibWeb/Rust/src/css/computed_longhand_table.rs
+++ b/Libraries/LibWeb/Rust/src/css/computed_longhand_table.rs
@@ -1537,22 +1537,13 @@ pub extern "C" fn rust_computed_longhand_table_inheritance_bits(table: &Computed
/// Replaces the whole importance and inheritance bitmaps, for the builder
/// seeding a fresh table from an existing style's published bitmaps.
-///
-/// # Safety
-/// `table` must be a valid, unfrozen, uniquely owned table; each bitmap must
-/// have exactly `LONGHAND_BITMAP_BYTES` readable bytes.
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn rust_computed_longhand_table_load_flag_bitmaps(
+pub extern "C" fn rust_computed_longhand_table_load_flag_bitmaps(
table: &mut ComputedLonghandTable,
- importance: *const u8,
- importance_count: usize,
- inheritance: *const u8,
- inheritance_count: usize,
+ importance: ak::Span<'_, u8>,
+ inheritance: ak::Span<'_, u8>,
) {
- table.load_flag_bitmaps(
- unsafe { ak::slice_from_raw_parts(importance, importance_count) },
- unsafe { ak::slice_from_raw_parts(inheritance, inheritance_count) },
- );
+ table.load_flag_bitmaps(importance.as_slice(), inheritance.as_slice());
}
/// Resets the state a fresh drive must not inherit from the style its table
diff --git a/Libraries/LibWeb/Rust/src/css/style/bridge.rs b/Libraries/LibWeb/Rust/src/css/style/bridge.rs
index 9ac961e9dcc..2d238323cfe 100644
--- a/Libraries/LibWeb/Rust/src/css/style/bridge.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/bridge.rs
@@ -1247,29 +1247,25 @@ unsafe impl Sync for FfiAppliedAnimationDefinition {}
/// The host publishes a scope whenever its rule cache is built, and keeps a reference to every set
/// the row names until it replaces or gives the row up. The row is written as the host's other
/// writes are, ahead of the next job, which is the first that resolves keyframes from it.
-///
-/// # Safety
-/// `host` must be a live document host, on its document's thread, and each buffer must hold the
-/// count it is given.
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn style_engine_set_tree_scope_animation_keyframes(
+pub extern "C" fn style_engine_set_tree_scope_animation_keyframes(
host: &DocumentHost,
tree_scope: u32,
shadow_root_identity: usize,
- name_lengths: *const u32,
- name_units: *const u16,
- name_unit_count: usize,
- keyframe_sets: *const usize,
- count: usize,
+ name_lengths: ak::Span<'_, u32>,
+ name_units: ak::Span<'_, u16>,
+ keyframe_sets: ak::Span<'_, usize>,
) {
- // SAFETY: Guaranteed by the caller.
- let row = unsafe {
- super::animations::AnimationKeyframes::row(
- ak::slice_from_raw_parts(name_lengths, count),
- ak::slice_from_raw_parts(name_units, name_unit_count),
- ak::slice_from_raw_parts(keyframe_sets, count),
- )
- };
+ assert_eq!(
+ name_lengths.as_slice().len(),
+ keyframe_sets.as_slice().len(),
+ "each keyframes name has a set"
+ );
+ let row = super::animations::AnimationKeyframes::row(
+ name_lengths.as_slice(),
+ name_units.as_slice(),
+ keyframe_sets.as_slice(),
+ );
let write = super::engine_calls::EngineWrite::AnimationKeyframes {
tree_scope: TreeScopeID(tree_scope),
shadow_root_identity,
@@ -1472,24 +1468,18 @@ pub unsafe extern "C" fn style_engine_set_element_animation_effect_descriptions(
/// Whether the engine describes one of an element's animation lists as holding exactly these
/// versions of its effects, in this order, so that the host need not describe them again. Only
/// the host describes them, so it knows without asking.
-///
-/// # Safety
-/// `host` must be a live document host, on its document's thread, and `versions` must hold `count`
-/// elements.
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn style_engine_describes_animation_effects(
+pub extern "C" fn style_engine_describes_animation_effects(
host: &DocumentHost,
node: u32,
slot: u8,
- versions: *const FfiAnimationEffectVersion,
- count: usize,
+ versions: ak::Span<'_, FfiAnimationEffectVersion>,
) -> bool {
- // SAFETY: Guaranteed by the caller.
StyleNodeID::from_raw(node).is_some_and(|node| {
host.engine_memo()
.described
.borrow()
- .describe(node, slot, unsafe { ak::slice_from_raw_parts(versions, count) })
+ .describe(node, slot, versions.as_slice())
})
}
diff --git a/Libraries/LibWeb/Rust/src/css/style/engine_calls.rs b/Libraries/LibWeb/Rust/src/css/style/engine_calls.rs
index 9b09e4cb28f..99e3f32d3bf 100644
--- a/Libraries/LibWeb/Rust/src/css/style/engine_calls.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/engine_calls.rs
@@ -356,16 +356,6 @@ pub(super) fn queue(host: &DocumentHost, write: EngineWrite) {
host.queue_change(ArenaChange::Engine(write));
}
-/// A copy of the `count` values at `values`.
-///
-/// # Safety
-///
-/// `values` must point at `count` readable values, or `count` be zero.
-unsafe fn owned<T: Copy>(values: *const T, count: usize) -> Box<[T]> {
- // SAFETY: Guaranteed by the caller.
- unsafe { borrow(values, count) }.into()
-}
-
/// Publishes the document's `@font-face` table and the memo of the cascades resolved from it, which every later font
/// resolution of the engine reads. Takes one reference to each. The shadow tree scopes that declare
/// `@font-feature-values` are the ones whose values the table carries beside the document's.
@@ -459,15 +449,12 @@ pub unsafe extern "C" fn style_engine_set_pseudo_element_custom_property_data(
host.queue_change(ArenaChange::Engine(write));
}
-/// Makes the `count` identities at `nodes`, which the host minted, live.
-///
-/// # Safety
-/// `host` must be a live document host, and `nodes` must point at `count` readable `u32` values.
+/// Makes the identities `nodes`, which the host minted, live.
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn style_engine_mint_style_nodes(host: &DocumentHost, nodes: *const u32, count: usize) {
- // SAFETY: Guaranteed by the caller.
- let nodes = unsafe { owned(nodes, count) };
- host.queue_change(ArenaChange::Engine(EngineWrite::MintStyleNodes(nodes)));
+pub extern "C" fn style_engine_mint_style_nodes(host: &DocumentHost, nodes: ak::Span<'_, u32>) {
+ host.queue_change(ArenaChange::Engine(EngineWrite::MintStyleNodes(
+ nodes.as_slice().into(),
+ )));
}
/// Stages the tree delta `delta` for the input the host submits next.
diff --git a/Libraries/LibWeb/Rust/src/css/style/identities.rs b/Libraries/LibWeb/Rust/src/css/style/identities.rs
index cae853c7d93..1a9dc8306ee 100644
--- a/Libraries/LibWeb/Rust/src/css/style/identities.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/identities.rs
@@ -90,23 +90,14 @@ pub extern "C" fn style_node_id_allocator_destroy(allocator: OwnedBox<StyleNodeI
drop(allocator);
}
-/// Mints `count` identities into `out`: text identities where `text`, otherwise element ones.
-///
-/// # Safety
-/// `allocator` must be live, and `out` must point at `count` writable `u32` values.
+/// Mints an identity into each slot of `out`: text identities where `text`, otherwise element ones.
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn style_node_id_allocator_mint(
- allocator: *mut StyleNodeIdAllocator,
+pub extern "C" fn style_node_id_allocator_mint(
+ allocator: &mut StyleNodeIdAllocator,
text: bool,
- out: *mut u32,
- count: usize,
+ out: ak::SpanMut<'_, u32>,
) {
- if count == 0 {
- return;
- }
- // SAFETY: Guaranteed by the caller.
- let (allocator, out) = unsafe { (&mut *allocator, ak::slice_from_raw_parts_mut(out, count)) };
- for slot in out {
+ for slot in out.into_slice() {
*slot = if text {
allocator.mint_text()
} else {
diff --git a/Libraries/LibWeb/Rust/src/layout/layout_changes.rs b/Libraries/LibWeb/Rust/src/layout/layout_changes.rs
index c0f6d95211f..7bb315f8772 100644
--- a/Libraries/LibWeb/Rust/src/layout/layout_changes.rs
+++ b/Libraries/LibWeb/Rust/src/layout/layout_changes.rs
@@ -465,21 +465,12 @@ pub extern "C" fn render_state_set_needs_layout_update(
/// Detaches what is left of the boxes of the `count` nodes `style_nodes` names as they leave the document (see
/// [`super::tree_builder::detach_remaining_rows_for_removal`]), as a write queued for the render state: the host pays what it owes
/// once the job that applies it is done. An identity of 0 names no node.
-///
-/// # Safety
-///
-/// `host` must be a live document host, on its document's thread, and `style_nodes` must point at `count` identities.
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn render_state_detach_remaining_rows_for_removal(
- host: &DocumentHost,
- style_nodes: *const u32,
- count: usize,
-) {
- if count == 0 {
+pub extern "C" fn render_state_detach_remaining_rows_for_removal(host: &DocumentHost, style_nodes: ak::Span<'_, u32>) {
+ let style_nodes = style_nodes.as_slice();
+ if style_nodes.is_empty() {
return;
}
- // SAFETY: Guaranteed by the caller.
- let style_nodes = unsafe { ak::slice_from_raw_parts(style_nodes, count) };
host.queue_change(ArenaChange::DetachForRemoval(style_nodes.into()));
}
@@ -501,24 +492,14 @@ pub extern "C" fn render_state_record_partial_relayout_escape(host: &DocumentHos
queue(host, LayoutChange::RecordPartialRelayoutEscape);
}
-/// # Safety
-///
-/// `host` must be a live document host, on the document's thread, and `generated_for` must point at `count` readable
-/// pseudo-element kinds.
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn render_state_style_node_changed(
+pub extern "C" fn render_state_style_node_changed(
host: &DocumentHost,
old: u32,
new: u32,
- generated_for: *const u8,
- count: usize,
+ generated_for: ak::Span<'_, u8>,
) {
- let generated_for = if count == 0 {
- SmallVec::new()
- } else {
- // SAFETY: Guaranteed by the caller.
- SmallVec::from_slice(unsafe { ak::slice_from_raw_parts(generated_for, count) })
- };
+ let generated_for = SmallVec::from_slice(generated_for.as_slice());
let new = StyleNodeID::from_raw(new);
let change = LayoutChange::StyleNodeChanged {
old: StyleNodeID::from_raw(old),
@@ -531,28 +512,22 @@ pub unsafe extern "C" fn render_state_style_node_changed(
}
}
-/// # Safety
-///
-/// `host` must be a live document host, on the document's thread, and `elements` must point at `count` readable
-/// element identities.
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn render_state_set_anchor_name_elements(
+pub extern "C" fn render_state_set_anchor_name_elements(
host: &DocumentHost,
scope_host: u32,
anchor_name: usize,
- elements: *const u32,
- count: usize,
+ elements: ak::Span<'_, u32>,
) {
- let elements: &[u32] = if count == 0 {
- &[]
- } else {
- // SAFETY: Guaranteed by the caller.
- unsafe { ak::slice_from_raw_parts(elements, count) }
- };
let change = LayoutChange::SetAnchorNameElements {
scope_host: StyleNodeID::from_raw(scope_host),
anchor_name,
- elements: elements.iter().copied().filter_map(StyleNodeID::from_raw).collect(),
+ elements: elements
+ .as_slice()
+ .iter()
+ .copied()
+ .filter_map(StyleNodeID::from_raw)
+ .collect(),
};
queue(host, change);
}
@@ -594,31 +569,20 @@ pub extern "C" fn render_state_set_identity_in_focused_text_control(host: &Docum
/// Publishes what the SVG element `element` names parses to. A `<polyline>` or `<polygon>` passes its `points` list
/// beside the facts, since it is the one geometry attribute that is not a fixed number of values.
-///
-/// # Safety
-///
-/// `host` must be a live document host, on the document's thread, and `points` must point at `count` readable points.
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn render_state_set_svg_attribute_facts(
+pub extern "C" fn render_state_set_svg_attribute_facts(
host: &DocumentHost,
element: u32,
facts: FfiSvgAttributeFacts,
- points: *const FfiFloatPoint,
- count: usize,
+ points: ak::Span<'_, FfiFloatPoint>,
) {
let Some(element) = StyleNodeID::from_raw(element) else {
return;
};
- let points = if count == 0 {
- &[][..]
- } else {
- // SAFETY: Guaranteed by the caller.
- unsafe { ak::slice_from_raw_parts(points, count) }
- };
let change = LayoutChange::SvgAttributeFacts {
element,
facts: Box::new(facts),
- points: points.into(),
+ points: points.as_slice().into(),
};
queue(host, change);
}
diff --git a/Libraries/LibWeb/Rust/src/painting/paint_changes.rs b/Libraries/LibWeb/Rust/src/painting/paint_changes.rs
index 6ae968efa18..3d28ecc383c 100644
--- a/Libraries/LibWeb/Rust/src/painting/paint_changes.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paint_changes.rs
@@ -244,28 +244,17 @@ pub extern "C" fn render_state_set_viewport_scroll_offset(host: &DocumentHost, o
queue(host, PaintChange::SetViewportScrollOffset(offset.into()));
}
-/// # Safety
-///
-/// `host` must be a live document host, on the document's thread, and `entries` must point at `entry_count` readable
-/// entries.
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn render_state_apply_selection(
+pub extern "C" fn render_state_apply_selection(
host: &DocumentHost,
viewport: NodeSlotId,
- entries: *const FfiSelectionEntry,
- entry_count: usize,
+ entries: ak::Span<'_, FfiSelectionEntry>,
start_offset: usize,
end_offset: usize,
) {
- let entries = if entry_count == 0 {
- Box::default()
- } else {
- // SAFETY: Guaranteed by the caller.
- unsafe { ak::slice_from_raw_parts(entries, entry_count) }.into()
- };
let change = PaintChange::ApplySelection {
viewport,
- entries,
+ entries: entries.as_slice().into(),
start_offset,
end_offset,
};
@@ -277,36 +266,19 @@ pub extern "C" fn render_state_clear_selection(host: &DocumentHost, viewport: No
queue(host, PaintChange::ClearSelection { viewport });
}
-/// # Safety
-///
-/// `host` must be a live document host, on the document's thread, `ranges` must point at `range_count` readable
-/// ranges and `entries` at `entry_count` readable entries.
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn render_state_apply_search_text(
+pub extern "C" fn render_state_apply_search_text(
host: &DocumentHost,
viewport: NodeSlotId,
- ranges: *const FfiSearchTextRange,
- range_count: usize,
- entries: *const FfiSelectionEntry,
- entry_count: usize,
+ ranges: ak::Span<'_, FfiSearchTextRange>,
+ entries: ak::Span<'_, FfiSelectionEntry>,
) {
- let ranges = if range_count == 0 {
- Box::default()
- } else {
- // SAFETY: Guaranteed by the caller.
- unsafe { ak::slice_from_raw_parts(ranges, range_count) }.into()
- };
- let entries = if entry_count == 0 {
- Box::default()
- } else {
- // SAFETY: Guaranteed by the caller.
- unsafe { ak::slice_from_raw_parts(entries, entry_count) }.into()
- };
- host.host_tables().shows_search_text.set(range_count != 0);
+ let ranges: Box<[FfiSearchTextRange]> = ranges.as_slice().into();
+ host.host_tables().shows_search_text.set(!ranges.is_empty());
let change = PaintChange::ApplySearchText {
viewport,
ranges,
- entries,
+ entries: entries.as_slice().into(),
};
queue(host, change);
}
@@ -321,24 +293,14 @@ pub extern "C" fn render_state_clear_search_text(host: &DocumentHost) {
queue(host, PaintChange::ClearSearchText);
}
-/// # Safety
-///
-/// `host` must be a live document host, on the document's thread, and `errors` must point at `error_count` readable
-/// errors.
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn render_state_apply_spelling_errors(
+pub extern "C" fn render_state_apply_spelling_errors(
host: &DocumentHost,
viewport: NodeSlotId,
- errors: *const FfiSpellingError,
- error_count: usize,
+ errors: ak::Span<'_, FfiSpellingError>,
) {
- let errors = if error_count == 0 {
- Box::default()
- } else {
- // SAFETY: Guaranteed by the caller.
- unsafe { ak::slice_from_raw_parts(errors, error_count) }.into()
- };
- host.host_tables().shows_spelling_errors.set(error_count != 0);
+ let errors: Box<[FfiSpellingError]> = errors.as_slice().into();
+ host.host_tables().shows_spelling_errors.set(!errors.is_empty());
queue(host, PaintChange::ApplySpellingErrors { viewport, errors });
}
@@ -533,29 +495,17 @@ pub unsafe extern "C" fn render_state_set_video_paint_facts(
}
/// Publishes the `<area>` elements of the image map the image `node` is associated with, in tree order. Publishing no
-/// area is how an image with no image map is named.
-///
-/// # Safety
-///
-/// `host` must be a live document host, on the document's thread; `areas` must point at `area_count` readable areas,
-/// and `coords` at `coords_count` readable coordinates, which the areas index.
+/// area is how an image with no image map is named. The areas index `coords`.
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn render_state_publish_image_map_areas(
+pub extern "C" fn render_state_publish_image_map_areas(
host: &DocumentHost,
node: NodeSlotId,
- areas: *const FfiImageMapArea,
- area_count: usize,
- coords: *const f64,
- coords_count: usize,
+ areas: ak::Span<'_, FfiImageMapArea>,
+ coords: ak::Span<'_, f64>,
) {
- // SAFETY: Guaranteed by the caller.
- let (areas, coords) = unsafe {
- (
- ak::slice_from_raw_parts(areas, area_count),
- ak::slice_from_raw_parts(coords, coords_count),
- )
- };
+ let coords = coords.as_slice();
let areas = areas
+ .as_slice()
.iter()
.map(|area| {
let start = area.coords_offset as usize;
diff --git a/Libraries/LibWeb/Rust/src/render_state/clock.rs b/Libraries/LibWeb/Rust/src/render_state/clock.rs
index 6222cc1a91b..6b7e5fa63ce 100644
--- a/Libraries/LibWeb/Rust/src/render_state/clock.rs
+++ b/Libraries/LibWeb/Rust/src/render_state/clock.rs
@@ -1576,24 +1576,14 @@ impl ClockRecorder {
}
/// Hands the lanes `ticks` belong to a display tick at `frame_time_nanoseconds`, at which the compositor had scrolled to
-/// the `scroll_offset_count` offsets at `scroll_offsets`, and answers whether they want the next one.
-///
-/// # Safety
-///
-/// `ticks` must come from `document_host_clock_ticks` and not be released yet, and `scroll_offsets` must hold
-/// `scroll_offset_count` offsets.
+/// the offsets `scroll_offsets`, and answers whether they want the next one.
#[unsafe(no_mangle)]
-pub unsafe extern "C" fn clock_ticks_tick(
- ticks: *const ClockTicks,
+pub extern "C" fn clock_ticks_tick(
+ ticks: crate::css::ffi_support::ArcRef<'_, ClockTicks>,
frame_time_nanoseconds: i64,
- scroll_offsets: *const FfiScrollOffset,
- scroll_offset_count: usize,
+ scroll_offsets: ak::Span<'_, FfiScrollOffset>,
) -> bool {
- // SAFETY: Guaranteed by the caller, whose reference this borrows.
- let ticks = std::mem::ManuallyDrop::new(unsafe { Arc::from_raw(ticks) });
- // SAFETY: Guaranteed by the caller.
- let scroll_offsets = unsafe { ak::slice_from_raw_parts(scroll_offsets, scroll_offset_count) };
- ticks.tick(frame_time_nanoseconds, scroll_offsets)
+ ticks.to_arc().tick(frame_time_nanoseconds, scroll_offsets.as_slice())
}
/// Gives up the reference `ticks` holds.