Truly independent web browser
LibWeb: Type host callback tables as safe function pointers
Andreas Klingcdf37bfb0d35
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex fa7e71e4594..35fb56348b8 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -914,6 +914,9 @@ pub(crate) struct FlexLayoutData {/// receives the registered `context`, the owning document, as its first argument. The fields are/// private: the callbacks are reached only through the methods below, which take the main thread/// token.+///+/// NB: The callbacks are typed as safe functions because the table only comes from the host through an export+/// whose safety contract keeps them callable, and the private fields let nothing else call them.#[derive(Clone, Copy)]#[repr(C)]pub struct FfiLayoutHostCallbacks {@@ -921,13 +924,13 @@ pub struct FfiLayoutHostCallbacks {/// The commit messages a finished commit leaves for the document, in the order it produced/// them.deliver_commit_messages:- unsafe extern "C" fn(*mut c_void, &crate::render_state::BegunRead, *const commit::FfiCommitMessage, usize),+ extern "C" fn(*mut c_void, &crate::render_state::BegunRead, *const commit::FfiCommitMessage, usize),/// What a container-relative length on the element with the given identity resolves against.- container_length_bases: unsafe extern "C" fn(*mut c_void, u32) -> svg_formatting_context::FfiContainerLengthBases,+ container_length_bases: extern "C" fn(*mut c_void, u32) -> svg_formatting_context::FfiContainerLengthBases,/// The scroll containers a finished layout tree build gave a style, each with whether it is a/// scroll snap container.take_built_scroll_containers:- unsafe extern "C" fn(*mut c_void, &crate::render_state::BegunRead, *const FfiBuiltScrollContainer, usize),+ extern "C" fn(*mut c_void, &crate::render_state::BegunRead, *const FfiBuiltScrollContainer, usize),}/// A scroll container a layout tree build gave a style, with whether it was a scroll snap@@ -962,8 +965,8 @@ impl FfiLayoutHostCallbacks {if messages.is_empty() {return;}- // SAFETY: The document registered the host with the arena and outlives this call.- unsafe { (self.deliver_commit_messages)(self.context, read, messages.as_ptr(), messages.len()) };+ // The document registered the host with the arena and outlives this call.+ (self.deliver_commit_messages)(self.context, read, messages.as_ptr(), messages.len());}/// Hands the document the scroll containers a build gave a style, in `read`.@@ -980,8 +983,8 @@ impl FfiLayoutHostCallbacks {if built.is_empty() {return;}- // SAFETY: The document registered the host with the arena and outlives this call.- unsafe { (self.take_built_scroll_containers)(self.context, read, built.as_ptr(), built.len()) };+ // The document registered the host with the arena and outlives this call.+ (self.take_built_scroll_containers)(self.context, read, built.as_ptr(), built.len());}/// The one question a layout pass may ask the document while it runs.diff --git a/Libraries/LibWeb/Rust/src/layout/update_layout.rs b/Libraries/LibWeb/Rust/src/layout/update_layout.rsindex 7162597ae3f..79a6efb8fd5 100644--- a/Libraries/LibWeb/Rust/src/layout/update_layout.rs+++ b/Libraries/LibWeb/Rust/src/layout/update_layout.rs@@ -59,42 +59,46 @@ fn read_arena<A, R>(host: &DocumentHost, read: &BegunRead, args: A, answer: fn(&/// `context`, the owning document, first and answers synchronously; any of them may run the/// layout update of another document, so the loop holds no arena borrow across a call. The/// methods below, which take the main thread token, are the only way to call them.+///+/// NB: The callbacks are typed as safe functions because the table only comes from the host's+/// `document_host_set_layout_update_host_callbacks`, whose contract keeps them callable with+/// `context` until they are cleared, and the private fields let nothing else call them.#[derive(Clone, Copy)]#[repr(C)]pub struct FfiLayoutUpdateHostCallbacks {context: *mut c_void,- connected_element_count: unsafe extern "C" fn(*mut c_void, &BegunRead) -> u32,- update_style: unsafe extern "C" fn(*mut c_void, &BegunRead),- process_pending_list_item_renumbers: unsafe extern "C" fn(*mut c_void, &BegunRead),- process_pending_top_layer_layout_changes: unsafe extern "C" fn(*mut c_void, &BegunRead),- document_facts: unsafe extern "C" fn(*mut c_void, &BegunRead) -> FfiLayoutUpdateDocumentFacts,+ connected_element_count: extern "C" fn(*mut c_void, &BegunRead) -> u32,+ update_style: extern "C" fn(*mut c_void, &BegunRead),+ process_pending_list_item_renumbers: extern "C" fn(*mut c_void, &BegunRead),+ process_pending_top_layer_layout_changes: extern "C" fn(*mut c_void, &BegunRead),+ document_facts: extern "C" fn(*mut c_void, &BegunRead) -> FfiLayoutUpdateDocumentFacts,/// True when a size container waits for its queries to be evaluated after the next full layout. Only an update/// that may take the partial relayout path asks.- container_query_evaluation_is_pending: unsafe extern "C" fn(*mut c_void, &BegunRead) -> bool,- needs_style_update_after_layout: unsafe extern "C" fn(*mut c_void, &BegunRead) -> bool,- prepare_for_rendering: unsafe extern "C" fn(*mut c_void, &BegunRead),+ container_query_evaluation_is_pending: extern "C" fn(*mut c_void, &BegunRead) -> bool,+ needs_style_update_after_layout: extern "C" fn(*mut c_void, &BegunRead) -> bool,+ prepare_for_rendering: extern "C" fn(*mut c_void, &BegunRead),/// Readies the document for a layout tree build, and answers the document's style, interned as a/// record, where the flag says the build may build the viewport, and 0 otherwise.- prepare_layout_tree_build: unsafe extern "C" fn(*mut c_void, &BegunRead, bool) -> u64,+ prepare_layout_tree_build: extern "C" fn(*mut c_void, &BegunRead, bool) -> u64,/// Retires the tree a build replaced once the host has been paid for the build: the viewport/// before the build, then the one it placed.- finish_layout_tree_build: unsafe extern "C" fn(*mut c_void, &BegunRead, NodeSlotId, NodeSlotId),+ finish_layout_tree_build: extern "C" fn(*mut c_void, &BegunRead, NodeSlotId, NodeSlotId),/// True when stale list-item counters marked more of the tree for a rebuild, given the DOM nodes whose subtrees the/// build rebuilt.reconcile_stale_list_item_counters_after_tree_build:- unsafe extern "C" fn(*mut c_void, *const FfiNodeIdentity, usize) -> bool,+ extern "C" fn(*mut c_void, *const FfiNodeIdentity, usize) -> bool,/// Refreshes what derives from committed layout; the flag says whether the tree changed.- after_layout_commit: unsafe extern "C" fn(*mut c_void, &BegunRead, bool),- note_full_layout_performed: unsafe extern "C" fn(*mut c_void),- evaluate_pending_container_queries: unsafe extern "C" fn(*mut c_void, &BegunRead),- record_stabilization_bound_failure: unsafe extern "C" fn(*mut c_void),+ after_layout_commit: extern "C" fn(*mut c_void, &BegunRead, bool),+ note_full_layout_performed: extern "C" fn(*mut c_void),+ evaluate_pending_container_queries: extern "C" fn(*mut c_void, &BegunRead),+ record_stabilization_bound_failure: extern "C" fn(*mut c_void),/// Attaches the image resources a box's style asks for. The flag says the box replaces its/// element's contents with a single image, whose provider it owns.- attach_style_resources: unsafe extern "C" fn(*mut c_void, &BegunRead, NodeSlotId, bool, FfiStyleImageFacts),+ attach_style_resources: extern "C" fn(*mut c_void, &BegunRead, NodeSlotId, bool, FfiStyleImageFacts),/// Gives a generated image box the provider of the image it shows, which the box owns, and/// attaches the box's style resources. The image is the `<image>` at the given index of the/// pseudo-element's `content`, or the given marker's `list-style-image`.- attach_generated_image: unsafe extern "C" fn(+ attach_generated_image: extern "C" fn(*mut c_void,&BegunRead,NodeSlotId,@@ -147,41 +151,40 @@ pub struct FfiLayoutTreeBuildStats {}impl FfiLayoutUpdateHostCallbacks {- // SAFETY (for every call below): The C++ host answers synchronously from its live document.fn connected_element_count(&self, _: &MainThread, read: &BegunRead) -> u32 {- unsafe { (self.connected_element_count)(self.context, read) }+ (self.connected_element_count)(self.context, read)}fn update_style(&self, _: &MainThread, read: &BegunRead) {- unsafe { (self.update_style)(self.context, read) }+ (self.update_style)(self.context, read);}fn process_pending_list_item_renumbers(&self, _: &MainThread, read: &BegunRead) {- unsafe { (self.process_pending_list_item_renumbers)(self.context, read) }+ (self.process_pending_list_item_renumbers)(self.context, read);}fn process_pending_top_layer_layout_changes(&self, _: &MainThread, read: &BegunRead) {- unsafe { (self.process_pending_top_layer_layout_changes)(self.context, read) }+ (self.process_pending_top_layer_layout_changes)(self.context, read);}fn document_facts(&self, _: &MainThread, read: &BegunRead) -> FfiLayoutUpdateDocumentFacts {- unsafe { (self.document_facts)(self.context, read) }+ (self.document_facts)(self.context, read)}fn container_query_evaluation_is_pending(&self, _: &MainThread, read: &BegunRead) -> bool {- unsafe { (self.container_query_evaluation_is_pending)(self.context, read) }+ (self.container_query_evaluation_is_pending)(self.context, read)}fn needs_style_update_after_layout(&self, _: &MainThread, read: &BegunRead) -> bool {- unsafe { (self.needs_style_update_after_layout)(self.context, read) }+ (self.needs_style_update_after_layout)(self.context, read)}fn prepare_for_rendering(&self, _: &MainThread, read: &BegunRead) {- unsafe { (self.prepare_for_rendering)(self.context, read) }+ (self.prepare_for_rendering)(self.context, read);}fn prepare_layout_tree_build(&self, _: &MainThread, read: &BegunRead, may_create_viewport: bool) -> Option<u64> {- let record = unsafe { (self.prepare_layout_tree_build)(self.context, read, may_create_viewport) };+ let record = (self.prepare_layout_tree_build)(self.context, read, may_create_viewport);(record != 0).then_some(record)}@@ -192,7 +195,7 @@ impl FfiLayoutUpdateHostCallbacks {replaced_viewport: NodeSlotId,viewport: NodeSlotId,) {- unsafe { (self.finish_layout_tree_build)(self.context, read, replaced_viewport, viewport) }+ (self.finish_layout_tree_build)(self.context, read, replaced_viewport, viewport);}fn reconcile_stale_list_item_counters_after_tree_build(@@ -200,29 +203,27 @@ impl FfiLayoutUpdateHostCallbacks {_: &MainThread,rebuilt_roots: &[FfiNodeIdentity],) -> bool {- unsafe {- (self.reconcile_stale_list_item_counters_after_tree_build)(- self.context,- rebuilt_roots.as_ptr(),- rebuilt_roots.len(),- )- }+ (self.reconcile_stale_list_item_counters_after_tree_build)(+ self.context,+ rebuilt_roots.as_ptr(),+ rebuilt_roots.len(),+ )}fn after_layout_commit(&self, _: &MainThread, read: &BegunRead, layout_tree_changed: bool) {- unsafe { (self.after_layout_commit)(self.context, read, layout_tree_changed) }+ (self.after_layout_commit)(self.context, read, layout_tree_changed);}fn note_full_layout_performed(&self, _: &MainThread) {- unsafe { (self.note_full_layout_performed)(self.context) }+ (self.note_full_layout_performed)(self.context);}fn evaluate_pending_container_queries(&self, _: &MainThread, read: &BegunRead) {- unsafe { (self.evaluate_pending_container_queries)(self.context, read) }+ (self.evaluate_pending_container_queries)(self.context, read);}fn record_stabilization_bound_failure(&self, _: &MainThread) {- unsafe { (self.record_stabilization_bound_failure)(self.context) }+ (self.record_stabilization_bound_failure)(self.context);}/// Hands the boxes the tree builds of the update stamped the image resources they are owed,@@ -245,14 +246,12 @@ impl FfiLayoutUpdateHostCallbacks {match owed {OwedImageResources::StyleResources {owns_content_replacement_image,- } => unsafe {- (self.attach_style_resources)(self.context, read, row, owns_content_replacement_image, images);- },+ } => (self.attach_style_resources)(self.context, read, row, owns_content_replacement_image, images),OwedImageResources::GeneratedImage {generator,pseudo_element,image,- } => unsafe {+ } => {(self.attach_generated_image)(self.context,read,@@ -262,7 +261,7 @@ impl FfiLayoutUpdateHostCallbacks {image,images,);- },+ }}}}diff --git a/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs b/Libraries/LibWeb/Rust/src/painting/display_list/dump.rsindex a7ed11e95ee..d4581d12304 100644--- a/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs+++ b/Libraries/LibWeb/Rust/src/painting/display_list/dump.rs@@ -33,36 +33,39 @@ crate::stage::main_thread_ffi_entries!();/// What a display list dump asks the document. The fields are private: the callbacks are reached/// only through the methods below, which take the main thread token.+///+/// NB: The callbacks are typed as safe functions because the table only comes from the host through an export+/// whose safety contract keeps them callable, and the private fields let nothing else call them.#[derive(Clone, Copy)]#[repr(C)]pub struct FfiPaintingDumpCallbacks {context: *mut c_void,/// Describes the row in the slot, as its layout node describes itself.- debug_description: unsafe extern "C" fn(context: *mut c_void, slot: NodeSlotId, description_sink: *mut c_void),+ debug_description: extern "C" fn(context: *mut c_void, slot: NodeSlotId, description_sink: *mut c_void),/// Answers the storage handle of a nested display list.- nested_display_list: unsafe extern "C" fn(context: *mut c_void, display_list_id: u64) -> *const c_void,- append_text: unsafe extern "C" fn(context: *mut c_void, bytes: *const u8, byte_count: usize),+ nested_display_list: extern "C" fn(context: *mut c_void, display_list_id: u64) -> *const c_void,+ append_text: extern "C" fn(context: *mut c_void, bytes: *const u8, byte_count: usize),}impl FfiPaintingDumpCallbacks {fn debug_description(&self, _: &MainThread, slot: NodeSlotId) -> String {let mut description = Vec::new();- // SAFETY: The C++ host fills the description sink synchronously through the exported push+ // The C++ host fills the description sink synchronously through the exported push// function.- unsafe { (self.debug_description)(self.context, slot, (&raw mut description).cast()) };+ (self.debug_description)(self.context, slot, (&raw mut description).cast());String::from_utf8_lossy(&description).into_owned()}fn nested_display_list(&self, _: &MainThread, display_list_id: DisplayListResourceId) -> *const c_void {- // SAFETY: Nested ids come from records the host produced, so they resolve in its storage.- let display_list = unsafe { (self.nested_display_list)(self.context, display_list_id.0) };+ // Nested ids come from records the host produced, so they resolve in its storage.+ let display_list = (self.nested_display_list)(self.context, display_list_id.0);assert!(!display_list.is_null());display_list}fn append_text(&self, _: &MainThread, text: &str) {- // SAFETY: The C++ sink copies the completed dump synchronously.- unsafe { (self.append_text)(self.context, text.as_ptr(), text.len()) };+ // The C++ sink copies the completed dump synchronously.+ (self.append_text)(self.context, text.as_ptr(), text.len());}}@@ -130,7 +133,6 @@ pub unsafe extern "C" fn painting_dump(let main_thread = unsafe { main_thread(host) };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 = {crate::painting::ffi::read_arena(host, read, viewport, |arena, viewport| {let mut owners = VisualContextNodeOwners::collect(arena, viewport);diff --git a/Libraries/LibWeb/Rust/src/painting/host/mod.rs b/Libraries/LibWeb/Rust/src/painting/host/mod.rsindex f63b40aad18..bcf7ca7137b 100644--- a/Libraries/LibWeb/Rust/src/painting/host/mod.rs+++ b/Libraries/LibWeb/Rust/src/painting/host/mod.rs@@ -32,11 +32,14 @@ impl Default for RootBackgroundSource {/// What geometry tells the document. The fields are private, so the callbacks are reached only/// through the methods below, which take the main thread token.+///+/// NB: The callbacks are typed as safe functions because the table only comes from the host through an export+/// whose safety contract keeps them callable, and the private fields let nothing else call them.#[derive(Clone, Copy)]#[repr(C)]pub struct FfiGeometryHostCallbacks {context: *mut std::ffi::c_void,- set_scroll_offset: unsafe extern "C" fn(+ set_scroll_offset: extern "C" fn(*mut std::ffi::c_void,&crate::render_state::BegunRead,crate::layout::node_data::NodeSlotId,@@ -58,7 +61,6 @@ impl FfiGeometryHostCallbacks {slot: crate::layout::node_data::NodeSlotId,offset: crate::layout::used_values::FfiCssPixelPoint,) {- // SAFETY: Guaranteed by the caller.- unsafe { (self.set_scroll_offset)(self.context, read, slot, offset) };+ (self.set_scroll_offset)(self.context, read, slot, offset);}}diff --git a/Libraries/LibWeb/Rust/src/painting/host/paint.rs b/Libraries/LibWeb/Rust/src/painting/host/paint.rsindex d36d4f05c7c..956eb6e2c7c 100644--- a/Libraries/LibWeb/Rust/src/painting/host/paint.rs+++ b/Libraries/LibWeb/Rust/src/painting/host/paint.rs@@ -529,25 +529,28 @@ pub struct FfiSnapAreaGeometry {/// Where a recording's resources go once it is published. The fields are private: the callbacks/// are reached only through the methods below, which take the main thread token.+///+/// NB: The callbacks are typed as safe functions because the table only comes from the host through an export+/// whose safety contract keeps them callable, and the private fields let nothing else call them.#[derive(Clone, Copy)]#[repr(C)]pub struct FfiRecordingPublishCallbacks {context: *mut c_void,- add_font: unsafe extern "C" fn(*mut c_void, *const c_void),- add_image_frame: unsafe extern "C" fn(*mut c_void, *const c_void),- resolve_vector_image_display_list: unsafe extern "C" fn(*mut c_void, *const FfiVectorImageRenderRequest) -> u64,- add_video_sink: unsafe extern "C" fn(*mut c_void, u64, u64),+ add_font: extern "C" fn(*mut c_void, *const c_void),+ add_image_frame: extern "C" fn(*mut c_void, *const c_void),+ resolve_vector_image_display_list: extern "C" fn(*mut c_void, *const FfiVectorImageRenderRequest) -> u64,+ add_video_sink: extern "C" fn(*mut c_void, u64, u64),}impl FfiRecordingPublishCallbacks {pub(crate) fn add_font(&self, _: &MainThread, font: &libgfx_rust::font::FontHandle) {- // SAFETY: The C++ host registers the live font synchronously.- unsafe { (self.add_font)(self.context, font.as_raw()) };+ // The C++ host registers the live font synchronously.+ (self.add_font)(self.context, font.as_raw());}pub(crate) fn add_image_frame(&self, _: &MainThread, frame: &libgfx_rust::image_frame::ImageFrameHandle) {- // SAFETY: The C++ host copies the live frame synchronously.- unsafe { (self.add_image_frame)(self.context, frame.as_raw()) };+ // The C++ host copies the live frame synchronously.+ (self.add_image_frame)(self.context, frame.as_raw());}pub(crate) fn resolve_vector_image_display_list(@@ -555,13 +558,13 @@ impl FfiRecordingPublishCallbacks {_: &MainThread,request: &FfiVectorImageRenderRequest,) -> u64 {- // SAFETY: The C++ host records the image's display list synchronously and reads the+ // The C++ host records the image's display list synchronously and reads the// request only for the duration of the call.- unsafe { (self.resolve_vector_image_display_list)(self.context, request) }+ (self.resolve_vector_image_display_list)(self.context, request)}pub(crate) fn add_video_sink(&self, _: &MainThread, resource_id: u64, sink_handle: u64) {- // SAFETY: The C++ host registers the sink synchronously.- unsafe { (self.add_video_sink)(self.context, resource_id, sink_handle) };+ // The C++ host registers the sink synchronously.+ (self.add_video_sink)(self.context, resource_id, sink_handle);}}diff --git a/Libraries/LibWeb/Rust/src/painting/layout_tree_dump.rs b/Libraries/LibWeb/Rust/src/painting/layout_tree_dump.rsindex 32957d25e0f..325ef9b3658 100644--- a/Libraries/LibWeb/Rust/src/painting/layout_tree_dump.rs+++ b/Libraries/LibWeb/Rust/src/painting/layout_tree_dump.rs@@ -37,32 +37,32 @@ pub struct FfiNestedLayoutRoot {/// What a layout tree dump asks the document. The fields are private: the callbacks are reached/// only through the methods below, which take the main thread token.+///+/// NB: The callbacks are typed as safe functions because the table only comes from the host through an export+/// whose safety contract keeps them callable, and the private fields let nothing else call them.#[derive(Clone, Copy)]#[repr(C)]pub struct FfiLayoutTreeDumpCallbacks {context: *mut c_void,/// The document whose rows are dumped, which resolves the nodes they stand for.document: *mut c_void,- describe_dom_node: unsafe extern "C" fn(+ describe_dom_node: extern "C" fn(document: *mut c_void,node: FfiNodeIdentity,tag_name_sink: *mut c_void,identifier_sink: *mut c_void,),- navigable_container_content_document: unsafe extern "C" fn(- document: *mut c_void,- node: FfiNodeIdentity,- url_sink: *mut c_void,- ) -> FfiNestedLayoutRoot,- svg_as_image_layout_root: unsafe extern "C" fn(document: *mut c_void, node: FfiNodeIdentity) -> *mut c_void,- dump_nested_layout_tree: unsafe extern "C" fn(+ navigable_container_content_document:+ extern "C" fn(document: *mut c_void, node: FfiNodeIdentity, url_sink: *mut c_void) -> FfiNestedLayoutRoot,+ svg_as_image_layout_root: extern "C" fn(document: *mut c_void, node: FfiNodeIdentity) -> *mut c_void,+ dump_nested_layout_tree: extern "C" fn(context: *mut c_void,layout_root: *mut c_void,indent: usize,interactive: bool,output_sink: *mut c_void,),- append_text: unsafe extern "C" fn(context: *mut c_void, bytes: *const u8, byte_count: usize),+ append_text: extern "C" fn(context: *mut c_void, bytes: *const u8, byte_count: usize),}impl FfiLayoutTreeDumpCallbacks {@@ -73,8 +73,8 @@ impl FfiLayoutTreeDumpCallbacks {tag_name_sink: &mut Vec<u8>,identifier_sink: &mut Vec<u8>,) {- // SAFETY: The C++ host fills both sinks synchronously through the exported push function.- unsafe {+ // The C++ host fills both sinks synchronously through the exported push function.+ {(self.describe_dom_node)(self.document,node,@@ -90,14 +90,14 @@ impl FfiLayoutTreeDumpCallbacks {node: FfiNodeIdentity,) -> Option<(Vec<u8>, *mut c_void)> {let mut url = Vec::new();- // SAFETY: The C++ host fills the url sink synchronously through the exported push function.- let nested = unsafe { (self.navigable_container_content_document)(self.document, node, (&raw mut url).cast()) };+ // The C++ host fills the url sink synchronously through the exported push function.+ let nested = (self.navigable_container_content_document)(self.document, node, (&raw mut url).cast());nested.has_document.then_some((url, nested.layout_root))}fn svg_as_image_layout_root(&self, _: &MainThread, node: FfiNodeIdentity) -> *mut c_void {- // SAFETY: The C++ host answers synchronously.- unsafe { (self.svg_as_image_layout_root)(self.document, node) }+ // The C++ host answers synchronously.+ (self.svg_as_image_layout_root)(self.document, node)}fn dump_nested_layout_tree(@@ -108,10 +108,10 @@ impl FfiLayoutTreeDumpCallbacks {interactive: bool,output: &mut Vec<u8>,) {- // SAFETY: The C++ host re-enters the dump for the nested document's own arena and appends+ // The C++ host re-enters the dump for the nested document's own arena and appends// into the output sink synchronously through the exported push function; no reference to// the output vector is alive across the call.- unsafe {+ {(self.dump_nested_layout_tree)(self.context,layout_root,@@ -123,8 +123,8 @@ impl FfiLayoutTreeDumpCallbacks {}fn append_text(&self, _: &MainThread, bytes: &[u8]) {- // SAFETY: The C++ sink copies the completed dump synchronously.- unsafe { (self.append_text)(self.context, bytes.as_ptr(), bytes.len()) };+ // The C++ sink copies the completed dump synchronously.+ (self.append_text)(self.context, bytes.as_ptr(), bytes.len());}}@@ -143,7 +143,6 @@ 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 = {crate::painting::ffi::read_arena(host,diff --git a/Libraries/LibWeb/Rust/src/painting/stacking_context/dump.rs b/Libraries/LibWeb/Rust/src/painting/stacking_context/dump.rsindex 4f5711540a5..6b63b585ab3 100644--- a/Libraries/LibWeb/Rust/src/painting/stacking_context/dump.rs+++ b/Libraries/LibWeb/Rust/src/painting/stacking_context/dump.rs@@ -17,13 +17,16 @@ use std::fmt::Write;/// What a stacking context dump asks the document. The fields are private: the callbacks are/// reached only through the methods below, which take the main thread token.+///+/// NB: The callbacks are typed as safe functions because the table only comes from the host through an export+/// whose safety contract keeps them callable, and the private fields let nothing else call them.#[derive(Clone, Copy)]#[repr(C)]pub struct FfiStackingContextDumpCallbacks {context: *mut c_void,/// Describes the row in the slot, as its layout node describes itself.- debug_description: unsafe extern "C" fn(context: *mut c_void, slot: NodeSlotId, description_sink: *mut c_void),- append_text: unsafe extern "C" fn(context: *mut c_void, bytes: *const u8, byte_count: usize),+ debug_description: extern "C" fn(context: *mut c_void, slot: NodeSlotId, description_sink: *mut c_void),+ append_text: extern "C" fn(context: *mut c_void, bytes: *const u8, byte_count: usize),}crate::stage::main_thread_ffi_entries!();@@ -31,15 +34,15 @@ crate::stage::main_thread_ffi_entries!();impl FfiStackingContextDumpCallbacks {fn debug_description(&self, _: &MainThread, slot: NodeSlotId) -> String {let mut description = Vec::new();- // SAFETY: The C++ host fills the description sink synchronously through the exported push+ // The C++ host fills the description sink synchronously through the exported push// function.- unsafe { (self.debug_description)(self.context, slot, (&raw mut description).cast()) };+ (self.debug_description)(self.context, slot, (&raw mut description).cast());String::from_utf8_lossy(&description).into_owned()}fn append_text(&self, _: &MainThread, text: &str) {- // SAFETY: The C++ sink copies the completed dump synchronously.- unsafe { (self.append_text)(self.context, text.as_ptr(), text.len()) };+ // The C++ sink copies the completed dump synchronously.+ (self.append_text)(self.context, text.as_ptr(), text.len());}}@@ -56,7 +59,6 @@ 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 = {crate::painting::ffi::read_arena(host, read, viewport, |arena, viewport| {let mut lines = Vec::new();