mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-21 08:41:35 +00:00
Add a structural
bindgen attribute
This attribute indicates that methods are to be accessed in a structural method rather than through their class. This should allow direct access to properties embedded on objects rather than forcing all objects to have a class/prototype.
This commit is contained in:
@ -670,6 +670,16 @@ impl BindgenAttrs {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn structural(&self) -> bool {
|
||||
self.attrs.iter()
|
||||
.any(|a| {
|
||||
match *a {
|
||||
BindgenAttr::Structural => true,
|
||||
_ => false,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl syn::synom::Synom for BindgenAttrs {
|
||||
@ -695,6 +705,7 @@ enum BindgenAttr {
|
||||
Module(String),
|
||||
Getter,
|
||||
Setter,
|
||||
Structural,
|
||||
}
|
||||
|
||||
impl syn::synom::Synom for BindgenAttr {
|
||||
@ -709,6 +720,8 @@ impl syn::synom::Synom for BindgenAttr {
|
||||
|
|
||||
call!(term, "setter") => { |_| BindgenAttr::Setter }
|
||||
|
|
||||
call!(term, "structural") => { |_| BindgenAttr::Structural }
|
||||
|
|
||||
do_parse!(
|
||||
call!(term, "js_namespace") >>
|
||||
punct!(=) >>
|
||||
|
@ -349,6 +349,16 @@ impl ToTokens for ast::ImportType {
|
||||
}
|
||||
}
|
||||
|
||||
impl ::wasm_bindgen::convert::FromRefWasmBoundary for #name {
|
||||
type RefAnchor = ::std::mem::ManuallyDrop<#name>;
|
||||
unsafe fn from_js_ref(js: Self::Js) -> Self::RefAnchor {
|
||||
let obj = <::wasm_bindgen::JsValue as ::wasm_bindgen::convert::WasmBoundary>
|
||||
::from_js(js);
|
||||
::std::mem::ManuallyDrop::new(#name { obj })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl From<::wasm_bindgen::JsValue> for #name {
|
||||
fn from(obj: ::wasm_bindgen::JsValue) -> #name {
|
||||
#name { obj }
|
||||
|
@ -242,6 +242,7 @@ impl Literal for ast::ImportFunction {
|
||||
|
||||
let mut getter = None;
|
||||
let mut setter = None;
|
||||
let structural = self.function.opts.structural();
|
||||
|
||||
if self.function.opts.getter() {
|
||||
getter = Some(self.infer_getter_property());
|
||||
@ -254,6 +255,7 @@ impl Literal for ast::ImportFunction {
|
||||
("catch", &|a| a.bool(self.function.opts.catch())),
|
||||
("method", &|a| a.bool(method)),
|
||||
("js_new", &|a| a.bool(js_new)),
|
||||
("structural", &|a| a.bool(structural)),
|
||||
("getter", &|a| match getter {
|
||||
Some(ref s) => a.str(s),
|
||||
None => a.append("null"),
|
||||
|
Reference in New Issue
Block a user