Skip to content

Commit

Permalink
Fix to_vm_extern function in JS
Browse files Browse the repository at this point in the history
  • Loading branch information
fschutt committed Aug 25, 2022
1 parent 63e2046 commit 42cbe14
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
8 changes: 4 additions & 4 deletions lib/api/src/js/externals/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -969,7 +969,7 @@ mod inner {
T: Sized,
{
Self {
address: <F as HostFunction<(), Args, Rets, WithoutEnv>>::function_body_ptr(),
address: function.function_body_ptr(),
_phantom: PhantomData,
}
}
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion lib/api/src/js/externals/global.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion lib/api/src/js/externals/memory.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/api/src/sys/externals/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,14 @@ 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,
func,
});
let function_type = FunctionType::new(Args::wasm_types(), Rets::wasm_types());

let func_ptr = <F as HostFunction<(), Args, Rets, WithoutEnv>>::function_body_ptr();
let type_index = store
.as_store_mut()
.engine()
Expand Down Expand Up @@ -289,14 +289,14 @@ 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(),
func,
});
let function_type = FunctionType::new(Args::wasm_types(), Rets::wasm_types());

let func_ptr = <F as HostFunction<T, Args, Rets, WithEnv>>::function_body_ptr();
let type_index = store
.as_store_mut()
.engine()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1268,7 +1268,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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 42cbe14

Please sign in to comment.