Truly independent web browser
LibWeb: Take references in FFI entry points that only dereference
Andreas Klingf032bebcfc87
diff --git a/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rs b/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rsindex 1728cf03033..0a6c4af7beb 100644--- a/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/web_gl/exports.rs@@ -147,10 +147,8 @@ unsafe fn with_context<R>(context: *mut c_void, function: impl FnOnce(&ContextSt#[unsafe(no_mangle)]pub unsafe extern "C" fn web_webgl_context_create(vm: *mut c_void,- arguments: *const ContextCreationArguments,+ arguments: &ContextCreationArguments,) -> *mut c_void {- // SAFETY: The caller passes live arguments.- let arguments = unsafe { &*arguments };// SAFETY: The caller passes the live VM and a live realm.let (vm, realm) = unsafe { realm_arguments(vm, arguments.realm) };verify_that_rust_and_cpp_agree_on_layouts_and_constants();diff --git a/Libraries/LibWeb/Rust/src/css/calc.rs b/Libraries/LibWeb/Rust/src/css/calc.rsindex 6023eede345..5f7f4bdd274 100644--- a/Libraries/LibWeb/Rust/src/css/calc.rs+++ b/Libraries/LibWeb/Rust/src/css/calc.rs@@ -522,16 +522,13 @@ pub enum FfiNumericTypeMatch {}/// Applies one numeric type algebra operation for C++ callers.-///-/// # Safety-/// `first` must be valid. `second` must also be valid for binary operations.#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_numeric_type_operate(+pub extern "C" fn rust_numeric_type_operate(operation: FfiNumericTypeOperation,- first: *const FfiNumericType,+ first: &FfiNumericType,second: &FfiNumericType,) -> FfiNumericType {- let first = unsafe { &*first }.to_calc();+ let first = first.to_calc();let result = match operation {FfiNumericTypeOperation::Add => first.added_to(&second.to_calc()),FfiNumericTypeOperation::Multiply => first.multiplied_by(&second.to_calc()),@@ -541,18 +538,15 @@ pub unsafe extern "C" fn rust_numeric_type_operate(}/// Tests a numeric type against one of the CSS numeric matching categories.-///-/// # Safety-/// `numeric_type` must be valid.#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_numeric_type_matches(+pub extern "C" fn rust_numeric_type_matches(match_kind: FfiNumericTypeMatch,- numeric_type: *const FfiNumericType,+ numeric_type: &FfiNumericType,base_type: u8,has_percentages_resolve_as: bool,percentages_resolve_as: u8,) -> bool {- let numeric_type = unsafe { &*numeric_type }.to_calc();+ let numeric_type = numeric_type.to_calc();let resolve_as = resolve_as_for_value_type(has_percentages_resolve_as.then_some(percentages_resolve_as));match match_kind {FfiNumericTypeMatch::Dimension => numeric_type.matches_dimension(base_type as usize, resolve_as),diff --git a/Libraries/LibWeb/Rust/src/css/container_conditions.rs b/Libraries/LibWeb/Rust/src/css/container_conditions.rsindex cd8419e58e5..2d0b52d28ff 100644--- a/Libraries/LibWeb/Rust/src/css/container_conditions.rs+++ b/Libraries/LibWeb/Rust/src/css/container_conditions.rs@@ -70,8 +70,8 @@ pub unsafe extern "C" fn rust_container_conditions_release(conditions: *const Co}#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_container_conditions_count(conditions: *const ContainerConditionsData) -> usize {- unsafe { &*conditions }.conditions.len()+pub extern "C" fn rust_container_conditions_count(conditions: &ContainerConditionsData) -> usize {+ conditions.conditions.len()}#[unsafe(no_mangle)]@@ -85,11 +85,11 @@ pub extern "C" fn rust_container_conditions_name(}#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_container_conditions_query(- conditions: *const ContainerConditionsData,+pub extern "C" fn rust_container_conditions_query(+ conditions: &ContainerConditionsData,index: usize,) -> *const FfiQueryHandle {- unsafe { &*conditions }.conditions[index]+ conditions.conditions[index].query.as_ref().map_or(std::ptr::null(), Arc::as_ptr)diff --git a/Libraries/LibWeb/Rust/src/css/layer_names.rs b/Libraries/LibWeb/Rust/src/css/layer_names.rsindex 47328e9007f..5b85b60a3bf 100644--- a/Libraries/LibWeb/Rust/src/css/layer_names.rs+++ b/Libraries/LibWeb/Rust/src/css/layer_names.rs@@ -19,8 +19,8 @@ const _: () = {};#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_layer_names_count(names: *const LayerNames) -> usize {- unsafe { &*names }.names.len()+pub extern "C" fn rust_layer_names_count(names: &LayerNames) -> usize {+ names.names.len()}#[unsafe(no_mangle)]diff --git a/Libraries/LibWeb/Rust/src/css/parser/syntax_parser.rs b/Libraries/LibWeb/Rust/src/css/parser/syntax_parser.rsindex 297b17e1965..8fb57ec5ff9 100644--- a/Libraries/LibWeb/Rust/src/css/parser/syntax_parser.rs+++ b/Libraries/LibWeb/Rust/src/css/parser/syntax_parser.rs@@ -3745,15 +3745,11 @@ pub extern "C" fn rust_css_syntax_parse_declaration_block(}/// Retains parsed descriptor lists from block contents, ignoring rules.-///-/// # Safety-/// `parse` must be a live result of `rust_parse_css_block_syntax`.#[unsafe(no_mangle)]-pub unsafe extern "C" fn rust_css_syntax_parse_descriptor_block(- parse: *const ParsedStyleSheet,+pub extern "C" fn rust_css_syntax_parse_descriptor_block(+ parsed: &ParsedStyleSheet,) -> *mut crate::css::descriptor_block::FfiDescriptorBlock {use crate::css::descriptor_block::FfiDescriptorBlock;- let parsed = unsafe { &*parse };// https://drafts.csswg.org/cssom/#parse-a-css-declaration-block// 2. Let parsed declarations be a new empty list.let mut descriptors: Option<Arc<DescriptorBlockData>> = None;diff --git a/Libraries/LibWeb/Rust/src/painting/ffi.rs b/Libraries/LibWeb/Rust/src/painting/ffi.rsindex 06430791f91..cd420f2e871 100644--- a/Libraries/LibWeb/Rust/src/painting/ffi.rs+++ b/Libraries/LibWeb/Rust/src/painting/ffi.rs@@ -1278,12 +1278,12 @@ pub unsafe extern "C" fn compositor_animation_effect_build(state: *mut c_void,document_host: &DocumentHost,request: *const crate::painting::host::FfiCompositorAnimationRequest,- host: *const crate::painting::host::FfiCompositorAnimationHost,+ host: &crate::painting::host::FfiCompositorAnimationHost,) -> crate::painting::host::FfiCompositorAnimationBuildOutcome {use crate::painting::visual_animation_builder::{Host, Request, effect_state_from_handle};let state = unsafe { effect_state_from_handle(state) };let request = unsafe { Request::new(&*request) };- let host = Host::new(unsafe { &*host });+ let host = Host::new(host);let layout_node = request.layout_node();state.build(&request, &host, |kind| {read_arena(