mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-12 20:41:24 +00:00
Switch all imports to structural
by default
This commit switches all imports of JS methods to `structural` by default. Proposed in [RFC 5] this should increase the performance of bindings today while also providing future-proofing for possible confusion with the recent addition of the `Deref` trait for all imported types by default as well. A new attribute, `host_binding`, is introduced in this PR as well to recover the old behavior of binding directly to an imported function which will one day be the precise function on the prototype. Eventually `web-sys` will switcsh over entirely to being driven via `host_binding` methods, but for now it's been measured to be not quite as fast so we're not making that switch yet. Note that `host_binding` differs from the proposed name of `final` due to the controversy, and its hoped that `host_binding` is a good middle-ground! [RFC 5]: https://rustwasm.github.io/rfcs/005-structural-and-deref.html
This commit is contained in:
@ -149,6 +149,14 @@ impl BindgenAttrs {
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether the `host_binding` attribute is present
|
||||
fn host_binding(&self) -> bool {
|
||||
self.attrs.iter().any(|a| match *a {
|
||||
BindgenAttr::HostBinding => true,
|
||||
_ => false,
|
||||
})
|
||||
}
|
||||
|
||||
/// Whether the readonly attributes is present
|
||||
fn readonly(&self) -> bool {
|
||||
self.attrs.iter().any(|a| match *a {
|
||||
@ -229,6 +237,7 @@ pub enum BindgenAttr {
|
||||
IndexingSetter,
|
||||
IndexingDeleter,
|
||||
Structural,
|
||||
HostBinding,
|
||||
Readonly,
|
||||
JsName(String, Span),
|
||||
JsClass(String),
|
||||
@ -262,6 +271,9 @@ impl Parse for BindgenAttr {
|
||||
if attr == "structural" {
|
||||
return Ok(BindgenAttr::Structural);
|
||||
}
|
||||
if attr == "host_binding" {
|
||||
return Ok(BindgenAttr::HostBinding);
|
||||
}
|
||||
if attr == "readonly" {
|
||||
return Ok(BindgenAttr::Readonly);
|
||||
}
|
||||
@ -549,7 +561,7 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a Option<String>)> for syn::ForeignItemFn
|
||||
js_ret,
|
||||
catch,
|
||||
variadic,
|
||||
structural: opts.structural(),
|
||||
structural: opts.structural() || !opts.host_binding(),
|
||||
rust_name: self.ident.clone(),
|
||||
shim: Ident::new(&shim, Span::call_site()),
|
||||
doc_comment: None,
|
||||
|
Reference in New Issue
Block a user