Commit Graph

162 Commits

Author SHA1 Message Date
Richard Dodd
ce1cb84327 Merge branch 'master' into variadic_js_functions 2018-08-31 10:08:53 +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
Alex Crichton
9729efe50e Remove casting to &mut T for JS casts
I discussed this with @fitzgen awhile back and this sort of casting seems
especially problematic when you have code along the lines of:

    let mut x: HtmlElement = ...;
    {
        let y: &mut JsValue = x.as_ref();
        *y = 3.into();
    }
    x.some_html_element_method();

as that will immediately throw! We didn't have a use case for mutable casting
other than consistency, so this commit removes it for now. We can possibly add
it back in later if motivated, but for now it seems reasonable to try to avoid
these sorts of pitfalls!
2018-08-24 20:45:11 -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
Alex Crichton
a4e8fb6686 Fix compile on latest nightly 2018-08-16 23:30:40 -07:00
Alex Crichton
d6e48195b3 Implement support for WebIDL dictionaries
This commit adds support for generating bindings for dictionaries defined in
WebIDL. Dictionaries are associative arrays which are simply objects in JS with
named keys and some values. In Rust given a dictionary like:

    dictionary Foo {
        long field;
    };

we'll generate a struct like:

    pub struct Foo {
        obj: js_sys::Object,
    }

    impl Foo {
        pub fn new() -> Foo { /* make a blank object */ }

        pub fn field(&mut self, val: i32) -> &mut Self {
            // set the field using `js_sys::Reflect`
        }
    }

    // plus a bunch of AsRef, From, and wasm abi impls

At the same time this adds support for partial dictionaries and dictionary
inheritance. All dictionary fields are optional by default and hence only have
builder-style setters, but dictionaries can also have required fields. Required
fields are exposed as arguments to the `new` constructor.

Closes #241
2018-08-15 17:08:27 -07:00
Andrew Chin
ca5e7b8542 Fix for some unused import warnings 2018-08-14 19:11:38 -04:00
Nick Fitzgerald
8974a57fb9 Bump to version 0.2.16 2018-08-13 14:27:10 -07:00
Anton Danilkin
f35296f8ac Merge branch 'master' of https://github.com/rustwasm/wasm-bindgen 2018-08-13 18:59:52 +03:00
R. Andrew Ohana
36fe4c23dc
Merge pull request #678 from derekdreery/webidl_namespace_support
Add support webidl namespaces.
2018-08-12 17:41:54 -07:00
Nick Fitzgerald
016449ab3c backend: when complaining about setter names, show the name we are complaining about 2018-08-10 13:15:12 -07:00
Richard Dodd
0d897e9b8d Unsure about error 2018-08-10 19:00:56 +01:00
Richard Dodd
6c1f32fa5b Saving commit 2018-08-10 17:06:11 +01:00
Richard Dodd
615f8fbc4d Push updates - still WIP 2018-08-09 21:38:37 +01:00
Anton Danilkin
703b1ab91d Add support for unions in arguments and for optional arguments 2018-08-09 20:49:28 +03:00
Richard Dodd
1e02ca7eab Add support for modules to the backend. 2018-08-09 18:07:41 +01: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
Alex Crichton
f3f11ed8eb Clean up generated code for imported types
Group all the generated impls in a `const` block so we can use `use` without
clashing with the outside scope.
2018-08-07 12:59:51 -07: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
Anton Danilkin
da9203142f Add applying of typedefs, remove generation of type aliases 2018-08-04 14:04:24 +03:00
Anton Danilkin
07b4ef5838 Add support for empty enum variants and enum variants that start with a digit 2018-08-03 17:41:24 -05: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
4a78769349
Convert some more macro panics to diagnostics (#611)
This should hopefully be the last of the manually written diagnostics!
2018-08-02 11:12:50 -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
Alex Crichton
d876475ce3
Fix some situations with duplicate imports (#589)
* Fix importing the same identifier from two modules

This needed a fix in two locations:

* First the generated descriptor function needed its hash to include the module
  that the import came from in order to generate unique descriptor functions.
* Second the generation of the JS shim needed to handle duplicate identifiers in
  a more uniform fashion, ensuring that imported names didn't clash.

* Fix importing the same name in two modules

Previously two descriptor functions with duplicate symbols were emitted, and now
only one function is emitted by using a global table to keep track of state
across macro invocations.
2018-07-30 10:50:43 -07:00
Richard Dodd (dodj)
71255acf5d Try to enable all webidls (#573)
* Try to enable all webidls

* Separate out unavailable webidl files by reason.

* Create record of fully tested WebIDL files

* Update notes to reflect new situation with web-idl

* Make a blank ident fail, disable the necessary widls.

It turns out that all the blank idents came from blank enum variants,
which is allowed in webidl apparently.
2018-07-29 16:07:19 -07:00
Jonathan Kingston
b7af4e3169 Add documentation and MDN links for webidl files. Fixes #513 (#581) 2018-07-29 09:12:36 -07:00
Nick Fitzgerald
9a0470b1c4 Bump to 0.2.15 2018-07-26 14:53:59 -07:00
Alex Crichton
19acb5bb72
Only emit static descriptors on wasm (#554)
This is a bit of a refinement of the solution from #548 to make sure that these
statics are only present on the `wasm32-*` targets, as otherwise these
descriptors are completely inert on other platforms!
2018-07-25 16:56:27 -05:00
Nick Fitzgerald
dbb498174e
Merge pull request #547 from derekdreery/extra_docs
Extra docs
2018-07-25 12:04:29 -07:00
Richard Dodd
66bc98cc4b Fix mistakes/nits. 2018-07-25 18:08:57 +01:00
Nick Fitzgerald
3f5a0fb31c Bump to 0.2.14 2018-07-25 09:46:45 -07:00
Chinedu Francis Nwafili
c8f0304163
Fix LLVM ERROR
fixes #545
2018-07-25 07:24:39 -04:00
Richard Dodd
ba67089501 Some docs for functions in the parsing/codegen crates. 2018-07-25 11:42:01 +01:00
Richard Dodd
2ee80a6c44 Add some docs 2018-07-24 17:37:49 +01:00
Jonathan Kingston
4b4bed5ce2 Initial support for Document, EventTarget, NodeList and Iterator (#541)
* Adding document and node support

* Initial support for Document, EventTarget, NodeList and Iterator

* Add in support for output option type
2018-07-24 09:00:46 -05:00
Stephan Wolski
b3ee71c20b WebIDL: Handle Invalid Enum Returns (#477)
* move ImportEnum attributes to a property

* borrow from_js_value argument

* make WebIDL enums non-exhaustive

* add more tests for WebIDL enums
2018-07-23 10:04:28 -05:00