Commit Graph

151 Commits

Author SHA1 Message Date
Benjamin Kampmann
8b08fc16c5 Making ArrayBufferView & BufferSource a union 2018-09-06 16:23:39 +02:00
Benjamin Kampmann
031ba39036 Bump weedle version 2018-09-06 16:22:26 +02:00
Benjamin Kampmann
cb8411b346 Add BufferSource && ArrayBufferView to &[u8] 2018-09-06 16:22:24 +02:00
Alex Crichton
269c491380
Gate web-sys APIs on activated features (#790)
* Gate `web-sys` APIs on activated features

Currently the compile times of `web-sys` are unfortunately prohibitive,
increasing the barrier to using it. This commit updates the crate to instead
have all APIs gated by a set of Cargo features which affect what bindings are
generated at compile time (and which are then compiled by rustc). It's
significantly faster to activate only a handful of features vs all thousand of
them!

A magical env var is added to print the list of all features that should be
generated, and then necessary logic is added to ferry features from the build
script to the webidl crate which then uses that as a filter to remove items
after parsing. Currently parsing is pretty speedy so we'll unconditionally parse
all WebIDL files, but this may change in the future!

For now this will make the `web-sys` crate a bit less ergonomic to use as lots
of features will need to be specified, but it should make it much more
approachable in terms of first-user experience with compile times.

* Fix AppVeyor testing web-sys

* FIx a typo

* Udpate feature listings from rebase conflicts

* Add some crate docs and such
2018-09-05 12:55:30 -07:00
Alex Crichton
c6d3011cff
Merge pull request #785 from afdw/master
Add initial support for unions in return types, add more fixes for case of identifiers
2018-09-05 09:26:42 -07:00
Anton Danilkin
e5f382eccf Remove support for non-object unions, add more comments 2018-09-05 18:15:02 +03:00
Alex Crichton
6b0cea73cd Fix regression of missing documentation
I forgot to add MDN docs for #765 to member operations, but this commit adds
them back!

Closes #786
2018-09-04 14:52:56 -07:00
Anton Danilkin
fcd890a70e Remove dead code 2018-09-04 21:03:23 +03:00
Anton Danilkin
095f86fa51 Use object type whenever possible 2018-09-03 21:37:58 +03:00
Alex Crichton
1a00e94324
Merge pull request #726 from derekdreery/variadic_js_functions
Support variadic javascript function parameters
2018-09-03 10:28:58 -07:00
Anton Danilkin
75ac7ca64e Fix nullable union types 2018-09-02 20:37:12 +03:00
Anton Danilkin
ff516d0211 Add initial support for unions in return types, add more fixes for case of identifiers 2018-09-02 15:09:51 +03:00
Richard Dodd
e279987fa4 Merge remote-tracking branch 'upstream/master' into variadic_js_functions 2018-09-01 22:24:27 +01:00
Alex Crichton
cfb4be8d3c Handle [Unforgeable] on interfaces
In addition to handling it on methods look like it also shows up on interfaces!

Closes #780
2018-08-31 17:38:34 -07:00
Richard Dodd
ce1cb84327 Merge branch 'master' into variadic_js_functions 2018-08-31 10:08:53 +01:00
Alex Crichton
3204c514ab Fix typos 2018-08-30 22:31:03 -07:00
Alex Crichton
c9c776b0b4 Review comments 2018-08-30 16:29:51 -07:00
Alex Crichton
dd3dba9285 Delete lots of now-unused code 2018-08-30 12:54:54 -07:00
Alex Crichton
923abc7d85 Migrate constructors to new naming scheme 2018-08-30 12:54:54 -07:00
Alex Crichton
5a4a34d4a1 Migrate methods to new naming scheme
Allows deletion of `create_basic_method`!
2018-08-30 12:54:54 -07:00
Alex Crichton
15d4338abe Reimplement name disambiguation on overloading
This commit reimplements how we disambiguate function names on overloading.
Previously functions would be first be disambiguated if they had multiple
instances of the same name, and *then* functions would be disambiguated
aftewards by if their arguments expanded to more than one type to generate.

This commit instead collects everything into one list during the first pass.
This one list contains all signatures known for a given name. Later this list is
walked in one pass to generate all methods necessary, expanding names all at
once instead of two steps.

This should improve the naming of methods across multiple functions which also
have optional arguments. Support in this commit is just enough for namespaces,
but following commits will update the strategy for mixins/interfaces.
Additionally only new code was added in this commit which duplicates a lot of
functionality, but subsequent commits will remove the old code that will
eventually no longer be used.
2018-08-30 12:54:54 -07:00
Alex Crichton
0a18ca4490 Minor tweaks to first_pass.rs
Nothing much of consequence
2018-08-30 12:54:54 -07:00
Alex Crichton
6cf3b90e63 Deindent a few helper functions in dictionaries
No need for it to be an inner function now that it's using methods!
2018-08-30 12:54:54 -07:00
Alex Crichton
4f76a00024 Refactor creation of functions in the backend
This commit refactors the lowest-level primitive for creating functions into a
new `create_one_function` function. This doesn't take into account overloading
but is suitable for things like `create_{getter,setter}`. Eventually the
overloading will be implemented in terms of this function.
2018-08-30 12:54:54 -07:00
Alex Crichton
0a38e44f1f Refactor a method for listing all mixins
This'll hopefully be reusable in more than one location!
2018-08-30 12:54:54 -07:00
Alex Crichton
b9dc937d73 Refactor WebIDL code generation
This commit refactors WebIDL code generation to walk over the fields of
`FirstPassRecord` instead of walking the AST again. This helps remove
redundancies like checking `is_chrome_only` as well as revisiting partial
interfaces and such. This should make it more clear that the first pass's job is
to walk the AST and collect all relevant information, while the codegen pass is
purely about appending items to a `Program`.

Additionally this refactoring will also soon be used to prepare different data
structures for operation overloadings, avoiding the need to walk those ASTs
twice.
2018-08-30 12:54:54 -07:00
Alex Crichton
e25feccc11 webidl: Remove support for Uint8ClampedArray
Our bindings currently translate this to `&[u8]` which is actually `Uint8Array`.
We'll need to fix #421 before supporting this.
2018-08-30 10:34:50 -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
ddc42738cf Tweak some WebIDL type names in methods
Instead of `dom_str`, `byte_str`, and `usv_str`, emit `str` for all of them.
Similarly for `unrestricted_f64` just do `f64` instead. This reflects how we
interpret the types already in terms of Rust types and although technically
makes it possible to have name collisions in WebIDL they don't come up in
practice.
2018-08-20 10:32:04 -07:00
Alex Crichton
92b7de3d3d Skip args in overloaded method names if all same
This commit updates how we name overloaded methods. Previously all argument
names were concatenated, but after this commit it only concatenates argument
names where at least one possibility has a different type. Otherwise if all
possibilities have the same type name it in theory isn't adding too much more
information!

Additionally this commit also switches to using `_with_` consistently everywhere
instead of `_with_` for constructors and `_using_` for methods.

Closes #712
2018-08-20 10:30:02 -07:00
Richard Dodd
003cf102f1 Fix webidl 2018-08-19 14:28:45 +01:00
Alex Crichton
57693ee11a Bump to 0.2.17 2018-08-16 23:36:42 -07:00
R. Andrew Ohana
25b6f5d982
Merge pull request #702 from alexcrichton/dictionaries
Implement support for WebIDL dictionaries
2018-08-16 13:06:06 -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
Nick Fitzgerald
69cc7725d6 webidl: Add some more logging for debugging code generation 2018-08-15 16:57:23 -07:00
Nick Fitzgerald
88582ec47c webidl: Fix warning about partial interfaces without non-partial definition 2018-08-15 16:57:23 -07:00
Nick Fitzgerald
21063fd42f webidl: Make logging a little more consistently formatted
This commit makes these changes:

* Unsupported constructs always log "unsupported" for easy `grep`ing
* There is always a "<generic message> : <details>" format now, so we can easily
  use `cut` to grab the generic message and count which kinds of things are our
  biggest missing features.
* Make sure that we have different `warn!` logs for each kind of unsupported
  thing, instead of grouping them together.

Put all that together and this is the current state of `wasm-bindgen-webidl` and
`web-sys`:

```
$ grep WARN stderr.txt | grep wasm_bindgen_webidl | grep -i unsupported | cut -d ' ' -f5- | cut -d ':' -f 1 | sort | uniq -c | sort -rn
    387 Unsupported WebIDL Dictionary definition
    139 Unsupported argument type
     70 Unsupported return type
     47 Unsupported WebIDL Callback definition
     22 Unsupported WebIDL extended attribute
     18 Unsupported unnamed operation
      9 Unsupported WebIDL CallbackInterface definition
      7 Unsupported WebIDL Stringifier interface member
      7 Unsupported WebIDL Maplike interface member
      2 Unsupported webidl stringifier
      2 Unsupported WebIDL Setlike interface member
      2 Unsupported stringifier on type
```
2018-08-15 14:24:09 -07:00
Nick Fitzgerald
c1f7b42662 web-sys: Provide more info in logs when type conversion fails 2018-08-15 11:45:45 -07:00
Alex Crichton
f5ab32a8bc Translate WebIDL promise type to js_sys::Promise
This does involve us losing the type argument present in the WebIDL, but for now
that should be fine as we're exposing low-level bindings and it's not otherwise
clear whether having a typed wrapper is a great option. Usage of `JsCast` can
convert the incoming value to a different object fairly easily.

The purpose of the `web-sys` crate is to expose functionality of the web, not
necessarily take an opinionated stance on how it should be exposed. In that
sense it should be able to work with the `Promise` as you would a typed promise
in terms of no functionality is left out. That being said we'll likely want to
be sure to reconsider this before 1.0-stabilizing the `web-sys` crate!
2018-08-14 15:52:52 -07:00
Alex Crichton
dce4a88f7d Generate const mixin bindings
Whenever an interface includes a mixin which includes consts, inline the consts
onto the interface.
2018-08-13 21:58:40 -07:00
Alex Crichton
03eb1b1d01 Support named "special" operations in WebIDL
This commit adds support for two different features of the "special" operations
in WebIDL. First, it implements the desugaring [described by WebIDL][1] where
this:

    interface Dictionary {
      getter double getProperty(DOMString propertyName);
      setter void setProperty(DOMString propertyName, double propertyValue);
    };

becomes ...

    interface Dictionary {
      double getProperty(DOMString propertyName);
      void setProperty(DOMString propertyName, double propertyValue);

      getter double (DOMString propertyName);
      setter void (DOMString propertyName, double propertyValue);
    };

where specifically a named `getter` generates both a getter and a named
function.

Second it implements the distinction between two different types of getters in
WebIDL, described as:

> Getters and setters come in two varieties: ones that take a DOMString as a
> property name, known as named property getters and named property setters, and
> ones that take an unsigned long as a property index, known as indexed property
> getters and indexed property setters.

The name `get` is given to DOMString arguments, and the name `get_idx` is given
to index property getters.

[1]: https://heycam.github.io/webidl/#idl-special-operations
2018-08-13 17:52:34 -07:00
Nick Fitzgerald
8974a57fb9 Bump to version 0.2.16 2018-08-13 14:27:10 -07:00
Anton Danilkin
c666f752fa Add OptionalAndUnionArguments test 2018-08-13 23:18:16 +03:00
Anton Danilkin
f35296f8ac Merge branch 'master' of https://github.com/rustwasm/wasm-bindgen 2018-08-13 18:59:52 +03:00
Richard Dodd
833099dd0d Fix error 2018-08-12 13:11:53 +01:00
Richard Dodd
e66d4da835 Fix some of @ohanar issues 2018-08-12 12:11:09 +01:00
Anton Danilkin
e92374a8c8 Migrate to IdlType 2018-08-11 23:46:33 +03:00
Richard Dodd
eaacdc8966 Mark that link is checked; 2018-08-11 12:57:45 +01:00