mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-13 05:48:45 +00:00
Fix f64 -> RawValue in JS API
This commit is contained in:
12
lib/api/src/js/externals/function.rs
vendored
12
lib/api/src/js/externals/function.rs
vendored
@@ -26,6 +26,7 @@ fn result_to_js(val: &Value) -> JsValue {
|
|||||||
Value::I64(i) => JsValue::from_f64(*i as _),
|
Value::I64(i) => JsValue::from_f64(*i as _),
|
||||||
Value::F32(f) => JsValue::from_f64(*f as _),
|
Value::F32(f) => JsValue::from_f64(*f as _),
|
||||||
Value::F64(f) => JsValue::from_f64(*f),
|
Value::F64(f) => JsValue::from_f64(*f),
|
||||||
|
Value::V128(f) => JsValue::from_f64(*f as _),
|
||||||
val => unimplemented!(
|
val => unimplemented!(
|
||||||
"The value `{:?}` is not yet supported in the JS Function API",
|
"The value `{:?}` is not yet supported in the JS Function API",
|
||||||
val
|
val
|
||||||
@@ -607,7 +608,7 @@ mod inner {
|
|||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::panic::{self, AssertUnwindSafe};
|
use std::panic::{self, AssertUnwindSafe};
|
||||||
|
|
||||||
use wasmer_types::{FunctionType, NativeWasmType, Type};
|
use wasmer_types::{FunctionType, RawValue, NativeWasmType, Type};
|
||||||
// use wasmer::{raise_user_trap, resume_panic};
|
// use wasmer::{raise_user_trap, resume_panic};
|
||||||
|
|
||||||
/// A trait to convert a Rust value to a `WasmNativeType` value,
|
/// A trait to convert a Rust value to a `WasmNativeType` value,
|
||||||
@@ -783,10 +784,10 @@ mod inner {
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
unsafe fn into_c_struct(self, store: &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`.
|
/// Writes the contents of a C struct to an array of `RawValue`.
|
||||||
///
|
///
|
||||||
/// # Safety
|
/// # Safety
|
||||||
unsafe fn write_c_struct_to_ptr(c_struct: Self::CStruct, ptr: *mut f64);
|
unsafe fn write_c_struct_to_ptr(c_struct: Self::CStruct, ptr: *mut RawValue);
|
||||||
|
|
||||||
/// Get the Wasm types for the tuple (list) of currently
|
/// Get the Wasm types for the tuple (list) of currently
|
||||||
/// represented values.
|
/// represented values.
|
||||||
@@ -838,6 +839,7 @@ mod inner {
|
|||||||
mod test_into_result {
|
mod test_into_result {
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
|
use wasmer_types::RawValue;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_into_result_over_t() {
|
fn test_into_result_over_t() {
|
||||||
@@ -1067,7 +1069,7 @@ mod inner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
unsafe fn write_c_struct_to_ptr(c_struct: Self::CStruct, _ptr: *mut f64) {
|
unsafe fn write_c_struct_to_ptr(c_struct: Self::CStruct, _ptr: *mut RawValue) {
|
||||||
// Unpack items of the tuple.
|
// Unpack items of the tuple.
|
||||||
let $c_struct_name( $( $x ),* ) = c_struct;
|
let $c_struct_name( $( $x ),* ) = c_struct;
|
||||||
|
|
||||||
@@ -1264,7 +1266,7 @@ mod inner {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn write_c_struct_to_ptr(_: Self::CStruct, _: *mut f64) {}
|
unsafe fn write_c_struct_to_ptr(_: Self::CStruct, _: *mut RawValue) {}
|
||||||
|
|
||||||
fn wasm_types() -> &'static [Type] {
|
fn wasm_types() -> &'static [Type] {
|
||||||
&[]
|
&[]
|
||||||
|
|||||||
@@ -318,6 +318,33 @@ impl Module {
|
|||||||
Self::new(_store, bytes).map_err(|e| DeserializeError::Compiler(e))
|
Self::new(_store, bytes).map_err(|e| DeserializeError::Compiler(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(feature = "compiler")]
|
||||||
|
/// Deserializes a a serialized Module located in a `Path` into a `Module`.
|
||||||
|
/// > Note: the module has to be serialized before with the `serialize` method.
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// Please check [`Module::deserialize`].
|
||||||
|
///
|
||||||
|
/// # Usage
|
||||||
|
///
|
||||||
|
/// ```ignore
|
||||||
|
/// # use wasmer::*;
|
||||||
|
/// # let mut store = Store::default();
|
||||||
|
/// # fn main() -> anyhow::Result<()> {
|
||||||
|
/// let module = Module::deserialize_from_file(&store, path)?;
|
||||||
|
/// # Ok(())
|
||||||
|
/// # }
|
||||||
|
/// ```
|
||||||
|
pub unsafe fn deserialize_from_file(
|
||||||
|
store: &impl AsStoreRef,
|
||||||
|
path: impl AsRef<Path>,
|
||||||
|
) -> Result<Self, DeserializeError> {
|
||||||
|
let artifact = std::fs::read(path.as_ref())?;
|
||||||
|
Ok(Self::new(store, bytes).map_err(|e| DeserializeError::Compiler(e)))
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets the name of the current module.
|
/// Sets the name of the current module.
|
||||||
/// This is normally useful for stacktraces and debugging.
|
/// This is normally useful for stacktraces and debugging.
|
||||||
///
|
///
|
||||||
|
|||||||
Reference in New Issue
Block a user