diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c88d46a1df..c06151ecfeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,9 @@ RISCV Support, new Runners (WCGI), API convergence for JS/SYS, and WASI eXtended - [#3761](https://github.com/wasmerio/wasmer/pull/3761) Fix error in Korean translation +## Added + +- [#3762](https://github.com/wasmerio/wasmer/issues/3762) Implemented `NativeWasmTypeInto` for `u32` and `u64` for the web target (`js` feature) ## 3.2.0-beta.2 - 05/04/2023 diff --git a/lib/api/src/native_type.rs b/lib/api/src/native_type.rs index 8b6f08bd91a..b7c62d3cbee 100644 --- a/lib/api/src/native_type.rs +++ b/lib/api/src/native_type.rs @@ -77,6 +77,50 @@ impl NativeWasmTypeInto for i64 { } } +impl NativeWasmTypeInto for u32 { + #[inline] + unsafe fn from_abi(_store: &mut impl AsStoreMut, abi: Self::Abi) -> Self { + abi + } + + #[inline] + fn into_abi(self, _store: &mut impl AsStoreMut) -> Self::Abi { + self + } + + #[inline] + fn into_raw(self, _store: &mut impl AsStoreMut) -> RawValue { + RawValue { u32: self } + } + + #[inline] + unsafe fn from_raw(_store: &mut impl AsStoreMut, raw: RawValue) -> Self { + raw.u32 + } +} + +impl NativeWasmTypeInto for u64 { + #[inline] + unsafe fn from_abi(_store: &mut impl AsStoreMut, abi: Self::Abi) -> Self { + abi + } + + #[inline] + fn into_abi(self, _store: &mut impl AsStoreMut) -> Self::Abi { + self + } + + #[inline] + fn into_raw(self, _store: &mut impl AsStoreMut) -> RawValue { + RawValue { u64: self } + } + + #[inline] + unsafe fn from_raw(_store: &mut impl AsStoreMut, raw: RawValue) -> Self { + raw.u64 + } +} + impl NativeWasmTypeInto for f32 { #[inline] unsafe fn from_abi(_store: &mut impl AsStoreMut, abi: Self::Abi) -> Self { diff --git a/lib/types/src/lib.rs b/lib/types/src/lib.rs index 268c59b5ce4..35989c87f51 100644 --- a/lib/types/src/lib.rs +++ b/lib/types/src/lib.rs @@ -179,6 +179,16 @@ mod native { type Abi = Self; } + impl NativeWasmType for u32 { + const WASM_TYPE: Type = Type::I32; + type Abi = Self; + } + + impl NativeWasmType for u64 { + const WASM_TYPE: Type = Type::I64; + type Abi = Self; + } + impl NativeWasmType for f32 { const WASM_TYPE: Type = Type::F32; type Abi = Self;