mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-16 17:18:57 +00:00
Remove deprecated Export type. Updated structure to use VMExtern
This commit is contained in:
23
lib/api/src/js/externals/function.rs
vendored
23
lib/api/src/js/externals/function.rs
vendored
@@ -1,9 +1,10 @@
|
|||||||
pub use self::inner::{FromToNativeWasmType, HostFunction, WasmTypeList, WithEnv, WithoutEnv};
|
pub use self::inner::{FromToNativeWasmType, HostFunction, WasmTypeList, WithEnv, WithoutEnv};
|
||||||
use crate::js::exports::{ExportError, Exportable};
|
use crate::js::exports::{ExportError, Exportable};
|
||||||
use crate::js::externals::{Extern, VMExtern};
|
use crate::js::externals::Extern;
|
||||||
use crate::js::function_env::FunctionEnvMut;
|
use crate::js::function_env::FunctionEnvMut;
|
||||||
use crate::js::store::{AsStoreMut, AsStoreRef, StoreMut};
|
use crate::js::store::{AsStoreMut, AsStoreRef, StoreMut};
|
||||||
use crate::js::types::{param_from_js, AsJs}; /* ValFuncRef */
|
use crate::js::types::{param_from_js, AsJs}; /* ValFuncRef */
|
||||||
|
use crate::js::vm::VMExtern;
|
||||||
use crate::js::RuntimeError;
|
use crate::js::RuntimeError;
|
||||||
use crate::js::TypedFunction;
|
use crate::js::TypedFunction;
|
||||||
use crate::js::Value;
|
use crate::js::Value;
|
||||||
@@ -13,7 +14,7 @@ use std::iter::FromIterator;
|
|||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
use wasm_bindgen::JsCast;
|
use wasm_bindgen::JsCast;
|
||||||
|
|
||||||
use crate::js::export::VMFunction;
|
use crate::js::vm::VMFunction;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
@@ -190,7 +191,7 @@ impl Function {
|
|||||||
JSFunction::new_with_args("f", "return f(Array.prototype.slice.call(arguments, 1))");
|
JSFunction::new_with_args("f", "return f(Array.prototype.slice.call(arguments, 1))");
|
||||||
let binded_func = dyn_func.bind1(&JsValue::UNDEFINED, &wrapped_func);
|
let binded_func = dyn_func.bind1(&JsValue::UNDEFINED, &wrapped_func);
|
||||||
let vm_function = VMFunction::new(binded_func, func_ty);
|
let vm_function = VMFunction::new(binded_func, func_ty);
|
||||||
Self::from_vm_export(&mut store, vm_function)
|
Self::from_vm_extern(&mut store, vm_function)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deprecated(
|
#[deprecated(
|
||||||
@@ -214,7 +215,7 @@ impl Function {
|
|||||||
Args: WasmTypeList,
|
Args: WasmTypeList,
|
||||||
Rets: WasmTypeList,
|
Rets: WasmTypeList,
|
||||||
{
|
{
|
||||||
let mut store = store.as_store_mut();
|
let store = store.as_store_mut();
|
||||||
if std::mem::size_of::<F>() != 0 {
|
if std::mem::size_of::<F>() != 0 {
|
||||||
Self::closures_unsupported_panic();
|
Self::closures_unsupported_panic();
|
||||||
}
|
}
|
||||||
@@ -281,7 +282,7 @@ impl Function {
|
|||||||
Args: WasmTypeList,
|
Args: WasmTypeList,
|
||||||
Rets: WasmTypeList,
|
Rets: WasmTypeList,
|
||||||
{
|
{
|
||||||
let mut store = store.as_store_mut();
|
let store = store.as_store_mut();
|
||||||
if std::mem::size_of::<F>() != 0 {
|
if std::mem::size_of::<F>() != 0 {
|
||||||
Self::closures_unsupported_panic();
|
Self::closures_unsupported_panic();
|
||||||
}
|
}
|
||||||
@@ -321,7 +322,7 @@ impl Function {
|
|||||||
/// assert_eq!(f.ty().params(), vec![Type::I32, Type::I32]);
|
/// assert_eq!(f.ty().params(), vec![Type::I32, Type::I32]);
|
||||||
/// assert_eq!(f.ty().results(), vec![Type::I32]);
|
/// assert_eq!(f.ty().results(), vec![Type::I32]);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn ty(&self, store: &impl AsStoreRef) -> FunctionType {
|
pub fn ty(&self, _store: &impl AsStoreRef) -> FunctionType {
|
||||||
self.handle.ty.clone()
|
self.handle.ty.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -465,13 +466,7 @@ impl Function {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from_vm_export(store: &mut impl AsStoreMut, vm_function: VMFunction) -> Self {
|
pub(crate) fn from_vm_extern(_store: &mut impl AsStoreMut, internal: VMFunction) -> Self {
|
||||||
Self {
|
|
||||||
handle: vm_function,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn from_vm_extern(store: &mut impl AsStoreMut, internal: VMFunction) -> Self {
|
|
||||||
Self { handle: internal }
|
Self { handle: internal }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -609,7 +604,7 @@ impl Function {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Checks whether this `Function` can be used with the given context.
|
/// Checks whether this `Function` can be used with the given context.
|
||||||
pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool {
|
pub fn is_from_store(&self, _store: &impl AsStoreRef) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
lib/api/src/js/externals/global.rs
vendored
16
lib/api/src/js/externals/global.rs
vendored
@@ -1,8 +1,8 @@
|
|||||||
use crate::js::export::VMGlobal;
|
|
||||||
use crate::js::exports::{ExportError, Exportable};
|
use crate::js::exports::{ExportError, Exportable};
|
||||||
use crate::js::externals::{Extern, VMExtern};
|
use crate::js::externals::Extern;
|
||||||
use crate::js::store::{AsStoreMut, AsStoreRef};
|
use crate::js::store::{AsStoreMut, AsStoreRef};
|
||||||
use crate::js::value::Value;
|
use crate::js::value::Value;
|
||||||
|
use crate::js::vm::{VMExtern, VMGlobal};
|
||||||
use crate::js::wasm_bindgen_polyfill::Global as JSGlobal;
|
use crate::js::wasm_bindgen_polyfill::Global as JSGlobal;
|
||||||
use crate::js::GlobalType;
|
use crate::js::GlobalType;
|
||||||
use crate::js::Mutability;
|
use crate::js::Mutability;
|
||||||
@@ -95,7 +95,7 @@ impl Global {
|
|||||||
let js_global = JSGlobal::new(&descriptor, &value).unwrap();
|
let js_global = JSGlobal::new(&descriptor, &value).unwrap();
|
||||||
let vm_global = VMGlobal::new(js_global, global_ty);
|
let vm_global = VMGlobal::new(js_global, global_ty);
|
||||||
|
|
||||||
Ok(Self::from_vm_export(store, vm_global))
|
Ok(Self::from_vm_extern(store, vm_global))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the [`GlobalType`] of the `Global`.
|
/// Returns the [`GlobalType`] of the `Global`.
|
||||||
@@ -112,7 +112,7 @@ impl Global {
|
|||||||
/// assert_eq!(c.ty(), &GlobalType::new(Type::I32, Mutability::Const));
|
/// assert_eq!(c.ty(), &GlobalType::new(Type::I32, Mutability::Const));
|
||||||
/// assert_eq!(v.ty(), &GlobalType::new(Type::I64, Mutability::Var));
|
/// assert_eq!(v.ty(), &GlobalType::new(Type::I64, Mutability::Var));
|
||||||
/// ```
|
/// ```
|
||||||
pub fn ty(&self, store: &impl AsStoreRef) -> GlobalType {
|
pub fn ty(&self, _store: &impl AsStoreRef) -> GlobalType {
|
||||||
self.handle.ty
|
self.handle.ty
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,18 +205,14 @@ impl Global {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from_vm_export(store: &mut impl AsStoreMut, vm_global: VMGlobal) -> Self {
|
pub(crate) fn from_vm_extern(store: &mut impl AsStoreMut, vm_global: VMGlobal) -> Self {
|
||||||
use crate::js::store::StoreObject;
|
use crate::js::store::StoreObject;
|
||||||
VMGlobal::list_mut(store.objects_mut()).push(vm_global.clone());
|
VMGlobal::list_mut(store.objects_mut()).push(vm_global.clone());
|
||||||
Self { handle: vm_global }
|
Self { handle: vm_global }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from_vm_extern(store: &mut impl AsStoreMut, internal: VMGlobal) -> Self {
|
|
||||||
Self { handle: internal }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks whether this `Global` can be used with the given store.
|
/// Checks whether this `Global` can be used with the given store.
|
||||||
pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool {
|
pub fn is_from_store(&self, _store: &impl AsStoreRef) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
20
lib/api/src/js/externals/memory.rs
vendored
20
lib/api/src/js/externals/memory.rs
vendored
@@ -1,7 +1,7 @@
|
|||||||
use crate::js::export::VMMemory;
|
|
||||||
use crate::js::exports::{ExportError, Exportable};
|
use crate::js::exports::{ExportError, Exportable};
|
||||||
use crate::js::externals::{Extern, VMExtern};
|
use crate::js::externals::Extern;
|
||||||
use crate::js::store::{AsStoreMut, AsStoreRef, StoreObjects};
|
use crate::js::store::{AsStoreMut, AsStoreRef, StoreObjects};
|
||||||
|
use crate::js::vm::{VMExtern, VMMemory};
|
||||||
use crate::js::{MemoryAccessError, MemoryType};
|
use crate::js::{MemoryAccessError, MemoryType};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::mem::MaybeUninit;
|
use std::mem::MaybeUninit;
|
||||||
@@ -87,7 +87,7 @@ impl Memory {
|
|||||||
/// ```
|
/// ```
|
||||||
pub fn new(store: &mut impl AsStoreMut, ty: MemoryType) -> Result<Self, MemoryError> {
|
pub fn new(store: &mut impl AsStoreMut, ty: MemoryType) -> Result<Self, MemoryError> {
|
||||||
let vm_memory = VMMemory::new(Self::new_internal(ty.clone())?, ty);
|
let vm_memory = VMMemory::new(Self::new_internal(ty.clone())?, ty);
|
||||||
Ok(Self::from_vm_export(store, vm_memory))
|
Ok(Self::from_vm_extern(store, vm_memory))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn new_internal(ty: MemoryType) -> Result<js_sys::WebAssembly::Memory, MemoryError> {
|
pub(crate) fn new_internal(ty: MemoryType) -> Result<js_sys::WebAssembly::Memory, MemoryError> {
|
||||||
@@ -141,7 +141,7 @@ impl Memory {
|
|||||||
///
|
///
|
||||||
/// assert_eq!(m.ty(), mt);
|
/// assert_eq!(m.ty(), mt);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn ty(&self, store: &impl AsStoreRef) -> MemoryType {
|
pub fn ty(&self, _store: &impl AsStoreRef) -> MemoryType {
|
||||||
self.handle.ty
|
self.handle.ty
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,26 +234,22 @@ impl Memory {
|
|||||||
Ok(new_memory)
|
Ok(new_memory)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from_vm_export(store: &mut impl AsStoreMut, vm_memory: VMMemory) -> Self {
|
pub(crate) fn from_vm_extern(_store: &mut impl AsStoreMut, internal: VMMemory) -> Self {
|
||||||
Self { handle: vm_memory }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn from_vm_extern(store: &mut impl AsStoreMut, internal: VMMemory) -> Self {
|
|
||||||
Self { handle: internal }
|
Self { handle: internal }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempts to clone this memory (if its clonable)
|
/// Attempts to clone this memory (if its clonable)
|
||||||
pub fn try_clone(&self, store: &impl AsStoreRef) -> Option<VMMemory> {
|
pub fn try_clone(&self, _store: &impl AsStoreRef) -> Option<VMMemory> {
|
||||||
self.handle.try_clone()
|
self.handle.try_clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks whether this `Global` can be used with the given context.
|
/// Checks whether this `Global` can be used with the given context.
|
||||||
pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool {
|
pub fn is_from_store(&self, _store: &impl AsStoreRef) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Copies this memory to a new memory
|
/// Copies this memory to a new memory
|
||||||
pub fn duplicate(&mut self, store: &impl AsStoreRef) -> Result<VMMemory, MemoryError> {
|
pub fn duplicate(&mut self, _store: &impl AsStoreRef) -> Result<VMMemory, MemoryError> {
|
||||||
self.handle.duplicate()
|
self.handle.duplicate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
lib/api/src/js/externals/memory_view.rs
vendored
2
lib/api/src/js/externals/memory_view.rs
vendored
@@ -26,7 +26,7 @@ pub struct MemoryView<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> MemoryView<'a> {
|
impl<'a> MemoryView<'a> {
|
||||||
pub(crate) fn new(memory: &Memory, store: &impl AsStoreRef) -> Self {
|
pub(crate) fn new(memory: &Memory, _store: &impl AsStoreRef) -> Self {
|
||||||
Self::new_raw(&memory.handle.memory)
|
Self::new_raw(&memory.handle.memory)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
108
lib/api/src/js/externals/mod.rs
vendored
108
lib/api/src/js/externals/mod.rs
vendored
@@ -10,102 +10,13 @@ pub use self::memory::{Memory, MemoryError};
|
|||||||
pub use self::memory_view::MemoryView;
|
pub use self::memory_view::MemoryView;
|
||||||
pub use self::table::Table;
|
pub use self::table::Table;
|
||||||
|
|
||||||
use crate::js::error::WasmError;
|
|
||||||
use crate::js::export::{Export, VMFunction, VMGlobal, VMMemory, VMTable};
|
|
||||||
use crate::js::exports::{ExportError, Exportable};
|
use crate::js::exports::{ExportError, Exportable};
|
||||||
use crate::js::store::StoreObject;
|
|
||||||
use crate::js::store::{AsStoreMut, AsStoreRef};
|
use crate::js::store::{AsStoreMut, AsStoreRef};
|
||||||
use crate::js::types::AsJs;
|
use crate::js::types::AsJs;
|
||||||
use crate::js::wasm_bindgen_polyfill::Global as JsGlobal;
|
use crate::js::vm::VMExtern;
|
||||||
use js_sys::Function as JsFunction;
|
|
||||||
use js_sys::WebAssembly::{Memory as JsMemory, Table as JsTable};
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use wasm_bindgen::{JsCast, JsValue};
|
|
||||||
use wasmer_types::ExternType;
|
use wasmer_types::ExternType;
|
||||||
|
|
||||||
/// The value of an export passed from one instance to another.
|
|
||||||
pub enum VMExtern {
|
|
||||||
/// A function export value.
|
|
||||||
Function(VMFunction),
|
|
||||||
|
|
||||||
/// A table export value.
|
|
||||||
Table(VMTable),
|
|
||||||
|
|
||||||
/// A memory export value.
|
|
||||||
Memory(VMMemory),
|
|
||||||
|
|
||||||
/// A global export value.
|
|
||||||
Global(VMGlobal),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl VMExtern {
|
|
||||||
/// Return the export as a `JSValue`.
|
|
||||||
pub fn as_jsvalue<'context>(&self, store: &'context impl AsStoreRef) -> JsValue {
|
|
||||||
match self {
|
|
||||||
Self::Memory(js_wasm_memory) => js_wasm_memory.memory.clone().into(),
|
|
||||||
Self::Function(js_func) => js_func.function.clone().into(),
|
|
||||||
Self::Table(js_wasm_table) => js_wasm_table.table.clone().into(),
|
|
||||||
Self::Global(js_wasm_global) => js_wasm_global.global.clone().into(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convert a `JsValue` into an `Export` within a given `Context`.
|
|
||||||
pub fn from_js_value(
|
|
||||||
val: JsValue,
|
|
||||||
store: &mut impl AsStoreMut,
|
|
||||||
extern_type: ExternType,
|
|
||||||
) -> Result<Self, WasmError> {
|
|
||||||
match extern_type {
|
|
||||||
ExternType::Memory(memory_type) => {
|
|
||||||
if val.is_instance_of::<JsMemory>() {
|
|
||||||
Ok(Self::Memory(VMMemory::new(
|
|
||||||
val.unchecked_into::<JsMemory>(),
|
|
||||||
memory_type,
|
|
||||||
)))
|
|
||||||
} else {
|
|
||||||
Err(WasmError::TypeMismatch(
|
|
||||||
val.js_typeof()
|
|
||||||
.as_string()
|
|
||||||
.map(Into::into)
|
|
||||||
.unwrap_or("unknown".into()),
|
|
||||||
"Memory".into(),
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ExternType::Global(global_type) => {
|
|
||||||
if val.is_instance_of::<JsGlobal>() {
|
|
||||||
Ok(Self::Global(VMGlobal::new(
|
|
||||||
val.unchecked_into::<JsGlobal>(),
|
|
||||||
global_type,
|
|
||||||
)))
|
|
||||||
} else {
|
|
||||||
panic!("Extern type doesn't match js value type");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ExternType::Function(function_type) => {
|
|
||||||
if val.is_instance_of::<JsFunction>() {
|
|
||||||
Ok(Self::Function(VMFunction::new(
|
|
||||||
val.unchecked_into::<JsFunction>(),
|
|
||||||
function_type,
|
|
||||||
)))
|
|
||||||
} else {
|
|
||||||
panic!("Extern type doesn't match js value type");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ExternType::Table(table_type) => {
|
|
||||||
if val.is_instance_of::<JsTable>() {
|
|
||||||
Ok(Self::Table(VMTable::new(
|
|
||||||
val.unchecked_into::<JsTable>(),
|
|
||||||
table_type,
|
|
||||||
)))
|
|
||||||
} else {
|
|
||||||
panic!("Extern type doesn't match js value type");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An `Extern` is the runtime representation of an entity that
|
/// An `Extern` is the runtime representation of an entity that
|
||||||
/// can be imported or exported.
|
/// can be imported or exported.
|
||||||
///
|
///
|
||||||
@@ -162,24 +73,15 @@ impl Extern {
|
|||||||
Self::Table(val) => val.is_from_store(store),
|
Self::Table(val) => val.is_from_store(store),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_export(&self) -> Export {
|
|
||||||
match self {
|
|
||||||
Self::Function(val) => Export::Function(val.handle.clone()),
|
|
||||||
Self::Memory(val) => Export::Memory(val.handle.clone()),
|
|
||||||
Self::Global(val) => Export::Global(val.handle.clone()),
|
|
||||||
Self::Table(val) => Export::Table(val.handle.clone()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsJs for Extern {
|
impl AsJs for Extern {
|
||||||
fn as_jsvalue(&self, store: &impl AsStoreRef) -> wasm_bindgen::JsValue {
|
fn as_jsvalue(&self, store: &impl AsStoreRef) -> wasm_bindgen::JsValue {
|
||||||
match self {
|
match self {
|
||||||
Self::Function(_) => self.to_export().as_jsvalue(store),
|
Self::Function(_) => self.to_vm_extern().as_jsvalue(store),
|
||||||
Self::Global(_) => self.to_export().as_jsvalue(store),
|
Self::Global(_) => self.to_vm_extern().as_jsvalue(store),
|
||||||
Self::Table(_) => self.to_export().as_jsvalue(store),
|
Self::Table(_) => self.to_vm_extern().as_jsvalue(store),
|
||||||
Self::Memory(_) => self.to_export().as_jsvalue(store),
|
Self::Memory(_) => self.to_vm_extern().as_jsvalue(store),
|
||||||
}
|
}
|
||||||
.clone()
|
.clone()
|
||||||
}
|
}
|
||||||
|
|||||||
16
lib/api/src/js/externals/table.rs
vendored
16
lib/api/src/js/externals/table.rs
vendored
@@ -1,8 +1,8 @@
|
|||||||
use crate::js::export::{VMFunction, VMTable};
|
|
||||||
use crate::js::exports::{ExportError, Exportable};
|
use crate::js::exports::{ExportError, Exportable};
|
||||||
use crate::js::externals::{Extern, VMExtern};
|
use crate::js::externals::Extern;
|
||||||
use crate::js::store::{AsStoreMut, AsStoreRef};
|
use crate::js::store::{AsStoreMut, AsStoreRef};
|
||||||
use crate::js::value::Value;
|
use crate::js::value::Value;
|
||||||
|
use crate::js::vm::{VMExtern, VMFunction, VMTable};
|
||||||
use crate::js::RuntimeError;
|
use crate::js::RuntimeError;
|
||||||
use crate::js::{FunctionType, TableType};
|
use crate::js::{FunctionType, TableType};
|
||||||
use js_sys::Function;
|
use js_sys::Function;
|
||||||
@@ -74,7 +74,7 @@ impl Table {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the [`TableType`] of the `Table`.
|
/// Returns the [`TableType`] of the `Table`.
|
||||||
pub fn ty(&self, store: &impl AsStoreRef) -> TableType {
|
pub fn ty(&self, _store: &impl AsStoreRef) -> TableType {
|
||||||
self.handle.ty
|
self.handle.ty
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +83,7 @@ impl Table {
|
|||||||
if let Some(func) = self.handle.table.get(index).ok() {
|
if let Some(func) = self.handle.table.get(index).ok() {
|
||||||
let ty = FunctionType::new(vec![], vec![]);
|
let ty = FunctionType::new(vec![], vec![]);
|
||||||
let vm_function = VMFunction::new(func, ty);
|
let vm_function = VMFunction::new(func, ty);
|
||||||
let function = crate::js::externals::Function::from_vm_export(store, vm_function);
|
let function = crate::js::externals::Function::from_vm_extern(store, vm_function);
|
||||||
Some(Value::FuncRef(Some(function)))
|
Some(Value::FuncRef(Some(function)))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@@ -102,7 +102,7 @@ impl Table {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves the size of the `Table` (in elements)
|
/// Retrieves the size of the `Table` (in elements)
|
||||||
pub fn size(&self, store: &impl AsStoreRef) -> u32 {
|
pub fn size(&self, _store: &impl AsStoreRef) -> u32 {
|
||||||
self.handle.table.length()
|
self.handle.table.length()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,12 +142,12 @@ impl Table {
|
|||||||
unimplemented!("Table.copy is not natively supported in Javascript");
|
unimplemented!("Table.copy is not natively supported in Javascript");
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from_vm_extern(store: &mut impl AsStoreMut, internal: VMTable) -> Self {
|
pub(crate) fn from_vm_extern(_store: &mut impl AsStoreMut, internal: VMTable) -> Self {
|
||||||
Self { handle: internal }
|
Self { handle: internal }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks whether this `Table` can be used with the given context.
|
/// Checks whether this `Table` can be used with the given context.
|
||||||
pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool {
|
pub fn is_from_store(&self, _store: &impl AsStoreRef) -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,7 +161,7 @@ impl Table {
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub unsafe fn get_vm_table<'context>(
|
pub unsafe fn get_vm_table<'context>(
|
||||||
&'context self,
|
&'context self,
|
||||||
store: &'context impl AsStoreRef,
|
_store: &'context impl AsStoreRef,
|
||||||
) -> &'context VMTable {
|
) -> &'context VMTable {
|
||||||
&self.handle
|
&self.handle
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use crate::js::exports::Exports;
|
|||||||
use crate::js::module::Module;
|
use crate::js::module::Module;
|
||||||
use crate::js::store::{AsStoreMut, AsStoreRef};
|
use crate::js::store::{AsStoreMut, AsStoreRef};
|
||||||
use crate::js::types::AsJs;
|
use crate::js::types::AsJs;
|
||||||
|
use crate::js::vm::VMExtern;
|
||||||
use crate::js::ExternType;
|
use crate::js::ExternType;
|
||||||
use crate::Extern;
|
use crate::Extern;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@@ -206,7 +207,6 @@ impl Imports {
|
|||||||
module: &Module,
|
module: &Module,
|
||||||
object: js_sys::Object,
|
object: js_sys::Object,
|
||||||
) -> Result<Self, WasmError> {
|
) -> Result<Self, WasmError> {
|
||||||
use crate::js::externals::VMExtern;
|
|
||||||
let module_imports: HashMap<(String, String), ExternType> = module
|
let module_imports: HashMap<(String, String), ExternType> = module
|
||||||
.imports()
|
.imports()
|
||||||
.map(|import| {
|
.map(|import| {
|
||||||
@@ -457,162 +457,4 @@ mod test {
|
|||||||
assert!(happy.is_some());
|
assert!(happy.is_some());
|
||||||
assert!(small.is_some());
|
assert!(small.is_some());
|
||||||
}
|
}
|
||||||
// fn namespace() {
|
|
||||||
// let mut store = Store::default();
|
|
||||||
// let g1 = Global::new(&store, Val::I32(0));
|
|
||||||
// let namespace = namespace! {
|
|
||||||
// "happy" => g1
|
|
||||||
// };
|
|
||||||
// let imports1 = imports! {
|
|
||||||
// "dog" => namespace
|
|
||||||
// };
|
|
||||||
|
|
||||||
// let happy_dog_entry = imports1.get_export("dog", "happy").unwrap();
|
|
||||||
|
|
||||||
// assert!(
|
|
||||||
// if let Export::Global(happy_dog_global) = happy_dog_entry.to_export() {
|
|
||||||
// happy_dog_global.ty.ty == Type::I32
|
|
||||||
// } else {
|
|
||||||
// false
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn imports_macro_allows_trailing_comma_and_none() {
|
|
||||||
// use crate::js::Function;
|
|
||||||
|
|
||||||
// let mut store = Default::default();
|
|
||||||
|
|
||||||
// fn func(arg: i32) -> i32 {
|
|
||||||
// arg + 1
|
|
||||||
// }
|
|
||||||
|
|
||||||
// let _ = imports! {
|
|
||||||
// "env" => {
|
|
||||||
// "func" => Function::new_typed(&store, func),
|
|
||||||
// },
|
|
||||||
// };
|
|
||||||
// let _ = imports! {
|
|
||||||
// "env" => {
|
|
||||||
// "func" => Function::new_typed(&store, func),
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// let _ = imports! {
|
|
||||||
// "env" => {
|
|
||||||
// "func" => Function::new_typed(&store, func),
|
|
||||||
// },
|
|
||||||
// "abc" => {
|
|
||||||
// "def" => Function::new_typed(&store, func),
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// let _ = imports! {
|
|
||||||
// "env" => {
|
|
||||||
// "func" => Function::new_typed(&store, func)
|
|
||||||
// },
|
|
||||||
// };
|
|
||||||
// let _ = imports! {
|
|
||||||
// "env" => {
|
|
||||||
// "func" => Function::new_typed(&store, func)
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// let _ = imports! {
|
|
||||||
// "env" => {
|
|
||||||
// "func1" => Function::new_typed(&store, func),
|
|
||||||
// "func2" => Function::new_typed(&store, func)
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// let _ = imports! {
|
|
||||||
// "env" => {
|
|
||||||
// "func1" => Function::new_typed(&store, func),
|
|
||||||
// "func2" => Function::new_typed(&store, func),
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn chaining_works() {
|
|
||||||
// let mut store = Store::default();
|
|
||||||
// let g = Global::new(&store, Val::I32(0));
|
|
||||||
|
|
||||||
// let mut imports1 = imports! {
|
|
||||||
// "dog" => {
|
|
||||||
// "happy" => g.clone()
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
// let imports2 = imports! {
|
|
||||||
// "dog" => {
|
|
||||||
// "small" => g.clone()
|
|
||||||
// },
|
|
||||||
// "cat" => {
|
|
||||||
// "small" => g.clone()
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
// imports1.extend(&imports2);
|
|
||||||
|
|
||||||
// let small_cat_export = imports1.get_export("cat", "small");
|
|
||||||
// assert!(small_cat_export.is_some());
|
|
||||||
|
|
||||||
// let happy = imports1.get_export("dog", "happy");
|
|
||||||
// let small = imports1.get_export("dog", "small");
|
|
||||||
// assert!(happy.is_some());
|
|
||||||
// assert!(small.is_some());
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fn extending_conflict_overwrites() {
|
|
||||||
// let mut store = Store::default();
|
|
||||||
// let g1 = Global::new(&store, Val::I32(0));
|
|
||||||
// let g2 = Global::new(&store, Val::F32(0.));
|
|
||||||
|
|
||||||
// let mut imports1 = imports! {
|
|
||||||
// "dog" => {
|
|
||||||
// "happy" => g1,
|
|
||||||
// },
|
|
||||||
// };
|
|
||||||
|
|
||||||
// let imports2 = imports! {
|
|
||||||
// "dog" => {
|
|
||||||
// "happy" => g2,
|
|
||||||
// },
|
|
||||||
// };
|
|
||||||
|
|
||||||
// imports1.extend(&imports2);
|
|
||||||
// let happy_dog_entry = imports1.get_export("dog", "happy").unwrap();
|
|
||||||
|
|
||||||
// assert!(
|
|
||||||
// if let Export::Global(happy_dog_global) = happy_dog_entry.to_export() {
|
|
||||||
// happy_dog_global.ty.ty == Type::F32
|
|
||||||
// } else {
|
|
||||||
// false
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
|
|
||||||
// // now test it in reverse
|
|
||||||
// let mut store = Store::default();
|
|
||||||
// let g1 = Global::new(&store, Val::I32(0));
|
|
||||||
// let g2 = Global::new(&store, Val::F32(0.));
|
|
||||||
|
|
||||||
// let imports1 = imports! {
|
|
||||||
// "dog" => {
|
|
||||||
// "happy" => g1,
|
|
||||||
// },
|
|
||||||
// };
|
|
||||||
|
|
||||||
// let mut imports2 = imports! {
|
|
||||||
// "dog" => {
|
|
||||||
// "happy" => g2,
|
|
||||||
// },
|
|
||||||
// };
|
|
||||||
|
|
||||||
// imports2.extend(&imports1);
|
|
||||||
// let happy_dog_entry = imports2.get_export("dog", "happy").unwrap();
|
|
||||||
|
|
||||||
// assert!(
|
|
||||||
// if let Export::Global(happy_dog_global) = happy_dog_entry.to_export() {
|
|
||||||
// happy_dog_global.ty.ty == Type::I32
|
|
||||||
// } else {
|
|
||||||
// false
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use crate::js::externals::Extern;
|
|||||||
use crate::js::imports::Imports;
|
use crate::js::imports::Imports;
|
||||||
use crate::js::module::Module;
|
use crate::js::module::Module;
|
||||||
use crate::js::store::{AsStoreMut, AsStoreRef};
|
use crate::js::store::{AsStoreMut, AsStoreRef};
|
||||||
|
use crate::js::vm::VMExtern;
|
||||||
use js_sys::WebAssembly;
|
use js_sys::WebAssembly;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
@@ -68,7 +69,6 @@ impl Instance {
|
|||||||
|
|
||||||
let mut self_instance = Self::from_module_and_instance(store, module, instance)?;
|
let mut self_instance = Self::from_module_and_instance(store, module, instance)?;
|
||||||
self_instance.ensure_memory_export(store, externs);
|
self_instance.ensure_memory_export(store, externs);
|
||||||
//self_instance.init_envs(&imports.iter().map(Extern::to_export).collect::<Vec<_>>())?;
|
|
||||||
Ok(self_instance)
|
Ok(self_instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,8 +108,6 @@ impl Instance {
|
|||||||
module: &Module,
|
module: &Module,
|
||||||
instance: WebAssembly::Instance,
|
instance: WebAssembly::Instance,
|
||||||
) -> Result<Self, InstantiationError> {
|
) -> Result<Self, InstantiationError> {
|
||||||
use crate::js::externals::VMExtern;
|
|
||||||
|
|
||||||
let instance_exports = instance.exports();
|
let instance_exports = instance.exports();
|
||||||
|
|
||||||
let exports = module
|
let exports = module
|
||||||
@@ -140,6 +138,7 @@ impl Instance {
|
|||||||
/// This will check the memory is correctly setup
|
/// This will check the memory is correctly setup
|
||||||
/// If the memory is imported then also export it for backwards compatibility reasons
|
/// If the memory is imported then also export it for backwards compatibility reasons
|
||||||
/// (many will assume the memory is always exported) - later we can remove this
|
/// (many will assume the memory is always exported) - later we can remove this
|
||||||
|
/// TODO: This is trialing from WASIX, we should remove this or move it to the wasmer-wasi crate
|
||||||
pub fn ensure_memory_export(&mut self, store: &mut impl AsStoreMut, externs: Vec<Extern>) {
|
pub fn ensure_memory_export(&mut self, store: &mut impl AsStoreMut, externs: Vec<Extern>) {
|
||||||
if self.exports.get_memory("memory").is_err() {
|
if self.exports.get_memory("memory").is_err() {
|
||||||
if let Some(memory) = externs
|
if let Some(memory) = externs
|
||||||
@@ -161,7 +160,7 @@ impl Instance {
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn raw<'context>(
|
pub fn raw<'context>(
|
||||||
&'context self,
|
&'context self,
|
||||||
store: &'context impl AsStoreRef,
|
_store: &'context impl AsStoreRef,
|
||||||
) -> &'context WebAssembly::Instance {
|
) -> &'context WebAssembly::Instance {
|
||||||
&self.handle
|
&self.handle
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ mod lib {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) mod error;
|
pub(crate) mod error;
|
||||||
mod export;
|
|
||||||
mod exports;
|
mod exports;
|
||||||
mod externals;
|
mod externals;
|
||||||
mod function_env;
|
mod function_env;
|
||||||
@@ -41,10 +40,10 @@ mod store;
|
|||||||
mod trap;
|
mod trap;
|
||||||
mod types;
|
mod types;
|
||||||
mod value;
|
mod value;
|
||||||
|
mod vm;
|
||||||
mod wasm_bindgen_polyfill;
|
mod wasm_bindgen_polyfill;
|
||||||
|
|
||||||
pub use crate::js::error::{DeserializeError, InstantiationError, SerializeError};
|
pub use crate::js::error::{DeserializeError, InstantiationError, SerializeError};
|
||||||
pub use crate::js::export::Export;
|
|
||||||
pub use crate::js::exports::{ExportError, Exportable, Exports, ExportsIterator};
|
pub use crate::js::exports::{ExportError, Exportable, Exports, ExportsIterator};
|
||||||
pub use crate::js::externals::{
|
pub use crate::js::externals::{
|
||||||
Extern, FromToNativeWasmType, Function, Global, HostFunction, Memory, MemoryError, MemoryView,
|
Extern, FromToNativeWasmType, Function, Global, HostFunction, Memory, MemoryError, MemoryView,
|
||||||
@@ -71,11 +70,6 @@ pub use crate::js::types::{
|
|||||||
pub use crate::js::value::Value;
|
pub use crate::js::value::Value;
|
||||||
pub use crate::js::value::Value as Val;
|
pub use crate::js::value::Value as Val;
|
||||||
|
|
||||||
pub mod vm {
|
|
||||||
//! The `vm` module re-exports wasmer-vm types.
|
|
||||||
pub use crate::js::export::VMMemory;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub use wasmer_types::is_wasm;
|
pub use wasmer_types::is_wasm;
|
||||||
// TODO: OnCalledAction is needed for asyncify. It will be refactored with https://github.com/wasmerio/wasmer/issues/3451
|
// TODO: OnCalledAction is needed for asyncify. It will be refactored with https://github.com/wasmerio/wasmer/issues/3451
|
||||||
pub use wasmer_types::{
|
pub use wasmer_types::{
|
||||||
|
|||||||
@@ -645,7 +645,7 @@ impl Module {
|
|||||||
pub fn custom_sections<'a>(&'a self, name: &'a str) -> impl Iterator<Item = Box<[u8]>> + 'a {
|
pub fn custom_sections<'a>(&'a self, name: &'a str) -> impl Iterator<Item = Box<[u8]>> + 'a {
|
||||||
WebAssembly::Module::custom_sections(&self.module, name)
|
WebAssembly::Module::custom_sections(&self.module, name)
|
||||||
.iter()
|
.iter()
|
||||||
.map(move |(buf_val)| {
|
.map(move |buf_val| {
|
||||||
let typebuf: js_sys::Uint8Array = js_sys::Uint8Array::new(&buf_val);
|
let typebuf: js_sys::Uint8Array = js_sys::Uint8Array::new(&buf_val);
|
||||||
typebuf.to_vec().into_boxed_slice()
|
typebuf.to_vec().into_boxed_slice()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ use crate::js::externals::Function;
|
|||||||
use crate::js::store::{AsStoreMut, AsStoreRef};
|
use crate::js::store::{AsStoreMut, AsStoreRef};
|
||||||
use crate::js::{FromToNativeWasmType, RuntimeError, WasmTypeList};
|
use crate::js::{FromToNativeWasmType, RuntimeError, WasmTypeList};
|
||||||
// use std::panic::{catch_unwind, AssertUnwindSafe};
|
// use std::panic::{catch_unwind, AssertUnwindSafe};
|
||||||
use crate::js::export::VMFunction;
|
|
||||||
use crate::js::types::param_from_js;
|
use crate::js::types::param_from_js;
|
||||||
use crate::js::types::AsJs;
|
use crate::js::types::AsJs;
|
||||||
|
use crate::js::vm::VMFunction;
|
||||||
use js_sys::Array;
|
use js_sys::Array;
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
use wasm_bindgen::JsValue;
|
use wasm_bindgen::JsValue;
|
||||||
@@ -38,7 +38,7 @@ where
|
|||||||
Rets: WasmTypeList,
|
Rets: WasmTypeList,
|
||||||
{
|
{
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) fn new<T>(store: &mut impl AsStoreMut, vm_function: VMFunction) -> Self {
|
pub(crate) fn new<T>(_store: &mut impl AsStoreMut, vm_function: VMFunction) -> Self {
|
||||||
Self {
|
Self {
|
||||||
handle: vm_function,
|
handle: vm_function,
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
|
|||||||
@@ -205,16 +205,11 @@ pub use objects::{StoreHandle, StoreId, StoreObjects};
|
|||||||
mod objects {
|
mod objects {
|
||||||
use wasm_bindgen::JsValue;
|
use wasm_bindgen::JsValue;
|
||||||
|
|
||||||
use crate::js::{
|
use crate::js::{function_env::VMFunctionEnvironment, vm::VMGlobal};
|
||||||
export::{VMFunction, VMGlobal, VMMemory, VMTable},
|
|
||||||
function_env::VMFunctionEnvironment,
|
|
||||||
};
|
|
||||||
use std::{
|
use std::{
|
||||||
cell::UnsafeCell,
|
|
||||||
fmt,
|
fmt,
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
num::{NonZeroU64, NonZeroUsize},
|
num::{NonZeroU64, NonZeroUsize},
|
||||||
ptr::NonNull,
|
|
||||||
sync::atomic::{AtomicU64, Ordering},
|
sync::atomic::{AtomicU64, Ordering},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ pub fn param_from_js(ty: &ValType, js_val: &JsValue) -> Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AsJs for Value {
|
impl AsJs for Value {
|
||||||
fn as_jsvalue(&self, store: &impl AsStoreRef) -> JsValue {
|
fn as_jsvalue(&self, _store: &impl AsStoreRef) -> JsValue {
|
||||||
match self {
|
match self {
|
||||||
Self::I32(i) => JsValue::from_f64(*i as f64),
|
Self::I32(i) => JsValue::from_f64(*i as f64),
|
||||||
Self::I64(i) => JsValue::from_f64(*i as f64),
|
Self::I64(i) => JsValue::from_f64(*i as f64),
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ impl Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Converts the `Value` into a `f64`.
|
/// Converts the `Value` into a `f64`.
|
||||||
pub fn as_raw(&self, store: &impl AsStoreRef) -> f64 {
|
pub fn as_raw(&self, _store: &impl AsStoreRef) -> f64 {
|
||||||
match *self {
|
match *self {
|
||||||
Self::I32(v) => v as f64,
|
Self::I32(v) => v as f64,
|
||||||
Self::I64(v) => v as f64,
|
Self::I64(v) => v as f64,
|
||||||
|
|||||||
@@ -1,9 +1,18 @@
|
|||||||
|
/// This module is mainly used to create the `VM` types that will hold both
|
||||||
|
/// the JS values of the `Memory`, `Table`, `Global` and `Function` and also
|
||||||
|
/// it's types.
|
||||||
|
/// This module should not be needed any longer (with the exception of the memory)
|
||||||
|
/// once the type reflection is added to the WebAssembly JS API.
|
||||||
|
/// https://github.com/WebAssembly/js-types/
|
||||||
use crate::js::error::WasmError;
|
use crate::js::error::WasmError;
|
||||||
use crate::js::store::{AsStoreMut, AsStoreRef};
|
use crate::js::store::{AsStoreMut, AsStoreRef};
|
||||||
use crate::js::wasm_bindgen_polyfill::Global;
|
use crate::js::wasm_bindgen_polyfill::Global;
|
||||||
|
use crate::js::wasm_bindgen_polyfill::Global as JsGlobal;
|
||||||
use crate::MemoryView;
|
use crate::MemoryView;
|
||||||
use js_sys::Function;
|
use js_sys::Function;
|
||||||
|
use js_sys::Function as JsFunction;
|
||||||
use js_sys::WebAssembly::{Memory, Table};
|
use js_sys::WebAssembly::{Memory, Table};
|
||||||
|
use js_sys::WebAssembly::{Memory as JsMemory, Table as JsTable};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
@@ -162,8 +171,7 @@ impl fmt::Debug for VMFunction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The value of an export passed from one instance to another.
|
/// The value of an export passed from one instance to another.
|
||||||
#[derive(Debug, Clone)]
|
pub enum VMExtern {
|
||||||
pub enum Export {
|
|
||||||
/// A function export value.
|
/// A function export value.
|
||||||
Function(VMFunction),
|
Function(VMFunction),
|
||||||
|
|
||||||
@@ -177,9 +185,9 @@ pub enum Export {
|
|||||||
Global(VMGlobal),
|
Global(VMGlobal),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Export {
|
impl VMExtern {
|
||||||
/// Return the export as a `JSValue`.
|
/// Return the export as a `JSValue`.
|
||||||
pub fn as_jsvalue(&self, _store: &impl AsStoreRef) -> JsValue {
|
pub fn as_jsvalue<'context>(&self, _store: &'context impl AsStoreRef) -> JsValue {
|
||||||
match self {
|
match self {
|
||||||
Self::Memory(js_wasm_memory) => js_wasm_memory.memory.clone().into(),
|
Self::Memory(js_wasm_memory) => js_wasm_memory.memory.clone().into(),
|
||||||
Self::Function(js_func) => js_func.function.clone().into(),
|
Self::Function(js_func) => js_func.function.clone().into(),
|
||||||
@@ -191,14 +199,14 @@ impl Export {
|
|||||||
/// Convert a `JsValue` into an `Export` within a given `Context`.
|
/// Convert a `JsValue` into an `Export` within a given `Context`.
|
||||||
pub fn from_js_value(
|
pub fn from_js_value(
|
||||||
val: JsValue,
|
val: JsValue,
|
||||||
store: &mut impl AsStoreMut,
|
_store: &mut impl AsStoreMut,
|
||||||
extern_type: ExternType,
|
extern_type: ExternType,
|
||||||
) -> Result<Self, WasmError> {
|
) -> Result<Self, WasmError> {
|
||||||
match extern_type {
|
match extern_type {
|
||||||
ExternType::Memory(memory_type) => {
|
ExternType::Memory(memory_type) => {
|
||||||
if val.is_instance_of::<Memory>() {
|
if val.is_instance_of::<JsMemory>() {
|
||||||
Ok(Self::Memory(VMMemory::new(
|
Ok(Self::Memory(VMMemory::new(
|
||||||
val.unchecked_into::<Memory>(),
|
val.unchecked_into::<JsMemory>(),
|
||||||
memory_type,
|
memory_type,
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
@@ -212,9 +220,9 @@ impl Export {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ExternType::Global(global_type) => {
|
ExternType::Global(global_type) => {
|
||||||
if val.is_instance_of::<Global>() {
|
if val.is_instance_of::<JsGlobal>() {
|
||||||
Ok(Self::Global(VMGlobal::new(
|
Ok(Self::Global(VMGlobal::new(
|
||||||
val.unchecked_into::<Global>(),
|
val.unchecked_into::<JsGlobal>(),
|
||||||
global_type,
|
global_type,
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
@@ -222,9 +230,9 @@ impl Export {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ExternType::Function(function_type) => {
|
ExternType::Function(function_type) => {
|
||||||
if val.is_instance_of::<Function>() {
|
if val.is_instance_of::<JsFunction>() {
|
||||||
Ok(Self::Function(VMFunction::new(
|
Ok(Self::Function(VMFunction::new(
|
||||||
val.unchecked_into::<Function>(),
|
val.unchecked_into::<JsFunction>(),
|
||||||
function_type,
|
function_type,
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
@@ -232,9 +240,9 @@ impl Export {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ExternType::Table(table_type) => {
|
ExternType::Table(table_type) => {
|
||||||
if val.is_instance_of::<Table>() {
|
if val.is_instance_of::<JsTable>() {
|
||||||
Ok(Self::Table(VMTable::new(
|
Ok(Self::Table(VMTable::new(
|
||||||
val.unchecked_into::<Table>(),
|
val.unchecked_into::<JsTable>(),
|
||||||
table_type,
|
table_type,
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
Reference in New Issue
Block a user