Truly independent web browser
LibWeb: Take the VM by reference in the Rust bindings exports
Andreas Kling40f013977cab
diff --git a/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/exports.rs b/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/exports.rsindex 8a12231518a..0ddc7603cc4 100644--- a/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/exports.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/canvas_2d/exports.rs@@ -67,15 +67,12 @@ fn with_context<R>(context: &ContextCell, function: impl FnOnce(&ContextState) -/// # Safety///-/// `vm` is the live VM, and the pointers of the arguments are what [`ContextCreationArguments`] describes.+/// The pointers of the arguments are what [`ContextCreationArguments`] describes.#[unsafe(no_mangle)]pub unsafe extern "C" fn web_canvas_2d_context_create(- vm: *mut c_void,+ vm: &libjs_rust::api::Vm,arguments: &ContextCreationArguments,) -> *mut c_void {- assert!(!vm.is_null(), "C++ passes the VM");- // SAFETY: The caller passes the live VM.- let vm = unsafe { &*vm.cast::<libjs_rust::api::Vm>() };let canvas = Canvas {cell: NonNull::new(arguments.canvas).expect("C++ passes the canvas"),host: NonNull::new(arguments.canvas_host).expect("C++ passes the canvas"),diff --git a/Libraries/LibWeb/Bindings/Rust/src/geometry/exports.rs b/Libraries/LibWeb/Bindings/Rust/src/geometry/exports.rsindex 1de83351470..fd8d9e0103a 100644--- a/Libraries/LibWeb/Bindings/Rust/src/geometry/exports.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/geometry/exports.rs@@ -22,15 +22,6 @@ use super::dom_rect_read_only::DOMRectReadOnly;use super::matrix::{ColumnMajor, Matrix4};use crate::bindings::interface::{Inherits, Interface, Ref, allocate, cell_from_abi, cell_if_abi, cell_into_abi};-/// # Safety-///-/// `vm` must be the live VM.-unsafe fn vm_from_abi<'vm>(vm: *mut c_void) -> &'vm Vm {- assert!(!vm.is_null(), "C++ passes the VM");- // SAFETY: The caller passes the live VM.- unsafe { &*vm.cast::<Vm>() }-}-/// The implementation of the object whose cell C++ lends, for as long as C++ keeps the cell alive.////// # Safety@@ -58,19 +49,8 @@ unsafe fn matrix_from_abi<'a>(cell: *mut c_void) -> &'a DOMMatrixReadOnly {unsafe { object_from_abi::<DOMMatrix>(cell) }.parent()}-/// # Safety-///-/// `vm` must be the live VM.#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_dom_point_read_only_create(- vm: *mut c_void,- x: f64,- y: f64,- z: f64,- w: f64,-) -> *mut c_void {- // SAFETY: The caller passes the live VM.- let vm = unsafe { vm_from_abi(vm) };+pub extern "C" fn web_dom_point_read_only_create(vm: &Vm, x: f64, y: f64, z: f64, w: f64) -> *mut c_void {cell_into_abi(allocate(vm, DOMPointReadOnly::new(x, y, z, w)))}@@ -96,39 +76,18 @@ pub unsafe extern "C" fn web_dom_point_set_x_and_y(point: *mut c_void, x: f64, yunsafe { object_from_abi::<DOMPoint>(point) }.set_x_and_y(x, y);}-/// # Safety-///-/// `vm` must be the live VM.#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_dom_point_create(vm: *mut c_void, x: f64, y: f64, z: f64, w: f64) -> *mut c_void {- // SAFETY: The caller passes the live VM.- let vm = unsafe { vm_from_abi(vm) };+pub extern "C" fn web_dom_point_create(vm: &Vm, x: f64, y: f64, z: f64, w: f64) -> *mut c_void {cell_into_abi(allocate(vm, DOMPoint::new(x, y, z, w)))}-/// # Safety-///-/// `vm` must be the live VM.#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_dom_rect_read_only_create(- vm: *mut c_void,- x: f64,- y: f64,- width: f64,- height: f64,-) -> *mut c_void {- // SAFETY: The caller passes the live VM.- let vm = unsafe { vm_from_abi(vm) };+pub extern "C" fn web_dom_rect_read_only_create(vm: &Vm, x: f64, y: f64, width: f64, height: f64) -> *mut c_void {cell_into_abi(allocate(vm, DOMRectReadOnly::new(x, y, width, height)))}-/// # Safety-///-/// `vm` must be the live VM.#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_dom_rect_create(vm: *mut c_void, x: f64, y: f64, width: f64, height: f64) -> *mut c_void {- // SAFETY: The caller passes the live VM.- let vm = unsafe { vm_from_abi(vm) };+pub extern "C" fn web_dom_rect_create(vm: &Vm, x: f64, y: f64, width: f64, height: f64) -> *mut c_void {cell_into_abi(allocate(vm, DOMRect::new(x, y, width, height)))}@@ -148,14 +107,8 @@ pub unsafe extern "C" fn web_dom_rect_set(rect: *mut c_void, x: f64, y: f64, wid}/// A new DOMRectList of new DOMRects, whose x, y, width and height are the groups of four values of `rects`.-///-/// # Safety-///-/// `vm` must be the live VM.#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_dom_rect_list_create(vm: *mut c_void, rects: ak::Span<'_, [f64; 4]>) -> *mut c_void {- // SAFETY: The caller passes the live VM.- let vm = unsafe { vm_from_abi(vm) };+pub extern "C" fn web_dom_rect_list_create(vm: &Vm, rects: ak::Span<'_, [f64; 4]>) -> *mut c_void {// NB: Creating a rectangle can collect, so the rectangles created before it are kept in a MarkedVec until the// list holds them.let created = MarkedVec::with_capacity(vm, rects.as_slice().len());@@ -167,14 +120,8 @@ pub unsafe extern "C" fn web_dom_rect_list_create(vm: *mut c_void, rects: ak::Sp}/// A new DOMMatrix whose elements m11, m12, m13, m14, m21, ..., m44 are the values, in that order.-///-/// # Safety-///-/// `vm` must be the live VM.#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_dom_matrix_create(vm: *mut c_void, elements: &[f64; 16], is_2d: bool) -> *mut c_void {- // SAFETY: The caller passes the live VM.- let vm = unsafe { vm_from_abi(vm) };+pub extern "C" fn web_dom_matrix_create(vm: &Vm, elements: &[f64; 16], is_2d: bool) -> *mut c_void {let matrix = DOMMatrixReadOnly::new(Matrix4::from_column_major(*elements), is_2d);cell_into_abi(allocate(vm, DOMMatrix::from_read_only(matrix)))}@@ -183,11 +130,9 @@ pub unsafe extern "C" fn web_dom_matrix_create(vm: *mut c_void, elements: &[f64;////// # Safety///-/// `vm` must be the live VM, and `matrix` the live cell of a DOMMatrixReadOnly or a DOMMatrix.+/// `matrix` must be the live cell of a DOMMatrixReadOnly or a DOMMatrix.#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_dom_matrix_create_from_read_only(vm: *mut c_void, matrix: *mut c_void) -> *mut c_void {- // SAFETY: The caller passes the live VM.- let vm = unsafe { vm_from_abi(vm) };+pub unsafe extern "C" fn web_dom_matrix_create_from_read_only(vm: &Vm, matrix: *mut c_void) -> *mut c_void {// SAFETY: The caller passes a live cell.let matrix = unsafe { matrix_from_abi(matrix) };let copy = DOMMatrixReadOnly::new(matrix.matrix(), matrix.is_2d());diff --git a/Libraries/LibWeb/Bindings/Rust/src/html/exports.rs b/Libraries/LibWeb/Bindings/Rust/src/html/exports.rsindex d9d06ff86fa..9f93634cc64 100644--- a/Libraries/LibWeb/Bindings/Rust/src/html/exports.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/html/exports.rs@@ -19,15 +19,6 @@ use super::image_data::ImageData;use crate::bindings::CallContext;use crate::bindings::interface::{Interface, Ref, cell_from_abi, cell_into_abi, realm_arguments};-/// # Safety-///-/// `vm` must be the live VM.-unsafe fn vm_from_abi<'vm>(vm: *mut c_void) -> &'vm Vm {- assert!(!vm.is_null(), "C++ passes the VM");- // SAFETY: The caller passes the live VM.- unsafe { &*vm.cast::<Vm>() }-}-/// The implementation of the object whose cell C++ lends, for as long as C++ keeps the cell alive.////// # Safety@@ -119,11 +110,9 @@ pub unsafe extern "C" fn web_image_data_pixels(image_data: *mut c_void) -> *mut////// # Safety///-/// `vm` must be the live VM, and `frame` a live frame or null.+/// `frame` must be a live frame or null.#[unsafe(no_mangle)]-pub unsafe extern "C" fn web_image_bitmap_create(vm: *mut c_void, frame: *const c_void) -> *mut c_void {- // SAFETY: The caller passes the live VM.- let vm = unsafe { vm_from_abi(vm) };+pub unsafe extern "C" fn web_image_bitmap_create(vm: &Vm, frame: *const c_void) -> *mut c_void {// SAFETY: The caller passes a live frame.let frame = (!frame.is_null()).then(|| unsafe { ImageFrameHandle::retain(frame) });cell_into_abi(ImageBitmap::create(vm, frame))