diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:25:56 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-19 09:25:56 +0000 |
commit | 018c4950b9406055dec02ef0fb52f132e2bb1e2c (patch) | |
tree | a835ebdf2088ef88fa681f8fad45f09922c1ae9a /vendor/wasm-bindgen-backend | |
parent | Adding debian version 1.75.0+dfsg1-5. (diff) | |
download | rustc-018c4950b9406055dec02ef0fb52f132e2bb1e2c.tar.xz rustc-018c4950b9406055dec02ef0fb52f132e2bb1e2c.zip |
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/wasm-bindgen-backend')
-rw-r--r-- | vendor/wasm-bindgen-backend/.cargo-checksum.json | 2 | ||||
-rw-r--r-- | vendor/wasm-bindgen-backend/Cargo.toml | 8 | ||||
-rw-r--r-- | vendor/wasm-bindgen-backend/src/codegen.rs | 307 |
3 files changed, 256 insertions, 61 deletions
diff --git a/vendor/wasm-bindgen-backend/.cargo-checksum.json b/vendor/wasm-bindgen-backend/.cargo-checksum.json index f6dcacd92..5bfe08391 100644 --- a/vendor/wasm-bindgen-backend/.cargo-checksum.json +++ b/vendor/wasm-bindgen-backend/.cargo-checksum.json @@ -1 +1 @@ -{"files":{"Cargo.toml":"c740e4f5745411a6dbca5e83747101fb23d2ed90bad92153458c5ba8d6d24585","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","src/ast.rs":"880a7260126a5d77ba1ad748b199c9a2ff2da806a8f849e1160495f5d2d62203","src/codegen.rs":"e61dbe3f95059afd3e43b252aaf6ceef399b32a4a43a855ab3edb323281e78e7","src/encode.rs":"1350ccc927d7afdc1379a41127ce890dd50350a7773660b73f37d505a6229c16","src/error.rs":"18e23656cf81d363dae25b6340a725b8135badd91a2702a83cd80e19821e99ba","src/lib.rs":"14ade320b537315ec4c575f9f3c7a35ff4e9385114c4c26a35b2ee270a897cb4","src/util.rs":"7f305ad4c71e9d11ac9c5e9ab452d3c885dcfe8141084411892f042ccc54ba5e"},"package":"5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd"}
\ No newline at end of file +{"files":{"Cargo.toml":"44a5e3d86443c6e093226483b305e8795d529e24ef5d59c676fc48ae1b21a5dd","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"378f5840b258e2779c39418f3f2d7b2ba96f1c7917dd6be0713f88305dbda397","src/ast.rs":"880a7260126a5d77ba1ad748b199c9a2ff2da806a8f849e1160495f5d2d62203","src/codegen.rs":"785225aea704dc0aa6d60b75c6beb61970a12b5e8a2eef6206163e6ac4d426b7","src/encode.rs":"1350ccc927d7afdc1379a41127ce890dd50350a7773660b73f37d505a6229c16","src/error.rs":"18e23656cf81d363dae25b6340a725b8135badd91a2702a83cd80e19821e99ba","src/lib.rs":"14ade320b537315ec4c575f9f3c7a35ff4e9385114c4c26a35b2ee270a897cb4","src/util.rs":"7f305ad4c71e9d11ac9c5e9ab452d3c885dcfe8141084411892f042ccc54ba5e"},"package":"1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826"}
\ No newline at end of file diff --git a/vendor/wasm-bindgen-backend/Cargo.toml b/vendor/wasm-bindgen-backend/Cargo.toml index 3a984670e..5e7a6efa0 100644 --- a/vendor/wasm-bindgen-backend/Cargo.toml +++ b/vendor/wasm-bindgen-backend/Cargo.toml @@ -11,16 +11,16 @@ [package] edition = "2018" -rust-version = "1.56" +rust-version = "1.57" name = "wasm-bindgen-backend" -version = "0.2.87" +version = "0.2.89" authors = ["The wasm-bindgen Developers"] description = """ Backend code generation of the wasm-bindgen tool """ homepage = "https://rustwasm.github.io/wasm-bindgen/" documentation = "https://docs.rs/wasm-bindgen-backend" -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" repository = "https://github.com/rustwasm/wasm-bindgen/tree/master/crates/backend" resolver = "2" @@ -44,7 +44,7 @@ version = "2.0" features = ["full"] [dependencies.wasm-bindgen-shared] -version = "=0.2.87" +version = "=0.2.89" [features] extra-traits = ["syn/extra-traits"] diff --git a/vendor/wasm-bindgen-backend/src/codegen.rs b/vendor/wasm-bindgen-backend/src/codegen.rs index a43fbf940..bfedcfbc2 100644 --- a/vendor/wasm-bindgen-backend/src/codegen.rs +++ b/vendor/wasm-bindgen-backend/src/codegen.rs @@ -3,6 +3,7 @@ use crate::encode; use crate::Diagnostic; use once_cell::sync::Lazy; use proc_macro2::{Ident, Literal, Span, TokenStream}; +use quote::format_ident; use quote::quote_spanned; use quote::{quote, ToTokens}; use std::collections::{HashMap, HashSet}; @@ -142,7 +143,7 @@ impl TryToTokens for ast::LinkToModule { let link_function_name = self.0.link_function_name(0); let name = Ident::new(&link_function_name, Span::call_site()); let wasm_bindgen = &self.0.wasm_bindgen; - let abi_ret = quote! { <std::string::String as #wasm_bindgen::convert::FromWasmAbi>::Abi }; + let abi_ret = quote! { #wasm_bindgen::convert::WasmRet<<std::string::String as #wasm_bindgen::convert::FromWasmAbi>::Abi> }; let extern_fn = extern_fn(&name, &[], &[], &[], abi_ret); (quote! { { @@ -150,7 +151,7 @@ impl TryToTokens for ast::LinkToModule { #extern_fn unsafe { - <std::string::String as #wasm_bindgen::convert::FromWasmAbi>::from_abi(#name()) + <std::string::String as #wasm_bindgen::convert::FromWasmAbi>::from_abi(#name().join()) } } }) @@ -164,9 +165,10 @@ impl ToTokens for ast::Struct { let name = &self.rust_name; let name_str = self.js_name.to_string(); let name_len = name_str.len() as u32; - let name_chars = name_str.chars().map(|c| c as u32); + let name_chars: Vec<u32> = name_str.chars().map(|c| c as u32).collect(); let new_fn = Ident::new(&shared::new_function(&name_str), Span::call_site()); let free_fn = Ident::new(&shared::free_function(&name_str), Span::call_site()); + let unwrap_fn = Ident::new(&shared::unwrap_function(&name_str), Span::call_site()); let wasm_bindgen = &self.wasm_bindgen; (quote! { #[automatically_derived] @@ -221,12 +223,12 @@ impl ToTokens for ast::Struct { let ptr = #wasm_bindgen::convert::IntoWasmAbi::into_abi(value); #[link(wasm_import_module = "__wbindgen_placeholder__")] - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))] extern "C" { fn #new_fn(ptr: u32) -> u32; } - #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + #[cfg(not(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))))] unsafe fn #new_fn(_: u32) -> u32 { panic!("cannot convert to JsValue outside of the wasm target") } @@ -238,7 +240,7 @@ impl ToTokens for ast::Struct { } } - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))] #[automatically_derived] const _: () = { #[no_mangle] @@ -293,6 +295,76 @@ impl ToTokens for ast::Struct { #[inline] fn is_none(abi: &Self::Abi) -> bool { *abi == 0 } } + + #[allow(clippy::all)] + impl #wasm_bindgen::convert::TryFromJsValue for #name { + type Error = #wasm_bindgen::JsValue; + + fn try_from_js_value(value: #wasm_bindgen::JsValue) + -> #wasm_bindgen::__rt::std::result::Result<Self, Self::Error> { + let idx = #wasm_bindgen::convert::IntoWasmAbi::into_abi(&value); + + #[link(wasm_import_module = "__wbindgen_placeholder__")] + #[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))] + extern "C" { + fn #unwrap_fn(ptr: u32) -> u32; + } + + #[cfg(not(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))))] + unsafe fn #unwrap_fn(_: u32) -> u32 { + panic!("cannot convert from JsValue outside of the wasm target") + } + + let ptr = unsafe { #unwrap_fn(idx) }; + if ptr == 0 { + #wasm_bindgen::__rt::std::result::Result::Err(value) + } else { + // Don't run `JsValue`'s destructor, `unwrap_fn` already did that for us. + #wasm_bindgen::__rt::std::mem::forget(value); + unsafe { + #wasm_bindgen::__rt::std::result::Result::Ok( + <Self as #wasm_bindgen::convert::FromWasmAbi>::from_abi(ptr) + ) + } + } + } + } + + impl #wasm_bindgen::describe::WasmDescribeVector for #name { + fn describe_vector() { + use #wasm_bindgen::describe::*; + inform(VECTOR); + inform(NAMED_EXTERNREF); + inform(#name_len); + #(inform(#name_chars);)* + } + } + + impl #wasm_bindgen::convert::VectorIntoWasmAbi for #name { + type Abi = < + #wasm_bindgen::__rt::std::boxed::Box<[#wasm_bindgen::JsValue]> + as #wasm_bindgen::convert::IntoWasmAbi + >::Abi; + + fn vector_into_abi( + vector: #wasm_bindgen::__rt::std::boxed::Box<[#name]> + ) -> Self::Abi { + #wasm_bindgen::convert::js_value_vector_into_abi(vector) + } + } + + impl #wasm_bindgen::convert::VectorFromWasmAbi for #name { + type Abi = < + #wasm_bindgen::__rt::std::boxed::Box<[#wasm_bindgen::JsValue]> + as #wasm_bindgen::convert::FromWasmAbi + >::Abi; + + unsafe fn vector_from_abi( + js: Self::Abi + ) -> #wasm_bindgen::__rt::std::boxed::Box<[#name]> { + #wasm_bindgen::convert::js_value_vector_from_abi(js) + } + } }) .to_tokens(tokens); @@ -327,10 +399,10 @@ impl ToTokens for ast::StructField { (quote! { #[automatically_derived] const _: () = { - #[cfg_attr(all(target_arch = "wasm32", not(target_os = "emscripten")), no_mangle)] + #[cfg_attr(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))), no_mangle)] #[doc(hidden)] pub unsafe extern "C" fn #getter(js: u32) - -> <#ty as #wasm_bindgen::convert::IntoWasmAbi>::Abi + -> #wasm_bindgen::convert::WasmRet<<#ty as #wasm_bindgen::convert::IntoWasmAbi>::Abi> { use #wasm_bindgen::__rt::{WasmRefCell, assert_not_null}; use #wasm_bindgen::convert::IntoWasmAbi; @@ -341,7 +413,7 @@ impl ToTokens for ast::StructField { let js = js as *mut WasmRefCell<#struct_name>; assert_not_null(js); let val = #val; - <#ty as IntoWasmAbi>::into_abi(val) + <#ty as IntoWasmAbi>::into_abi(val).into() } }; }) @@ -361,21 +433,25 @@ impl ToTokens for ast::StructField { return; } + let abi = quote! { <#ty as #wasm_bindgen::convert::FromWasmAbi>::Abi }; + let (args, names) = splat(wasm_bindgen, &Ident::new("val", rust_name.span()), &abi); + (quote! { - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))] #[automatically_derived] const _: () = { #[no_mangle] #[doc(hidden)] pub unsafe extern "C" fn #setter( js: u32, - val: <#ty as #wasm_bindgen::convert::FromWasmAbi>::Abi, + #(#args,)* ) { use #wasm_bindgen::__rt::{WasmRefCell, assert_not_null}; use #wasm_bindgen::convert::FromWasmAbi; let js = js as *mut WasmRefCell<#struct_name>; assert_not_null(js); + let val = <#abi as #wasm_bindgen::convert::WasmAbi>::join(#(#names),*); let val = <#ty as FromWasmAbi>::from_abi(val); (*js).borrow_mut().#rust_name = val; } @@ -447,59 +523,76 @@ impl TryToTokens for ast::Export { argtys.push(&*arg.ty); let i = i + offset; let ident = Ident::new(&format!("arg{}", i), Span::call_site()); - let ty = &arg.ty; - match &*arg.ty { + fn unwrap_nested_types(ty: &syn::Type) -> &syn::Type { + match &ty { + syn::Type::Group(syn::TypeGroup { ref elem, .. }) => unwrap_nested_types(elem), + syn::Type::Paren(syn::TypeParen { ref elem, .. }) => unwrap_nested_types(elem), + _ => ty, + } + } + let ty = unwrap_nested_types(&arg.ty); + + match &ty { syn::Type::Reference(syn::TypeReference { mutability: Some(_), elem, .. }) => { - args.push(quote! { - #ident: <#elem as #wasm_bindgen::convert::RefMutFromWasmAbi>::Abi - }); + let abi = quote! { <#elem as #wasm_bindgen::convert::RefMutFromWasmAbi>::Abi }; + let (prim_args, prim_names) = splat(wasm_bindgen, &ident, &abi); + args.extend(prim_args); arg_conversions.push(quote! { let mut #ident = unsafe { <#elem as #wasm_bindgen::convert::RefMutFromWasmAbi> - ::ref_mut_from_abi(#ident) + ::ref_mut_from_abi( + <#abi as #wasm_bindgen::convert::WasmAbi>::join(#(#prim_names),*) + ) }; let #ident = &mut *#ident; }); } syn::Type::Reference(syn::TypeReference { elem, .. }) => { if self.function.r#async { - args.push(quote! { - #ident: <#elem as #wasm_bindgen::convert::LongRefFromWasmAbi>::Abi - }); + let abi = + quote! { <#elem as #wasm_bindgen::convert::LongRefFromWasmAbi>::Abi }; + let (prim_args, prim_names) = splat(wasm_bindgen, &ident, &abi); + args.extend(prim_args); arg_conversions.push(quote! { let #ident = unsafe { <#elem as #wasm_bindgen::convert::LongRefFromWasmAbi> - ::long_ref_from_abi(#ident) + ::long_ref_from_abi( + <#abi as #wasm_bindgen::convert::WasmAbi>::join(#(#prim_names),*) + ) }; let #ident = <<#elem as #wasm_bindgen::convert::LongRefFromWasmAbi> ::Anchor as core::borrow::Borrow<#elem>> ::borrow(&#ident); }); } else { - args.push(quote! { - #ident: <#elem as #wasm_bindgen::convert::RefFromWasmAbi>::Abi - }); + let abi = quote! { <#elem as #wasm_bindgen::convert::RefFromWasmAbi>::Abi }; + let (prim_args, prim_names) = splat(wasm_bindgen, &ident, &abi); + args.extend(prim_args); arg_conversions.push(quote! { let #ident = unsafe { <#elem as #wasm_bindgen::convert::RefFromWasmAbi> - ::ref_from_abi(#ident) + ::ref_from_abi( + <#abi as #wasm_bindgen::convert::WasmAbi>::join(#(#prim_names),*) + ) }; let #ident = &*#ident; }); } } _ => { - args.push(quote! { - #ident: <#ty as #wasm_bindgen::convert::FromWasmAbi>::Abi - }); + let abi = quote! { <#ty as #wasm_bindgen::convert::FromWasmAbi>::Abi }; + let (prim_args, prim_names) = splat(wasm_bindgen, &ident, &abi); + args.extend(prim_args); arg_conversions.push(quote! { let #ident = unsafe { <#ty as #wasm_bindgen::convert::FromWasmAbi> - ::from_abi(#ident) + ::from_abi( + <#abi as #wasm_bindgen::convert::WasmAbi>::join(#(#prim_names),*) + ) }; }); } @@ -571,7 +664,7 @@ impl TryToTokens for ast::Export { } let projection = quote! { <#ret_ty as #wasm_bindgen::convert::ReturnWasmAbi> }; - let convert_ret = quote! { #projection::return_abi(#ret) }; + let convert_ret = quote! { #projection::return_abi(#ret).into() }; let describe_ret = quote! { <#ret_ty as WasmDescribe>::describe(); <#inner_ret_ty as WasmDescribe>::describe(); @@ -590,10 +683,10 @@ impl TryToTokens for ast::Export { const _: () = { #(#attrs)* #[cfg_attr( - all(target_arch = "wasm32", not(target_os = "emscripten")), + all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))), export_name = #export_name, )] - pub unsafe extern "C" fn #generated_name(#(#args),*) -> #projection::Abi { + pub unsafe extern "C" fn #generated_name(#(#args),*) -> #wasm_bindgen::convert::WasmRet<#projection::Abi> { #start_check let #ret = #call; @@ -726,6 +819,7 @@ impl ToTokens for ast::ImportType { #[automatically_derived] const _: () = { + use #wasm_bindgen::convert::TryFromJsValue; use #wasm_bindgen::convert::{IntoWasmAbi, FromWasmAbi}; use #wasm_bindgen::convert::{OptionIntoWasmAbi, OptionFromWasmAbi}; use #wasm_bindgen::convert::{RefFromWasmAbi, LongRefFromWasmAbi}; @@ -840,11 +934,11 @@ impl ToTokens for ast::ImportType { impl JsCast for #rust_name { fn instanceof(val: &JsValue) -> bool { #[link(wasm_import_module = "__wbindgen_placeholder__")] - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))] extern "C" { fn #instanceof_shim(val: u32) -> u32; } - #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + #[cfg(not(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))))] unsafe fn #instanceof_shim(_: u32) -> u32 { panic!("cannot check instanceof on non-wasm targets"); } @@ -1076,10 +1170,11 @@ impl TryToTokens for ast::ImportFunction { ), }; - abi_argument_names.push(name.clone()); - abi_arguments.push(quote! { - #name: <#ty as #wasm_bindgen::convert::IntoWasmAbi>::Abi - }); + let abi = quote! { <#ty as #wasm_bindgen::convert::IntoWasmAbi>::Abi }; + let (prim_args, prim_names) = splat(wasm_bindgen, &name, &abi); + abi_arguments.extend(prim_args); + abi_argument_names.extend(prim_names.iter().cloned()); + let var = if i == 0 && is_method { quote! { self } } else { @@ -1089,6 +1184,7 @@ impl TryToTokens for ast::ImportFunction { arg_conversions.push(quote! { let #name = <#ty as #wasm_bindgen::convert::IntoWasmAbi> ::into_abi(#var); + let (#(#prim_names),*) = <#abi as #wasm_bindgen::convert::WasmAbi>::split(#name); }); } let abi_ret; @@ -1102,12 +1198,13 @@ impl TryToTokens for ast::ImportFunction { } Some(ref ty) => { if self.function.r#async { - abi_ret = - quote! { <js_sys::Promise as #wasm_bindgen::convert::FromWasmAbi>::Abi }; + abi_ret = quote! { + #wasm_bindgen::convert::WasmRet<<#wasm_bindgen_futures::js_sys::Promise as #wasm_bindgen::convert::FromWasmAbi>::Abi> + }; let future = quote! { #wasm_bindgen_futures::JsFuture::from( - <js_sys::Promise as #wasm_bindgen::convert::FromWasmAbi> - ::from_abi(#ret_ident) + <#wasm_bindgen_futures::js_sys::Promise as #wasm_bindgen::convert::FromWasmAbi> + ::from_abi(#ret_ident.join()) ).await }; convert_ret = if self.catch { @@ -1117,22 +1214,23 @@ impl TryToTokens for ast::ImportFunction { }; } else { abi_ret = quote! { - <#ty as #wasm_bindgen::convert::FromWasmAbi>::Abi + #wasm_bindgen::convert::WasmRet<<#ty as #wasm_bindgen::convert::FromWasmAbi>::Abi> }; convert_ret = quote! { <#ty as #wasm_bindgen::convert::FromWasmAbi> - ::from_abi(#ret_ident) + ::from_abi(#ret_ident.join()) }; } } None => { if self.function.r#async { - abi_ret = - quote! { <js_sys::Promise as #wasm_bindgen::convert::FromWasmAbi>::Abi }; + abi_ret = quote! { + #wasm_bindgen::convert::WasmRet<<#wasm_bindgen_futures::js_sys::Promise as #wasm_bindgen::convert::FromWasmAbi>::Abi> + }; let future = quote! { #wasm_bindgen_futures::JsFuture::from( - <js_sys::Promise as #wasm_bindgen::convert::FromWasmAbi> - ::from_abi(#ret_ident) + <#wasm_bindgen_futures::js_sys::Promise as #wasm_bindgen::convert::FromWasmAbi> + ::from_abi(#ret_ident.join()) ).await }; convert_ret = if self.catch { @@ -1285,6 +1383,9 @@ impl<'a> ToTokens for DescribeImport<'a> { impl ToTokens for ast::Enum { fn to_tokens(&self, into: &mut TokenStream) { let enum_name = &self.rust_name; + let name_str = self.js_name.to_string(); + let name_len = name_str.len() as u32; + let name_chars = name_str.chars().map(|c| c as u32); let hole = &self.hole; let cast_clauses = self.variants.iter().map(|variant| { let variant_name = &variant.name; @@ -1294,6 +1395,7 @@ impl ToTokens for ast::Enum { } } }); + let try_from_cast_clauses = cast_clauses.clone(); let wasm_bindgen = &self.wasm_bindgen; (quote! { #[automatically_derived] @@ -1335,9 +1437,71 @@ impl ToTokens for ast::Enum { fn describe() { use #wasm_bindgen::describe::*; inform(ENUM); + inform(#name_len); + #(inform(#name_chars);)* inform(#hole); } } + + #[automatically_derived] + impl #wasm_bindgen::__rt::core::convert::From<#enum_name> for + #wasm_bindgen::JsValue + { + fn from(value: #enum_name) -> Self { + #wasm_bindgen::JsValue::from_f64((value as u32).into()) + } + } + + #[allow(clippy::all)] + impl #wasm_bindgen::convert::TryFromJsValue for #enum_name { + type Error = #wasm_bindgen::JsValue; + + fn try_from_js_value(value: #wasm_bindgen::JsValue) + -> #wasm_bindgen::__rt::std::result::Result<Self, <#enum_name as #wasm_bindgen::convert::TryFromJsValue>::Error> { + use #wasm_bindgen::__rt::core::convert::TryFrom; + let js = f64::try_from(&value)? as u32; + + #wasm_bindgen::__rt::std::result::Result::Ok( + #(#try_from_cast_clauses else)* { + return #wasm_bindgen::__rt::std::result::Result::Err(value) + } + ) + } + } + + impl #wasm_bindgen::describe::WasmDescribeVector for #enum_name { + fn describe_vector() { + use #wasm_bindgen::describe::*; + inform(VECTOR); + <#wasm_bindgen::JsValue as #wasm_bindgen::describe::WasmDescribe>::describe(); + } + } + + impl #wasm_bindgen::convert::VectorIntoWasmAbi for #enum_name { + type Abi = < + #wasm_bindgen::__rt::std::boxed::Box<[#wasm_bindgen::JsValue]> + as #wasm_bindgen::convert::IntoWasmAbi + >::Abi; + + fn vector_into_abi( + vector: #wasm_bindgen::__rt::std::boxed::Box<[#enum_name]> + ) -> Self::Abi { + #wasm_bindgen::convert::js_value_vector_into_abi(vector) + } + } + + impl #wasm_bindgen::convert::VectorFromWasmAbi for #enum_name { + type Abi = < + #wasm_bindgen::__rt::std::boxed::Box<[#wasm_bindgen::JsValue]> + as #wasm_bindgen::convert::FromWasmAbi + >::Abi; + + unsafe fn vector_from_abi( + js: Self::Abi + ) -> #wasm_bindgen::__rt::std::boxed::Box<[#enum_name]> { + #wasm_bindgen::convert::js_value_vector_from_abi(js) + } + } }) .to_tokens(into); } @@ -1350,22 +1514,27 @@ impl ToTokens for ast::ImportStatic { let shim_name = &self.shim; let vis = &self.vis; let wasm_bindgen = &self.wasm_bindgen; + + let abi_ret = quote! { + #wasm_bindgen::convert::WasmRet<<#ty as #wasm_bindgen::convert::FromWasmAbi>::Abi> + }; (quote! { #[automatically_derived] #vis static #name: #wasm_bindgen::JsStatic<#ty> = { fn init() -> #ty { #[link(wasm_import_module = "__wbindgen_placeholder__")] - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))] extern "C" { - fn #shim_name() -> <#ty as #wasm_bindgen::convert::FromWasmAbi>::Abi; + fn #shim_name() -> #abi_ret; } - #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] - unsafe fn #shim_name() -> <#ty as #wasm_bindgen::convert::FromWasmAbi>::Abi { + + #[cfg(not(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))))] + unsafe fn #shim_name() -> #abi_ret { panic!("cannot access imported statics on non-wasm targets") } unsafe { - <#ty as #wasm_bindgen::convert::FromWasmAbi>::from_abi(#shim_name()) + <#ty as #wasm_bindgen::convert::FromWasmAbi>::from_abi(#shim_name().join()) } } thread_local!(static _VAL: #ty = init();); @@ -1424,7 +1593,7 @@ impl<'a, T: ToTokens> ToTokens for Descriptor<'a, T> { let attrs = &self.attrs; let wasm_bindgen = &self.wasm_bindgen; (quote! { - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))] #[automatically_derived] const _: () = { #(#attrs)* @@ -1450,14 +1619,14 @@ fn extern_fn( abi_ret: TokenStream, ) -> TokenStream { quote! { - #[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] + #[cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi"))))] #(#attrs)* #[link(wasm_import_module = "__wbindgen_placeholder__")] extern "C" { fn #import_name(#(#abi_arguments),*) -> #abi_ret; } - #[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] + #[cfg(not(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))))] unsafe fn #import_name(#(#abi_arguments),*) -> #abi_ret { #( drop(#abi_argument_names); @@ -1468,6 +1637,32 @@ fn extern_fn( } } +/// Splats an argument with the given name and ABI type into 4 arguments, one +/// for each primitive that the ABI type splits into. +/// +/// Returns an `(args, names)` pair, where `args` is the list of arguments to +/// be inserted into the function signature, and `names` is a list of the names +/// of those arguments. +fn splat( + wasm_bindgen: &syn::Path, + name: &Ident, + abi: &TokenStream, +) -> (Vec<TokenStream>, Vec<Ident>) { + let mut args = Vec::new(); + let mut names = Vec::new(); + + for n in 1..=4 { + let arg_name = format_ident!("{name}_{n}"); + let prim_name = format_ident!("Prim{n}"); + args.push(quote! { + #arg_name: <#abi as #wasm_bindgen::convert::WasmAbi>::#prim_name + }); + names.push(arg_name); + } + + (args, names) +} + /// Converts `span` into a stream of tokens, and attempts to ensure that `input` /// has all the appropriate span information so errors in it point to `span`. fn respan(input: TokenStream, span: &dyn ToTokens) -> TokenStream { |