From 42cbe141fcf98d1811a9bfbbf2284c79badc2da2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Thu, 25 Aug 2022 13:11:36 +0200 Subject: [PATCH] Fix to_vm_extern function in JS --- lib/api/src/js/externals/function.rs | 8 ++++---- lib/api/src/js/externals/global.rs | 7 ++++++- lib/api/src/js/externals/memory.rs | 7 ++++++- lib/api/src/sys/externals/function.rs | 10 +++++----- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/api/src/js/externals/function.rs b/lib/api/src/js/externals/function.rs index a8a8bea243c..1a85ad83b13 100644 --- a/lib/api/src/js/externals/function.rs +++ b/lib/api/src/js/externals/function.rs @@ -908,7 +908,7 @@ mod inner { Kind: HostFunctionKind, { /// Get the pointer to the function body. - fn function_body_ptr() -> *const VMFunctionBody; + fn function_body_ptr(self) -> *const VMFunctionBody; // /// Get the pointer to the function call trampoline. // fn call_trampoline_address() -> VMTrampoline; @@ -969,7 +969,7 @@ mod inner { T: Sized, { Self { - address: >::function_body_ptr(), + address: function.function_body_ptr(), _phantom: PhantomData, } } @@ -1122,7 +1122,7 @@ mod inner { Func: Fn(FunctionEnvMut<'_, T>, $( $x , )*) -> RetsAsResult + 'static, { #[allow(non_snake_case)] - fn function_body_ptr() -> *const VMFunctionBody { + fn function_body_ptr(self) -> *const VMFunctionBody { /// This is a function that wraps the real host /// function. Its address will be used inside the /// runtime. @@ -1170,7 +1170,7 @@ mod inner { Func: Fn($( $x , )*) -> RetsAsResult + 'static, { #[allow(non_snake_case)] - fn function_body_ptr() -> *const VMFunctionBody { + fn function_body_ptr(self) -> *const VMFunctionBody { /// This is a function that wraps the real host /// function. Its address will be used inside the /// runtime. diff --git a/lib/api/src/js/externals/global.rs b/lib/api/src/js/externals/global.rs index 2892c1624ab..38e8ef6acd4 100644 --- a/lib/api/src/js/externals/global.rs +++ b/lib/api/src/js/externals/global.rs @@ -1,6 +1,6 @@ use crate::js::export::VMGlobal; use crate::js::exports::{ExportError, Exportable}; -use crate::js::externals::Extern; +use crate::js::externals::{Extern, VMExtern}; use crate::js::store::{AsStoreMut, AsStoreRef, InternalStoreHandle, StoreHandle}; use crate::js::value::Value; use crate::js::wasm_bindgen_polyfill::Global as JSGlobal; @@ -55,6 +55,11 @@ impl Global { Self::from_value(store, val, Mutability::Var).unwrap() } + /// To `VMExtern`. + pub(crate) fn to_vm_extern(&self) -> VMExtern { + VMExtern::Global(self.handle.internal_handle()) + } + /// Create a `Global` with the initial value [`Value`] and the provided [`Mutability`]. fn from_value( store: &mut impl AsStoreMut, diff --git a/lib/api/src/js/externals/memory.rs b/lib/api/src/js/externals/memory.rs index bfddab87f31..b57639b4897 100644 --- a/lib/api/src/js/externals/memory.rs +++ b/lib/api/src/js/externals/memory.rs @@ -1,6 +1,6 @@ use crate::js::export::VMMemory; use crate::js::exports::{ExportError, Exportable}; -use crate::js::externals::Extern; +use crate::js::externals::{Extern, VMExtern}; use crate::js::store::{AsStoreMut, AsStoreRef, InternalStoreHandle, StoreHandle, StoreObjects}; use crate::js::{MemoryAccessError, MemoryType}; use std::marker::PhantomData; @@ -118,6 +118,11 @@ impl Memory { Self::from_vm_extern(new_store, handle.internal_handle()) } + /// To `VMExtern`. + pub(crate) fn to_vm_extern(&self) -> VMExtern { + VMExtern::Memory(self.handle.internal_handle()) + } + /// Returns the [`MemoryType`] of the `Memory`. /// /// # Example diff --git a/lib/api/src/sys/externals/function.rs b/lib/api/src/sys/externals/function.rs index 87bfa8237eb..835eea097de 100644 --- a/lib/api/src/sys/externals/function.rs +++ b/lib/api/src/sys/externals/function.rs @@ -204,6 +204,7 @@ impl Function { Rets: WasmTypeList, { let env = FunctionEnv::new(store, ()); + let func_ptr = func.function_body_ptr(); let host_data = Box::new(StaticFunction { raw_store: store.as_store_mut().as_raw() as *mut u8, env, @@ -211,7 +212,6 @@ impl Function { }); let function_type = FunctionType::new(Args::wasm_types(), Rets::wasm_types()); - let func_ptr = >::function_body_ptr(); let type_index = store .as_store_mut() .engine() @@ -289,6 +289,7 @@ impl Function { { // println!("new native {:p}", &new_env); + let func_ptr = func.function_body_ptr(); let host_data = Box::new(StaticFunction { raw_store: store.as_store_mut().as_raw() as *mut u8, env: env.clone(), @@ -296,7 +297,6 @@ impl Function { }); let function_type = FunctionType::new(Args::wasm_types(), Rets::wasm_types()); - let func_ptr = >::function_body_ptr(); let type_index = store .as_store_mut() .engine() @@ -1092,7 +1092,7 @@ mod inner { Kind: HostFunctionKind, { /// Get the pointer to the function body. - fn function_body_ptr() -> *const VMFunctionBody; + fn function_body_ptr(self) -> *const VMFunctionBody; /// Get the pointer to the function call trampoline. fn call_trampoline_address() -> VMTrampoline; @@ -1268,7 +1268,7 @@ mod inner { Func: Fn(FunctionEnvMut, $( $x , )*) -> RetsAsResult + 'static, { #[allow(non_snake_case)] - fn function_body_ptr() -> *const VMFunctionBody { + fn function_body_ptr(self) -> *const VMFunctionBody { /// This is a function that wraps the real host /// function. Its address will be used inside the /// runtime. @@ -1352,7 +1352,7 @@ mod inner { Func: Fn($( $x , )*) -> RetsAsResult + 'static, { #[allow(non_snake_case)] - fn function_body_ptr() -> *const VMFunctionBody { + fn function_body_ptr(self) -> *const VMFunctionBody { /// This is a function that wraps the real host /// function. Its address will be used inside the /// runtime.