Truly independent web browser
LibWeb: Make exports safe that take plain-data FFI structs
Andreas Klingd2e166370956
diff --git a/Libraries/LibWeb/Rust/src/css/counter_style.rs b/Libraries/LibWeb/Rust/src/css/counter_style.rsindex ec69a6ff219..a8c08422577 100644--- a/Libraries/LibWeb/Rust/src/css/counter_style.rs+++ b/Libraries/LibWeb/Rust/src/css/counter_style.rs@@ -57,12 +57,12 @@ impl FfiCounterStyle {}#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_counter_style_descriptors(rule: &FfiCounterStyle) -> *mut FfiDescriptorBlock {+pub extern "C" fn rust_counter_style_descriptors(rule: &FfiCounterStyle) -> *mut FfiDescriptorBlock {rust_descriptor_block_retain(&rule.descriptors)}#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_counter_style_name(rule: &FfiCounterStyle) -> FfiUtf16View {+pub extern "C" fn rust_counter_style_name(rule: &FfiCounterStyle) -> FfiUtf16View {let name = rule.name.borrow();let name = name.units();FfiUtf16View {diff --git a/Libraries/LibWeb/Rust/src/css/parser/query_parser.rs b/Libraries/LibWeb/Rust/src/css/parser/query_parser.rsindex a3c01a4f48e..fefb30043a5 100644--- a/Libraries/LibWeb/Rust/src/css/parser/query_parser.rs+++ b/Libraries/LibWeb/Rust/src/css/parser/query_parser.rs@@ -2878,11 +2878,8 @@ pub unsafe extern "C" fn css_query_unref(handle: *const FfiQueryHandle) {/// Evaluates a retained supports condition whose feature results were captured while parsing./// Returns 3 when the handle does not contain a supports expression.-///-/// # Safety-/// `handle` must point to a live supports-expression handle.#[unsafe(no_mangle)]-pub unsafe extern "C" fn css_query_evaluate_supports(handle: Option<&FfiQueryHandle>) -> u8 {+pub extern "C" fn css_query_evaluate_supports(handle: Option<&FfiQueryHandle>) -> u8 {handle.and_then(FfiQueryHandle::evaluate_supports).map_or(3, |result| result as u8)@@ -3299,7 +3296,7 @@ mod tests {},};- assert_eq!(unsafe { css_query_evaluate_supports(None) }, 3);- assert_eq!(unsafe { css_query_evaluate_supports(Some(&handle)) }, 3);+ assert_eq!(css_query_evaluate_supports(None), 3);+ assert_eq!(css_query_evaluate_supports(Some(&handle)), 3);}}diff --git a/Libraries/LibWeb/Rust/src/css/parser/syntax_parser/ownership_tests.rs b/Libraries/LibWeb/Rust/src/css/parser/syntax_parser/ownership_tests.rsindex 43f28cc1d56..3c33ef08508 100644--- a/Libraries/LibWeb/Rust/src/css/parser/syntax_parser/ownership_tests.rs+++ b/Libraries/LibWeb/Rust/src/css/parser/syntax_parser/ownership_tests.rs@@ -548,7 +548,7 @@ fn import_preludes_outlive_the_worker_and_shared_sheet() {assert!(anonymous.layer.as_ref().unwrap().units().is_empty());assert!(unlayered.layer.is_none());assert!(unlayered.supports.is_none());- unsafe {+ {assert_eq!(css_query_evaluate_supports(named.supports.as_deref()), 1);assert_eq!(css_query_evaluate_supports(anonymous.supports.as_deref()), 0);assert_eq!(css_query_evaluate_supports(Some(&*supports)), 1);diff --git a/Libraries/LibWeb/Rust/src/css/style/engine_calls.rs b/Libraries/LibWeb/Rust/src/css/style/engine_calls.rsindex c422f61fbe9..7d85659c8e0 100644--- a/Libraries/LibWeb/Rust/src/css/style/engine_calls.rs+++ b/Libraries/LibWeb/Rust/src/css/style/engine_calls.rs@@ -468,11 +468,8 @@ pub unsafe extern "C" fn style_engine_mint_style_nodes(host: &DocumentHost, node}/// Stages the tree delta `delta` for the input the host submits next.-///-/// # Safety-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn style_engine_stage_tree_delta(host: &DocumentHost, delta: &FfiTreeDelta) {+pub extern "C" fn style_engine_stage_tree_delta(host: &DocumentHost, delta: &FfiTreeDelta) {host.engine_memo().staged_input.borrow_mut().tree.push(*delta);}@@ -502,29 +499,20 @@ pub unsafe extern "C" fn style_engine_stage_element_arrival(}/// Stages the local feature delta `delta` for the input the host submits next.-///-/// # Safety-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn style_engine_stage_local_feature_delta(host: &DocumentHost, delta: &FfiLocalFeatureDelta) {+pub extern "C" fn style_engine_stage_local_feature_delta(host: &DocumentHost, delta: &FfiLocalFeatureDelta) {host.engine_memo().staged_input.borrow_mut().features.push(*delta);}/// Stages the state delta `delta` for the input the host submits next.-///-/// # Safety-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn style_engine_stage_state_delta(host: &DocumentHost, delta: &FfiStateDelta) {+pub extern "C" fn style_engine_stage_state_delta(host: &DocumentHost, delta: &FfiStateDelta) {host.engine_memo().staged_input.borrow_mut().states.push(*delta);}/// Stages the element declaration delta `delta` for the input the host submits next.-///-/// # Safety-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn style_engine_stage_element_declaration_delta(+pub extern "C" fn style_engine_stage_element_declaration_delta(host: &DocumentHost,delta: &FfiElementDeclarationDelta,) {diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rsindex 9fb79c86c38..0cdb61e0fcd 100644--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs@@ -7129,12 +7129,8 @@ fn finalize_animated_box_type(/// Applies the box type transformation and element adjustments to the animated composition `animated_overlay` holds/// over `longhand_table`.-///-/// # Safety-/// `longhand_table` and `animated_overlay` must be live, and `input_line_height_metrics` a live metrics snapshot when-/// `box_type` asks to check an input's line-height.#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_finalize_animated_box_type(+pub extern "C" fn rust_finalize_animated_box_type(box_type: FfiBoxTypeTransformationInput,longhand_table: &ComputedLonghandTable,animated_overlay: &mut AnimatedOverlay,diff --git a/Libraries/LibWeb/Rust/src/layout/layout_changes.rs b/Libraries/LibWeb/Rust/src/layout/layout_changes.rsindex 20bca46a932..67346769acc 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_changes.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_changes.rs@@ -662,11 +662,8 @@ pub extern "C" fn render_state_set_node_flag(host: &DocumentHost, node: NodeSlotqueue(host, LayoutChange::SetNodeFlag { node, flag, value });}-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_set_owned_image_natural_size(+pub extern "C" fn render_state_set_owned_image_natural_size(host: &DocumentHost,node: NodeSlotId,natural_size: FfiNaturalSize,diff --git a/Libraries/LibWeb/Rust/src/layout/shell_reads.rs b/Libraries/LibWeb/Rust/src/layout/shell_reads.rsindex a05fb47675b..605f7440733 100644--- a/Libraries/LibWeb/Rust/src/layout/shell_reads.rs+++ b/Libraries/LibWeb/Rust/src/layout/shell_reads.rs@@ -195,12 +195,8 @@ pub unsafe extern "C" fn layout_row_bound_shell(host: &DocumentHost, read: &Begu/// The content size of the committed box of the row the element with `style_node` is bound to, or none where the/// element has no row or its row no committed box. It makes no layout node, so a host callback a layout round makes/// on the render owner may ask it.-///-/// # Safety-///-/// As for [`layout_row_bound_shell`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_bound_committed_content_size(+pub extern "C" fn layout_row_bound_committed_content_size(host: &DocumentHost,read: &BegunRead,style_node: u32,diff --git a/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rs b/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rsindex 47515802089..c6eb9cd65ea 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rs@@ -421,12 +421,8 @@ impl LayoutNodeArena {/// Has the render state invalidate the box of the DOM node `style_node` names, or the document's for 0, as the layout/// tree update `mark` on the node asks, as it applies the host's writes: the classification reads the arena, which the/// host does not wait for.-///-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_apply_layout_tree_update_mark(+pub extern "C" fn render_state_apply_layout_tree_update_mark(host: &DocumentHost,style_node: u32,mark: FfiLayoutTreeUpdateMark,diff --git a/Libraries/LibWeb/Rust/src/painting/ffi.rs b/Libraries/LibWeb/Rust/src/painting/ffi.rsindex 13a7c7e4a6e..7529e86e254 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi.rs@@ -351,11 +351,8 @@ pub extern "C" fn render_state_background_color_can_be_compositor_animated(})}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_paintable_visual_context_node_count(+pub extern "C" fn render_state_paintable_visual_context_node_count(host: &DocumentHost,slot: NodeSlotId,list: crate::painting::host::FfiVisualContextBoxNodeList,diff --git a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rsindex 1f47ac9cd6e..eb689759cf0 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi/main_thread_entries.rs@@ -40,11 +40,8 @@ pub extern "C" fn layout_row_paintable_physical_resize_axes(}}-/// # Safety-///-/// As for [`layout_row_paintable_physical_resize_axes`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_paintable_compute_scrollbar_data(+pub extern "C" fn layout_row_paintable_compute_scrollbar_data(host: &crate::render_state::DocumentHost,slot: NodeSlotId,direction: ScrollDirection,@@ -148,11 +145,8 @@ pub unsafe extern "C" fn layout_row_snap_container_geometry(true}-/// # Safety-///-/// As for [`layout_row_paintable_physical_resize_axes`].#[unsafe(no_mangle)]-pub unsafe extern "C" fn layout_row_scroll_snapport_rect(+pub extern "C" fn layout_row_scroll_snapport_rect(host: &crate::render_state::DocumentHost,snap_container: NodeSlotId,scrollport: FfiCssPixelRect,@@ -349,11 +343,8 @@ pub unsafe extern "C" fn render_state_prepare_for_rendering(prepared.outcome}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_update_accumulated_visual_contexts(+pub extern "C" fn render_state_update_accumulated_visual_contexts(host: &crate::render_state::DocumentHost,read: &crate::render_state::BegunRead,viewport: NodeSlotId,@@ -364,11 +355,8 @@ pub unsafe extern "C" fn render_state_update_accumulated_visual_contexts(})}-/// # Safety-///-/// `host` must be a live document host, on its document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_update_visual_viewport_transform(+pub extern "C" fn render_state_update_visual_viewport_transform(host: &crate::render_state::DocumentHost,read: &crate::render_state::BegunRead,inputs: FfiVisualContextTreeInputs,diff --git a/Libraries/LibWeb/Rust/src/painting/paint_changes.rs b/Libraries/LibWeb/Rust/src/painting/paint_changes.rsindex f1c17c2714c..ff6f4913d45 100644--- a/Libraries/LibWeb/Rust/src/painting/paint_changes.rs+++ b/Libraries/LibWeb/Rust/src/painting/paint_changes.rs@@ -399,11 +399,8 @@ fn queue_element_paint_facts(host: &DocumentHost, element: u32, facts: ReplacedP}}-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_set_form_control_paint_facts(+pub extern "C" fn render_state_set_form_control_paint_facts(host: &DocumentHost,element: u32,facts: FfiFormControlPaintFacts,@@ -414,28 +411,16 @@ pub unsafe extern "C" fn render_state_set_form_control_paint_facts(/// The canvas paints its surface's content of this size and generation now: where that changed, so does what its box/// paints.-///-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_set_canvas_paint_facts(- host: &DocumentHost,- element: u32,- facts: FfiCanvasPaintFacts,-) {+pub extern "C" fn render_state_set_canvas_paint_facts(host: &DocumentHost, element: u32, facts: FfiCanvasPaintFacts) {// SAFETY: Guaranteed by the caller.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/// what its row paints.-///-/// # Safety-///-/// `host` must be a live document host, on the document's thread.#[unsafe(no_mangle)]-pub unsafe extern "C" fn render_state_set_navigable_container_paint_facts(+pub extern "C" fn render_state_set_navigable_container_paint_facts(host: &DocumentHost,node: NodeSlotId,facts: FfiNavigableContainerPaintFacts,diff --git a/Libraries/LibWeb/Rust/src/render_state/clock.rs b/Libraries/LibWeb/Rust/src/render_state/clock.rsindex 623830a6f81..88120d49f69 100644--- a/Libraries/LibWeb/Rust/src/render_state/clock.rs+++ b/Libraries/LibWeb/Rust/src/render_state/clock.rs@@ -1745,13 +1745,8 @@ pub extern "C" fn document_host_clock_lane_is_coming(host: &DocumentHost) -> boo/// `scroll_offset`, if not null, and waits until the StyleLayout thread has run the jobs handed to it before, the tick/// among them, and the Paint thread the recording of the frame the tick presents. For a test, whose clock ticks only/// where it injects them.-///-/// # Safety-///-/// `host` must come from `document_host_create` and not be destroyed yet, on its document's thread, and-/// `scroll_offset` must be null or valid for reads.#[unsafe(no_mangle)]-pub unsafe extern "C" fn document_host_inject_clock_tick(+pub extern "C" fn document_host_inject_clock_tick(host: &DocumentHost,frame_time_nanoseconds: i64,scroll_offset: Option<&FfiScrollOffset>,