mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-13 13:01:22 +00:00
Add customisable is_type_of
This commit is contained in:
@ -183,6 +183,7 @@ pub struct ImportType {
|
||||
pub attrs: Vec<syn::Attribute>,
|
||||
pub doc_comment: Option<String>,
|
||||
pub instanceof_shim: String,
|
||||
pub is_type_of: Option<syn::Expr>,
|
||||
pub extends: Vec<syn::Path>,
|
||||
pub vendor_prefixes: Vec<Ident>,
|
||||
}
|
||||
|
@ -588,6 +588,13 @@ impl ToTokens for ast::ImportType {
|
||||
}
|
||||
};
|
||||
|
||||
let is_type_of = self.is_type_of.as_ref().map(|is_type_of| quote! {
|
||||
fn is_type_of(val: &JsValue) -> bool {
|
||||
let is_type_of: fn(&JsValue) -> bool = #is_type_of;
|
||||
is_type_of(val)
|
||||
}
|
||||
});
|
||||
|
||||
(quote! {
|
||||
#[allow(bad_style)]
|
||||
#(#attrs)*
|
||||
@ -720,6 +727,8 @@ impl ToTokens for ast::ImportType {
|
||||
panic!("cannot check instanceof on non-wasm targets");
|
||||
}
|
||||
|
||||
#is_type_of
|
||||
|
||||
#[inline]
|
||||
fn unchecked_from_js(val: JsValue) -> Self {
|
||||
#rust_name { obj: val.into() }
|
||||
|
Reference in New Issue
Block a user