Truly independent web browser
LibWeb: Take the objects C++ lends to FFI entry points by reference
Andreas Klingbbfe24da6b65
diff --git a/Libraries/LibWeb/CSS/RustDescriptorBlock.cpp b/Libraries/LibWeb/CSS/RustDescriptorBlock.cppindex 63b625abddd..8f91ad61980 100644--- a/Libraries/LibWeb/CSS/RustDescriptorBlock.cpp+++ b/Libraries/LibWeb/CSS/RustDescriptorBlock.cpp@@ -96,7 +96,7 @@ RefPtr<StyleValue const> RustDescriptorBlock::descriptor(DescriptorNameAndID conauto* value = rust_descriptor_block_get(m_block, to_underlying(name.id()), Parser::ffi_utf16_view(name.name()));if (!value)return nullptr;- return StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_retain(static_cast<StyleValueFFI::StyleValueData const*>(value)));+ return StyleValue::adopt_rust_style_value_data(StyleValueFFI::rust_style_value_retain(value));}RefPtr<StyleValue const> RustDescriptorBlock::descriptor_or_initial_value(AtRuleID at_rule, DescriptorNameAndID const& name) constdiff --git a/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/StyleValue.cppindex 46728c95bff..320e567af41 100644--- a/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp+++ b/Libraries/LibWeb/CSS/StyleValues/StyleValue.cpp@@ -78,7 +78,7 @@ namespace Web::CSS {Utf16FlyString css_string_from_rust(void const* string){- auto view = StyleValueFFI::rust_css_string_view(string);+ auto view = StyleValueFFI::rust_css_string_view(static_cast<StyleValueFFI::CssString const*>(string));return Utf16FlyString::from_utf16(Utf16View { reinterpret_cast<char16_t const*>(view.data), view.length });}diff --git a/Libraries/LibWeb/Rust/build.rs b/Libraries/LibWeb/Rust/build.rsindex 522765e52eb..72df65e1e85 100644--- a/Libraries/LibWeb/Rust/build.rs+++ b/Libraries/LibWeb/Rust/build.rs@@ -2446,6 +2446,15 @@ fn main() -> Result<(), Box<dyn Error>> {.rename.insert(rust_name.to_string(), cxx_name.to_string());}+ // A selector parses against a namespace context as the value parser header declares it.+ selector_config.export.rename.insert(+ "NativeNamespaceContext".to_string(),+ "Web::CSS::Parser::ValueParserFFI::NativeNamespaceContext".to_string(),+ );+ selector_config+ .after_includes+ .get_or_insert_with(String::new)+ .push_str("\nnamespace Web::CSS::Parser::ValueParserFFI { struct NativeNamespaceContext; }");generate_ffi_header(selector_config,@@ -2554,6 +2563,15 @@ fn main() -> Result<(), Box<dyn Error>> {.after_includes.get_or_insert_with(String::new).push_str("\nnamespace Web::CSS::ComputedValuesFFI { struct FfiLengthResolutionContext; }");+ // A counter style's system is read as the style value header declares it.+ value_parser_config.export.rename.insert(+ "StyleValueData".to_string(),+ "Web::CSS::StyleValueFFI::StyleValueData".to_string(),+ );+ value_parser_config+ .after_includes+ .get_or_insert_with(String::new)+ .push_str("\nnamespace Web::CSS::StyleValueFFI { union StyleValueData; }");generate_ffi_header(value_parser_config,@@ -2655,6 +2673,20 @@ fn main() -> Result<(), Box<dyn Error>> {.after_includes.get_or_insert_with(String::new).push_str("\nnamespace Web::DOM { class Element; }\nnamespace Web::CSS { struct StyleReactionApplication; }");+ // The native sheets, rules and declaration blocks the host publishes are named as the value parser header declares+ // them.+ for name in ["DeclarationBlock", "NativeRule", "NativeStyleSheet"] {+ style_engine_config+ .export+ .rename+ .insert(name.to_string(), format!("Web::CSS::Parser::ValueParserFFI::{name}"));+ }+ style_engine_config+ .after_includes+ .get_or_insert_with(String::new)+ .push_str(+ "\nnamespace Web::CSS::Parser::ValueParserFFI { struct DeclarationBlock; struct NativeRule; struct NativeStyleSheet; }",+ );generate_ffi_header(style_engine_config,diff --git a/Libraries/LibWeb/Rust/src/css/calc.rs b/Libraries/LibWeb/Rust/src/css/calc.rsindex 89aead3c267..ed11ac14117 100644--- a/Libraries/LibWeb/Rust/src/css/calc.rs+++ b/Libraries/LibWeb/Rust/src/css/calc.rs@@ -4541,16 +4541,11 @@ pub extern "C" fn rust_style_value_contains_anchor_function(value: &crate::css::/// The value of a computed `<length-percentage>` whose anchor() and anchor-size() functions are unresolvable: one/// strong reference to it with the functions replaced by their fallback values, or null when it holds no anchor/// functions or when one of them has no fallback value, which `is_invalid` tells apart.-///-/// # Safety-/// `value` must point at live style value data.#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_style_value_with_unresolvable_anchor_functions(- value: *const std::ffi::c_void,+pub extern "C" fn rust_style_value_with_unresolvable_anchor_functions(+ value: &crate::css::style_value::StyleValueData,is_invalid: &mut bool,) -> *const crate::css::style_value::StyleValueData {- // SAFETY: Guaranteed by the caller.- let value = unsafe { &*value.cast::<crate::css::style_value::StyleValueData>() };let substituted = substitute_unresolvable_anchor_functions(value);*is_invalid = substituted.is_none();substituteddiff --git a/Libraries/LibWeb/Rust/src/css/color_resolution.rs b/Libraries/LibWeb/Rust/src/css/color_resolution.rsindex bae625063c2..34e723130f7 100644--- a/Libraries/LibWeb/Rust/src/css/color_resolution.rs+++ b/Libraries/LibWeb/Rust/src/css/color_resolution.rs@@ -1628,14 +1628,12 @@ fn computed_value_form(value: StyleValueData) -> StyleValueData {/// resolve.////// # Safety-/// `value` must point at live style value data, and `style` must be null or point at a style-/// whose group payloads outlive the call.+/// `style` must be null or point at a style whose group payloads outlive the call.#[unsafe(no_mangle)]pub unsafe extern "C" fn rust_relative_color_resolved_value(- value: *const core::ffi::c_void,+ value: &StyleValueData,style: *const FfiColorResolutionStyle,) -> *const StyleValueData {- let value = unsafe { &*value.cast::<StyleValueData>() };// SAFETY: Guaranteed by the caller.let resolution_input = unsafe { ColorResolutionInput::for_ffi_style(style) };match resolve_relative_form(value, &resolution_input) {@@ -1649,14 +1647,12 @@ pub unsafe extern "C" fn rust_relative_color_resolved_value(/// one strong reference, or null when the value is no mix or does not resolve.////// # Safety-/// `value` must point at live style value data, and `style` must be null or point at a style-/// whose group payloads outlive the call.+/// `style` must be null or point at a style whose group payloads outlive the call.#[unsafe(no_mangle)]pub unsafe extern "C" fn rust_color_mix_resolved_value(- value: *const core::ffi::c_void,+ value: &StyleValueData,style: *const FfiColorResolutionStyle,) -> *const StyleValueData {- let value = unsafe { &*value.cast::<StyleValueData>() };if !matches!(value, StyleValueData::ColorMix { .. }) {return core::ptr::null();}@@ -2592,17 +2588,13 @@ pub struct FfiResolvedColorValue {/// Resolves a parsed style value to an sRGB color against a style record of `host`'s document, as the record/// computes its own values: its used color-scheme and `color`, and its lengths. A null record names no style.-///-/// # Safety-/// `host` must be a live document host, on its document's thread, and `value` must point at live style value data.#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_style_value_to_color_against_style_record(+pub extern "C" fn rust_style_value_to_color_against_style_record(host: &crate::render_state::DocumentHost,read: &crate::render_state::BegunRead,style_record: u64,- value: *const core::ffi::c_void,+ value: &crate::css::style_value::StyleValueData,) -> FfiResolvedColorValue {- let value = unsafe { &*value.cast::<crate::css::style_value::StyleValueData>() };let color = crate::css::style::engine_calls::with_engine(read, host, |engine| {engine.color_against_style_record(style_record, value)});@@ -2621,14 +2613,12 @@ pub unsafe extern "C" fn rust_style_value_to_color_against_style_record(/// Resolves an absolutized style value to an sRGB color against a style, or declines.////// # Safety-/// `value` must point at live style value data, and `style` must be null or point at a style whose group payloads-/// outlive the call.+/// `style` must be null or point at a style whose group payloads outlive the call.#[unsafe(no_mangle)]pub unsafe extern "C" fn rust_style_value_to_color(- value: *const core::ffi::c_void,+ value: &crate::css::style_value::StyleValueData,style: *const FfiColorResolutionStyle,) -> FfiResolvedColorValue {- let value = unsafe { &*value.cast::<crate::css::style_value::StyleValueData>() };// SAFETY: Guaranteed by the caller.let resolution_input = unsafe { ColorResolutionInput::for_ffi_style(style) };match to_color(value, &resolution_input) {diff --git a/Libraries/LibWeb/Rust/src/css/counter_style.rs b/Libraries/LibWeb/Rust/src/css/counter_style.rsindex 5e52b5ecd44..f8cbbb1a361 100644--- a/Libraries/LibWeb/Rust/src/css/counter_style.rs+++ b/Libraries/LibWeb/Rust/src/css/counter_style.rs@@ -544,36 +544,21 @@ pub unsafe extern "C" fn rust_counter_styles_resolve(/// Whether a rule whose `system` is `system`, null when it has none, still defines a counter style/// once its `symbols` descriptor, or its `additive-symbols` one when `additive`, lists `count`/// entries.-///-/// # Safety-///-/// `system` must be null or point to a live style value.#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_counter_style_system_accepts_symbols(- system: *const c_void,+pub extern "C" fn rust_counter_style_system_accepts_symbols(+ system: Option<&StyleValueData>,additive: bool,count: usize,) -> bool {- // SAFETY: Guaranteed by the caller.- let system = unsafe { system.cast::<StyleValueData>().as_ref() };symbol_counts_needed(system).is_some_and(|(symbols, additive_symbols)| count >= if additive { additive_symbols } else { symbols })}/// Whether setting a rule's `system` from `current` to `new` changes the algorithm it uses: the/// system itself, the first symbol of a fixed one or the style an extending one extends.-///-/// # Safety-///-/// `current` and `new` must point to live style values.#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_counter_style_system_changes_algorithm(- current: *const c_void,- new: *const c_void,-) -> bool {+pub extern "C" fn rust_counter_style_system_changes_algorithm(current: &StyleValueData, new: &StyleValueData) -> bool {use StyleValueData::CounterStyleSystem;- // SAFETY: Guaranteed by the caller.- let (current, new) = unsafe { (&*current.cast::<StyleValueData>(), &*new.cast::<StyleValueData>()) };match (current, new) {(CounterStyleSystem { kind: 0, system, .. },diff --git a/Libraries/LibWeb/Rust/src/css/css_string.rs b/Libraries/LibWeb/Rust/src/css/css_string.rsindex a017747c9b4..c0ec00f6372 100644--- a/Libraries/LibWeb/Rust/src/css/css_string.rs+++ b/Libraries/LibWeb/Rust/src/css/css_string.rs@@ -242,11 +242,10 @@ pub struct CssStringView {pub length: usize,}-/// # Safety-/// `string` must point to a live CssString. The returned view borrows its storage.+/// The returned view borrows the storage of `string`.#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_css_string_view(string: *const std::ffi::c_void) -> CssStringView {- let units = unsafe { &*string.cast::<CssString>() }.units();+pub extern "C" fn rust_css_string_view(string: &CssString) -> CssStringView {+ let units = string.units();CssStringView {data: units.as_ptr(),length: units.len(),diff --git a/Libraries/LibWeb/Rust/src/css/descriptor_block.rs b/Libraries/LibWeb/Rust/src/css/descriptor_block.rsindex ea0f21f09ca..9c1635f3f35 100644--- a/Libraries/LibWeb/Rust/src/css/descriptor_block.rs+++ b/Libraries/LibWeb/Rust/src/css/descriptor_block.rs@@ -163,7 +163,11 @@ pub extern "C" fn rust_descriptor_block_length(block: &FfiDescriptorBlock) -> us// The block owns the returned value until its next mutation.#[unsafe(no_mangle)]-pub extern "C" fn rust_descriptor_block_get(block: &FfiDescriptorBlock, id: u8, name: FfiUtf16View) -> *const c_void {+pub extern "C" fn rust_descriptor_block_get(+ block: &FfiDescriptorBlock,+ id: u8,+ name: FfiUtf16View,+) -> *const StyleValueData {let name = name.units().unwrap();block.data()@@ -180,7 +184,7 @@ pub extern "C" fn rust_descriptor_block_get(block: &FfiDescriptorBlock, id: u8,.enumerate().all(|(index, unit)| *unit == name.code_unit_at(index))))})- .map_or(std::ptr::null(), |descriptor| Arc::as_ptr(&descriptor.value).cast())+ .map_or(std::ptr::null(), |descriptor| Arc::as_ptr(&descriptor.value))}#[unsafe(no_mangle)]@@ -327,7 +331,7 @@ mod tests {let allocations = DESCRIPTOR_OWNER_ALLOCATIONS.get();let descriptor = snapshot.descriptors[0].view();let value = rust_descriptor_block_get(block, descriptor.id, descriptor.name);- assert_eq!(value, descriptor.value);+ assert_eq!(value.cast(), descriptor.value);assert_eq!(serialize_descriptors(&block.data()).into_utf16(),"font-family: 文字; src: url(\"font.woff\");"diff --git a/Libraries/LibWeb/Rust/src/css/parser/descriptor_parser.rs b/Libraries/LibWeb/Rust/src/css/parser/descriptor_parser.rsindex 221bcfc6e4d..71c1ef80b7f 100644--- a/Libraries/LibWeb/Rust/src/css/parser/descriptor_parser.rs+++ b/Libraries/LibWeb/Rust/src/css/parser/descriptor_parser.rs@@ -501,17 +501,14 @@ pub(crate) fn parse_descriptor(}/// Parses one descriptor value and returns retained Rust style-value data.-///-/// # Safety-/// Every view and `context` must remain readable for this call.#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_parse_css_descriptor(- context: *const ParseContext,+pub extern "C" fn rust_parse_css_descriptor(+ context: Option<&ParseContext>,at_rule: u8,name: FfiUtf16View,source: FfiUtf16View,) -> *const c_void {- let Some(context) = (unsafe { context.as_ref() }) else {+ let Some(context) = context else {return std::ptr::null();};let Some(name) = name.units() else {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 8cc786bf0b2..8eacdad75ab 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@@ -419,7 +419,7 @@ fn value_graphs_are_shared_and_destroyed_without_worker_callbacks() {for value in values {for _ in 0..100 {let copy = value.clone();- assert!(unsafe { rust_style_value_equals(Arc::as_ptr(&value), Arc::as_ptr(©)) });+ assert!(rust_style_value_equals(Some(&value), Some(©)));assert!(!serialize_style_value_to_utf16(©).is_empty());}}@@ -447,7 +447,7 @@ fn value_graphs_are_shared_and_destroyed_without_worker_callbacks() {);assert!(second.declarations.is_empty());let other = &first_rule_block(&second).properties[0].value;- assert!(unsafe { rust_style_value_equals(Arc::as_ptr(&value), Arc::as_ptr(other)) });+ assert!(rust_style_value_equals(Some(&value), Some(other)));}#[test]diff --git a/Libraries/LibWeb/Rust/src/css/selector_parser.rs b/Libraries/LibWeb/Rust/src/css/selector_parser.rsindex fa37f2b863a..7642f422984 100644--- a/Libraries/LibWeb/Rust/src/css/selector_parser.rs+++ b/Libraries/LibWeb/Rust/src/css/selector_parser.rs@@ -1305,19 +1305,16 @@ pub(crate) unsafe fn selector_parse(.map_or(std::ptr::null_mut(), |selectors| Box::into_raw(Box::new(selectors)))}-/// # Safety-/// Input and the optional immutable namespace context must be readable for this call.#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_selector_parse_with_namespace_context(+pub extern "C" fn rust_selector_parse_with_namespace_context(input: FfiUtf16View,- namespaces: *const std::ffi::c_void,+ namespaces: Option<&crate::css::rule::NativeNamespaceContext>,is_relative: bool,is_forgiving: bool,) -> *mut RustParsedSelectorList {let Some(input) = input.units() else {return std::ptr::null_mut();};- let namespaces = unsafe { namespaces.cast::<crate::css::rule::NativeNamespaceContext>().as_ref() };let namespaces: Vec<_> = namespaces.into_iter().flat_map(|namespaces| namespaces.prefixes.iter())diff --git a/Libraries/LibWeb/Rust/src/css/serialize.rs b/Libraries/LibWeb/Rust/src/css/serialize.rsindex 9bff2530eff..0f307e65244 100644--- a/Libraries/LibWeb/Rust/src/css/serialize.rs+++ b/Libraries/LibWeb/Rust/src/css/serialize.rs@@ -10,8 +10,6 @@//! The output stays ASCII until the first non-ASCII code unit forces UTF-16 storage, matching//! AK::Utf16String's ASCII-or-UTF16 representation, then moves a native string owner to C++.-use std::ffi::c_void;-mod shorthand;use crate::css::css_enums::keyword;@@ -3503,12 +3501,8 @@ pub(crate) fn sink_into_raw(sink: TextSink) -> usize {}/// Serializes a style value into native ASCII-or-UTF-16 storage.-///-/// # Safety-/// `value` must point at live style value data.#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_style_value_serialize(value: *const c_void, mode: u8) -> usize {- let value = unsafe { &*value.cast::<StyleValueData>() };+pub extern "C" fn rust_style_value_serialize(value: &StyleValueData, mode: u8) -> usize {let mut sink = TextSink::new();serialize_style_value(&mut sink, value, SerializationMode::from_ffi(mode));sink_into_raw(sink)diff --git a/Libraries/LibWeb/Rust/src/css/style/animations.rs b/Libraries/LibWeb/Rust/src/css/style/animations.rsindex a0117f6be16..5b3c4aae351 100644--- a/Libraries/LibWeb/Rust/src/css/style/animations.rs+++ b/Libraries/LibWeb/Rust/src/css/style/animations.rs@@ -88,8 +88,16 @@ impl FfiAppliedAnimationDefinition {(self.range_end_calculated, published.range_end_calculated),].into_iter()- .all(|(value, published_value)| unsafe {- crate::css::style_value::rust_style_value_equals(value.cast(), published_value.cast())+ .all(|(value, published_value)| {+ use crate::css::style_value::StyleValueData;+ // SAFETY: Each is null or a value the host holds live.+ let (value, published_value) = unsafe {+ (+ value.cast::<StyleValueData>().as_ref(),+ published_value.cast::<StyleValueData>().as_ref(),+ )+ };+ crate::css::style_value::optional_style_values_equal(value, published_value)})}}diff --git a/Libraries/LibWeb/Rust/src/css/style/bridge.rs b/Libraries/LibWeb/Rust/src/css/style/bridge.rsindex 2d238323cfe..9d4531bbded 100644--- a/Libraries/LibWeb/Rust/src/css/style/bridge.rs+++ b/Libraries/LibWeb/Rust/src/css/style/bridge.rs@@ -1750,22 +1750,17 @@ pub(crate) fn declares_transitions(declarations: &[crate::css::declaration_block/// Registers an element's native inline declaration block, or clears it when null./// Returns whether the declarations can define transitions.-///-/// # Safety-/// `host` must be a live document host, on its document's thread. A non-null `block` must borrow a-/// live `DeclarationBlock`.#[unsafe(no_mangle)]-pub unsafe extern "C" fn style_engine_set_element_inline_style_properties(+pub extern "C" fn style_engine_set_element_inline_style_properties(host: &DocumentHost,node: u32,- block: *const c_void,+ block: Option<&crate::css::declaration_block::DeclarationBlock>,) -> bool {use crate::css::declaration_block::DeclarationBlock;let Some(node) = StyleNodeID::from_raw(node) else {return false;};- // SAFETY: Guaranteed by the caller.- let data = unsafe { block.cast::<DeclarationBlock>().as_ref() }.map(DeclarationBlock::data);+ let data = block.map(DeclarationBlock::data);let has_transitions = data.as_ref().is_some_and(|data| declares_transitions(&data.properties));super::engine_calls::queue(host, super::engine_calls::EngineWrite::InlineStyle { node, data });has_transitions@@ -2798,19 +2793,15 @@ pub extern "C" fn style_engine_next_declaration_block_version(host: &DocumentHos/// sheet `sheet`, and answers whether they declare transitions. The host is told first, with no engine borrowed.////// # Safety-/// `host` must be a live document host, on its document's thread, and `rule` live. The callback-/// must not mutate the native rule graph, and must remain valid for this call.+/// The callback must not mutate the native rule graph, and must remain valid for this call.#[unsafe(no_mangle)]pub unsafe extern "C" fn style_engine_native_rule_declarations_changed(host: &DocumentHost,sheet: u32,- rule: *const c_void,+ rule: &crate::css::rule::NativeRule,context: *mut c_void,notify: unsafe extern "C" fn(*mut c_void),) -> bool {- // SAFETY: Guaranteed by the caller.- // SAFETY: Guaranteed by the caller.- let rule = unsafe { &*rule.cast::<crate::css::rule::NativeRule>() };let Some(identity) = rule.declaration_owner_identity().filter(|&identity| host.published_rules().contains(sheet, identity))@@ -2829,19 +2820,13 @@ pub unsafe extern "C" fn style_engine_native_rule_declarations_changed(/// The native identity of the first rule after an inserted native subtree that the host published to the sheet/// `sheet`, or 0 for none, without creating CSSOM objects.-///-/// # Safety-/// `host` must be a live document host, on its document's thread, and `native` a live native sheet.#[unsafe(no_mangle)]-pub unsafe extern "C" fn style_engine_native_rule_successor(+pub extern "C" fn style_engine_native_rule_successor(host: &DocumentHost,sheet: u32,- native: *const c_void,+ native: &crate::css::style_sheet::NativeStyleSheet,identity: u64,) -> u64 {- // SAFETY: Guaranteed by the caller.- // SAFETY: Guaranteed by the caller.- let native = unsafe { &*native.cast::<crate::css::style_sheet::NativeStyleSheet>() };host.published_rules().successor(sheet, native, identity)}diff --git a/Libraries/LibWeb/Rust/src/css/style/style_job.rs b/Libraries/LibWeb/Rust/src/css/style/style_job.rsindex ab97e013a3e..7d332919acb 100644--- a/Libraries/LibWeb/Rust/src/css/style/style_job.rs+++ b/Libraries/LibWeb/Rust/src/css/style/style_job.rs@@ -455,24 +455,19 @@ pub(crate) struct TakesFinishedStyleIn {const TAKES_FINISHED_STYLE_IN: TakesFinishedStyleIn = TakesFinishedStyleIn { _private: () };-/// Ends the transaction the host took last, and has `allocator` mint the identities its end released again first.-///-/// # Safety-///-/// `host` must be a live document host, on its document's thread, and `allocator` its document's allocator.+/// Ends the transaction the host took last, and has `allocator`, its document's allocator, mint the identities its end+/// released again first.#[unsafe(no_mangle)]-pub unsafe extern "C" fn style_engine_end_style_transaction(+pub extern "C" fn style_engine_end_style_transaction(host: &DocumentHost,read: &crate::render_state::BegunRead,- allocator: *mut StyleNodeIdAllocator,+ allocator: &mut StyleNodeIdAllocator,) {- assert!(!allocator.is_null());host.end_style_transaction();let released = with_engine(read, host, |engine| engine.discard_style_transaction_outputs());let memo = host.engine_memo();memo.held.borrow_mut().forget(&released);memo.described.borrow_mut().forget(&released);memo.baselines.borrow_mut().forget(&released);- // SAFETY: As above.- unsafe { &mut *allocator }.release(&released);+ allocator.release(&released);}diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rsindex ea9518fa609..02d2db32ed8 100644--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs@@ -4940,13 +4940,8 @@ fn calculated_offset(value: &StyleValueData) -> *const c_void {}/// The pixels of a computed length-percentage, resolving its percentages against `basis`.-///-/// # Safety-/// `value` must point at live style value data.#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_length_percentage_px(value: *const c_void, basis: f64) -> f64 {- // SAFETY: The caller passes a live style value.- let value = unsafe { &*value.cast::<StyleValueData>() };+pub extern "C" fn rust_length_percentage_px(value: &StyleValueData, basis: f64) -> f64 {crate::css::computed_value_views::LengthPercentageRef::over(value).to_px(CssPixels::nearest_value_for(basis)).to_double()@@ -4995,13 +4990,8 @@ fn view_timeline_inset(value: Option<&StyleValueData>) -> FfiViewTimelineInset {}/// The insets a computed `view-timeline-inset` item describes, for a timeline the host builds from script.-///-/// # Safety-/// `value` must point at live style value data.#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_view_timeline_inset(value: *const c_void) -> FfiViewTimelineInset {- // SAFETY: Guaranteed by the caller.- let value = unsafe { &*value.cast::<StyleValueData>() };+pub extern "C" fn rust_view_timeline_inset(value: &StyleValueData) -> FfiViewTimelineInset {let value = match value {StyleValueData::ValueList { values, separator, .. } if *separator == 1 => values.as_slice()[0].data(),value => value,@@ -5161,11 +5151,8 @@ pub extern "C" fn rust_animation_values_declare_timelines(}/// Whether a parsed `view-timeline-inset` value has a length in a unit that is not absolute.-///-/// # Safety-/// `value` must point at live style value data.#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_view_timeline_inset_has_relative_length(value: *const c_void) -> bool {+pub extern "C" fn rust_view_timeline_inset_has_relative_length(value: &StyleValueData) -> bool {let is_absolute = |unit: u8| {matches!(length_unit_kinds().get(unit as usize),@@ -5185,8 +5172,7 @@ pub unsafe extern "C" fn rust_view_timeline_inset_has_relative_length(value: *co_ => false,}}- // SAFETY: Guaranteed by the caller.- has_relative_length(unsafe { &*value.cast::<StyleValueData>() }, &is_absolute)+ has_relative_length(value, &is_absolute)}/// The timeline a computed `animation-timeline` item asks for.@@ -5309,17 +5295,12 @@ pub struct FfiAnimationRangeEdge {/// The edge a computed `animation-range-start` or `animation-range-end` value with a single item describes, for a range/// script sets. Answers false where the value has more than one item.-///-/// # Safety-/// `value` must point at live style value data.#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_animation_range_edge(- value: *const c_void,+pub extern "C" fn rust_animation_range_edge(+ value: &StyleValueData,is_end: bool,out: &mut FfiAnimationRangeEdge,) -> bool {- // SAFETY: Guaranteed by the caller.- let value = unsafe { &*value.cast::<StyleValueData>() };let item = match value {StyleValueData::ValueList { values, separator, .. } if *separator == 1 => match values.as_slice() {[item] => item.data(),diff --git a/Libraries/LibWeb/Rust/src/css/style_value.rs b/Libraries/LibWeb/Rust/src/css/style_value.rsindex 92858154c67..df9dabedd89 100644--- a/Libraries/LibWeb/Rust/src/css/style_value.rs+++ b/Libraries/LibWeb/Rust/src/css/style_value.rs@@ -3528,13 +3528,10 @@ pub unsafe extern "C" fn rust_style_value_release(value: *const StyleValueData)////// The addresses are compared first because a shared allocation is the common case, and the values/// otherwise: two allocations built from the same declaration are equal, and a caller holding a-/// freshly computed one has no way to know that from the pointer alone.-///-/// # Safety-/// `first` and `second` must be null or point at live `StyleValueData` allocated by this module.+/// freshly computed one has no way to know that from the pointer alone. Null stands for no value.#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_style_value_equals(first: *const StyleValueData, second: *const StyleValueData) -> bool {- optional_style_values_equal(unsafe { first.as_ref() }, unsafe { second.as_ref() })+pub extern "C" fn rust_style_value_equals(first: Option<&StyleValueData>, second: Option<&StyleValueData>) -> bool {+ optional_style_values_equal(first, second)}/// `rust_style_value_equals` for two handles.