mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 13:18:20 +00:00
Rename all mentions from ctx to store
Updated tests and examples Improved a bit the function types and results
This commit is contained in:
committed by
Manos Pitsidianakis
parent
a4b9d9efda
commit
43138b569c
@@ -99,19 +99,22 @@ pub enum Export {
|
||||
|
||||
impl Export {
|
||||
/// Return the export as a `JSValue`.
|
||||
pub fn as_jsvalue<'context>(&self, ctx: &'context impl AsStoreRef) -> &'context JsValue {
|
||||
pub fn as_jsvalue<'context>(&self, store: &'context impl AsStoreRef) -> &'context JsValue {
|
||||
match self {
|
||||
Self::Memory(js_wasm_memory) => js_wasm_memory
|
||||
.get(ctx.as_store_ref().objects())
|
||||
.get(store.as_store_ref().objects())
|
||||
.memory
|
||||
.as_ref(),
|
||||
Self::Function(js_func) => js_func.get(ctx.as_store_ref().objects()).function.as_ref(),
|
||||
Self::Function(js_func) => js_func
|
||||
.get(store.as_store_ref().objects())
|
||||
.function
|
||||
.as_ref(),
|
||||
Self::Table(js_wasm_table) => js_wasm_table
|
||||
.get(ctx.as_store_ref().objects())
|
||||
.get(store.as_store_ref().objects())
|
||||
.table
|
||||
.as_ref(),
|
||||
Self::Global(js_wasm_global) => js_wasm_global
|
||||
.get(ctx.as_store_ref().objects())
|
||||
.get(store.as_store_ref().objects())
|
||||
.global
|
||||
.as_ref(),
|
||||
}
|
||||
@@ -120,14 +123,14 @@ impl Export {
|
||||
/// Convert a `JsValue` into an `Export` within a given `Context`.
|
||||
pub fn from_js_value(
|
||||
val: JsValue,
|
||||
ctx: &mut impl AsStoreMut,
|
||||
store: &mut impl AsStoreMut,
|
||||
extern_type: ExternType,
|
||||
) -> Result<Self, WasmError> {
|
||||
match extern_type {
|
||||
ExternType::Memory(memory_type) => {
|
||||
if val.is_instance_of::<Memory>() {
|
||||
Ok(Self::Memory(InternalStoreHandle::new(
|
||||
&mut ctx.objects_mut(),
|
||||
&mut store.objects_mut(),
|
||||
VMMemory::new(val.unchecked_into::<Memory>(), memory_type),
|
||||
)))
|
||||
} else {
|
||||
@@ -143,7 +146,7 @@ impl Export {
|
||||
ExternType::Global(global_type) => {
|
||||
if val.is_instance_of::<Global>() {
|
||||
Ok(Self::Global(InternalStoreHandle::new(
|
||||
&mut ctx.objects_mut(),
|
||||
&mut store.objects_mut(),
|
||||
VMGlobal::new(val.unchecked_into::<Global>(), global_type),
|
||||
)))
|
||||
} else {
|
||||
@@ -153,7 +156,7 @@ impl Export {
|
||||
ExternType::Function(function_type) => {
|
||||
if val.is_instance_of::<Function>() {
|
||||
Ok(Self::Function(InternalStoreHandle::new(
|
||||
&mut ctx.objects_mut(),
|
||||
&mut store.objects_mut(),
|
||||
VMFunction::new(val.unchecked_into::<Function>(), function_type),
|
||||
)))
|
||||
} else {
|
||||
@@ -163,7 +166,7 @@ impl Export {
|
||||
ExternType::Table(table_type) => {
|
||||
if val.is_instance_of::<Table>() {
|
||||
Ok(Self::Table(InternalStoreHandle::new(
|
||||
&mut ctx.objects_mut(),
|
||||
&mut store.objects_mut(),
|
||||
VMTable::new(val.unchecked_into::<Table>(), table_type),
|
||||
)))
|
||||
} else {
|
||||
|
||||
@@ -141,14 +141,14 @@ impl Exports {
|
||||
/// Get an export as a `TypedFunction`.
|
||||
pub fn get_native_function<Args, Rets>(
|
||||
&self,
|
||||
ctx: &impl AsStoreRef,
|
||||
store: &impl AsStoreRef,
|
||||
name: &str,
|
||||
) -> Result<TypedFunction<Args, Rets>, ExportError>
|
||||
where
|
||||
Args: WasmTypeList,
|
||||
Rets: WasmTypeList,
|
||||
{
|
||||
self.get_typed_function(ctx, name)
|
||||
self.get_typed_function(store, name)
|
||||
}
|
||||
|
||||
/// Get an export as a `TypedFunction`.
|
||||
@@ -169,7 +169,7 @@ impl Exports {
|
||||
/// Hack to get this working with nativefunc too
|
||||
pub fn get_with_generics<'a, T, Args, Rets>(
|
||||
&'a self,
|
||||
ctx: &impl AsStoreRef,
|
||||
store: &impl AsStoreRef,
|
||||
name: &str,
|
||||
) -> Result<T, ExportError>
|
||||
where
|
||||
@@ -179,7 +179,7 @@ impl Exports {
|
||||
{
|
||||
match self.map.get(name) {
|
||||
None => Err(ExportError::Missing(name.to_string())),
|
||||
Some(extern_) => T::get_self_from_extern_with_generics(ctx, extern_),
|
||||
Some(extern_) => T::get_self_from_extern_with_generics(store, extern_),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,7 +187,7 @@ impl Exports {
|
||||
/// This is useful for passing data into Context data, for example.
|
||||
pub fn get_with_generics_weak<'a, T, Args, Rets>(
|
||||
&'a self,
|
||||
ctx: &impl AsStoreRef,
|
||||
store: &impl AsStoreRef,
|
||||
name: &str,
|
||||
) -> Result<T, ExportError>
|
||||
where
|
||||
@@ -195,7 +195,7 @@ impl Exports {
|
||||
Rets: WasmTypeList,
|
||||
T: ExportableWithGenerics<'a, Args, Rets>,
|
||||
{
|
||||
let out: T = self.get_with_generics(ctx, name)?;
|
||||
let out: T = self.get_with_generics(store, name)?;
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
@@ -334,7 +334,7 @@ pub trait Exportable<'a>: Sized {
|
||||
pub trait ExportableWithGenerics<'a, Args: WasmTypeList, Rets: WasmTypeList>: Sized {
|
||||
/// Get an export with the given generics.
|
||||
fn get_self_from_extern_with_generics(
|
||||
ctx: &impl AsStoreRef,
|
||||
store: &impl AsStoreRef,
|
||||
_extern: &'a Extern,
|
||||
) -> Result<Self, ExportError>;
|
||||
}
|
||||
@@ -343,7 +343,7 @@ pub trait ExportableWithGenerics<'a, Args: WasmTypeList, Rets: WasmTypeList>: Si
|
||||
/// with empty `Args` and `Rets`.
|
||||
impl<'a, T: Exportable<'a> + Clone + 'static> ExportableWithGenerics<'a, (), ()> for T {
|
||||
fn get_self_from_extern_with_generics(
|
||||
_ctx: &impl AsStoreRef,
|
||||
_store: &impl AsStoreRef,
|
||||
_extern: &'a Extern,
|
||||
) -> Result<Self, ExportError> {
|
||||
T::get_self_from_extern(_extern).map(|i| i.clone())
|
||||
|
||||
91
lib/api/src/js/externals/function.rs
vendored
91
lib/api/src/js/externals/function.rs
vendored
@@ -96,7 +96,7 @@ impl Function {
|
||||
#[allow(clippy::cast_ptr_alignment)]
|
||||
pub fn new<FT, F, T: Send + 'static>(
|
||||
store: &mut impl AsStoreMut,
|
||||
ctx: &FunctionEnv<T>,
|
||||
env: &FunctionEnv<T>,
|
||||
ty: FT,
|
||||
func: F,
|
||||
) -> Self
|
||||
@@ -111,46 +111,46 @@ impl Function {
|
||||
let function_type = ty.into();
|
||||
let func_ty = function_type.clone();
|
||||
let raw_store = store.as_raw() as *mut u8;
|
||||
let raw_ctx = ctx.clone();
|
||||
let raw_env = env.clone();
|
||||
let wrapped_func: JsValue = match function_type.results().len() {
|
||||
0 => Closure::wrap(Box::new(move |args: &Array| {
|
||||
let mut store: StoreMut = unsafe { StoreMut::from_raw(raw_store as _) };
|
||||
let mut ctx: FunctionEnvMut<T> = raw_ctx.clone().into_mut(&mut store);
|
||||
let mut env: FunctionEnvMut<T> = raw_env.clone().into_mut(&mut store);
|
||||
let wasm_arguments = function_type
|
||||
.params()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, param)| param_from_js(param, &args.get(i as u32)))
|
||||
.collect::<Vec<_>>();
|
||||
let _results = func(ctx, &wasm_arguments)?;
|
||||
let _results = func(env, &wasm_arguments)?;
|
||||
Ok(())
|
||||
})
|
||||
as Box<dyn FnMut(&Array) -> Result<(), JsValue>>)
|
||||
.into_js_value(),
|
||||
1 => Closure::wrap(Box::new(move |args: &Array| {
|
||||
let mut store: StoreMut = unsafe { StoreMut::from_raw(raw_store as _) };
|
||||
let mut ctx: FunctionEnvMut<T> = raw_ctx.clone().into_mut(&mut store);
|
||||
let mut env: FunctionEnvMut<T> = raw_env.clone().into_mut(&mut store);
|
||||
let wasm_arguments = function_type
|
||||
.params()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, param)| param_from_js(param, &args.get(i as u32)))
|
||||
.collect::<Vec<_>>();
|
||||
let results = func(ctx, &wasm_arguments)?;
|
||||
let results = func(env, &wasm_arguments)?;
|
||||
return Ok(result_to_js(&results[0]));
|
||||
})
|
||||
as Box<dyn FnMut(&Array) -> Result<JsValue, JsValue>>)
|
||||
.into_js_value(),
|
||||
_n => Closure::wrap(Box::new(move |args: &Array| {
|
||||
let mut store: StoreMut = unsafe { StoreMut::from_raw(raw_store as _) };
|
||||
let mut ctx: FunctionEnvMut<T> = raw_ctx.clone().into_mut(&mut store);
|
||||
let mut env: FunctionEnvMut<T> = raw_env.clone().into_mut(&mut store);
|
||||
let wasm_arguments = function_type
|
||||
.params()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, param)| param_from_js(param, &args.get(i as u32)))
|
||||
.collect::<Vec<_>>();
|
||||
let results = func(ctx, &wasm_arguments)?;
|
||||
let results = func(env, &wasm_arguments)?;
|
||||
return Ok(results_to_js_array(&results));
|
||||
})
|
||||
as Box<dyn FnMut(&Array) -> Result<Array, JsValue>>)
|
||||
@@ -231,8 +231,8 @@ impl Function {
|
||||
/// assert_eq!(f.ty().params(), vec![Type::I32, Type::I32]);
|
||||
/// assert_eq!(f.ty().results(), vec![Type::I32]);
|
||||
/// ```
|
||||
pub fn ty<'context>(&self, ctx: &'context impl AsStoreRef) -> &'context FunctionType {
|
||||
&self.handle.get(ctx.as_store_ref().objects()).ty
|
||||
pub fn ty<'context>(&self, store: &'context impl AsStoreRef) -> &'context FunctionType {
|
||||
&self.handle.get(store.as_store_ref().objects()).ty
|
||||
}
|
||||
|
||||
/// Returns the number of parameters that this function takes.
|
||||
@@ -244,7 +244,7 @@ impl Function {
|
||||
/// # let mut store = Store::default();
|
||||
/// # let env = FunctionEnv::new(&mut store, ());
|
||||
/// #
|
||||
/// fn sum(_ctx: FunctionEnvMut<()>, a: i32, b: i32) -> i32 {
|
||||
/// fn sum(_env: FunctionEnvMut<()>, a: i32, b: i32) -> i32 {
|
||||
/// a + b
|
||||
/// }
|
||||
///
|
||||
@@ -252,8 +252,8 @@ impl Function {
|
||||
///
|
||||
/// assert_eq!(f.param_arity(&store), 2);
|
||||
/// ```
|
||||
pub fn param_arity(&self, ctx: &impl AsStoreRef) -> usize {
|
||||
self.ty(ctx).params().len()
|
||||
pub fn param_arity(&self, store: &impl AsStoreRef) -> usize {
|
||||
self.ty(store).params().len()
|
||||
}
|
||||
|
||||
/// Returns the number of results this function produces.
|
||||
@@ -265,7 +265,7 @@ impl Function {
|
||||
/// # let mut store = Store::default();
|
||||
/// # let env = FunctionEnv::new(&mut store, ());
|
||||
/// #
|
||||
/// fn sum(_ctx: FunctionEnvMut<()>, a: i32, b: i32) -> i32 {
|
||||
/// fn sum(_env: FunctionEnvMut<()>, a: i32, b: i32) -> i32 {
|
||||
/// a + b
|
||||
/// }
|
||||
///
|
||||
@@ -273,8 +273,8 @@ impl Function {
|
||||
///
|
||||
/// assert_eq!(f.result_arity(&store), 1);
|
||||
/// ```
|
||||
pub fn result_arity(&self, ctx: &impl AsStoreRef) -> usize {
|
||||
self.ty(ctx).results().len()
|
||||
pub fn result_arity(&self, store: &impl AsStoreRef) -> usize {
|
||||
self.ty(store).results().len()
|
||||
}
|
||||
|
||||
/// Call the `Function` function.
|
||||
@@ -313,8 +313,8 @@ impl Function {
|
||||
) -> Result<Box<[Value]>, RuntimeError> {
|
||||
let arr = js_sys::Array::new_with_length(params.len() as u32);
|
||||
|
||||
// let raw_ctx = ctx.as_raw() as *mut u8;
|
||||
// let mut env = unsafe { FunctionEnvMut::from_raw(raw_ctx as *mut StoreInner<()>) };
|
||||
// let raw_env = env.as_raw() as *mut u8;
|
||||
// let mut env = unsafe { FunctionEnvMut::from_raw(raw_env as *mut StoreInner<()>) };
|
||||
|
||||
for (i, param) in params.iter().enumerate() {
|
||||
let js_value = param.as_jsvalue(&store.as_store_ref());
|
||||
@@ -345,19 +345,19 @@ impl Function {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn from_vm_export(ctx: &mut impl AsStoreMut, vm_function: VMFunction) -> Self {
|
||||
pub(crate) fn from_vm_export(store: &mut impl AsStoreMut, vm_function: VMFunction) -> Self {
|
||||
Self {
|
||||
handle: StoreHandle::new(ctx.objects_mut(), vm_function),
|
||||
handle: StoreHandle::new(store.objects_mut(), vm_function),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn from_vm_extern(
|
||||
ctx: &mut impl AsStoreMut,
|
||||
store: &mut impl AsStoreMut,
|
||||
internal: InternalStoreHandle<VMFunction>,
|
||||
) -> Self {
|
||||
Self {
|
||||
handle: unsafe {
|
||||
StoreHandle::from_internal(ctx.as_store_ref().objects().id(), internal)
|
||||
StoreHandle::from_internal(store.as_store_ref().objects().id(), internal)
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -439,17 +439,16 @@ impl Function {
|
||||
/// ```
|
||||
pub fn native<Args, Rets>(
|
||||
&self,
|
||||
ctx: &impl AsStoreRef,
|
||||
store: &impl AsStoreRef,
|
||||
) -> Result<TypedFunction<Args, Rets>, RuntimeError>
|
||||
where
|
||||
Args: WasmTypeList,
|
||||
Rets: WasmTypeList,
|
||||
{
|
||||
let vm_function = self.handle.get(ctx.as_store_ref().objects());
|
||||
|
||||
let ty = self.ty(store);
|
||||
// type check
|
||||
{
|
||||
let expected = vm_function.ty.params();
|
||||
let expected = ty.params();
|
||||
let given = Args::wasm_types();
|
||||
|
||||
if expected != given {
|
||||
@@ -462,7 +461,7 @@ impl Function {
|
||||
}
|
||||
|
||||
{
|
||||
let expected = vm_function.ty.results();
|
||||
let expected = ty.results();
|
||||
let given = Rets::wasm_types();
|
||||
|
||||
if expected != given {
|
||||
@@ -484,8 +483,8 @@ impl Function {
|
||||
}
|
||||
|
||||
/// Checks whether this `Function` can be used with the given context.
|
||||
pub fn is_from_store(&self, ctx: &impl AsStoreRef) -> bool {
|
||||
self.handle.store_id() == ctx.as_store_ref().objects().id()
|
||||
pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool {
|
||||
self.handle.store_id() == store.as_store_ref().objects().id()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -657,7 +656,7 @@ mod inner {
|
||||
/// Constructs `Self` based on an array of values.
|
||||
///
|
||||
/// # Safety
|
||||
unsafe fn from_array(ctx: &mut impl AsStoreMut, array: Self::Array) -> Self;
|
||||
unsafe fn from_array(store: &mut impl AsStoreMut, array: Self::Array) -> Self;
|
||||
|
||||
/// Constructs `Self` based on a slice of values.
|
||||
///
|
||||
@@ -668,7 +667,7 @@ mod inner {
|
||||
///
|
||||
/// # Safety
|
||||
unsafe fn from_slice(
|
||||
ctx: &mut impl AsStoreMut,
|
||||
store: &mut impl AsStoreMut,
|
||||
slice: &[f64],
|
||||
) -> Result<Self, TryFromSliceError>;
|
||||
|
||||
@@ -676,7 +675,7 @@ mod inner {
|
||||
/// (list) of values.
|
||||
///
|
||||
/// # Safety
|
||||
unsafe fn into_array(self, ctx: &mut impl AsStoreMut) -> Self::Array;
|
||||
unsafe fn into_array(self, store: &mut impl AsStoreMut) -> Self::Array;
|
||||
|
||||
/// Allocates and return an empty array of type `Array` that
|
||||
/// will hold a tuple (list) of values, usually to hold the
|
||||
@@ -687,13 +686,13 @@ mod inner {
|
||||
/// `CStruct`.
|
||||
///
|
||||
/// # Safety
|
||||
unsafe fn from_c_struct(ctx: &mut impl AsStoreMut, c_struct: Self::CStruct) -> Self;
|
||||
unsafe fn from_c_struct(store: &mut impl AsStoreMut, c_struct: Self::CStruct) -> Self;
|
||||
|
||||
/// Builds and returns a C struct of type `CStruct` from a
|
||||
/// tuple (list) of values.
|
||||
///
|
||||
/// # Safety
|
||||
unsafe fn into_c_struct(self, ctx: &mut impl AsStoreMut) -> Self::CStruct;
|
||||
unsafe fn into_c_struct(self, store: &mut impl AsStoreMut) -> Self::CStruct;
|
||||
|
||||
/// Writes the contents of a C struct to an array of `f64`.
|
||||
///
|
||||
@@ -879,7 +878,7 @@ mod inner {
|
||||
#[allow(unused_mut)]
|
||||
#[allow(clippy::unused_unit)]
|
||||
#[allow(clippy::missing_safety_doc)]
|
||||
unsafe fn from_array(mut _ctx: &mut impl AsStoreMut, array: Self::Array) -> Self {
|
||||
unsafe fn from_array(mut _store: &mut impl AsStoreMut, array: Self::Array) -> Self {
|
||||
// Unpack items of the array.
|
||||
#[allow(non_snake_case)]
|
||||
let [ $( $x ),* ] = array;
|
||||
@@ -887,19 +886,19 @@ mod inner {
|
||||
// Build the tuple.
|
||||
(
|
||||
$(
|
||||
FromToNativeWasmType::from_native(NativeWasmTypeInto::from_raw(_ctx, $x))
|
||||
FromToNativeWasmType::from_native(NativeWasmTypeInto::from_raw(_store, $x))
|
||||
),*
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(clippy::missing_safety_doc)]
|
||||
unsafe fn from_slice(ctx: &mut impl AsStoreMut, slice: &[f64]) -> Result<Self, TryFromSliceError> {
|
||||
Ok(Self::from_array(ctx, slice.try_into()?))
|
||||
unsafe fn from_slice(store: &mut impl AsStoreMut, slice: &[f64]) -> Result<Self, TryFromSliceError> {
|
||||
Ok(Self::from_array(store, slice.try_into()?))
|
||||
}
|
||||
|
||||
#[allow(unused_mut)]
|
||||
#[allow(clippy::missing_safety_doc)]
|
||||
unsafe fn into_array(self, mut _ctx: &mut impl AsStoreMut) -> Self::Array {
|
||||
unsafe fn into_array(self, mut _store: &mut impl AsStoreMut) -> Self::Array {
|
||||
// Unpack items of the tuple.
|
||||
#[allow(non_snake_case)]
|
||||
let ( $( $x ),* ) = self;
|
||||
@@ -907,7 +906,7 @@ mod inner {
|
||||
// Build the array.
|
||||
[
|
||||
$(
|
||||
FromToNativeWasmType::to_native($x).into_raw(_ctx)
|
||||
FromToNativeWasmType::to_native($x).into_raw(_store)
|
||||
),*
|
||||
]
|
||||
}
|
||||
@@ -920,28 +919,28 @@ mod inner {
|
||||
#[allow(unused_mut)]
|
||||
#[allow(clippy::unused_unit)]
|
||||
#[allow(clippy::missing_safety_doc)]
|
||||
unsafe fn from_c_struct(mut _ctx: &mut impl AsStoreMut, c_struct: Self::CStruct) -> Self {
|
||||
unsafe fn from_c_struct(mut _store: &mut impl AsStoreMut, c_struct: Self::CStruct) -> Self {
|
||||
// Unpack items of the C structure.
|
||||
#[allow(non_snake_case)]
|
||||
let $c_struct_name( $( $x ),* ) = c_struct;
|
||||
|
||||
(
|
||||
$(
|
||||
FromToNativeWasmType::from_native(NativeWasmTypeInto::from_abi(_ctx, $x))
|
||||
FromToNativeWasmType::from_native(NativeWasmTypeInto::from_abi(_store, $x))
|
||||
),*
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(unused_parens, non_snake_case, unused_mut)]
|
||||
#[allow(clippy::missing_safety_doc)]
|
||||
unsafe fn into_c_struct(self, mut _ctx: &mut impl AsStoreMut) -> Self::CStruct {
|
||||
unsafe fn into_c_struct(self, mut _store: &mut impl AsStoreMut) -> Self::CStruct {
|
||||
// Unpack items of the tuple.
|
||||
let ( $( $x ),* ) = self;
|
||||
|
||||
// Build the C structure.
|
||||
$c_struct_name(
|
||||
$(
|
||||
FromToNativeWasmType::to_native($x).into_abi(_ctx)
|
||||
FromToNativeWasmType::to_native($x).into_abi(_store)
|
||||
),*
|
||||
)
|
||||
}
|
||||
@@ -1000,8 +999,8 @@ mod inner {
|
||||
|
||||
let result = panic::catch_unwind(AssertUnwindSafe(|| {
|
||||
let handle: StoreHandle<VMFunctionEnvironment> = StoreHandle::from_internal(store2.objects_mut().id(), InternalStoreHandle::from_index(handle_index).unwrap());
|
||||
let ctx: FunctionEnvMut<T> = FunctionEnv::from_handle(handle).into_mut(&mut store2);
|
||||
func(ctx, $( FromToNativeWasmType::from_native(NativeWasmTypeInto::from_abi(&mut store, $x)) ),* ).into_result()
|
||||
let env: FunctionEnvMut<T> = FunctionEnv::from_handle(handle).into_mut(&mut store2);
|
||||
func(env, $( FromToNativeWasmType::from_native(NativeWasmTypeInto::from_abi(&mut store, $x)) ),* ).into_result()
|
||||
}));
|
||||
|
||||
match result {
|
||||
|
||||
14
lib/api/src/js/externals/global.rs
vendored
14
lib/api/src/js/externals/global.rs
vendored
@@ -34,8 +34,8 @@ impl Global {
|
||||
/// assert_eq!(g.get(), Value::I32(1));
|
||||
/// assert_eq!(g.ty().mutability, Mutability::Const);
|
||||
/// ```
|
||||
pub fn new(ctx: &mut impl AsStoreMut, val: Value) -> Self {
|
||||
Self::from_value(ctx, val, Mutability::Const).unwrap()
|
||||
pub fn new(store: &mut impl AsStoreMut, val: Value) -> Self {
|
||||
Self::from_value(store, val, Mutability::Const).unwrap()
|
||||
}
|
||||
|
||||
/// Create a mutable `Global` with the initial value [`Value`].
|
||||
@@ -51,17 +51,17 @@ impl Global {
|
||||
/// assert_eq!(g.get(), Value::I32(1));
|
||||
/// assert_eq!(g.ty().mutability, Mutability::Var);
|
||||
/// ```
|
||||
pub fn new_mut(ctx: &mut impl AsStoreMut, val: Value) -> Self {
|
||||
Self::from_value(ctx, val, Mutability::Var).unwrap()
|
||||
pub fn new_mut(store: &mut impl AsStoreMut, val: Value) -> Self {
|
||||
Self::from_value(store, val, Mutability::Var).unwrap()
|
||||
}
|
||||
|
||||
/// Create a `Global` with the initial value [`Value`] and the provided [`Mutability`].
|
||||
fn from_value(
|
||||
ctx: &mut impl AsStoreMut,
|
||||
store: &mut impl AsStoreMut,
|
||||
val: Value,
|
||||
mutability: Mutability,
|
||||
) -> Result<Self, RuntimeError> {
|
||||
if !val.is_from_store(ctx) {
|
||||
if !val.is_from_store(store) {
|
||||
return Err(RuntimeError::new(
|
||||
"cross-`WasmerEnv` values are not supported",
|
||||
));
|
||||
@@ -90,7 +90,7 @@ impl Global {
|
||||
let js_global = JSGlobal::new(&descriptor, &value).unwrap();
|
||||
let vm_global = VMGlobal::new(js_global, global_ty);
|
||||
|
||||
Ok(Self::from_vm_export(ctx, vm_global))
|
||||
Ok(Self::from_vm_export(store, vm_global))
|
||||
}
|
||||
|
||||
/// Returns the [`GlobalType`] of the `Global`.
|
||||
|
||||
42
lib/api/src/js/externals/memory.rs
vendored
42
lib/api/src/js/externals/memory.rs
vendored
@@ -100,7 +100,7 @@ impl Memory {
|
||||
/// #
|
||||
/// let m = Memory::new(&store, MemoryType::new(1, None, false)).unwrap();
|
||||
/// ```
|
||||
pub fn new(ctx: &mut impl AsStoreMut, ty: MemoryType) -> Result<Self, MemoryError> {
|
||||
pub fn new(store: &mut impl AsStoreMut, ty: MemoryType) -> Result<Self, MemoryError> {
|
||||
let descriptor = js_sys::Object::new();
|
||||
js_sys::Reflect::set(&descriptor, &"initial".into(), &ty.minimum.0.into()).unwrap();
|
||||
if let Some(max) = ty.maximum {
|
||||
@@ -112,7 +112,7 @@ impl Memory {
|
||||
.map_err(|_e| MemoryError::Generic("Error while creating the memory".to_owned()))?;
|
||||
|
||||
let vm_memory = VMMemory::new(js_memory, ty);
|
||||
Ok(Self::from_vm_export(ctx, vm_memory))
|
||||
Ok(Self::from_vm_export(store, vm_memory))
|
||||
}
|
||||
|
||||
/// Returns the [`MemoryType`] of the `Memory`.
|
||||
@@ -128,8 +128,8 @@ impl Memory {
|
||||
///
|
||||
/// assert_eq!(m.ty(), mt);
|
||||
/// ```
|
||||
pub fn ty(&self, ctx: &impl AsStoreRef) -> MemoryType {
|
||||
self.handle.get(ctx.as_store_ref().objects()).ty
|
||||
pub fn ty(&self, store: &impl AsStoreRef) -> MemoryType {
|
||||
self.handle.get(store.as_store_ref().objects()).ty
|
||||
}
|
||||
|
||||
/// Returns the pointer to the raw bytes of the `Memory`.
|
||||
@@ -139,11 +139,11 @@ impl Memory {
|
||||
}
|
||||
|
||||
/// Returns the size (in bytes) of the `Memory`.
|
||||
pub fn data_size(&self, ctx: &impl AsStoreRef) -> u64 {
|
||||
pub fn data_size(&self, store: &impl AsStoreRef) -> u64 {
|
||||
js_sys::Reflect::get(
|
||||
&self
|
||||
.handle
|
||||
.get(ctx.as_store_ref().objects())
|
||||
.get(store.as_store_ref().objects())
|
||||
.memory
|
||||
.buffer(),
|
||||
&"byteLength".into(),
|
||||
@@ -165,11 +165,11 @@ impl Memory {
|
||||
///
|
||||
/// assert_eq!(m.size(), Pages(1));
|
||||
/// ```
|
||||
pub fn size(&self, ctx: &impl AsStoreRef) -> Pages {
|
||||
pub fn size(&self, store: &impl AsStoreRef) -> Pages {
|
||||
let bytes = js_sys::Reflect::get(
|
||||
&self
|
||||
.handle
|
||||
.get(ctx.as_store_ref().objects())
|
||||
.get(store.as_store_ref().objects())
|
||||
.memory
|
||||
.buffer(),
|
||||
&"byteLength".into(),
|
||||
@@ -236,40 +236,40 @@ impl Memory {
|
||||
|
||||
/// Used by tests
|
||||
#[doc(hidden)]
|
||||
pub fn uint8view(&self, ctx: &impl AsStoreRef) -> js_sys::Uint8Array {
|
||||
pub fn uint8view(&self, store: &impl AsStoreRef) -> js_sys::Uint8Array {
|
||||
js_sys::Uint8Array::new(
|
||||
&self
|
||||
.handle
|
||||
.get(ctx.as_store_ref().objects())
|
||||
.get(store.as_store_ref().objects())
|
||||
.memory
|
||||
.buffer(),
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn buffer<'a>(&'a self, _ctx: &'a impl AsStoreRef) -> MemoryBuffer<'a> {
|
||||
pub(crate) fn buffer<'a>(&'a self, _store: &'a impl AsStoreRef) -> MemoryBuffer<'a> {
|
||||
MemoryBuffer {
|
||||
base: &self.view as *const _ as *mut _,
|
||||
marker: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn from_vm_export(ctx: &mut impl AsStoreMut, vm_memory: VMMemory) -> Self {
|
||||
pub(crate) fn from_vm_export(store: &mut impl AsStoreMut, vm_memory: VMMemory) -> Self {
|
||||
let view = js_sys::Uint8Array::new(&vm_memory.memory.buffer());
|
||||
Self {
|
||||
handle: StoreHandle::new(ctx.objects_mut(), vm_memory),
|
||||
handle: StoreHandle::new(store.objects_mut(), vm_memory),
|
||||
view,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn from_vm_extern(
|
||||
ctx: &mut impl AsStoreMut,
|
||||
store: &mut impl AsStoreMut,
|
||||
internal: InternalStoreHandle<VMMemory>,
|
||||
) -> Self {
|
||||
let view =
|
||||
js_sys::Uint8Array::new(&internal.get(ctx.as_store_ref().objects()).memory.buffer());
|
||||
js_sys::Uint8Array::new(&internal.get(store.as_store_ref().objects()).memory.buffer());
|
||||
Self {
|
||||
handle: unsafe {
|
||||
StoreHandle::from_internal(ctx.as_store_ref().objects().id(), internal)
|
||||
StoreHandle::from_internal(store.as_store_ref().objects().id(), internal)
|
||||
},
|
||||
view,
|
||||
}
|
||||
@@ -284,7 +284,7 @@ impl Memory {
|
||||
/// concurrent writes.
|
||||
pub fn read(
|
||||
&self,
|
||||
_ctx: &impl AsStoreRef,
|
||||
_store: &impl AsStoreRef,
|
||||
offset: u64,
|
||||
data: &mut [u8],
|
||||
) -> Result<(), MemoryAccessError> {
|
||||
@@ -314,7 +314,7 @@ impl Memory {
|
||||
/// concurrent writes.
|
||||
pub fn read_uninit<'a>(
|
||||
&self,
|
||||
_ctx: &impl AsStoreRef,
|
||||
_store: &impl AsStoreRef,
|
||||
offset: u64,
|
||||
buf: &'a mut [MaybeUninit<u8>],
|
||||
) -> Result<&'a mut [u8], MemoryAccessError> {
|
||||
@@ -349,7 +349,7 @@ impl Memory {
|
||||
/// concurrent reads/writes.
|
||||
pub fn write(
|
||||
&self,
|
||||
_ctx: &mut impl AsStoreMut,
|
||||
_store: &mut impl AsStoreMut,
|
||||
offset: u64,
|
||||
data: &[u8],
|
||||
) -> Result<(), MemoryAccessError> {
|
||||
@@ -368,8 +368,8 @@ impl Memory {
|
||||
}
|
||||
|
||||
/// Checks whether this `Global` can be used with the given context.
|
||||
pub fn is_from_store(&self, ctx: &impl AsStoreRef) -> bool {
|
||||
self.handle.store_id() == ctx.as_store_ref().objects().id()
|
||||
pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool {
|
||||
self.handle.store_id() == store.as_store_ref().objects().id()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
40
lib/api/src/js/externals/mod.rs
vendored
40
lib/api/src/js/externals/mod.rs
vendored
@@ -34,32 +34,32 @@ pub enum Extern {
|
||||
|
||||
impl Extern {
|
||||
/// Return the underlying type of the inner `Extern`.
|
||||
pub fn ty(&self, ctx: &impl AsStoreRef) -> ExternType {
|
||||
pub fn ty(&self, store: &impl AsStoreRef) -> ExternType {
|
||||
match self {
|
||||
Self::Function(ft) => ExternType::Function(ft.ty(ctx).clone()),
|
||||
Self::Memory(ft) => ExternType::Memory(ft.ty(ctx)),
|
||||
Self::Table(tt) => ExternType::Table(tt.ty(ctx)),
|
||||
Self::Global(gt) => ExternType::Global(gt.ty(ctx)),
|
||||
Self::Function(ft) => ExternType::Function(ft.ty(store).clone()),
|
||||
Self::Memory(ft) => ExternType::Memory(ft.ty(store)),
|
||||
Self::Table(tt) => ExternType::Table(tt.ty(store)),
|
||||
Self::Global(gt) => ExternType::Global(gt.ty(store)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Create an `Extern` from an `wasmer_compiler::Export`.
|
||||
pub fn from_vm_export(ctx: &mut impl AsStoreMut, export: Export) -> Self {
|
||||
pub fn from_vm_export(store: &mut impl AsStoreMut, export: Export) -> Self {
|
||||
match export {
|
||||
Export::Function(f) => Self::Function(Function::from_vm_extern(ctx, f)),
|
||||
Export::Memory(m) => Self::Memory(Memory::from_vm_extern(ctx, m)),
|
||||
Export::Global(g) => Self::Global(Global::from_vm_extern(ctx, g)),
|
||||
Export::Table(t) => Self::Table(Table::from_vm_extern(ctx, t)),
|
||||
Export::Function(f) => Self::Function(Function::from_vm_extern(store, f)),
|
||||
Export::Memory(m) => Self::Memory(Memory::from_vm_extern(store, m)),
|
||||
Export::Global(g) => Self::Global(Global::from_vm_extern(store, g)),
|
||||
Export::Table(t) => Self::Table(Table::from_vm_extern(store, t)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks whether this `Extern` can be used with the given context.
|
||||
pub fn is_from_store(&self, ctx: &impl AsStoreRef) -> bool {
|
||||
pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool {
|
||||
match self {
|
||||
Self::Function(val) => val.is_from_store(ctx),
|
||||
Self::Memory(val) => val.is_from_store(ctx),
|
||||
Self::Global(val) => val.is_from_store(ctx),
|
||||
Self::Table(val) => val.is_from_store(ctx),
|
||||
Self::Function(val) => val.is_from_store(store),
|
||||
Self::Memory(val) => val.is_from_store(store),
|
||||
Self::Global(val) => val.is_from_store(store),
|
||||
Self::Table(val) => val.is_from_store(store),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,12 +74,12 @@ impl Extern {
|
||||
}
|
||||
|
||||
impl AsJs for Extern {
|
||||
fn as_jsvalue(&self, ctx: &impl AsStoreRef) -> wasm_bindgen::JsValue {
|
||||
fn as_jsvalue(&self, store: &impl AsStoreRef) -> wasm_bindgen::JsValue {
|
||||
match self {
|
||||
Self::Function(_) => self.to_export().as_jsvalue(ctx),
|
||||
Self::Global(_) => self.to_export().as_jsvalue(ctx),
|
||||
Self::Table(_) => self.to_export().as_jsvalue(ctx),
|
||||
Self::Memory(_) => self.to_export().as_jsvalue(ctx),
|
||||
Self::Function(_) => self.to_export().as_jsvalue(store),
|
||||
Self::Global(_) => self.to_export().as_jsvalue(store),
|
||||
Self::Table(_) => self.to_export().as_jsvalue(store),
|
||||
Self::Memory(_) => self.to_export().as_jsvalue(store),
|
||||
}
|
||||
.clone()
|
||||
}
|
||||
|
||||
49
lib/api/src/js/externals/table.rs
vendored
49
lib/api/src/js/externals/table.rs
vendored
@@ -25,14 +25,14 @@ fn set_table_item(table: &VMTable, item_index: u32, item: &Function) -> Result<(
|
||||
table.table.set(item_index, item).map_err(|e| e.into())
|
||||
}
|
||||
|
||||
fn get_function(ctx: &mut impl AsStoreMut, val: Value) -> Result<Function, RuntimeError> {
|
||||
if !val.is_from_store(ctx) {
|
||||
fn get_function(store: &mut impl AsStoreMut, val: Value) -> Result<Function, RuntimeError> {
|
||||
if !val.is_from_store(store) {
|
||||
return Err(RuntimeError::new("cannot pass Value across contexts"));
|
||||
}
|
||||
match val {
|
||||
Value::FuncRef(Some(ref func)) => Ok(func
|
||||
.handle
|
||||
.get(&ctx.as_store_ref().objects())
|
||||
.get(&store.as_store_ref().objects())
|
||||
.function
|
||||
.clone()
|
||||
.into()),
|
||||
@@ -49,11 +49,11 @@ impl Table {
|
||||
/// This function will construct the `Table` using the store
|
||||
/// [`BaseTunables`][crate::js::tunables::BaseTunables].
|
||||
pub fn new(
|
||||
ctx: &mut impl AsStoreMut,
|
||||
store: &mut impl AsStoreMut,
|
||||
ty: TableType,
|
||||
init: Value,
|
||||
) -> Result<Self, RuntimeError> {
|
||||
let mut ctx = ctx;
|
||||
let mut store = store;
|
||||
let descriptor = js_sys::Object::new();
|
||||
js_sys::Reflect::set(&descriptor, &"initial".into(), &ty.minimum.into())?;
|
||||
if let Some(max) = ty.maximum {
|
||||
@@ -65,33 +65,33 @@ impl Table {
|
||||
let table = VMTable::new(js_table, ty);
|
||||
|
||||
let num_elements = table.table.length();
|
||||
let func = get_function(&mut ctx, init)?;
|
||||
let func = get_function(&mut store, init)?;
|
||||
for i in 0..num_elements {
|
||||
set_table_item(&table, i, &func)?;
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
handle: StoreHandle::new(ctx.objects_mut(), table),
|
||||
handle: StoreHandle::new(store.objects_mut(), table),
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns the [`TableType`] of the `Table`.
|
||||
pub fn ty(&self, ctx: &impl AsStoreRef) -> TableType {
|
||||
self.handle.get(ctx.as_store_ref().objects()).ty
|
||||
pub fn ty(&self, store: &impl AsStoreRef) -> TableType {
|
||||
self.handle.get(store.as_store_ref().objects()).ty
|
||||
}
|
||||
|
||||
/// Retrieves an element of the table at the provided `index`.
|
||||
pub fn get(&self, ctx: &mut impl AsStoreMut, index: u32) -> Option<Value> {
|
||||
pub fn get(&self, store: &mut impl AsStoreMut, index: u32) -> Option<Value> {
|
||||
if let Some(func) = self
|
||||
.handle
|
||||
.get(ctx.as_store_ref().objects())
|
||||
.get(store.as_store_ref().objects())
|
||||
.table
|
||||
.get(index)
|
||||
.ok()
|
||||
{
|
||||
let ty = FunctionType::new(vec![], vec![]);
|
||||
let vm_function = VMFunction::new(func, ty);
|
||||
let function = crate::js::externals::Function::from_vm_export(ctx, vm_function);
|
||||
let function = crate::js::externals::Function::from_vm_export(store, vm_function);
|
||||
Some(Value::FuncRef(Some(function)))
|
||||
} else {
|
||||
None
|
||||
@@ -101,17 +101,20 @@ impl Table {
|
||||
/// Sets an element `val` in the Table at the provided `index`.
|
||||
pub fn set(
|
||||
&self,
|
||||
ctx: &mut impl AsStoreMut,
|
||||
store: &mut impl AsStoreMut,
|
||||
index: u32,
|
||||
val: Value,
|
||||
) -> Result<(), RuntimeError> {
|
||||
let item = get_function(ctx, val)?;
|
||||
set_table_item(self.handle.get_mut(ctx.objects_mut()), index, &item)
|
||||
let item = get_function(store, val)?;
|
||||
set_table_item(self.handle.get_mut(store.objects_mut()), index, &item)
|
||||
}
|
||||
|
||||
/// Retrieves the size of the `Table` (in elements)
|
||||
pub fn size(&self, ctx: &impl AsStoreRef) -> u32 {
|
||||
self.handle.get(ctx.as_store_ref().objects()).table.length()
|
||||
pub fn size(&self, store: &impl AsStoreRef) -> u32 {
|
||||
self.handle
|
||||
.get(store.as_store_ref().objects())
|
||||
.table
|
||||
.length()
|
||||
}
|
||||
|
||||
/// Grows the size of the `Table` by `delta`, initializating
|
||||
@@ -150,19 +153,19 @@ impl Table {
|
||||
}
|
||||
|
||||
pub(crate) fn from_vm_extern(
|
||||
ctx: &mut impl AsStoreMut,
|
||||
store: &mut impl AsStoreMut,
|
||||
internal: InternalStoreHandle<VMTable>,
|
||||
) -> Self {
|
||||
Self {
|
||||
handle: unsafe {
|
||||
StoreHandle::from_internal(ctx.as_store_ref().objects().id(), internal)
|
||||
StoreHandle::from_internal(store.as_store_ref().objects().id(), internal)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks whether this `Table` can be used with the given context.
|
||||
pub fn is_from_store(&self, ctx: &impl AsStoreRef) -> bool {
|
||||
self.handle.store_id() == ctx.as_store_ref().objects().id()
|
||||
pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool {
|
||||
self.handle.store_id() == store.as_store_ref().objects().id()
|
||||
}
|
||||
|
||||
/// Get access to the backing VM value for this extern. This function is for
|
||||
@@ -175,9 +178,9 @@ impl Table {
|
||||
#[doc(hidden)]
|
||||
pub unsafe fn get_vm_table<'context>(
|
||||
&self,
|
||||
ctx: &'context impl AsStoreRef,
|
||||
store: &'context impl AsStoreRef,
|
||||
) -> &'context VMTable {
|
||||
self.handle.get(ctx.as_store_ref().objects())
|
||||
self.handle.get(store.as_store_ref().objects())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ impl Imports {
|
||||
}
|
||||
|
||||
/// Returns the `Imports` as a Javascript `Object`
|
||||
pub fn as_jsobject(&self, ctx: &impl AsStoreRef) -> js_sys::Object {
|
||||
pub fn as_jsobject(&self, store: &impl AsStoreRef) -> js_sys::Object {
|
||||
let imports = js_sys::Object::new();
|
||||
let namespaces: HashMap<&str, Vec<(&str, &Extern)>> =
|
||||
self.map
|
||||
@@ -166,7 +166,7 @@ impl Imports {
|
||||
for (ns, exports) in namespaces.into_iter() {
|
||||
let import_namespace = js_sys::Object::new();
|
||||
for (name, ext) in exports {
|
||||
js_sys::Reflect::set(&import_namespace, &name.into(), &ext.as_jsvalue(ctx))
|
||||
js_sys::Reflect::set(&import_namespace, &name.into(), &ext.as_jsvalue(store))
|
||||
.expect("Error while setting into the js namespace object");
|
||||
}
|
||||
js_sys::Reflect::set(&imports, &ns.into(), &import_namespace.into())
|
||||
|
||||
@@ -61,16 +61,16 @@ impl Instance {
|
||||
/// * Link errors that happen when plugging the imports into the instance
|
||||
/// * Runtime errors that happen when running the module `start` function.
|
||||
pub fn new(
|
||||
mut ctx: &mut impl AsStoreMut,
|
||||
mut store: &mut impl AsStoreMut,
|
||||
module: &Module,
|
||||
imports: &Imports,
|
||||
) -> Result<Self, InstantiationError> {
|
||||
let import_copy = imports.clone();
|
||||
let (instance, _imports): (StoreHandle<WebAssembly::Instance>, Vec<Extern>) = module
|
||||
.instantiate(&mut ctx, imports)
|
||||
.instantiate(&mut store, imports)
|
||||
.map_err(|e| InstantiationError::Start(e))?;
|
||||
|
||||
let self_instance = Self::from_module_and_instance(ctx, module, instance, import_copy)?;
|
||||
let self_instance = Self::from_module_and_instance(store, module, instance, import_copy)?;
|
||||
//self_instance.init_envs(&imports.iter().map(Extern::to_export).collect::<Vec<_>>())?;
|
||||
Ok(self_instance)
|
||||
}
|
||||
@@ -85,12 +85,12 @@ impl Instance {
|
||||
///
|
||||
/// *This method is only available when targeting JS environments*
|
||||
pub fn from_module_and_instance(
|
||||
mut ctx: &mut impl AsStoreMut,
|
||||
mut store: &mut impl AsStoreMut,
|
||||
module: &Module,
|
||||
instance: StoreHandle<WebAssembly::Instance>,
|
||||
imports: Imports,
|
||||
) -> Result<Self, InstantiationError> {
|
||||
let instance_exports = instance.get(ctx.as_store_ref().objects()).exports();
|
||||
let instance_exports = instance.get(store.as_store_ref().objects()).exports();
|
||||
let exports = module
|
||||
.exports()
|
||||
.map(|export_type| {
|
||||
@@ -104,8 +104,8 @@ impl Instance {
|
||||
))
|
||||
})?;
|
||||
let export: Export =
|
||||
Export::from_js_value(js_export, &mut ctx, extern_type)?.into();
|
||||
let extern_ = Extern::from_vm_export(&mut ctx, export);
|
||||
Export::from_js_value(js_export, &mut store, extern_type)?.into();
|
||||
let extern_ = Extern::from_vm_export(&mut store, export);
|
||||
Ok((name.to_string(), extern_))
|
||||
})
|
||||
.collect::<Result<Exports, InstantiationError>>()?;
|
||||
@@ -125,8 +125,11 @@ impl Instance {
|
||||
|
||||
/// Returns the inner WebAssembly Instance
|
||||
#[doc(hidden)]
|
||||
pub fn raw<'context>(&self, ctx: &'context impl AsStoreRef) -> &'context WebAssembly::Instance {
|
||||
&self._handle.get(ctx.as_store_ref().objects())
|
||||
pub fn raw<'context>(
|
||||
&self,
|
||||
store: &'context impl AsStoreRef,
|
||||
) -> &'context WebAssembly::Instance {
|
||||
&self._handle.get(store.as_store_ref().objects())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ impl JsImportObject {
|
||||
/// ```
|
||||
pub fn get_export(
|
||||
&self,
|
||||
ctx: &mut impl AsStoreMut,
|
||||
store: &mut impl AsStoreMut,
|
||||
module: &str,
|
||||
name: &str,
|
||||
) -> Result<Export, WasmError> {
|
||||
@@ -63,7 +63,11 @@ impl JsImportObject {
|
||||
.module_imports
|
||||
.get(&(module.to_string(), name.to_string()))
|
||||
{
|
||||
Some(extern_type) => Ok(Export::from_js_value(js_export, ctx, extern_type.clone())?),
|
||||
Some(extern_type) => Ok(Export::from_js_value(
|
||||
js_export,
|
||||
store,
|
||||
extern_type.clone(),
|
||||
)?),
|
||||
None => Err(WasmError::Generic(format!(
|
||||
"Name {} not found in module {}",
|
||||
name, module
|
||||
|
||||
@@ -61,9 +61,9 @@ pub struct WasmRef<'a, T: ValueType> {
|
||||
impl<'a, T: ValueType> WasmRef<'a, T> {
|
||||
/// Creates a new `WasmRef` at the given offset in a memory.
|
||||
#[inline]
|
||||
pub fn new(ctx: &'a impl AsStoreRef, memory: &'a Memory, offset: u64) -> Self {
|
||||
pub fn new(store: &'a impl AsStoreRef, memory: &'a Memory, offset: u64) -> Self {
|
||||
Self {
|
||||
buffer: memory.buffer(ctx),
|
||||
buffer: memory.buffer(store),
|
||||
offset,
|
||||
marker: PhantomData,
|
||||
}
|
||||
@@ -160,7 +160,7 @@ impl<'a, T: ValueType> WasmSlice<'a, T> {
|
||||
/// Returns a `MemoryAccessError` if the slice length overflows.
|
||||
#[inline]
|
||||
pub fn new(
|
||||
ctx: &'a impl AsStoreRef,
|
||||
store: &'a impl AsStoreRef,
|
||||
memory: &'a Memory,
|
||||
offset: u64,
|
||||
len: u64,
|
||||
@@ -172,7 +172,7 @@ impl<'a, T: ValueType> WasmSlice<'a, T> {
|
||||
.checked_add(total_len)
|
||||
.ok_or(MemoryAccessError::Overflow)?;
|
||||
Ok(Self {
|
||||
buffer: memory.buffer(ctx),
|
||||
buffer: memory.buffer(store),
|
||||
offset,
|
||||
len,
|
||||
marker: PhantomData,
|
||||
|
||||
@@ -66,11 +66,11 @@ macro_rules! impl_native_traits {
|
||||
{
|
||||
/// Call the typed func and return results.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn call(&self, mut ctx: &mut impl AsStoreMut, $( $x: $x, )* ) -> Result<Rets, RuntimeError> where
|
||||
pub fn call(&self, mut store: &mut impl AsStoreMut, $( $x: $x, )* ) -> Result<Rets, RuntimeError> where
|
||||
$( $x: FromToNativeWasmType + crate::js::NativeWasmTypeInto, )*
|
||||
{
|
||||
let params_list: Vec<JsValue> = vec![ $( JsValue::from_f64($x.into_raw(&mut ctx))),* ];
|
||||
let results = self.handle.get(ctx.as_store_ref().objects()).function.apply(
|
||||
let params_list: Vec<JsValue> = vec![ $( JsValue::from_f64($x.into_raw(&mut store))),* ];
|
||||
let results = self.handle.get(store.as_store_ref().objects()).function.apply(
|
||||
&JsValue::UNDEFINED,
|
||||
&Array::from_iter(params_list.iter())
|
||||
)?;
|
||||
@@ -81,7 +81,7 @@ macro_rules! impl_native_traits {
|
||||
1 => unsafe {
|
||||
let ty = Rets::wasm_types()[0];
|
||||
let val = param_from_js(&ty, &results);
|
||||
*mut_rets = val.as_raw(&mut ctx);
|
||||
*mut_rets = val.as_raw(&mut store);
|
||||
}
|
||||
_n => {
|
||||
let results: Array = results.into();
|
||||
@@ -90,12 +90,12 @@ macro_rules! impl_native_traits {
|
||||
unsafe {
|
||||
let val = param_from_js(&ret_type, &ret);
|
||||
let slot = mut_rets.add(i);
|
||||
*slot = val.as_raw(&mut ctx);
|
||||
*slot = val.as_raw(&mut store);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(unsafe { Rets::from_array(ctx, rets_list_array) })
|
||||
Ok(unsafe { Rets::from_array(store, rets_list_array) })
|
||||
}
|
||||
|
||||
}
|
||||
@@ -106,9 +106,9 @@ macro_rules! impl_native_traits {
|
||||
$( $x: FromToNativeWasmType, )*
|
||||
Rets: WasmTypeList,
|
||||
{
|
||||
fn get_self_from_extern_with_generics(ctx: &impl AsStoreRef, _extern: &crate::js::externals::Extern) -> Result<Self, crate::js::exports::ExportError> {
|
||||
fn get_self_from_extern_with_generics(store: &impl AsStoreRef, _extern: &crate::js::externals::Extern) -> Result<Self, crate::js::exports::ExportError> {
|
||||
use crate::js::exports::Exportable;
|
||||
crate::js::Function::get_self_from_extern(_extern)?.native(ctx).map_err(|_| crate::js::exports::ExportError::IncompatibleType)
|
||||
crate::js::Function::get_self_from_extern(_extern)?.native(store).map_err(|_| crate::js::exports::ExportError::IncompatibleType)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -11,105 +11,105 @@ use super::store::AsStoreMut;
|
||||
/// types with a context.
|
||||
pub trait NativeWasmTypeInto: NativeWasmType + Sized {
|
||||
#[doc(hidden)]
|
||||
fn into_abi(self, ctx: &mut impl AsStoreMut) -> Self::Abi;
|
||||
fn into_abi(self, store: &mut impl AsStoreMut) -> Self::Abi;
|
||||
|
||||
#[doc(hidden)]
|
||||
unsafe fn from_abi(ctx: &mut impl AsStoreMut, abi: Self::Abi) -> Self;
|
||||
unsafe fn from_abi(store: &mut impl AsStoreMut, abi: Self::Abi) -> Self;
|
||||
|
||||
/// Convert self to raw value representation.
|
||||
fn into_raw(self, ctx: &mut impl AsStoreMut) -> f64;
|
||||
fn into_raw(self, store: &mut impl AsStoreMut) -> f64;
|
||||
|
||||
/// Convert to self from raw value representation.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
unsafe fn from_raw(ctx: &mut impl AsStoreMut, raw: f64) -> Self;
|
||||
unsafe fn from_raw(store: &mut impl AsStoreMut, raw: f64) -> Self;
|
||||
}
|
||||
|
||||
impl NativeWasmTypeInto for i32 {
|
||||
#[inline]
|
||||
unsafe fn from_abi(_ctx: &mut impl AsStoreMut, abi: Self::Abi) -> Self {
|
||||
unsafe fn from_abi(_store: &mut impl AsStoreMut, abi: Self::Abi) -> Self {
|
||||
abi
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn into_abi(self, _ctx: &mut impl AsStoreMut) -> Self::Abi {
|
||||
fn into_abi(self, _store: &mut impl AsStoreMut) -> Self::Abi {
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn into_raw(self, _ctx: &mut impl AsStoreMut) -> f64 {
|
||||
fn into_raw(self, _store: &mut impl AsStoreMut) -> f64 {
|
||||
self.into()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn from_raw(_ctx: &mut impl AsStoreMut, raw: f64) -> Self {
|
||||
unsafe fn from_raw(_store: &mut impl AsStoreMut, raw: f64) -> Self {
|
||||
raw as _
|
||||
}
|
||||
}
|
||||
|
||||
impl NativeWasmTypeInto for i64 {
|
||||
#[inline]
|
||||
unsafe fn from_abi(_ctx: &mut impl AsStoreMut, abi: Self::Abi) -> Self {
|
||||
unsafe fn from_abi(_store: &mut impl AsStoreMut, abi: Self::Abi) -> Self {
|
||||
abi
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn into_abi(self, _ctx: &mut impl AsStoreMut) -> Self::Abi {
|
||||
fn into_abi(self, _store: &mut impl AsStoreMut) -> Self::Abi {
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn into_raw(self, _ctx: &mut impl AsStoreMut) -> f64 {
|
||||
fn into_raw(self, _store: &mut impl AsStoreMut) -> f64 {
|
||||
self as _
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn from_raw(_ctx: &mut impl AsStoreMut, raw: f64) -> Self {
|
||||
unsafe fn from_raw(_store: &mut impl AsStoreMut, raw: f64) -> Self {
|
||||
raw as _
|
||||
}
|
||||
}
|
||||
|
||||
impl NativeWasmTypeInto for f32 {
|
||||
#[inline]
|
||||
unsafe fn from_abi(_ctx: &mut impl AsStoreMut, abi: Self::Abi) -> Self {
|
||||
unsafe fn from_abi(_store: &mut impl AsStoreMut, abi: Self::Abi) -> Self {
|
||||
abi
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn into_abi(self, _ctx: &mut impl AsStoreMut) -> Self::Abi {
|
||||
fn into_abi(self, _store: &mut impl AsStoreMut) -> Self::Abi {
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn into_raw(self, _ctx: &mut impl AsStoreMut) -> f64 {
|
||||
fn into_raw(self, _store: &mut impl AsStoreMut) -> f64 {
|
||||
self as _
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn from_raw(_ctx: &mut impl AsStoreMut, raw: f64) -> Self {
|
||||
unsafe fn from_raw(_store: &mut impl AsStoreMut, raw: f64) -> Self {
|
||||
raw as _
|
||||
}
|
||||
}
|
||||
|
||||
impl NativeWasmTypeInto for f64 {
|
||||
#[inline]
|
||||
unsafe fn from_abi(_ctx: &mut impl AsStoreMut, abi: Self::Abi) -> Self {
|
||||
unsafe fn from_abi(_store: &mut impl AsStoreMut, abi: Self::Abi) -> Self {
|
||||
abi
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn into_abi(self, _ctx: &mut impl AsStoreMut) -> Self::Abi {
|
||||
fn into_abi(self, _store: &mut impl AsStoreMut) -> Self::Abi {
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn into_raw(self, _ctx: &mut impl AsStoreMut) -> f64 {
|
||||
fn into_raw(self, _store: &mut impl AsStoreMut) -> f64 {
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn from_raw(_ctx: &mut impl AsStoreMut, raw: f64) -> Self {
|
||||
unsafe fn from_raw(_store: &mut impl AsStoreMut, raw: f64) -> Self {
|
||||
raw
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,25 +138,25 @@ impl<T: ValueType, M: MemorySize> WasmPtr<T, M> {
|
||||
/// Creates a `WasmRef` from this `WasmPtr` which allows reading and
|
||||
/// mutating of the value being pointed to.
|
||||
#[inline]
|
||||
pub fn deref<'a>(self, ctx: &'a impl AsStoreRef, memory: &'a Memory) -> WasmRef<'a, T> {
|
||||
WasmRef::new(ctx, memory, self.offset.into())
|
||||
pub fn deref<'a>(self, store: &'a impl AsStoreRef, memory: &'a Memory) -> WasmRef<'a, T> {
|
||||
WasmRef::new(store, memory, self.offset.into())
|
||||
}
|
||||
|
||||
/// Reads the address pointed to by this `WasmPtr` in a memory.
|
||||
#[inline]
|
||||
pub fn read(self, ctx: &impl AsStoreRef, memory: &Memory) -> Result<T, MemoryAccessError> {
|
||||
self.deref(ctx, memory).read()
|
||||
pub fn read(self, store: &impl AsStoreRef, memory: &Memory) -> Result<T, MemoryAccessError> {
|
||||
self.deref(store, memory).read()
|
||||
}
|
||||
|
||||
/// Writes to the address pointed to by this `WasmPtr` in a memory.
|
||||
#[inline]
|
||||
pub fn write(
|
||||
self,
|
||||
ctx: &impl AsStoreRef,
|
||||
store: &impl AsStoreRef,
|
||||
memory: &Memory,
|
||||
val: T,
|
||||
) -> Result<(), MemoryAccessError> {
|
||||
self.deref(ctx, memory).write(val)
|
||||
self.deref(store, memory).write(val)
|
||||
}
|
||||
|
||||
/// Creates a `WasmSlice` starting at this `WasmPtr` which allows reading
|
||||
@@ -167,11 +167,11 @@ impl<T: ValueType, M: MemorySize> WasmPtr<T, M> {
|
||||
#[inline]
|
||||
pub fn slice<'a>(
|
||||
self,
|
||||
ctx: &'a impl AsStoreRef,
|
||||
store: &'a impl AsStoreRef,
|
||||
memory: &'a Memory,
|
||||
len: M::Offset,
|
||||
) -> Result<WasmSlice<'a, T>, MemoryAccessError> {
|
||||
WasmSlice::new(ctx, memory, self.offset.into(), len.into())
|
||||
WasmSlice::new(store, memory, self.offset.into(), len.into())
|
||||
}
|
||||
|
||||
/// Reads a sequence of values from this `WasmPtr` until a value that
|
||||
@@ -181,14 +181,14 @@ impl<T: ValueType, M: MemorySize> WasmPtr<T, M> {
|
||||
#[inline]
|
||||
pub fn read_until<'a>(
|
||||
self,
|
||||
ctx: &'a impl AsStoreRef,
|
||||
store: &'a impl AsStoreRef,
|
||||
memory: &'a Memory,
|
||||
mut end: impl FnMut(&T) -> bool,
|
||||
) -> Result<Vec<T>, MemoryAccessError> {
|
||||
let mut vec = Vec::new();
|
||||
for i in 0u64.. {
|
||||
let i = M::Offset::try_from(i).map_err(|_| MemoryAccessError::Overflow)?;
|
||||
let val = self.add_offset(i)?.deref(ctx, memory).read()?;
|
||||
let val = self.add_offset(i)?.deref(store, memory).read()?;
|
||||
if end(&val) {
|
||||
break;
|
||||
}
|
||||
@@ -206,11 +206,11 @@ impl<M: MemorySize> WasmPtr<u8, M> {
|
||||
#[inline]
|
||||
pub fn read_utf8_string<'a>(
|
||||
self,
|
||||
ctx: &'a impl AsStoreRef,
|
||||
store: &'a impl AsStoreRef,
|
||||
memory: &'a Memory,
|
||||
len: M::Offset,
|
||||
) -> Result<String, MemoryAccessError> {
|
||||
let vec = self.slice(ctx, memory, len)?.read_to_vec()?;
|
||||
let vec = self.slice(store, memory, len)?.read_to_vec()?;
|
||||
Ok(String::from_utf8(vec)?)
|
||||
}
|
||||
|
||||
@@ -221,10 +221,10 @@ impl<M: MemorySize> WasmPtr<u8, M> {
|
||||
#[inline]
|
||||
pub fn read_utf8_string_with_nul<'a>(
|
||||
self,
|
||||
ctx: &'a impl AsStoreRef,
|
||||
store: &'a impl AsStoreRef,
|
||||
memory: &'a Memory,
|
||||
) -> Result<String, MemoryAccessError> {
|
||||
let vec = self.read_until(ctx, memory, |&byte| byte == 0)?;
|
||||
let vec = self.read_until(store, memory, |&byte| byte == 0)?;
|
||||
Ok(String::from_utf8(vec)?)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,19 +218,19 @@ mod objects {
|
||||
/// Trait to represent an object managed by a context. This is implemented on
|
||||
/// the VM types managed by the context.
|
||||
pub trait StoreObject: Sized {
|
||||
fn list(ctx: &StoreObjects) -> &Vec<Self>;
|
||||
fn list_mut(ctx: &mut StoreObjects) -> &mut Vec<Self>;
|
||||
fn list(store: &StoreObjects) -> &Vec<Self>;
|
||||
fn list_mut(store: &mut StoreObjects) -> &mut Vec<Self>;
|
||||
}
|
||||
|
||||
macro_rules! impl_store_object {
|
||||
($($field:ident => $ty:ty,)*) => {
|
||||
$(
|
||||
impl StoreObject for $ty {
|
||||
fn list(ctx: &StoreObjects) -> &Vec<Self> {
|
||||
&ctx.$field
|
||||
fn list(store: &StoreObjects) -> &Vec<Self> {
|
||||
&store.$field
|
||||
}
|
||||
fn list_mut(ctx: &mut StoreObjects) -> &mut Vec<Self> {
|
||||
&mut ctx.$field
|
||||
fn list_mut(store: &mut StoreObjects) -> &mut Vec<Self> {
|
||||
&mut store.$field
|
||||
}
|
||||
}
|
||||
)*
|
||||
@@ -318,23 +318,23 @@ mod objects {
|
||||
|
||||
impl<T: StoreObject> StoreHandle<T> {
|
||||
/// Moves the given object into a context and returns a handle to it.
|
||||
pub fn new(ctx: &mut StoreObjects, val: T) -> Self {
|
||||
pub fn new(store: &mut StoreObjects, val: T) -> Self {
|
||||
Self {
|
||||
id: ctx.id,
|
||||
internal: InternalStoreHandle::new(ctx, val),
|
||||
id: store.id,
|
||||
internal: InternalStoreHandle::new(store, val),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a reference to the object that this handle points to.
|
||||
pub fn get<'a>(&self, ctx: &'a StoreObjects) -> &'a T {
|
||||
assert_eq!(self.id, ctx.id, "object used with the wrong context");
|
||||
self.internal.get(ctx)
|
||||
pub fn get<'a>(&self, store: &'a StoreObjects) -> &'a T {
|
||||
assert_eq!(self.id, store.id, "object used with the wrong context");
|
||||
self.internal.get(store)
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the object that this handle points to.
|
||||
pub fn get_mut<'a>(&self, ctx: &'a mut StoreObjects) -> &'a mut T {
|
||||
assert_eq!(self.id, ctx.id, "object used with the wrong context");
|
||||
self.internal.get_mut(ctx)
|
||||
pub fn get_mut<'a>(&self, store: &'a mut StoreObjects) -> &'a mut T {
|
||||
assert_eq!(self.id, store.id, "object used with the wrong context");
|
||||
self.internal.get_mut(store)
|
||||
}
|
||||
|
||||
/// Returns the internal handle contains within this handle.
|
||||
@@ -390,8 +390,8 @@ mod objects {
|
||||
|
||||
impl<T: StoreObject> InternalStoreHandle<T> {
|
||||
/// Moves the given object into a context and returns a handle to it.
|
||||
pub fn new(ctx: &mut StoreObjects, val: T) -> Self {
|
||||
let list = T::list_mut(ctx);
|
||||
pub fn new(store: &mut StoreObjects, val: T) -> Self {
|
||||
let list = T::list_mut(store);
|
||||
let idx = NonZeroUsize::new(list.len() + 1).unwrap();
|
||||
list.push(val);
|
||||
Self {
|
||||
@@ -401,13 +401,13 @@ mod objects {
|
||||
}
|
||||
|
||||
/// Returns a reference to the object that this handle points to.
|
||||
pub fn get<'a>(&self, ctx: &'a StoreObjects) -> &'a T {
|
||||
&T::list(ctx)[self.idx.get() - 1]
|
||||
pub fn get<'a>(&self, store: &'a StoreObjects) -> &'a T {
|
||||
&T::list(store)[self.idx.get() - 1]
|
||||
}
|
||||
|
||||
/// Returns a mutable reference to the object that this handle points to.
|
||||
pub fn get_mut<'a>(&self, ctx: &'a mut StoreObjects) -> &'a mut T {
|
||||
&mut T::list_mut(ctx)[self.idx.get() - 1]
|
||||
pub fn get_mut<'a>(&self, store: &'a mut StoreObjects) -> &'a mut T {
|
||||
&mut T::list_mut(store)[self.idx.get() - 1]
|
||||
}
|
||||
|
||||
pub(crate) fn index(&self) -> usize {
|
||||
|
||||
@@ -19,7 +19,7 @@ pub use wasmer_types::{
|
||||
//pub type Value = Value<Function>;
|
||||
|
||||
pub trait AsJs {
|
||||
fn as_jsvalue(&self, ctx: &impl AsStoreRef) -> JsValue;
|
||||
fn as_jsvalue(&self, store: &impl AsStoreRef) -> JsValue;
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -37,7 +37,7 @@ pub fn param_from_js(ty: &ValType, js_val: &JsValue) -> Value {
|
||||
}
|
||||
|
||||
impl AsJs for Value {
|
||||
fn as_jsvalue(&self, ctx: &impl AsStoreRef) -> JsValue {
|
||||
fn as_jsvalue(&self, store: &impl AsStoreRef) -> JsValue {
|
||||
match self {
|
||||
Self::I32(i) => JsValue::from_f64(*i as f64),
|
||||
Self::I64(i) => JsValue::from_f64(*i as f64),
|
||||
@@ -45,7 +45,7 @@ impl AsJs for Value {
|
||||
Self::F64(f) => JsValue::from_f64(*f),
|
||||
Self::FuncRef(Some(func)) => func
|
||||
.handle
|
||||
.get(ctx.as_store_ref().objects())
|
||||
.get(store.as_store_ref().objects())
|
||||
.function
|
||||
.clone()
|
||||
.into(),
|
||||
|
||||
@@ -82,7 +82,7 @@ impl Value {
|
||||
}
|
||||
|
||||
/// Converts the `Value` into a `f64`.
|
||||
pub fn as_raw(&self, ctx: &impl AsStoreRef) -> f64 {
|
||||
pub fn as_raw(&self, store: &impl AsStoreRef) -> f64 {
|
||||
match *self {
|
||||
Self::I32(v) => v as f64,
|
||||
Self::I64(v) => v as f64,
|
||||
@@ -90,7 +90,7 @@ impl Value {
|
||||
Self::F64(v) => v,
|
||||
Self::FuncRef(Some(ref f)) => f
|
||||
.handle
|
||||
.get(ctx.as_store_ref().objects())
|
||||
.get(store.as_store_ref().objects())
|
||||
.function
|
||||
.as_f64()
|
||||
.unwrap_or(0_f64), //TODO is this correct?
|
||||
@@ -105,7 +105,7 @@ impl Value {
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
pub unsafe fn from_raw(_ctx: &impl AsStoreRef, ty: Type, raw: f64) -> Self {
|
||||
pub unsafe fn from_raw(_store: &impl AsStoreRef, ty: Type, raw: f64) -> Self {
|
||||
match ty {
|
||||
Type::I32 => Self::I32(raw as i32),
|
||||
Type::I64 => Self::I64(raw as i64),
|
||||
@@ -116,7 +116,7 @@ impl Value {
|
||||
Type::ExternRef => todo!(),
|
||||
//Self::ExternRef(
|
||||
//{
|
||||
//VMExternRef::from_raw(raw).map(|e| ExternRef::from_vm_externref(ctx, e)),
|
||||
//VMExternRef::from_raw(raw).map(|e| ExternRef::from_vm_externref(store, e)),
|
||||
//),
|
||||
}
|
||||
}
|
||||
@@ -128,7 +128,7 @@ impl Value {
|
||||
///
|
||||
/// Externref and funcref values are tied to a context and can only be used
|
||||
/// with that context.
|
||||
pub fn is_from_store(&self, ctx: &impl AsStoreRef) -> bool {
|
||||
pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool {
|
||||
match self {
|
||||
Self::I32(_)
|
||||
| Self::I64(_)
|
||||
@@ -136,8 +136,8 @@ impl Value {
|
||||
| Self::F64(_)
|
||||
//| Self::ExternRef(None)
|
||||
| Self::FuncRef(None) => true,
|
||||
//Self::ExternRef(Some(e)) => e.is_from_store(ctx),
|
||||
Self::FuncRef(Some(f)) => f.is_from_store(ctx),
|
||||
//Self::ExternRef(Some(e)) => e.is_from_store(store),
|
||||
Self::FuncRef(Some(f)) => f.is_from_store(store),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user