mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-13 05:48:45 +00:00
make test-js passes
This commit is contained in:
2
lib/api/src/js/externals/global.rs
vendored
2
lib/api/src/js/externals/global.rs
vendored
@@ -128,7 +128,7 @@ impl Global {
|
|||||||
///
|
///
|
||||||
/// assert_eq!(g.get(), Value::I32(1));
|
/// assert_eq!(g.get(), Value::I32(1));
|
||||||
/// ```
|
/// ```
|
||||||
pub fn get(&self, store: &mut impl AsStoreMut) -> Value {
|
pub fn get(&self, store: &impl AsStoreRef) -> Value {
|
||||||
unsafe {
|
unsafe {
|
||||||
let raw = self
|
let raw = self
|
||||||
.handle
|
.handle
|
||||||
|
|||||||
35
lib/api/src/js/externals/mod.rs
vendored
35
lib/api/src/js/externals/mod.rs
vendored
@@ -12,14 +12,25 @@ pub use self::table::Table;
|
|||||||
|
|
||||||
use crate::js::export::{Export, VMFunction, VMGlobal, VMMemory, VMTable};
|
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::InternalStoreHandle;
|
|
||||||
use crate::js::store::StoreObject;
|
|
||||||
use crate::js::store::{AsStoreMut, AsStoreRef};
|
|
||||||
use crate::js::types::AsJs;
|
use crate::js::types::AsJs;
|
||||||
|
use crate::js::store::StoreObject;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
use crate::js::store::InternalStoreHandle;
|
||||||
|
use crate::js::store::{AsStoreMut, AsStoreRef};
|
||||||
use crate::js::ExternType;
|
use crate::js::ExternType;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use wasm_bindgen::{JsValue, JsCast};
|
*/
|
||||||
use crate::js::error::WasmError;
|
use crate::js::error::WasmError;
|
||||||
|
use crate::js::store::{AsStoreMut, AsStoreRef, InternalStoreHandle};
|
||||||
|
use crate::js::wasm_bindgen_polyfill::Global as JsGlobal;
|
||||||
|
use js_sys::Function as JsFunction;
|
||||||
|
use js_sys::WebAssembly::{Memory as JsMemory, Table as JsTable};
|
||||||
|
use std::fmt;
|
||||||
|
use wasm_bindgen::{JsCast, JsValue};
|
||||||
|
use wasmer_types::{ExternType, FunctionType, GlobalType, MemoryType, TableType};
|
||||||
|
|
||||||
/// The value of an export passed from one instance to another.
|
/// The value of an export passed from one instance to another.
|
||||||
pub enum VMExtern {
|
pub enum VMExtern {
|
||||||
@@ -67,10 +78,10 @@ impl VMExtern {
|
|||||||
) -> 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(InternalStoreHandle::new(
|
Ok(Self::Memory(InternalStoreHandle::new(
|
||||||
&mut store.objects_mut(),
|
&mut store.objects_mut(),
|
||||||
VMMemory::new(val.unchecked_into::<Memory>(), memory_type),
|
VMMemory::new(val.unchecked_into::<JsMemory>(), memory_type),
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
Err(WasmError::TypeMismatch(
|
Err(WasmError::TypeMismatch(
|
||||||
@@ -83,30 +94,30 @@ impl VMExtern {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ExternType::Global(global_type) => {
|
ExternType::Global(global_type) => {
|
||||||
if val.is_instance_of::<Global>() {
|
if val.is_instance_of::<JsGlobal>() {
|
||||||
Ok(Self::Global(InternalStoreHandle::new(
|
Ok(Self::Global(InternalStoreHandle::new(
|
||||||
&mut store.objects_mut(),
|
&mut store.objects_mut(),
|
||||||
VMGlobal::new(val.unchecked_into::<Global>(), global_type),
|
VMGlobal::new(val.unchecked_into::<JsGlobal>(), global_type),
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
panic!("Extern type doesn't match js value type");
|
panic!("Extern type doesn't match js value type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ExternType::Function(function_type) => {
|
ExternType::Function(function_type) => {
|
||||||
if val.is_instance_of::<Function>() {
|
if val.is_instance_of::<JsFunction>() {
|
||||||
Ok(Self::Function(InternalStoreHandle::new(
|
Ok(Self::Function(InternalStoreHandle::new(
|
||||||
&mut store.objects_mut(),
|
&mut store.objects_mut(),
|
||||||
VMFunction::new(val.unchecked_into::<Function>(), function_type),
|
VMFunction::new(val.unchecked_into::<JsFunction>(), function_type),
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
panic!("Extern type doesn't match js value type");
|
panic!("Extern type doesn't match js value type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ExternType::Table(table_type) => {
|
ExternType::Table(table_type) => {
|
||||||
if val.is_instance_of::<Table>() {
|
if val.is_instance_of::<JsTable>() {
|
||||||
Ok(Self::Table(InternalStoreHandle::new(
|
Ok(Self::Table(InternalStoreHandle::new(
|
||||||
&mut store.objects_mut(),
|
&mut store.objects_mut(),
|
||||||
VMTable::new(val.unchecked_into::<Table>(), table_type),
|
VMTable::new(val.unchecked_into::<JsTable>(), table_type),
|
||||||
)))
|
)))
|
||||||
} else {
|
} else {
|
||||||
panic!("Extern type doesn't match js value type");
|
panic!("Extern type doesn't match js value type");
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ impl AsJs for Value {
|
|||||||
Self::I64(i) => JsValue::from_f64(*i as f64),
|
Self::I64(i) => JsValue::from_f64(*i as f64),
|
||||||
Self::F32(f) => JsValue::from_f64(*f as f64),
|
Self::F32(f) => JsValue::from_f64(*f as f64),
|
||||||
Self::F64(f) => JsValue::from_f64(*f),
|
Self::F64(f) => JsValue::from_f64(*f),
|
||||||
|
Self::V128(f) => JsValue::from_f64(*f as f64),
|
||||||
Self::FuncRef(Some(func)) => func
|
Self::FuncRef(Some(func)) => func
|
||||||
.handle
|
.handle
|
||||||
.get(store.as_store_ref().objects())
|
.get(store.as_store_ref().objects())
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ impl Value {
|
|||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
pub unsafe fn from_raw(store: &mut impl AsStoreMut, ty: Type, raw: f64) -> Self {
|
pub unsafe fn from_raw(_store: &impl AsStoreRef, ty: Type, raw: f64) -> Self {
|
||||||
match ty {
|
match ty {
|
||||||
Type::I32 => Self::I32(raw as _),
|
Type::I32 => Self::I32(raw as _),
|
||||||
Type::I64 => Self::I64(raw as _),
|
Type::I64 => Self::I64(raw as _),
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ mod js {
|
|||||||
fn global_get() {
|
fn global_get() {
|
||||||
let mut store = Store::default();
|
let mut store = Store::default();
|
||||||
let global_i32 = Global::new(&mut store, Value::I32(10));
|
let global_i32 = Global::new(&mut store, Value::I32(10));
|
||||||
assert_eq!(global_i32.get(&store), Value::I32(10));
|
assert_eq!(global_i32.get(&mut store), Value::I32(10));
|
||||||
// 64-bit values are not yet fully supported in some versions of Node
|
// 64-bit values are not yet fully supported in some versions of Node
|
||||||
// Commenting this tests for now:
|
// Commenting this tests for now:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user