* 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
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.
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.
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.
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
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.
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
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
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
```
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!
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