mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-13 21:11:22 +00:00
Rename host_binding
to final
This commit is contained in:
@ -149,10 +149,10 @@ impl BindgenAttrs {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether the `host_binding` attribute is present
|
/// Whether the `final` attribute is present
|
||||||
fn host_binding(&self) -> Option<&Ident> {
|
fn final_(&self) -> Option<&Ident> {
|
||||||
self.attrs.iter().filter_map(|a| match a {
|
self.attrs.iter().filter_map(|a| match a {
|
||||||
BindgenAttr::HostBinding(i) => Some(i),
|
BindgenAttr::Final(i) => Some(i),
|
||||||
_ => None,
|
_ => None,
|
||||||
}).next()
|
}).next()
|
||||||
}
|
}
|
||||||
@ -237,7 +237,7 @@ pub enum BindgenAttr {
|
|||||||
IndexingSetter,
|
IndexingSetter,
|
||||||
IndexingDeleter,
|
IndexingDeleter,
|
||||||
Structural,
|
Structural,
|
||||||
HostBinding(Ident),
|
Final(Ident),
|
||||||
Readonly,
|
Readonly,
|
||||||
JsName(String, Span),
|
JsName(String, Span),
|
||||||
JsClass(String),
|
JsClass(String),
|
||||||
@ -249,7 +249,8 @@ pub enum BindgenAttr {
|
|||||||
impl Parse for BindgenAttr {
|
impl Parse for BindgenAttr {
|
||||||
fn parse(input: ParseStream) -> SynResult<Self> {
|
fn parse(input: ParseStream) -> SynResult<Self> {
|
||||||
let original = input.fork();
|
let original = input.fork();
|
||||||
let attr: Ident = input.parse()?;
|
let attr: AnyIdent = input.parse()?;
|
||||||
|
let attr = attr.0;
|
||||||
if attr == "catch" {
|
if attr == "catch" {
|
||||||
return Ok(BindgenAttr::Catch);
|
return Ok(BindgenAttr::Catch);
|
||||||
}
|
}
|
||||||
@ -271,8 +272,8 @@ impl Parse for BindgenAttr {
|
|||||||
if attr == "structural" {
|
if attr == "structural" {
|
||||||
return Ok(BindgenAttr::Structural);
|
return Ok(BindgenAttr::Structural);
|
||||||
}
|
}
|
||||||
if attr == "host_binding" {
|
if attr == "final" {
|
||||||
return Ok(BindgenAttr::HostBinding(attr))
|
return Ok(BindgenAttr::Final(attr))
|
||||||
}
|
}
|
||||||
if attr == "readonly" {
|
if attr == "readonly" {
|
||||||
return Ok(BindgenAttr::Readonly);
|
return Ok(BindgenAttr::Readonly);
|
||||||
@ -555,9 +556,9 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a Option<String>)> for syn::ForeignItemFn
|
|||||||
ShortHash(data)
|
ShortHash(data)
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
if let Some(ident) = opts.host_binding() {
|
if let Some(ident) = opts.final_() {
|
||||||
if opts.structural() {
|
if opts.structural() {
|
||||||
bail_span!(ident, "cannot specify both `structural` and `host_binding`");
|
bail_span!(ident, "cannot specify both `structural` and `final`");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(ast::ImportKind::Function(ast::ImportFunction {
|
Ok(ast::ImportKind::Function(ast::ImportFunction {
|
||||||
@ -566,7 +567,7 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a Option<String>)> for syn::ForeignItemFn
|
|||||||
js_ret,
|
js_ret,
|
||||||
catch,
|
catch,
|
||||||
variadic,
|
variadic,
|
||||||
structural: opts.structural() || opts.host_binding().is_none(),
|
structural: opts.structural() || opts.final_().is_none(),
|
||||||
rust_name: self.ident.clone(),
|
rust_name: self.ident.clone(),
|
||||||
shim: Ident::new(&shim, Span::call_site()),
|
shim: Ident::new(&shim, Span::call_site()),
|
||||||
doc_comment: None,
|
doc_comment: None,
|
||||||
|
@ -6,6 +6,6 @@ use wasm_bindgen::prelude::*;
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
type Foo;
|
type Foo;
|
||||||
|
|
||||||
#[wasm_bindgen(method, structural, host_binding)]
|
#[wasm_bindgen(method, structural, final)]
|
||||||
fn bar(this: &Foo);
|
fn bar(this: &Foo);
|
||||||
}
|
}
|
8
crates/macro/ui-tests/structural-and-final.stderr
Normal file
8
crates/macro/ui-tests/structural-and-final.stderr
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
error: cannot specify both `structural` and `final`
|
||||||
|
--> $DIR/structural-and-final.rs:9:40
|
||||||
|
|
|
||||||
|
9 | #[wasm_bindgen(method, structural, final)]
|
||||||
|
| ^^^^^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
@ -1,8 +0,0 @@
|
|||||||
error: cannot specify both `structural` and `host_binding`
|
|
||||||
--> $DIR/structural-and-host-binding.rs:9:40
|
|
||||||
|
|
|
||||||
9 | #[wasm_bindgen(method, structural, host_binding)]
|
|
||||||
| ^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: aborting due to previous error
|
|
||||||
|
|
@ -61,7 +61,7 @@
|
|||||||
- [`constructor`](./reference/attributes/on-js-imports/constructor.md)
|
- [`constructor`](./reference/attributes/on-js-imports/constructor.md)
|
||||||
- [`extends`](./reference/attributes/on-js-imports/extends.md)
|
- [`extends`](./reference/attributes/on-js-imports/extends.md)
|
||||||
- [`getter` and `setter`](./reference/attributes/on-js-imports/getter-and-setter.md)
|
- [`getter` and `setter`](./reference/attributes/on-js-imports/getter-and-setter.md)
|
||||||
- [`host_binding`](./reference/attributes/on-js-imports/host_binding.md)
|
- [`final`](./reference/attributes/on-js-imports/final.md)
|
||||||
- [`indexing_getter`, `indexing_setter`, and `indexing_deleter`](./reference/attributes/on-js-imports/indexing-getter-setter-deleter.md)
|
- [`indexing_getter`, `indexing_setter`, and `indexing_deleter`](./reference/attributes/on-js-imports/indexing-getter-setter-deleter.md)
|
||||||
- [`js_class = "Blah"`](./reference/attributes/on-js-imports/js_class.md)
|
- [`js_class = "Blah"`](./reference/attributes/on-js-imports/js_class.md)
|
||||||
- [`js_name`](./reference/attributes/on-js-imports/js_name.md)
|
- [`js_name`](./reference/attributes/on-js-imports/js_name.md)
|
||||||
|
@ -12,7 +12,7 @@ prototype chain of an object.
|
|||||||
|
|
||||||
The `final` attribute is intended to be purely related to performance. It
|
The `final` attribute is intended to be purely related to performance. It
|
||||||
ideally has no user-visible effect, and `structural` imports (the default)
|
ideally has no user-visible effect, and `structural` imports (the default)
|
||||||
should be able to transparently switch to `host_binding` eventually.
|
should be able to transparently switch to `final` eventually.
|
||||||
|
|
||||||
The eventual performance aspect is that with the [host bindings
|
The eventual performance aspect is that with the [host bindings
|
||||||
proposal][host-bindings] then `wasm-bindgen` will need to generate far fewer JS
|
proposal][host-bindings] then `wasm-bindgen` will need to generate far fewer JS
|
||||||
|
@ -4,23 +4,23 @@ use wasm_bindgen_test::*;
|
|||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern "C" {
|
extern "C" {
|
||||||
type Math;
|
type Math;
|
||||||
#[wasm_bindgen(static_method_of = Math, host_binding)]
|
#[wasm_bindgen(static_method_of = Math, final)]
|
||||||
fn log(f: f32) -> f32;
|
fn log(f: f32) -> f32;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen(module = "tests/wasm/host_binding.js")]
|
#[wasm_bindgen(module = "tests/wasm/final.js")]
|
||||||
extern "C" {
|
extern "C" {
|
||||||
type MyType;
|
type MyType;
|
||||||
#[wasm_bindgen(constructor, host_binding)]
|
#[wasm_bindgen(constructor, final)]
|
||||||
fn new(x: u32) -> MyType;
|
fn new(x: u32) -> MyType;
|
||||||
#[wasm_bindgen(static_method_of = MyType, host_binding)]
|
#[wasm_bindgen(static_method_of = MyType, final)]
|
||||||
fn foo(a: &str) -> String;
|
fn foo(a: &str) -> String;
|
||||||
#[wasm_bindgen(method, host_binding)]
|
#[wasm_bindgen(method, final)]
|
||||||
fn bar(this: &MyType, arg: bool) -> f32;
|
fn bar(this: &MyType, arg: bool) -> f32;
|
||||||
|
|
||||||
#[wasm_bindgen(method, getter, host_binding)]
|
#[wasm_bindgen(method, getter, final)]
|
||||||
fn a(this: &MyType) -> u32;
|
fn a(this: &MyType) -> u32;
|
||||||
#[wasm_bindgen(method, setter, host_binding)]
|
#[wasm_bindgen(method, setter, final)]
|
||||||
fn set_a(this: &MyType, a: u32);
|
fn set_a(this: &MyType, a: u32);
|
||||||
}
|
}
|
||||||
|
|
@ -32,12 +32,12 @@ extern "C" {
|
|||||||
fn switch_methods_a();
|
fn switch_methods_a();
|
||||||
fn switch_methods_b();
|
fn switch_methods_b();
|
||||||
type SwitchMethods;
|
type SwitchMethods;
|
||||||
#[wasm_bindgen(constructor, host_binding)]
|
#[wasm_bindgen(constructor, final)]
|
||||||
fn new() -> SwitchMethods;
|
fn new() -> SwitchMethods;
|
||||||
#[wasm_bindgen(js_namespace = SwitchMethods, host_binding)]
|
#[wasm_bindgen(js_namespace = SwitchMethods, final)]
|
||||||
fn a();
|
fn a();
|
||||||
fn switch_methods_called() -> bool;
|
fn switch_methods_called() -> bool;
|
||||||
#[wasm_bindgen(method, host_binding)]
|
#[wasm_bindgen(method, final)]
|
||||||
fn b(this: &SwitchMethods);
|
fn b(this: &SwitchMethods);
|
||||||
|
|
||||||
type Properties;
|
type Properties;
|
||||||
|
@ -18,7 +18,8 @@ pub mod comments;
|
|||||||
pub mod duplicate_deps;
|
pub mod duplicate_deps;
|
||||||
pub mod duplicates;
|
pub mod duplicates;
|
||||||
pub mod enums;
|
pub mod enums;
|
||||||
pub mod host_binding;
|
#[path = "final.rs"]
|
||||||
|
pub mod final_;
|
||||||
pub mod import_class;
|
pub mod import_class;
|
||||||
pub mod imports;
|
pub mod imports;
|
||||||
pub mod js_objects;
|
pub mod js_objects;
|
||||||
|
Reference in New Issue
Block a user