Skip to content

Commit

Permalink
Rename host_binding to final
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Nov 9, 2018
1 parent 2c9084d commit cb246e3
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 32 deletions.
21 changes: 11 additions & 10 deletions crates/macro-support/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ impl BindgenAttrs {
})
}

/// Whether the `host_binding` attribute is present
fn host_binding(&self) -> Option<&Ident> {
/// Whether the `final` attribute is present
fn final_(&self) -> Option<&Ident> {
self.attrs.iter().filter_map(|a| match a {
BindgenAttr::HostBinding(i) => Some(i),
BindgenAttr::Final(i) => Some(i),
_ => None,
}).next()
}
Expand Down Expand Up @@ -237,7 +237,7 @@ pub enum BindgenAttr {
IndexingSetter,
IndexingDeleter,
Structural,
HostBinding(Ident),
Final(Ident),
Readonly,
JsName(String, Span),
JsClass(String),
Expand All @@ -249,7 +249,8 @@ pub enum BindgenAttr {
impl Parse for BindgenAttr {
fn parse(input: ParseStream) -> SynResult<Self> {
let original = input.fork();
let attr: Ident = input.parse()?;
let attr: AnyIdent = input.parse()?;
let attr = attr.0;
if attr == "catch" {
return Ok(BindgenAttr::Catch);
}
Expand All @@ -271,8 +272,8 @@ impl Parse for BindgenAttr {
if attr == "structural" {
return Ok(BindgenAttr::Structural);
}
if attr == "host_binding" {
return Ok(BindgenAttr::HostBinding(attr))
if attr == "final" {
return Ok(BindgenAttr::Final(attr))
}
if attr == "readonly" {
return Ok(BindgenAttr::Readonly);
Expand Down Expand Up @@ -555,9 +556,9 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a Option<String>)> for syn::ForeignItemFn
ShortHash(data)
)
};
if let Some(ident) = opts.host_binding() {
if let Some(ident) = opts.final_() {
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 {
Expand All @@ -566,7 +567,7 @@ impl<'a> ConvertToAst<(BindgenAttrs, &'a Option<String>)> for syn::ForeignItemFn
js_ret,
catch,
variadic,
structural: opts.structural() || opts.host_binding().is_none(),
structural: opts.structural() || opts.final_().is_none(),
rust_name: self.ident.clone(),
shim: Ident::new(&shim, Span::call_site()),
doc_comment: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ use wasm_bindgen::prelude::*;
extern "C" {
type Foo;

#[wasm_bindgen(method, structural, host_binding)]
#[wasm_bindgen(method, structural, final)]
fn bar(this: &Foo);
}
8 changes: 8 additions & 0 deletions crates/macro/ui-tests/structural-and-final.stderr
Original file line number Diff line number Diff line change
@@ -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

8 changes: 0 additions & 8 deletions crates/macro/ui-tests/structural-and-host-binding.stderr

This file was deleted.

2 changes: 1 addition & 1 deletion guide/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
- [`constructor`](./reference/attributes/on-js-imports/constructor.md)
- [`extends`](./reference/attributes/on-js-imports/extends.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)
- [`js_class = "Blah"`](./reference/attributes/on-js-imports/js_class.md)
- [`js_name`](./reference/attributes/on-js-imports/js_name.md)
Expand Down
2 changes: 1 addition & 1 deletion guide/src/reference/attributes/on-js-imports/final.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ prototype chain of an object.

The `final` attribute is intended to be purely related to performance. It
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
proposal][host-bindings] then `wasm-bindgen` will need to generate far fewer JS
Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions tests/wasm/host_binding.rs → tests/wasm/final.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ use wasm_bindgen_test::*;
#[wasm_bindgen]
extern "C" {
type Math;
#[wasm_bindgen(static_method_of = Math, host_binding)]
#[wasm_bindgen(static_method_of = Math, final)]
fn log(f: f32) -> f32;
}

#[wasm_bindgen(module = "tests/wasm/host_binding.js")]
#[wasm_bindgen(module = "tests/wasm/final.js")]
extern "C" {
type MyType;
#[wasm_bindgen(constructor, host_binding)]
#[wasm_bindgen(constructor, final)]
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;
#[wasm_bindgen(method, host_binding)]
#[wasm_bindgen(method, final)]
fn bar(this: &MyType, arg: bool) -> f32;

#[wasm_bindgen(method, getter, host_binding)]
#[wasm_bindgen(method, getter, final)]
fn a(this: &MyType) -> u32;
#[wasm_bindgen(method, setter, host_binding)]
#[wasm_bindgen(method, setter, final)]
fn set_a(this: &MyType, a: u32);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/wasm/import_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ extern "C" {
fn switch_methods_a();
fn switch_methods_b();
type SwitchMethods;
#[wasm_bindgen(constructor, host_binding)]
#[wasm_bindgen(constructor, final)]
fn new() -> SwitchMethods;
#[wasm_bindgen(js_namespace = SwitchMethods, host_binding)]
#[wasm_bindgen(js_namespace = SwitchMethods, final)]
fn a();
fn switch_methods_called() -> bool;
#[wasm_bindgen(method, host_binding)]
#[wasm_bindgen(method, final)]
fn b(this: &SwitchMethods);

type Properties;
Expand Down
3 changes: 2 additions & 1 deletion tests/wasm/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ pub mod comments;
pub mod duplicate_deps;
pub mod duplicates;
pub mod enums;
pub mod host_binding;
#[path = "final.rs"]
pub mod final_;
pub mod import_class;
pub mod imports;
pub mod js_objects;
Expand Down

0 comments on commit cb246e3

Please sign in to comment.