From 1b48fb0836c6230f2bef0eed71a56d03293d9b3c Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Thu, 17 Apr 2025 19:57:25 +0200 Subject: [PATCH 1/3] Added support for tags in JS --- lib/api/Cargo.toml | 6 +-- lib/api/src/backend/js/entities/module.rs | 2 +- lib/api/src/backend/js/entities/tag.rs | 62 +++++++++++++++++++++-- lib/api/src/backend/js/utils/convert.rs | 40 ++++++++++++--- lib/api/src/backend/js/vm/external.rs | 9 +++- lib/api/src/backend/js/vm/mod.rs | 5 +- lib/api/src/backend/js/vm/tag.rs | 18 +++++++ lib/api/src/lib.rs | 2 +- lib/types/src/module.rs | 2 +- lib/types/src/types.rs | 29 +++++------ 10 files changed, 140 insertions(+), 35 deletions(-) create mode 100644 lib/api/src/backend/js/vm/tag.rs diff --git a/lib/api/Cargo.toml b/lib/api/Cargo.toml index 77987655af43..2ffa0d9f40b8 100644 --- a/lib/api/Cargo.toml +++ b/lib/api/Cargo.toml @@ -86,14 +86,14 @@ macro-wasmer-universal-test = { version = "6.0.0-beta.1", path = "./macro-wasmer wasmer-types = { path = "../types", version = "=6.0.0-beta.1", default-features = false, features = [ "std", ] } -wasm-bindgen = "0.2.74" -js-sys = "0.3.51" +wasm-bindgen = "0.2.100" +js-sys = "0.3.77" wasmer-derive = { path = "../derive", version = "=6.0.0-beta.1" } wasmer-compiler = { path = "../compiler", version = "=6.0.0-beta.1" } # - Optional dependencies for `js`. wasmparser = { workspace = true, default-features = false, optional = true } hashbrown = { version = "0.11", optional = true } -serde-wasm-bindgen = { version = "0.4.5" } +serde-wasm-bindgen = { version = "0.6.5" } serde = { version = "1.0", features = ["derive"] } target-lexicon = { workspace = true } diff --git a/lib/api/src/backend/js/entities/module.rs b/lib/api/src/backend/js/entities/module.rs index de9e03aab65d..36cb11d4784d 100644 --- a/lib/api/src/backend/js/entities/module.rs +++ b/lib/api/src/backend/js/entities/module.rs @@ -73,7 +73,7 @@ impl Module { ) -> Result { let js_bytes = Uint8Array::view(binary); let module = WebAssembly::Module::new(&js_bytes.into()) - .map_err(|e| CompileError::Validate(format!("{}", e.as_string().unwrap())))?; + .map_err(|e| CompileError::Validate(format!("{}", e.as_string().unwrap_or("Unknown validation error".to_string()))))?; Ok(Self::from_js_module(module, binary)) } diff --git a/lib/api/src/backend/js/entities/tag.rs b/lib/api/src/backend/js/entities/tag.rs index 08d08a0d6d9d..77bde59353b3 100644 --- a/lib/api/src/backend/js/entities/tag.rs +++ b/lib/api/src/backend/js/entities/tag.rs @@ -1,6 +1,8 @@ use wasmer_types::{TagType, Type}; use crate::{ + BackendTag, + TagKind, js::vm::VMTag, vm::{VMExtern, VMExternTag}, AsStoreMut, AsStoreRef, @@ -21,22 +23,72 @@ unsafe impl Sync for Tag {} impl Tag { pub fn new>>(store: &mut impl AsStoreMut, params: P) -> Self { - panic!("EH not supported yet!") + // unimplemented!("Tag is not yet supported in Javascript"); + // VMExtern::Tag(crate::js::vm::VMExtern::Tag(self.handle.clone())) + // let descriptor = js_sys::WebAssembly::TagDescriptor::new(params); + let descriptor = js_sys::Object::new(); + let params: Box<[Type]> = params.into(); + let parameters: Vec = params.into_iter().map(|param| { + match param { + Type::I32 => "i32".to_string(), + Type::I64 => "i64".to_string(), + Type::F32 => "f32".to_string(), + Type::F64 => "f64".to_string(), + _ => unimplemented!("The type is not yet supported in the JS Global API"), + } + }).collect(); + // This is the value type as string, even though is incorrectly called "value" + // in the JS API. + js_sys::Reflect::set(&descriptor, &"parameters".into(), ¶meters.into()).unwrap(); + + let tag = js_sys::WebAssembly::Tag::new(&descriptor); + let ty = TagType::new(TagKind::Exception, params); + let handle = VMTag::new(tag.unwrap(), ty); + Self { handle } } pub fn ty(&self, store: &impl AsStoreRef) -> TagType { - panic!("EH not supported yet!") + self.handle.ty.clone() } pub(crate) fn from_vm_extern(store: &mut impl AsStoreMut, vm_extern: VMExternTag) -> Self { - panic!("EH not supported yet!") + Self { + handle: vm_extern.into_js(), + } } pub fn is_from_store(&self, store: &impl AsStoreRef) -> bool { - panic!("EH not supported yet!") + true } pub(crate) fn to_vm_extern(&self) -> VMExtern { - panic!("EH not supported yet!") + VMExtern::Js(crate::js::vm::VMExtern::Tag(self.handle.clone())) + } +} + + +impl crate::Tag { + /// Consume [`self`] into [`crate::backend::js::tag::Tag`]. + pub fn into_js(self) -> crate::backend::js::tag::Tag { + match self.0 { + BackendTag::Js(s) => s, + _ => panic!("Not a `js` tag!"), + } + } + + /// Convert a reference to [`self`] into a reference [`crate::backend::js::tag::Tag`]. + pub fn as_js(&self) -> &crate::backend::js::tag::Tag { + match self.0 { + BackendTag::Js(ref s) => s, + _ => panic!("Not a `js` tag!"), + } + } + + /// Convert a mutable reference to [`self`] into a mutable reference [`crate::backend::js::tag::Tag`]. + pub fn as_js_mut(&mut self) -> &mut crate::backend::js::tag::Tag { + match self.0 { + BackendTag::Js(ref mut s) => s, + _ => panic!("Not a `js` tag!"), + } } } diff --git a/lib/api/src/backend/js/utils/convert.rs b/lib/api/src/backend/js/utils/convert.rs index 483a7b5bfe03..5a7b1c952fdf 100644 --- a/lib/api/src/backend/js/utils/convert.rs +++ b/lib/api/src/backend/js/utils/convert.rs @@ -2,7 +2,7 @@ use std::{collections::HashMap, convert::TryInto}; use js_sys::{ Function as JsFunction, - WebAssembly::{Memory as JsMemory, Table as JsTable}, + WebAssembly::{Memory as JsMemory, Table as JsTable, Tag as JsTag}, }; use wasm_bindgen::{JsCast, JsError, JsValue}; use wasmer_types::ExternType; @@ -13,11 +13,11 @@ use crate::{ js::{ instance::Instance as JsInstance, utils::polyfill::Global as JsGlobal, - vm::{VMFunction, VMGlobal, VMMemory, VMTable}, + vm::{VMFunction, VMGlobal, VMMemory, VMTable, VMTag}, }, store::{AsStoreMut, AsStoreRef}, value::Value, - Extern, Function, Global, Memory, Table, Type, + Extern, Function, Global, Memory, Table, Type, Tag, }; /// Convert the given type to a [`JsValue`]. @@ -193,7 +193,7 @@ impl AsJs for Extern { Self::Function(function) => function.as_js().handle.function.clone().into(), Self::Table(table) => table.as_js().handle.table.clone().into(), Self::Global(global) => global.as_js().handle.global.clone().into(), - Self::Tag(_) => unimplemented!("Tags are not yet supported in the JS Function API"), + Self::Tag(tag) => tag.as_js().handle.tag.clone().into(), } } @@ -219,8 +219,8 @@ impl AsJs for Extern { ExternType::Table(table_type) => { Ok(Self::Table(Table::from_jsvalue(store, table_type, val)?)) } - ExternType::Tag(_) => { - unimplemented!("Tags are not yet supported in the JS Function API") + ExternType::Tag(tag_type) => { + Ok(Self::Tag(Tag::from_jsvalue(store, tag_type, val)?)) } } } @@ -303,6 +303,34 @@ impl AsJs for Function { } } +impl AsJs for Tag { + type DefinitionType = crate::TagType; + fn as_jsvalue(&self, _store: &impl AsStoreRef) -> wasm_bindgen::JsValue { + self.as_js().handle.tag.clone().into() + } + + fn from_jsvalue( + store: &mut impl AsStoreMut, + tag: &Self::DefinitionType, + value: &JsValue, + ) -> Result { + if value.is_instance_of::() { + Ok(Tag::from_vm_extern( + store, + crate::vm::VMExternTag::Js(VMTag::new( + value.clone().unchecked_into::(), + tag.clone(), + )), + )) + } else { + Err(JsError::new(&format!( + "Extern expect to be of type Tag, but received {:?}", + value + ))) + } + } +} + impl AsJs for Global { type DefinitionType = crate::GlobalType; diff --git a/lib/api/src/backend/js/vm/external.rs b/lib/api/src/backend/js/vm/external.rs index f273a11fd169..ec324cdda56c 100644 --- a/lib/api/src/backend/js/vm/external.rs +++ b/lib/api/src/backend/js/vm/external.rs @@ -2,7 +2,7 @@ use wasmer_types::RawValue; use crate::{AsStoreMut, Extern, VMExternToExtern}; -use super::{function::VMFunction, global::VMGlobal, memory::VMMemory, table::VMTable}; +use super::{function::VMFunction, global::VMGlobal, memory::VMMemory, table::VMTable, tag::VMTag}; /// The value of an export passed from one instance to another in the `js` VM. pub enum VMExtern { @@ -17,6 +17,9 @@ pub enum VMExtern { /// A global export value. Global(VMGlobal), + + /// A tag export value. + Tag(VMTag), } impl VMExternToExtern for VMExtern { @@ -38,6 +41,10 @@ impl VMExternToExtern for VMExtern { store, crate::vm::VMExternTable::Js(t), )), + Self::Tag(t) => Extern::Tag(crate::Tag::from_vm_extern( + store, + crate::vm::VMExternTag::Js(t), + )), } } } diff --git a/lib/api/src/backend/js/vm/mod.rs b/lib/api/src/backend/js/vm/mod.rs index 5ef1b1f5fd8b..eb8e63afdae7 100644 --- a/lib/api/src/backend/js/vm/mod.rs +++ b/lib/api/src/backend/js/vm/mod.rs @@ -3,6 +3,7 @@ pub(crate) mod function; pub(crate) mod global; pub(crate) mod memory; pub(crate) mod table; +pub(crate) mod tag; pub use super::error::Trap; pub use external::*; @@ -10,6 +11,7 @@ pub use function::*; pub use global::*; pub use memory::*; pub use table::*; +pub use tag::*; /// The type of instances in the `js` VM. pub type VMInstance = js_sys::WebAssembly::Instance; @@ -27,8 +29,7 @@ pub(crate) type VMExternFunction = VMFunction; // No EH for now. pub(crate) type VMException = (); -pub(crate) type VMTag = (); -pub(crate) type VMExternTag = (); +pub(crate) type VMExternTag = VMTag; pub struct VMExceptionRef; impl VMExceptionRef { diff --git a/lib/api/src/backend/js/vm/tag.rs b/lib/api/src/backend/js/vm/tag.rs new file mode 100644 index 000000000000..d0118137b8e0 --- /dev/null +++ b/lib/api/src/backend/js/vm/tag.rs @@ -0,0 +1,18 @@ +use js_sys::WebAssembly::Tag as JsTag; +use wasmer_types::TagType; + +/// The VM Tag type +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct VMTag { + pub(crate) tag: JsTag, + pub(crate) ty: TagType, +} + +impl VMTag { + pub(crate) fn new(tag: JsTag, ty: TagType) -> Self { + Self { tag, ty } + } +} + +unsafe impl Send for VMTag {} +unsafe impl Sync for VMTag {} diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index 4ab5d1fc89a7..566460d05ab0 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -443,7 +443,7 @@ pub use wasmer_types::{ FunctionType, GlobalInit, GlobalType, ImportType, LocalFunctionIndex, MemoryError, MemoryStyle, MemoryType, Mutability, OnCalledAction, Pages, ParseCpuFeatureError, SerializeError, TableStyle, TableType, Type, ValueType, WasmError, WasmResult, WASM_MAX_PAGES, WASM_MIN_PAGES, - WASM_PAGE_SIZE, + WASM_PAGE_SIZE, TagType, TagKind, }; #[cfg(feature = "wasmparser")] diff --git a/lib/types/src/module.rs b/lib/types/src/module.rs index 97312ad27890..93c02a48a092 100644 --- a/lib/types/src/module.rs +++ b/lib/types/src/module.rs @@ -403,7 +403,7 @@ impl ModuleInfo { ExternType::Tag(TagType { kind: crate::types::TagKind::Exception, - ty: tag_type.clone(), + params: tag_type.params().into(), }) } }; diff --git a/lib/types/src/types.rs b/lib/types/src/types.rs index 74ff720a1e4a..a74994e3d6de 100644 --- a/lib/types/src/types.rs +++ b/lib/types/src/types.rs @@ -475,35 +475,35 @@ pub enum TagKind { pub struct TagType { /// The kind of the tag. pub kind: TagKind, - /// The type of the tag. - pub ty: FunctionType, + /// The parameters of the function + pub params: Box<[Type]>, } impl TagType { /// Creates a new [`TagType`] with the given kind, parameter and return types. - pub fn new(kind: TagKind, params: Params, returns: Returns) -> Self + pub fn new(kind: TagKind, params: Params) -> Self where Params: Into>, - Returns: Into>, { - let ty = FunctionType::new(params.into(), returns.into()); - - Self::from_fn_type(kind, ty) + Self { + kind, + params: params.into(), + } } - /// Return types. - pub fn results(&self) -> &[Type] { - self.ty.results() - } + // /// Return types. + // pub fn results(&self) -> &[Type] { + // self.ty.results() + // } /// Parameter types. pub fn params(&self) -> &[Type] { - self.ty.params() + &self.params } /// Create a new [`TagType`] with the given kind and the associated type. pub fn from_fn_type(kind: TagKind, ty: FunctionType) -> Self { - Self { kind, ty } + Self { kind, params: ty.params().into() } } } @@ -511,10 +511,9 @@ impl fmt::Display for TagType { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, - "({:?}) {:?} -> {:?}", + "({:?}) {:?}", self.kind, self.params(), - self.results() ) } } From e4f496dff46cdf46c38013ac60f0f00ab0156628 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Tue, 22 Apr 2025 12:12:00 +0200 Subject: [PATCH 2/3] Improved tag implementation. Removed Global polyfill --- Cargo.lock | 6 ++--- lib/api/src/backend/js/entities/global.rs | 5 ++-- lib/api/src/backend/js/entities/module.rs | 9 +++++-- lib/api/src/backend/js/entities/tag.rs | 19 +++++-------- lib/api/src/backend/js/utils/convert.rs | 9 +++---- lib/api/src/backend/js/utils/mod.rs | 1 - lib/api/src/backend/js/utils/polyfill.rs | 33 ----------------------- lib/api/src/backend/js/vm/global.rs | 2 +- lib/api/src/backend/sys/entities/tag.rs | 5 ++-- lib/api/src/lib.rs | 4 +-- lib/types/src/types.rs | 17 ++++-------- 11 files changed, 33 insertions(+), 77 deletions(-) delete mode 100644 lib/api/src/backend/js/utils/polyfill.rs diff --git a/Cargo.lock b/Cargo.lock index 075db0049a4a..43c9c0ab5f8d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2921,7 +2921,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -4798,9 +4798,9 @@ dependencies = [ [[package]] name = "serde-wasm-bindgen" -version = "0.4.5" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3b4c031cd0d9014307d82b8abf653c0290fbdaeb4c02d00c63cf52f728628bf" +checksum = "8302e169f0eddcc139c70f139d19d6467353af16f9fce27e8c30158036a1e16b" dependencies = [ "js-sys", "serde", diff --git a/lib/api/src/backend/js/entities/global.rs b/lib/api/src/backend/js/entities/global.rs index 5c23cbb89619..9b5ca611e417 100644 --- a/lib/api/src/backend/js/entities/global.rs +++ b/lib/api/src/backend/js/entities/global.rs @@ -2,10 +2,11 @@ use wasm_bindgen::{prelude::*, JsValue}; use wasmer_types::{GlobalType, Mutability, RawValue, Type}; use crate::{ - js::{utils::polyfill::Global as JsGlobal, vm::VMGlobal}, + js::vm::VMGlobal, vm::{VMExtern, VMExternGlobal}, AsStoreMut, AsStoreRef, BackendGlobal, RuntimeError, Value, }; +use js_sys::WebAssembly; #[derive(Debug, Clone, PartialEq, Eq)] /// A WebAssembly `global` in `js`. @@ -54,7 +55,7 @@ impl Global { &mutability.is_mutable().into(), )?; - let js_global = JsGlobal::new(&descriptor, &value).unwrap(); + let js_global = WebAssembly::Global::new(&descriptor, &value).unwrap(); let vm_global = VMGlobal::new(js_global, global_ty); Ok(Self::from_vm_extern(store, VMExternGlobal::Js(vm_global))) diff --git a/lib/api/src/backend/js/entities/module.rs b/lib/api/src/backend/js/entities/module.rs index 36cb11d4784d..b734661f96f8 100644 --- a/lib/api/src/backend/js/entities/module.rs +++ b/lib/api/src/backend/js/entities/module.rs @@ -72,8 +72,13 @@ impl Module { binary: &[u8], ) -> Result { let js_bytes = Uint8Array::view(binary); - let module = WebAssembly::Module::new(&js_bytes.into()) - .map_err(|e| CompileError::Validate(format!("{}", e.as_string().unwrap_or("Unknown validation error".to_string()))))?; + let module = WebAssembly::Module::new(&js_bytes.into()).map_err(|e| { + CompileError::Validate(format!( + "{}", + e.as_string() + .unwrap_or("Unknown validation error".to_string()) + )) + })?; Ok(Self::from_js_module(module, binary)) } diff --git a/lib/api/src/backend/js/entities/tag.rs b/lib/api/src/backend/js/entities/tag.rs index 77bde59353b3..b00c9c3b9fb6 100644 --- a/lib/api/src/backend/js/entities/tag.rs +++ b/lib/api/src/backend/js/entities/tag.rs @@ -1,11 +1,9 @@ use wasmer_types::{TagType, Type}; use crate::{ - BackendTag, - TagKind, js::vm::VMTag, vm::{VMExtern, VMExternTag}, - AsStoreMut, AsStoreRef, + AsStoreMut, AsStoreRef, BackendTag, TagKind, }; #[derive(Debug, Clone, PartialEq, Eq)] @@ -23,22 +21,18 @@ unsafe impl Sync for Tag {} impl Tag { pub fn new>>(store: &mut impl AsStoreMut, params: P) -> Self { - // unimplemented!("Tag is not yet supported in Javascript"); - // VMExtern::Tag(crate::js::vm::VMExtern::Tag(self.handle.clone())) - // let descriptor = js_sys::WebAssembly::TagDescriptor::new(params); let descriptor = js_sys::Object::new(); let params: Box<[Type]> = params.into(); - let parameters: Vec = params.into_iter().map(|param| { - match param { + let parameters: Vec = params + .into_iter() + .map(|param| match param { Type::I32 => "i32".to_string(), Type::I64 => "i64".to_string(), Type::F32 => "f32".to_string(), Type::F64 => "f64".to_string(), _ => unimplemented!("The type is not yet supported in the JS Global API"), - } - }).collect(); - // This is the value type as string, even though is incorrectly called "value" - // in the JS API. + }) + .collect(); js_sys::Reflect::set(&descriptor, &"parameters".into(), ¶meters.into()).unwrap(); let tag = js_sys::WebAssembly::Tag::new(&descriptor); @@ -66,7 +60,6 @@ impl Tag { } } - impl crate::Tag { /// Consume [`self`] into [`crate::backend::js::tag::Tag`]. pub fn into_js(self) -> crate::backend::js::tag::Tag { diff --git a/lib/api/src/backend/js/utils/convert.rs b/lib/api/src/backend/js/utils/convert.rs index 5a7b1c952fdf..c65008478f6b 100644 --- a/lib/api/src/backend/js/utils/convert.rs +++ b/lib/api/src/backend/js/utils/convert.rs @@ -2,7 +2,7 @@ use std::{collections::HashMap, convert::TryInto}; use js_sys::{ Function as JsFunction, - WebAssembly::{Memory as JsMemory, Table as JsTable, Tag as JsTag}, + WebAssembly::{Global as JsGlobal, Memory as JsMemory, Table as JsTable, Tag as JsTag}, }; use wasm_bindgen::{JsCast, JsError, JsValue}; use wasmer_types::ExternType; @@ -12,12 +12,11 @@ use crate::{ instance::Instance, js::{ instance::Instance as JsInstance, - utils::polyfill::Global as JsGlobal, vm::{VMFunction, VMGlobal, VMMemory, VMTable, VMTag}, }, store::{AsStoreMut, AsStoreRef}, value::Value, - Extern, Function, Global, Memory, Table, Type, Tag, + Extern, Function, Global, Memory, Table, Tag, Type, }; /// Convert the given type to a [`JsValue`]. @@ -219,9 +218,7 @@ impl AsJs for Extern { ExternType::Table(table_type) => { Ok(Self::Table(Table::from_jsvalue(store, table_type, val)?)) } - ExternType::Tag(tag_type) => { - Ok(Self::Tag(Tag::from_jsvalue(store, tag_type, val)?)) - } + ExternType::Tag(tag_type) => Ok(Self::Tag(Tag::from_jsvalue(store, tag_type, val)?)), } } } diff --git a/lib/api/src/backend/js/utils/mod.rs b/lib/api/src/backend/js/utils/mod.rs index d5b6cb45911b..14f75ed02400 100644 --- a/lib/api/src/backend/js/utils/mod.rs +++ b/lib/api/src/backend/js/utils/mod.rs @@ -1,6 +1,5 @@ pub(crate) mod convert; pub(crate) mod js_handle; -pub(crate) mod polyfill; pub use convert::*; pub use js_handle::*; diff --git a/lib/api/src/backend/js/utils/polyfill.rs b/lib/api/src/backend/js/utils/polyfill.rs deleted file mode 100644 index 80f89a6a7029..000000000000 --- a/lib/api/src/backend/js/utils/polyfill.rs +++ /dev/null @@ -1,33 +0,0 @@ -use js_sys::Object; -use wasm_bindgen::prelude::*; - -// WebAssembly.Global -#[wasm_bindgen] -extern "C" { - /// The `WebAssembly.Global()` constructor creates a new `Global` object - /// of the given type and value. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global) - #[wasm_bindgen(js_namespace = WebAssembly, extends = Object, typescript_type = "WebAssembly.Global")] - #[derive(Clone, Debug, PartialEq, Eq)] - pub type Global; - - /// The `WebAssembly.Global()` constructor creates a new `Global` object - /// of the given type and value. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global) - #[allow(unused_doc_comments)] - #[wasm_bindgen(constructor, js_namespace = WebAssembly, catch)] - pub fn new(global_descriptor: &Object, value: &JsValue) -> Result; - - /// The value prototype property of the `WebAssembly.Global` object - /// returns the value of the global. - /// - /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global) - #[allow(unused_doc_comments)] - #[wasm_bindgen(method, getter, structural, js_namespace = WebAssembly)] - pub fn value(this: &Global) -> JsValue; - - #[wasm_bindgen(method, setter = value, structural, js_namespace = WebAssembly)] - pub fn set_value(this: &Global, value: &JsValue); -} diff --git a/lib/api/src/backend/js/vm/global.rs b/lib/api/src/backend/js/vm/global.rs index a8d5cead3fef..dec457067fa0 100644 --- a/lib/api/src/backend/js/vm/global.rs +++ b/lib/api/src/backend/js/vm/global.rs @@ -1,4 +1,4 @@ -use crate::backend::js::utils::polyfill::Global as JsGlobal; +use js_sys::WebAssembly::Global as JsGlobal; use wasmer_types::GlobalType; /// The VM Global type diff --git a/lib/api/src/backend/sys/entities/tag.rs b/lib/api/src/backend/sys/entities/tag.rs index 81e7170ba152..8f1de9b06a64 100644 --- a/lib/api/src/backend/sys/entities/tag.rs +++ b/lib/api/src/backend/sys/entities/tag.rs @@ -39,11 +39,12 @@ impl Tag { pub fn ty(&self, store: &impl AsStoreRef) -> TagType { TagType { kind: wasmer_types::TagKind::Exception, - ty: self + params: self .handle .get(store.as_store_ref().objects().as_sys()) .signature - .clone(), + .params() + .into(), } } diff --git a/lib/api/src/lib.rs b/lib/api/src/lib.rs index 566460d05ab0..36270943339d 100644 --- a/lib/api/src/lib.rs +++ b/lib/api/src/lib.rs @@ -442,8 +442,8 @@ pub use wasmer_types::{ is_wasm, Bytes, CompileError, DeserializeError, ExportIndex, ExportType, ExternType, FrameInfo, FunctionType, GlobalInit, GlobalType, ImportType, LocalFunctionIndex, MemoryError, MemoryStyle, MemoryType, Mutability, OnCalledAction, Pages, ParseCpuFeatureError, SerializeError, - TableStyle, TableType, Type, ValueType, WasmError, WasmResult, WASM_MAX_PAGES, WASM_MIN_PAGES, - WASM_PAGE_SIZE, TagType, TagKind, + TableStyle, TableType, TagKind, TagType, Type, ValueType, WasmError, WasmResult, + WASM_MAX_PAGES, WASM_MIN_PAGES, WASM_PAGE_SIZE, }; #[cfg(feature = "wasmparser")] diff --git a/lib/types/src/types.rs b/lib/types/src/types.rs index a74994e3d6de..91379d3fd877 100644 --- a/lib/types/src/types.rs +++ b/lib/types/src/types.rs @@ -491,11 +491,6 @@ impl TagType { } } - // /// Return types. - // pub fn results(&self) -> &[Type] { - // self.ty.results() - // } - /// Parameter types. pub fn params(&self) -> &[Type] { &self.params @@ -503,18 +498,16 @@ impl TagType { /// Create a new [`TagType`] with the given kind and the associated type. pub fn from_fn_type(kind: TagKind, ty: FunctionType) -> Self { - Self { kind, params: ty.params().into() } + Self { + kind, + params: ty.params().into(), + } } } impl fmt::Display for TagType { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!( - f, - "({:?}) {:?}", - self.kind, - self.params(), - ) + write!(f, "({:?}) {:?}", self.kind, self.params(),) } } From ca7ff3ecdaf1751448a52c552e620626941a8bed Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Tue, 22 Apr 2025 13:48:37 +0200 Subject: [PATCH 3/3] Improved TagType::new --- lib/api/src/backend/v8/entities/tag.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/api/src/backend/v8/entities/tag.rs b/lib/api/src/backend/v8/entities/tag.rs index 79fa5dd379dd..bc2aeeb9f7db 100644 --- a/lib/api/src/backend/v8/entities/tag.rs +++ b/lib/api/src/backend/v8/entities/tag.rs @@ -69,7 +69,7 @@ impl Tag { res }; - TagType::new(wasmer_types::TagKind::Exception, params, vec![]) + TagType::new(wasmer_types::TagKind::Exception, params) } pub(crate) fn from_vm_extern(store: &mut impl AsStoreMut, vm_tag: VMExternTag) -> Self {