Commit Graph

53 Commits

Author SHA1 Message Date
Alex Crichton
5df8e20815 Parse Paths in extends attributes
Closes #916
2018-10-03 09:14:23 -07:00
Alex Crichton
f75349262a Rename polyfill to vendor_prefix
cc #906
2018-10-01 14:45:30 -07:00
Alex Crichton
3c14f7a6eb Implement a polyfill attribute for imports
Allow using imported APIs under alternative names, such as prefixed
names, for web APIs when the exact API differs across browsers.
2018-09-28 13:43:00 -07:00
Alex Crichton
7ecf4aae87 cargo +nightly fmt --all
Rustfmt all the things!
2018-09-26 08:26:00 -07:00
Nick Fitzgerald
f834a427d7 Bump to version 0.2.23 (and js-sys and wasm-bindgen-futures to 0.3.0) 2018-09-26 07:31:54 -07:00
Alex Crichton
9a1fa5a81b
Merge pull request #870 from alexcrichton/no-constructor-token
Remove the need for a `ConstructorToken`
2018-09-21 21:40:08 -07:00
Alex Crichton
75f005be23 Support #[wasm_bindgen(setter, js_name = ...)]
Previously we'd require the explicit `js_name` to *also* start with
`set_`, but when explicitly specified it shouldn't be mangled at all!

Closes #584
2018-09-21 17:54:26 -07:00
Alex Crichton
3f85d7db9f Remove the need for a ConstructorToken
This commit removes the need for an injected `ConstructorToken` type and
also cleans up the story we have for generating constructors a bit.
After this commit a `constructor()` is omitted entirely if we're in
non-debug mode and there's no actual listed constructor. Additionally we
don't deal with splat arguments and rerouting constructors, Nick was
kind enough to enlighten me about `Object.create` which is creating an
instance without running the constructor!

Instances of an exported type are now created through one of two
methods:

* If `#[wasm_bindgen(constructor)]` is present, then a `constructor` is
  generated with the appropriate signature. If a constructor is not
  present and we're in debug mode, a throwing constructor is generated.
  If we're in release mode and there's no constructor, no constructor is
  generated.

* Otherwise if a binding returns an instance of a type (or otherwise
  needs to manfuacture an instance, then it will cause an internal
  `__wrap` function to be generated. This function will use
  `Object.create` to create an instance without running the constructor.

This should ideally clean up our generated JS for classes quite a bit,
making it much more lean-and-mean!
2018-09-21 17:42:06 -07:00
Alex Crichton
534cceafc8 Improve error message for infer_setter_property
If the setter doesn't start with `set_*` then we currently panic, but
panicking is bad! Instead let's thread through structured errors to make
sure they make their way to the top
2018-09-21 17:29:50 -07:00
Alex Crichton
51ec485c94 Bump to 0.2.22 2018-09-21 13:41:58 -07:00
Alex Crichton
5832ff3ca1
Merge pull request #847 from alexcrichton/fix-window
Move all methods on `Window` back to methods
2018-09-18 16:59:46 -07:00
Alex Crichton
7cf4213283 Allow returning Result from functions
This commit adds support for exporting a function defined in Rust that returns a
`Result`, translating the `Ok` variant to the actual return value and the `Err`
variant to an exception that's thrown in JS.

The support for return types and descriptors was rejiggered a bit to be a bit
more abstract and more well suited for this purpose. We no longer distinguish
between functions with a return value and those without a return value.
Additionally a new trait, `ReturnWasmAbi`, is used for converting return values.
This trait is an internal implementation detail, however, and shouldn't surface
itself to users much (if at all).

Closes #841
2018-09-18 13:13:59 -07:00
Alex Crichton
c67582a315 Remove support for scoped static methods
This is intended to address #834 where we don't actually want methods scoped
like this! Instead we'll provide one unique accessor for the `window` object
itself.
2018-09-17 17:36:53 -07:00
Alex Crichton
f18b10ca52 Bump to 0.2.21 2018-09-06 22:10:11 -07:00
Alex Crichton
8f9514d216 Update syn to 0.15
New and faster parsers!
2018-09-06 15:01:24 -07:00
Alex Crichton
9d5898ab48 Bump to 0.2.20 2018-09-06 14:49:43 -07:00
Richard Dodd
7d5d845608 Add docs and remove typecheck from variadic attribute 2018-09-01 13:55:35 +01:00
Richard Dodd
ce1cb84327 Merge branch 'master' into variadic_js_functions 2018-08-31 10:08:53 +01:00
Richard Dodd
958e557c86 try removing typecheck 2018-08-31 09:59:11 +01:00
Alex Crichton
1565459107
Merge pull request #761 from alexcrichton/more-globals
web-sys: Add support for `Global`-scope methods
2018-08-28 18:36:53 -07:00
Alex Crichton
0fb31b2bc4 Don't enable nightly feature of proc-macro2
This is no longer needed as of rustc 1.30.0 and the `proc-macro2` crate will now
automatically detect whether it can use spans or not!
2018-08-28 17:24:43 -07:00
Alex Crichton
36b854b69c web-sys: Add support for Global-scope methods
This commit adds further support for the `Global` attribute to not only emit
structural accessors but also emit functions that don't take `&self`. All
methods on a `[Global]` interface will not require `&self` and will call
functions and/or access properties on the global scope.

This should enable things like:

    Window::location() // returns `Location`
    Window::fetch(...) // invokes the `fetch` function

Closes #659
2018-08-28 17:20:31 -07:00
Alex Crichton
d9bc0a3176 Bump to 0.2.19 2018-08-27 13:39:23 -07:00
Alex Crichton
98008b9e77 Bump to 0.2.18
At the same time, also add a `publish.rs` script to ease our publishing woes.
2018-08-27 13:37:55 -07:00
Richard Dodd
e92536f300 Allow Vec as well as slice 2018-08-21 13:47:00 +01:00
Richard Dodd
496d8cadd8 Actually span makes more sense on whole function 2018-08-21 13:12:25 +01:00
Richard Dodd
5342a26fd0 Clean up checking code a bit 2018-08-21 13:11:53 +01:00
Richard Dodd
385e805509 Work on review comments 2018-08-21 12:55:09 +01:00
Alex Crichton
86d1ab513b
Merge pull request #741 from alexcrichton/duplicate-statics
Support importing same-name statics from two modules
2018-08-20 11:37:21 -07:00
Alex Crichton
f8cf4ab732 Support importing same-name statics from two modules
Closes #714
2018-08-20 10:56:58 -07:00
Alex Crichton
4195af68e7 Fix the constructor and catch attributes combined
This commit fixes annotations that include both the `constructor` and `catch`
attributes on imported types, ensuring that we infer the right type being
returned after extracting the first type parameter of the `Result`.

Closes #735
2018-08-20 10:40:54 -07:00
Richard Dodd
d9fd2147a0 [wip] support variadic javascript function parameters 2018-08-18 22:15:29 +01:00
Alex Crichton
57693ee11a Bump to 0.2.17 2018-08-16 23:36:42 -07:00
Nick Fitzgerald
8974a57fb9 Bump to version 0.2.16 2018-08-13 14:27:10 -07:00
Danielle Pham
aa735d221a Use js_class for static method bindings as well 2018-08-12 23:16:18 -04:00
Nick Fitzgerald
4148d3b4ac macro-support: obey js_class = ... for constructor methods
Fixes #668
2018-08-10 13:36:47 -07:00
Nick Fitzgerald
2f455f1f7a macro-support: Run rustfmt on src/parser.rs 2018-08-08 14:42:53 -07:00
Nick Fitzgerald
998d37a353 Use the JS name of an imported type for instanceof checks 2018-08-08 14:42:21 -07:00
Nick Fitzgerald
9104bf87e9 backend: Rename ast::ImportType::name to ast::ImportType::rust_name
This helps pave the way for adding a js_name, and makes it more clear which name
this is.
2018-08-07 16:09:38 -07:00
Alex Crichton
37db88ebfa Implement #[wasm_bindgen(extends = ...)]
This commit implements the `extends` attribute for `#[wasm_bindgen]` to
statically draw the inheritance hierarchy in the generated bindings, generating
appropriate `AsRef`, `AsMut`, and `From` implementations.
2018-08-07 13:04:11 -07:00
Alex Crichton
11553a1af2 Implement JsCast for all imported types
This commit implements the `JsCast` trait automatically for all imported types
in `#[wasm_bindgen] extern { ... }` blocks. The main change here was to generate
an `instanceof` shim for all imported types in case it's needed.

All imported types now also implement `AsRef<JsValue>` and `AsMut<JsValue>`
2018-08-07 12:59:51 -07:00
Anton Danilkin
d396c168a5 Fix comments in parser 2018-08-07 00:48:03 +03:00
Anton Danilkin
e70c9015ff Rename special to indexing 2018-08-07 00:06:04 +03:00
Anton Danilkin
ef3f086102 Merge remote-tracking branch 'upstream/master'
# Conflicts:
#	crates/webidl/src/first_pass.rs
#	crates/webidl/src/lib.rs
#	crates/webidl/src/util.rs
2018-08-06 23:37:12 +03:00
Alex Crichton
d5b81595ec Remove support for the version attribute
First added in #161 this never ended up panning out, so let's remove the
experimental suport which isn't actually used by anything today and hold off on
any other changes until an RFC happens.
2018-08-06 13:30:28 -05:00
Michael Hoffmann
21c36d3902 Allow js_name attribute to accept a string 2018-08-06 09:06:00 -05:00
Anton Danilkin
fd2b2140a9 Add support for getters, setters and deleters 2018-08-05 23:32:51 +03:00
Alex Crichton
2a6d98a6c9
Remove usage of syn's visit-mut feature (#631)
Looks like we're the only one in the dependency graph enabling this, so let's
try to cut down on compile times by not requiring it.
2018-08-03 14:11:44 -05:00
Alex Crichton
bdec2582aa
Result-ify src/parser.rs (#608)
* Make ConvertToAst trait fallible

It's got some panics, and we'll be switching those to errors!

* First example of a diagnostic-driven error

Add a diagnostic-driven error `#[wasm_bindgen]` being attached to public
functions, and add some macros to boot to make it easier to generate errors!

* Result-ify `src/parser.rs`

This commit converts all of `src/parser.rs` away from panics to using
`Diagnostic` instead. Along the way this adds a test case per changed `panic!`,
ensuring that we don't regress in these areas!
2018-08-01 18:59:59 -05:00
Alex Crichton
c4dcaee1b9
Prepare to have targeted error diagnostics (#604)
This commit starts to add infrastructure for targeted diagnostics in the
`#[wasm_bindgen]` attribute, intended eventually at providing much better errors
as they'll be pointing to exactly the code in question rather than always to a
`#[wasm_bindgen]` attribute.

The general changes are are:

* A new `Diagnostic` error type is added to the backend. A `Diagnostic` is
  created with a textual error or with a span, and it can also be created from a
  list of diagnostics. A `Diagnostic` implements `ToTokens` which emits a bunch
  of invocations of `compile_error!` that will cause rustc to later generate
  errors.

* Fallible implementations of `ToTokens` have switched to using a new trait,
  `TryToTokens`, which returns a `Result` to use `?` with.

* The `MacroParse` trait has changed to returning a `Result` to propagate errors
  upwards.

* A new `ui-tests` crate was added which uses `compiletest_rs` to add UI tests.
  These UI tests will verify that our output improves over time and does not
  regress. This test suite is added to CI as a new builder as well.

* No `Diagnostic` instances are created just yet, everything continues to panic
  and return `Ok`, with the one exception of the top-level invocations of
  `syn::parse` which now create a `Diagnostic` and pass it along.

This commit does not immediately improve diagnostics but the intention is that
it is laying the groundwork for improving diagnostics over time. It should
ideally be much easier to contribute improved diagnostics after this commit!

cc #601
2018-08-01 17:15:27 -05:00