Commit Graph

1008 Commits

Author SHA1 Message Date
Alex Crichton
c9c776b0b4 Review comments 2018-08-30 16:29:51 -07:00
Alex Crichton
de6aa6c97e Automatically change the schema version on all publishes
Closes #773
2018-08-30 13:26:07 -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
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
5ed7b806d1 Fix getStringFromWasm for shared memory
We currently pass a raw view into wasm's memory for `getStringFromWasm`, but if
the memory is actually shared then `TextDecoder` rejects `SharedArrayBuffer` and
won't actually decode anything. Work around this for now with an extra copy into
a local buffer, and then pass that buffer to `getStringFromWasm` whenever memory
is shared.
2018-08-28 10:58:26 -07:00
Alex Crichton
f7e6fa2a04 Bump dependency on parity-wasm to 0.32.0
Brings support for atomic instructions!
2018-08-28 10:12:56 -07:00
Nick Fitzgerald
26c351ecf4 js-sys: Make MDN URLs into links 2018-08-27 15:18:48 -07:00
Alex Crichton
d9bc0a3176 Bump to 0.2.19 2018-08-27 13:39:23 -07:00
Alex Crichton
c89182b1fd Merge remote-tracking branch 'origin/master' into bump 2018-08-27 13:38:53 -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
e1474110d4 Add an accessor for wasm's own memory as a JS object
In addition to closing #495 this'll be useful eventually when instantiating
multiple wasm modules from Rust as you'd now be able to acquire a reference to
the current module in Rust itself.
2018-08-27 11:05:55 -07:00
Alex Crichton
85fd49f90a Fix importing same types in two modules/crates
This'll hopefully fix fallout from 4f4da747ad
2018-08-27 09:59:47 -07:00
Alex Crichton
9fc43f8a19
Merge pull request #752 from alexcrichton/remove-hack
Remove a hack around an LLVM bug
2018-08-26 15:43:07 -07:00
Alex Crichton
856892d11d
Merge pull request #750 from alexcrichton/import-memory
Add support for modules importing memory
2018-08-26 15:42:24 -07:00
Alex Crichton
335c0b1ab6 Add support for modules importing memory
The default of Rust wasm binaries is to export the memory that they contain, but
LLD also supports an `--import-memory` option where memory is imported into a
module instead. It's looking like importing memory is along the lines of how
shared memory wasm modules will work (they'll all import the same memory).

This commit adds support to wasm-bindgen to support modules which import memory.
Memory accessors are tweaked to no longer always assume that the wasm module
exports its memory. Additionally JS bindings will create a `memory` option
automatically because LLD always imports memory from an `env` module which won't
actually exist.
2018-08-26 15:41:36 -07:00
Alex Crichton
0cd04ca85e
Merge pull request #749 from alexcrichton/wasm-memory
Add WebAssembly.Memory to js-sys
2018-08-26 15:40:58 -07:00
Alex Crichton
bb7ca348c2 Add WebAssembly.Memory to js-sys
This adds definitions for the `WebAssembly.Memory` type to `js-sys`.
2018-08-26 15:40:37 -07:00
Alex Crichton
4f4da747ad Remove a hack around an LLVM bug
This has since been fixed in rust-lang/rust#52506
2018-08-25 10:45:51 -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
Roberto Huertas
042cfad5ce feat(extends): extend promise 2018-08-24 02:15:02 +02: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
bf791efe2c Fix wasm-interpreter with mixed types of imports
We counted all imports until the index of the descriptor function, now we only
count imported functions
2018-08-20 16:18:09 -07:00
Alex Crichton
6343f2659a Remove dependency on wasmi
This is a pretty heavyweight dependency which accounts for a surprising amount
of runtime for larger modules in `wasm-bindgen`. We don't need 90% of the crate
and so this commit bundles a small interpreter for instructions we know are only
going to appear in describe-related functions.
2018-08-20 15:14:56 -07:00
Alex Crichton
7486fa5104
Merge pull request #710 from RazerM/master
Add more WebAssembly bindings
2018-08-20 14:17:24 -07:00
Alex Crichton
2972599ee3 Fix some mistakes from WeakRef support
* Be sure to free the pointer, not `this.ptr` which is always 0
* Unconditionally attempt to free data and let Rust throw an exception if it's
  null
2018-08-20 14:14:55 -07:00
Frazer McLean
1ea1410f98 Catch errors in Table and Module constructors 2018-08-20 22:12:29 +02:00
Frazer McLean
7432f5ff5c Merge branch 'master' of git://github.com/rustwasm/wasm-bindgen 2018-08-20 21:55:42 +02: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
ccae331b2a
Merge pull request #740 from alexcrichton/catch-constructors
Fix the `constructor` and `catch` attributes combined
2018-08-20 11:37:02 -07:00
Alex Crichton
61491eafbf Add experimental support for WeakRef
This commit adds experimental support for `WeakRef` to be used to automatically
free wasm objects instead of having to always call the `free` function manually.
Note that when enabled the `free` function for all exported objects is still
generated, it's just optionally invoked by the application.

Support isn't exposed through a CLI flag right now due to the early stages of
the `WeakRef` proposal, but the env var `WASM_BINDGEN_WEAKREF` can be used to
enable this generation. Upon doing so the output can then be edited slightly as
well to work in the SpiderMonkey shell and it looks like this is working!

Closes #704
2018-08-20 11:18:02 -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
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
Alex Crichton
a4bf239eff
Merge pull request #739 from Hywan/string-replace-regexp
feat(js-sys) Implement `String.replace(&str, …)`
2018-08-20 07:55:05 -07:00
Ivan Enderlin
1e27b588e2
feat(js-sys) Implement String.replace(&str, …). 2018-08-20 11:01:56 +02:00
Ivan Enderlin
a9a1e69f30
feat(js-sys) Implement String.split with regexp. 2018-08-20 10:42:12 +02:00
Alex Crichton
6d49c76bc4
Merge pull request #734 from alexcrichton/stabilize
Remove `use_extern_macros` features
2018-08-19 18:12:00 -07:00
Frazer McLean
19ee28d769 Don’t need catch for Module static methods 2018-08-20 01:50:27 +02:00
Alex Crichton
d4297ad2d3 Remove use_extern_macros features
This has now been stabilized!
2018-08-19 14:33:01 -07:00
Danielle Pham
4f294224f0 Add bindings for String.prototype.split 2018-08-19 15:09:45 -04:00
Danielle Pham
8698084a43 Add binding for String.prototype.search 2018-08-19 14:52:10 -04:00
Danielle Pham
44877880bb Add bindings for String.prototype.replace 2018-08-19 14:42:22 -04:00
Danielle Pham
7b53b1c88e Add binding for String.prototype.match 2018-08-19 13:59:00 -04:00
Mason Stallmo
b330bd1bf1 Refactor inheritance checks into their own tests 2018-08-19 11:27:04 -05:00
Mason Stallmo
1762b3cba0 Add extends to js-sys:Intl.PluralRules 2018-08-19 11:03:55 -05:00
Mason Stallmo
ee131888da Add extends to js-sys:Intl.NumberFormat 2018-08-19 10:19:03 -05:00
Mason Stallmo
780c7236f1 Add extends to js-sys:Intl.DateTimeFormat 2018-08-19 10:13:25 -05:00
Mason Stallmo
f0811d5ac0 Add extends to js-sys:Intl.Collater 2018-08-19 10:03:56 -05:00
Richard Dodd
003cf102f1 Fix webidl 2018-08-19 14:28:45 +01:00
Richard Dodd
7c83c73919 Comment typo 2018-08-19 13:41:23 +01:00
Richard Dodd
a4835304eb Add codegen to make test work. 2018-08-19 13:39:16 +01:00
Alex Crichton
9c6225fd80
Merge pull request #720 from kraai/patch-1
Test for and add extends attributes
2018-08-18 22:15:30 -07:00
Alex Crichton
1fd52b08a3
Merge pull request #724 from eminence/partial_mixin
Fix missing WindowOrWorkerGlobalScope partial interface mixins.
2018-08-18 22:10:17 -07:00
Alex Crichton
3697ddf4c0
Merge pull request #723 from mstallmo/add-extends-to-js-sys
Add extends attributes for js_sys:Generator
2018-08-18 22:09:16 -07:00
Alex Crichton
a12fc46a55
Merge pull request #728 from quelledanielle/js_string_from_code_point
Add bindings for String.from_code_point
2018-08-18 22:08:48 -07:00
Danielle Pham
27d48ad267 Add bindings for String.from_code_point 2018-08-18 21:35:38 -04:00
Danielle Pham
00a0152adf Rename local param to locale 2018-08-18 21:05:12 -04:00
Danielle Pham
0d3f706195 Add binding for String.prototype.localeCompare 2018-08-18 21:05:02 -04:00
Richard Dodd
d9fd2147a0 [wip] support variadic javascript function parameters 2018-08-18 22:15:29 +01:00
Andrew Chin
302f7ba21d Fix missing WindowOrWorkerGlobalScope partial interface mixins.
Without the "mixin" keyword, wasm_bindgen_webidl would report:

     Partial interface WindowOrWorkerGlobalScope missing non-partial interface

Also, including the "mixin" keyword here is consistent with the official
webidl spec (for example see https://fetch.spec.whatwg.org/#fetch-method)
2018-08-18 11:23:29 -04:00
Mason Stallmo
c543b5d149 Add extends attributes for js_sys:Generator 2018-08-18 09:11:07 -05:00
Frazer McLean
751f226170 Merge branch 'master' of git://github.com/rustwasm/wasm-bindgen 2018-08-18 01:58:11 +02:00
Matt Kraai
6dccb7f777 Remove blank line
Part of #670
2018-08-17 14:50:15 -07:00
Matt Kraai
bec3178e3c Make all errors extend Object
Part of #670
2018-08-17 13:10:56 -07:00
Matt Kraai
687412ec50 Test for AsRef implementations
Part of #670
2018-08-17 13:09:30 -07: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
37068cb47f Fix tests on nightly 2018-08-16 23:25:57 -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
Frazer McLean
ffccfdee7d WebAssembly::Table::new takes an object 2018-08-16 20:41:07 +02:00
Frazer McLean
b519c290f9 futures should be a dev dependency 2018-08-16 20:40:19 +02:00
Matt Kraai
c8d0c57990 Check that all errors are instances of Object
Part of #670
2018-08-16 07:14:12 -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
b8afa0abde web-sys: Use mixins instead of [NoInterfaceObject] interfaces and implements
I think these might all be from before WebIDL mixins existed. Either way,
multiple inheritance of interfaces that don't have exposed interface objects is
equivalent to mixins.
2018-08-15 16:57:23 -07:00
Nick Fitzgerald
69cc7725d6 webidl: Add some more logging for debugging code generation 2018-08-15 16:57:23 -07:00
Nick Fitzgerald
9616ef3633 web-sys: Remove a bunch of mozilla extensions from our webidl 2018-08-15 16:57:23 -07:00
Nick Fitzgerald
703e2a3fbe web-sys: Fix typedef of nsISupports
The JS Object type is named "object" in webidl, not "Object".
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
13fe2b4aca
Merge pull request #709 from fitzgen/webidl-and-logging
Webidl and logging
2018-08-15 15:09:53 -07:00
Frazer McLean
b698eb5d6a Add more WebAssembly bindings 2018-08-15 23:45:28 +02:00
Sendil Kumar N
190b45d59c
Merge pull request #708 from sendilkumarn/extends-arr
Adds Extends to TypedArrays
2018-08-15 23:45:04 +02:00
Nick Fitzgerald
ea137a951b web-sys: Remove a few more interfaces from gecko's test suite 2018-08-15 14:34:59 -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
Sendil Kumar
af9ecac296 js-sys: Add extends attributes for js_sys::Float64Array
address review comments

add review comments
2018-08-15 22:50:27 +02:00
Nick Fitzgerald
c1f7b42662 web-sys: Provide more info in logs when type conversion fails 2018-08-15 11:45:45 -07:00
Nick Fitzgerald
a40f83ea1b web-sys: Remove a bunch of non-standard, Mozilla-specific Web IDL 2018-08-15 11:12:22 -07:00
Nick Fitzgerald
6b5beda8d1 web-sys: Add a type alias to Object from nsISupports 2018-08-15 10:54:50 -07:00
Alex Crichton
a45676045e
Merge pull request #705 from alexcrichton/promise
Translate WebIDL `promise` type to `js_sys::Promise`
2018-08-14 21:41:25 -07:00
Alex Crichton
b15ebf27a8
Merge pull request #687 from eminence/misc_fixes
Misc fixes and enable tests on appveyor
2018-08-14 18:59:44 -07:00
Andrew Chin
156eb24359 Use raw string in paths in webidl-tests generated code
This fixes things on Windows, which uses backslashes in their paths
2018-08-14 19:11:58 -04:00
Andrew Chin
ca5e7b8542 Fix for some unused import warnings 2018-08-14 19:11:38 -04:00
Alex Crichton
da95415bec
Merge pull request #697 from thomaseizinger/bindings/remaining-intl-bindings
Add remaining bindings for the Intl namespace
2018-08-14 15:54:18 -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
Nick Fitzgerald
79f9d966e5
Merge pull request #698 from alexcrichton/const-mixins
Generate const mixin bindings
2018-08-14 11:27:33 -07:00
Sendil Kumar
d9fbc48daa js-sys: Add extends attributes for js_sys::Float32Array 2018-08-14 19:38:33 +02:00
Sendil Kumar
10bc69a8cd js-sys: Add extends attributes for js_sys::Int32Array 2018-08-14 19:34:59 +02:00
Sendil Kumar
2d737c5634 js-sys: Add extends attributes for js_sys::Int16Array 2018-08-14 19:34:43 +02:00
Sendil Kumar
17ef5f9702 js-sys: Add extends attributes for js_sys::Int8Array 2018-08-14 19:34:26 +02:00
Sendil Kumar
b80090d395 js-sys: Add extends attributes for js_sys::UInt32Array 2018-08-14 19:32:34 +02:00
Sendil Kumar
e58e231fdf js-sys: Add extends attributes for js_sys::UInt16Array 2018-08-14 19:32:14 +02:00
Sendil Kumar
2979618842 js-sys: Add extends attributes for js_sys::UInt8ClampedArray 2018-08-14 19:31:49 +02:00
Sendil Kumar
ea0ac134db js-sys: Add extends attributes for js_sys::Uint8Array 2018-08-14 19:29:13 +02:00
gnzlbg
5ab54a4094
Remove warning, was fixed with the 0.2.16 release 2018-08-14 10:02:30 +02: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
Thomas Eizinger
44f2ac0e9f Add bindings for Intl.NumberFormat and Intl.PluralRules 2018-08-14 13:46:06 +10:00
Thomas Eizinger
ade4a2c97a Fix typo in Intl.DateTimeFormat documentation 2018-08-14 13:45:49 +10: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
Alex Crichton
c0c27775f3
Merge pull request #681 from sepiropht/master
[670] add extends for some types
2018-08-13 18:39:53 -06:00
Alex Crichton
595162b35d
Merge pull request #691 from thomaseizinger/bindings/intl-datetimeformat
Add bindings for Intl.DateTimeFormat
2018-08-13 18:23:57 -06:00
sepiropht
96c24c47a2 add extends for JsString 2018-08-14 00:47:36 +02:00
Thomas Eizinger
ea74b8acba Add bindings for Intl.DateTimeFormat 2018-08-14 07:50:13 +10:00
Nick Fitzgerald
f4012defac futures: Add metadata to Cargo.toml 2018-08-13 14:35:35 -07:00
Nick Fitzgerald
a434880229 Bump js-sys to 0.2.1 2018-08-13 14:32:52 -07:00
Nick Fitzgerald
8974a57fb9 Bump to version 0.2.16 2018-08-13 14:27:10 -07:00
Nick Fitzgerald
ea27a172d9
Merge pull request #692 from quelledanielle/js_string_bindings
Add bindings for static method String.from_char_code
2018-08-13 14:27:00 -07:00
Danielle Pham
30fc99b724 Use u32 params for String.from_char_code bindings 2018-08-13 17:03:58 -04:00
Anton Danilkin
c666f752fa Add OptionalAndUnionArguments test 2018-08-13 23:18:16 +03:00
Anton Danilkin
7840367476 Fix console test 2018-08-13 20:09:18 +03:00
Anton Danilkin
f35296f8ac Merge branch 'master' of https://github.com/rustwasm/wasm-bindgen 2018-08-13 18:59:52 +03:00
Danielle Pham
fd5958b51b Add bindings for String.from_char_code 2018-08-13 00:19:43 -04:00
Danielle Pham
aa735d221a Use js_class for static method bindings as well 2018-08-12 23:16:18 -04: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
Richard Dodd
4f0ddd25ce Fix tests 2018-08-12 21:27:27 +01:00
Richard Dodd
23009dbc1e Add simple test for namespaces. 2018-08-12 21:11:02 +01: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
Richard Dodd
df1342398d Add support for partial namespaces 2018-08-11 12:50:18 +01:00
Richard Dodd
a23fa03ad0 Closer to finished
- Tried `cargo doc` and seen methods generated.
 - Added test with a few method calls to the console operations.
2018-08-11 12:38:58 +01:00
Sendil Kumar N
539e987cdb
Merge pull request #685 from fitzgen/a-few-more-js-sys-things
A few more js sys things
2018-08-11 07:52:26 +02:00
Nick Fitzgerald
36e15149c7 js-sys: Add bindings for TypeError 2018-08-10 13:45:39 -07:00
Nick Fitzgerald
38ef5f9ffe js-sys: Add bindings for SyntaxError 2018-08-10 13:42:13 -07:00
Nick Fitzgerald
a58c2584b3 js-sys: Add bindings to URIError 2018-08-10 13:37:34 -07:00
Nick Fitzgerald
4148d3b4ac macro-support: obey js_class = ... for constructor methods
Fixes #668
2018-08-10 13:36:47 -07:00
Nick Fitzgerald
2a3d01c380
Merge pull request #683 from eminence/json
Add initial support and tests for JSON
2018-08-10 13:27:40 -07:00
Nick Fitzgerald
7af4e62d99 js-sys: Add bindings for Symbol.unscopables 2018-08-10 13:23:17 -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
Nick Fitzgerald
178a5e89df js-sys: add bindings for regexp.lastIndex 2018-08-10 13:14:54 -07:00
Nick Fitzgerald
dc028d38c8 js-sys: Add bindings to ReferenceError 2018-08-10 13:03:56 -07:00
Nick Fitzgerald
879fd43edb js-sys: Add bindings to RangeError 2018-08-10 13:03:44 -07:00
Anton Danilkin
2c0e13a033 Move get_arguments_possibilities into a function 2018-08-10 22:17:29 +03:00
Nick Fitzgerald
adad606ee3 js-sys: Add bindings for Object.create 2018-08-10 11:49:22 -07:00
Nick Fitzgerald
4ea1603ddb js-sys: Add bindings to Object.assign 2018-08-10 11:41:58 -07:00
Andrew Chin
1092816652 Use Reflect::set instead of javascript helper 2018-08-10 14:33:21 -04:00
Nick Fitzgerald
f0444d1614 js-sys: Add bindings for Intl.Collator 2018-08-10 11:20:06 -07:00
Andrew Chin
f5203bba8a Handle exceptions from JSON::stringify 2018-08-10 14:13:57 -04:00
Richard Dodd
0d897e9b8d Unsure about error 2018-08-10 19:00:56 +01:00
Nick Fitzgerald
7f5d0a2158 js-sys: Move Intl from a type to a module, since it is a namespace 2018-08-10 10:46:53 -07:00
Nick Fitzgerald
a66c4de892 js-sys: remove extra new line 2018-08-10 10:40:43 -07:00
Nick Fitzgerald
e667400a83 js-sys: Remove unused import in symbol tests 2018-08-10 10:29:35 -07:00
Nick Fitzgerald
95c55d0b4c js-sys: Add bindings to Array.of 2018-08-10 10:29:22 -07:00
Richard Dodd
6c1f32fa5b Saving commit 2018-08-10 17:06:11 +01:00
Anton Danilkin
ce2c0ded74 Fix chrome only checks 2018-08-10 17:19:40 +03:00
Anton Danilkin
5ae18d18e9 Add macro for implementing simple type names 2018-08-10 16:43:06 +03:00
Anton Danilkin
90f172a34f Fix too much newlines 2018-08-10 15:56:57 +03:00
Anton Danilkin
22f92af124 Fix example in docs 2018-08-10 15:54:19 +03:00
Andrew Chin
23cb0ea656 Add initial support and tests for JSON 2018-08-09 20:54:13 -04:00
Alex Crichton
d390f2fe04
Merge pull request #680 from fitzgen/js-sys-promise-arguments-by-shared-ref
Js sys promise arguments by shared ref
2018-08-09 18:52:32 -06:00
Andrew Chin
70406fe18a Add support and tests for EvalError 2018-08-09 19:26:00 -04:00
Nick Fitzgerald
ff83594882 futures: Add sanity tests for conversion between Promises and Futures
Part of #614
2018-08-09 16:21:49 -07:00
Nick Fitzgerald
f9ac4e9c90 Always bind static operations to their class
For example, `Promise.resolve` must always be called with the `Promise`
constructor as its `this`, or else it will throw an error.
2018-08-09 16:17:34 -07:00
Anton Danilkin
e2af5639c5 Add documentation for GetArgumentPossibilities 2018-08-10 01:12:12 +03:00
Anton Danilkin
b6ba5cf4f1 Replace unwrap with expect 2018-08-10 00:55:46 +03:00
Anton Danilkin
d9d8f761f1 Add Exposed 2018-08-10 00:52:12 +03:00
Richard Dodd
615f8fbc4d Push updates - still WIP 2018-08-09 21:38:37 +01:00
Nick Fitzgerald
96ad97a9f9 js-sys: Document that new bindings should take JS things by shared ref 2018-08-09 13:08:51 -07:00
Nick Fitzgerald
e3011d629e js-sys: Promise methods should take JS things by shared reference 2018-08-09 13:08:30 -07:00
Anton Danilkin
5127dd3f95 Fix tests 2018-08-09 22:13:50 +03:00
Anton Danilkin
131f223241 Use argument names instead of argument type names if possible 2018-08-09 21:51:41 +03:00
Andrew Chin
c371c4a509 Fixup from merge commit 2018-08-09 14:36:37 -04:00
Nick Fitzgerald
f8af399301
Merge branch 'master' into extends_object 2018-08-09 10:57:15 -07: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
Alex Crichton
f85fd0e2ad
Merge pull request #675 from sepiropht/master
[670] add extends for Array type
2018-08-09 09:52:13 -05:00
Nick Fitzgerald
bd62fdbd8b
Merge pull request #672 from bokuweb/number-extends-attributes
js-sys: Add extends attributes for js_sys::Number
2018-08-09 07:35:35 -07:00
sepiropht
e9e7072687 [670] add extends for Array type 2018-08-09 14:35:44 +02:00
Alex Crichton
157ba00660
Merge pull request #673 from fitzgen/futures-docs
wasm-bindgen-futures docs and example usage
2018-08-08 23:23:48 -05:00
Andrew Chin
cc8095d065 Add extends attributes for several types
Part of #670
2018-08-08 23:16:57 -04:00
bokuweb
42e02f7769 js-sys: Add extends attributes for js_sys::Number 2018-08-09 10:10:20 +09:00
Alex Crichton
505037ffae
Merge pull request #669 from fitzgen/contributing-testing
Contributing testing docs
2018-08-08 19:50:00 -05:00
Nick Fitzgerald
170f20e1fd futures: Add more documentation and example usage
Adds an example future that becomes ready on the next tick of the JavaScript
micro task queue.

Part of #614
2018-08-08 17:44:38 -07:00
Nick Fitzgerald
235f9cc04e js-sys: Add extends attributes for js_sys::RegExp
Part of #670
2018-08-08 16:23:12 -07:00
Nick Fitzgerald
e8a6341d2b test: Add documentation about configuring headless browser testing 2018-08-08 15:47:46 -07:00
Nick Fitzgerald
66f10b0c72
Merge pull request #666 from fitzgen/instanceof-renamed-import-types
Instanceof renamed import types
2018-08-08 15:31:24 -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
gnzlbg
153505f6c7
Document workaround for avoiding duplicated symbols when using wasm-bindgen-test from git 2018-08-08 20:28:49 +02: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
Alex Crichton
0d18c8c397 Fix consuming a struct and returning a slice
This came up in a [recent comment][1] and it turns out we're accidentally
generating two `const ptr = ...` declarations, invalid JS! While Node doesn't
catch this it looks like firefox does.

[1]: https://github.com/rustwasm/wasm-bindgen/issues/329#issuecomment-411082013
2018-08-07 08:46:38 -07:00
Alex Crichton
b6a6dee7f1
Merge pull request #652 from afdw/master
Add support for getters, setters and deleters
2018-08-06 21:43:53 -05:00
Anton Danilkin
86b5ba6431 Add missing indexing words 2018-08-07 02:45:08 +03:00
Anton Danilkin
d396c168a5 Fix comments in parser 2018-08-07 00:48:03 +03:00
Anton Danilkin
3ad5493d23 Add a test for webidl 2018-08-07 00:42:47 +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
b2977a4262 Delete wasm-bindgen-test-project-builder
No more tests use it!
2018-08-06 11:48:34 -07: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
Alex Crichton
6edf063c94 Allow disabling --debug in wasm-bindgen-test-runner
Afterwards remove the `non_debug` test as we're running the entire test suite in
non-debug mode!
2018-08-06 09:57:41 -07:00
Camille TJHOA
aeca24c7ab Add ArrayBuffer.prototype.byteLength to js-sys 2018-08-06 11:44:24 -05:00
Alex Crichton
0bdb31d41e Migrate the serde-serialize test to wasm 2018-08-06 09:43:55 -07:00
Alex Crichton
f96fcf78a1 Explicitly ignore some extended attributes
Cut down on generated warnings by explicitly ignoring attributes which it looks
like we don't need to handle at all.
2018-08-06 10:56:12 -05:00
Alex Crichton
72fff9c43e Ignore implements items explicitly
No need to warn about them because there's not much to handle with them anyway!
2018-08-06 10:56:12 -05:00
Michael Hoffmann
73e89fc59b Add bindings for RegExp.$1-$9 2018-08-06 10:41:06 -05:00
Alex Crichton
e35295d376 Migrate from the webidl crate to weedle
This commit migrates the `wasm-bindgen-webidl` crate from the `webidl` parser to
`weedle`. The main rationale for doing this is that `webidl` depends on
`lalrpop`, which is quite a large dependency and takes a good deal of time to
compile. The `weedle` crate, however, depends on `nom` and is much faster to
compile.

Almost all translations were pretty straightforward. Some abstractions changed
and/or were introduced in this commit when moving to `weedle` like the
`ToSynType` trait, but otherwise the generated bindings should be the same. It's
been verified that the `weedle`-generated bindings are exactly the same as the
`webidl`-generated bindings, with the one exception of `weedle` generates one
more method, `WebGpuCommandEncoder::transition_buffer`. It's not clear currently
why `webidl` didn't generate this method, as its [idl] is pretty straightforward!

This commit is using a [fork] of `weedle` currently which has a number of fixes
for parsing our WebIDL, although all the fixes are quite minor!

Closes #620

[idl]: d66b834afd/crates/web-sys/webidls/enabled/WebGPU.webidl (L499)
[fork]: https://github.com/alexcrichton/weedle/tree/fix-for-web-sys
2018-08-06 10:27:03 -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
e9f9ede1fa Switch to openssl's vendored feature for musl builds
This should give us updates for free!
2018-08-05 10:40:08 -05:00
Anton Danilkin
5b66045aff Add a test 2018-08-05 10:39:54 -05:00
Anton Danilkin
ebab7d9fc8 Enable structural mode for all operations if there is a Global extended attribute on the interface 2018-08-05 10:39:54 -05:00
Alex Crichton
90579416cf Add WebIDL support for the object type
This maps to the `Object` type in the `js_sys` crate.
2018-08-05 01:04:28 -05:00
Alex Crichton
25a1bcb5be Fix tests on master 2018-08-04 15:16:02 -07:00
Alex Crichton
a98b5ea2a0 Add WebIDL support for the ArrayBuffer type
Should help enable a slew of new bindings as well.
2018-08-04 16:34:12 -05:00
Alex Crichton
5d4c135c31 Run Chrome headless tests on CI
Closes #622
2018-08-04 10:48:49 -05:00
Anton Danilkin
da9203142f Add applying of typedefs, remove generation of type aliases 2018-08-04 14:04:24 +03:00
Anton Danilkin
9c275d1f1d Use instantiateStreaming for --no-modules mode if possible 2018-08-03 22:34:59 -05:00
Tyler Wilcock
0624b0cf2e Add unit tests for even more 'web-sys' bindings
That list includes:
 * HtmlMenuElement
 * HtmlMenuItemElement
 * HtmlMetaElement
 * HtmlMeterElement
2018-08-03 17:41:38 -05: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
Anton Danilkin
afaf94a428 Add support for optional chars 2018-08-03 15:59:27 -05:00
Anton Danilkin
4a0c69ffed Add support for optional bools 2018-08-03 15:59:27 -05:00
Anton Danilkin
0ef528165f Rename functions, remove escaped newlines 2018-08-03 15:59:27 -05:00
Anton Danilkin
2249032ba8 Revert WebIDLs with optional enum types, they are still not implemented 2018-08-03 15:59:27 -05:00
Anton Danilkin
c49c18826d Add support for optional numbers 2018-08-03 15:59:27 -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
YUyz
3d3bf5dc83 add test for HTMLTableElement in web-sys crate (#629) 2018-08-03 09:02:31 -05:00
Alex Crichton
88db12669f Add support for Option<&T> in imported argument lists
Closes #619
2018-08-02 22:40:42 -07:00
Tyler Wilcock
d47fc61c36 Add unit tests for more 'web-sys' HTML bindings (#617)
That list includes:
 * HtmlOptionElement
 * HtmlOptGroupElement
 * HtmlOListElement
 * HtmlModElement
2018-08-02 18:40:32 -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
71dbd08c00
Default to headless testing for the test runner (#610)
We've gotten a number of reports that the interactive tests are a bit surprising
and confusing (also because it barely prints anything!). Instead let's default
to headless testing which matches the Rust style of testing much better.

The error message for a missing WebDriver binary has been updated with a note of
how to *not* do headless testing and the message for interactive testing was
also updated to display more information as well.
2018-08-02 10:30:07 -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
Tyler Wilcock
e3546863bb Add unit tests for various 'web-sys' HTML element bindings
That list includes:
 * HtmlOptionsCollection
 * HtmlOutputElement
 * HtmlParagraphElement
 * HtmlParamElement
 * HtmlPreElement
 * HtmlProgressElement
 * HtmlQuoteElement
 * HtmlSlotElement
2018-08-01 18:14:03 -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
6def60681b
Upgrade failure and fix deprecation warnings (#605) 2018-08-01 16:15:09 -05:00
Alex Crichton
eee71de0ce
Support asynchronous tests (#600)
* Tweak the implementation of heap closures

This commit updates the implementation of the `Closure` type to internally store
an `Rc` and be suitable for dropping a `Closure` during the execution of the
closure. This is currently needed for promises but may be generally useful as
well!

* Support asynchronous tests

This commit adds support for executing tests asynchronously. This is modeled
by tests returning a `Future` instead of simply executing inline, and is
signified with `#[wasm_bindgen_test(async)]`.

Support for this is added through a new `wasm-bindgen-futures` crate which is a
binding between the `futures` crate and JS `Promise` objects.

Lots more details can be found in the details of the commit, but one of the end
results is that the `web-sys` tests are now entirely contained in the same test
suite and don't need `npm install` to be run to execute them!

* Review tweaks

* Add some bindings for `Function.call` to `js_sys`

Name them `call0`, `call1`, `call2`, ... for the number of arguments being
passed.

* Use oneshots channels with `JsFuture`

It did indeed clean up the implementation!
2018-08-01 15:52:24 -05:00
Alex Crichton
4181afea45
Start migrating wasm_bindgen tests to wasm_bindgen_test (#602)
This commit starts migrating the `wasm_bindgen` tests to the `wasm_bindgen_test`
framework, starting to assemble the coffin for
`wasm-bindgen-test-project-builder`. Over time all of the tests in
`tests/all/*.rs` should be migrated to `wasm_bindgen_test`, although they may
not all want to go into a monolithic test suite so we can continue to test for
some more subtle situations with `#[wasm_bindgen]`.

In the meantime those, the `tests/all/api.rs` tests can certainly migrate!
2018-08-01 14:19:19 -05:00
Tyler Wilcock
c1f182cca7 Add unit test for HtmlSelectElement binding. (#598) 2018-08-01 00:01:03 -05:00
Jonathan Kingston
26a3e57536 Testing web-sys for input, heading and title elements. (#596) 2018-07-31 08:57:16 -07:00
Tyler Wilcock
05f3eec76d Fix web-sys history unit test (#592)
In an actual browser, the changing of the history using the binding
worked a little too well, and caused the test to fail if you refreshed
the page or manually used the back and forward buttons.  The stateful
stuff has been removed - the remaining two assertions should adequately
test that the binding works, which is the point of these tests anyways.
2018-07-31 06:55:30 -07:00
Tyler Wilcock
c971620039 Add unit test for HtmlHrElement web_sys binding (#591) 2018-07-30 18:25:48 -07:00
Alex Crichton
c760b2120a No need to work around ourselves any more 2018-07-30 11:10:48 -07:00
Alex Crichton
4282ec25bd Move web-sys tests to the new test framework
Migrate most `web-sys` tests to the new `wasm_bindgen_test` framework with the
new headless browser capabilities!
2018-07-30 11:07:07 -07:00
Alex Crichton
79e281128e Clarify test suite 2018-07-30 11:07:07 -07:00
Alex Crichton
ae034bb410 More descriptive error with no WebDriver binary 2018-07-30 11:07:07 -07:00
Alex Crichton
738372f769 Use Drop implementations instead of OnDrop 2018-07-30 11:07:07 -07:00
Alex Crichton
081f2fdc65 Add Function construtor to js-sys 2018-07-30 11:07:07 -07:00
Alex Crichton
8cd8ae6d10 Don't reformat browser errors 2018-07-30 11:07:07 -07:00
Alex Crichton
833024fe3e Don't reformat browser errors 2018-07-30 11:07:07 -07:00
Alex Crichton
851debbec1 Fix compile on Windows 2018-07-30 11:07:07 -07:00
Alex Crichton
a1ffa8abd3 Add some dox 2018-07-30 11:07:07 -07:00
Alex Crichton
7b4f0072c8 Add support for headless testing
This commit adds support to the `wasm-bindgen-test-runner` binary to
perform headless testing via browsers. The previous commit introduced a
local server to serve up files and run tests in a browser, and this
commit adds support for executing that in an automated fashion.

The general idea here is that each browser has a binary that implements
the WebDriver specification. These binaries (typically `foodriver` for
the browser "Foo") are interfaced with using HTTP and JSON messages. The
implementation was simple enough and the crates.io support was lacking
enough that a small implementation of the WebDriver protocol was added
directly to this crate.

Currently Firefox (`geckodriver`), Chrome (`chromedriver`), and Safari
(`safaridriver`) are supported for running tests. The test harness will
recognize env vars like `GECKODRIVER=foo` to specifically use one or
otherwise detects the first driver in `PATH`. Eventually we may wish to
automatically download a driver if one isn't found, but that isn't
implemented yet.

Headless testing is turned on with the `CI=1` env var currently to be
amenable with things like Travis and AppVeyor, but this may wish to grow
an explicit option to run headless tests in the future.
2018-07-30 11:07:07 -07:00
Alex Crichton
8fc40e4c0f Update test harness for browser testing
This commit updates the test harness for in-browser testing. It now no longer
unconditionally uses `fs.writeSync`, for example. Instead a `Formatter` trait is
introduced for both Node/browser environments and at runtime we detect which is
the appropriate one to use.
2018-07-30 11:07:07 -07:00
Alex Crichton
0770f830e7 Start supporting in-browser testing
This commit starts to add support for in-browser testing with
`wasm-bindgen-test-runner`. The current idea here is that somehow it'll be
configured and it'll spawn a little HTTP server serving up files from the
filesystem. This has been tested in various ways but isn't hooked up just yet,
wanted to make sure this was somewhat standalone! Future support for actually
running these tests will be coming in later commits.
2018-07-30 11:07:07 -07:00
Alex Crichton
7e16690f10
Migrate webidl tests to wasm_bindgen_test (#590)
This commit moves the `webidl/tests` folder to a new `crates/webidl-tests` crate
(to have a test-only build script) and ports them to the `#[wasm_bindgen_test]`
attribute, which should hopefully make testing much speedier for execution!
2018-07-30 11:06:29 -07: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
afdw
7fda07f797 Add renaming of conflicting constructors and operations (#579)
* Add renaming of conflicting constructors and operations

* Rename conflicting to overloaded

* Fix newlines

* Use or_insert_with, add a comment to TypeToString

* Use more Rust-like names

* Use opt instead of nullable

* Use argument names instead of argument types if possible

* Drop new for overloaded constructots

* Remove extra newline

* Move WebIDL files from unavailable_overloaded_fn

* Move RTCDataChannel, RTCPeerConnection and Selection to unavailable_option_primitive
2018-07-30 07:41:22 -07:00
Sendil Kumar N
c975895c98
Merge pull request #585 from twilco/master
Add web_sys binding for XPathResult
2018-07-30 07:04:03 +02:00
twilco
70f5183985 Add web_sys binding for XPathResult 2018-07-29 22:43:09 -05:00
Michael Hoffmann
f5f541337c Create bindings for RegExp (#580)
* Create bindings for RegExp

* Address review comments

- Split the constructor into two: `new` and `new_regexp`. This way we
  can write RegExp::new("foo", "g") rather than
  RegExp::new(&JsValue::from("foo"), "g").

- The js_name for the setter for lastIndex should be `lastIndex` and
  not `set_lastIndex`. But fixing this causes a panic. Remove the
  method for now.
2018-07-29 16:13:42 -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
konstin
0bd21b7bd2 Move the macro support code into its own crate (#529) 2018-07-29 08:59:46 -07:00
Jonathan Kingston
0f50f39079 Adding tests for script and style elements. (#578) 2018-07-28 14:44:41 -07:00
Jonathan Kingston
2a721737ab Add button element tests for web-sys. (#577) 2018-07-28 09:36:50 -07:00
Joel Gallant
01194558bf Adds Array.prototype.splice() to js-sys (#571) 2018-07-27 10:07:21 -07:00
Jonathan Kingston
67b43ee389 Adding in initial support for all HTML*Element interfaces. (#568)
* Adding in initial support for all HTML*Element interfaces.

* Fix camelcasing of short HTML interface names

* Disabling span test as breaks on taskcluster
2018-07-27 09:57:24 -07:00
Jonas Trollvik
037915827b
Fix incorrect url 2018-07-27 10:10:11 +02:00
Nick Fitzgerald
7da0220b10 test: Add cargo.toml metadata 2018-07-26 15:11:34 -07:00
Nick Fitzgerald
da1e16d46c test-macro: Add Cargo.toml metadata 2018-07-26 15:08:59 -07:00
Nick Fitzgerald
8ec9713dd9 js-sys: Add some more Cargo.toml metadata like license 2018-07-26 15:06:24 -07:00
Nick Fitzgerald
6203fc8f98 js-sys: Add a js-sys specific CHANGELOG.md 2018-07-26 15:05:00 -07:00
Nick Fitzgerald
9a0470b1c4 Bump to 0.2.15 2018-07-26 14:53:59 -07:00
Nick Fitzgerald
a204c8d4b7
Merge pull request #565 from fitzgen/js-sys-iterator-protocol
js-sys: Unify all iterators under one generic iterator type
2018-07-26 14:22:34 -07:00
Nick Fitzgerald
58482b07a8
Merge pull request #558 from alexcrichton/wasm2es6js
Simplify wasm2es6js output
2018-07-26 13:51:56 -07:00
Nick Fitzgerald
62de3bad67 js-sys: Unify all iterators under one generic iterator type
The JS iterator protocol uses duck typing and we don't need separate
ArrayIterator and SetIterator etc types, we can have a single iterator type for
the whole protocol.
2018-07-26 13:48:52 -07:00
Nick Fitzgerald
54109f9ccf
Merge pull request #556 from alexcrichton/fewer-copies
Optimize the execution time of wasm-bindgen tools
2018-07-26 12:38:25 -07:00
Nick Fitzgerald
b3458307a7
Merge pull request #557 from alexcrichton/pass-in-firefox
Tweak js-sys tests to pass in Firefox
2018-07-26 12:35:49 -07:00
Tyler Wilcock
ba98491fc1 Enable History Web API (#561)
* Add Number.isNaN() binding

* Add binding for Math.hypot()

* Implement Math.min() and Math.max() bindings

* Enable History API
2018-07-26 10:21:04 -07:00
Richard Dodd (dodj)
2c69d25289 Add file location information when failing to parse WebIDL files. (#562) 2018-07-26 10:09:04 -07:00
Alex Crichton
55a9ec1b21 Simplify wasm2es6js output
Currently it generates a lot of shim functions which delegate to the wasm module
when loaded, but it turns out with `export let` we can just update the bindings!
Instead of exporting a bunch of shims this updates the export functionality to
only update the `export let` directives with the direct values from the wasm
module once the module is done loading.
2018-07-25 16:56:43 -07:00
Alex Crichton
41200743af Tweak js-sys tests to pass in Firefox
Turns out date parsing is slightly different there!
2018-07-25 16:55:11 -07:00
Nick Fitzgerald
64591ef403 Js sys use &str arguments (#555)
* js-sys: imports should take &str parameters instead of &JsString

* js-sys: Imports should take Option<&str> instead of Option<String>
2018-07-25 18:50:30 -05:00
Alex Crichton
0992e45e7f Use std::fs read/write conveniences
In addition to being more ergonomic these are much more efficient at reading
large files as they preallocate internally. This provides a nice speed boost
locally, reducing the overhead of `wasm-bindgen-test-runner` from 0.23s to
0.19s, yay!
2018-07-25 16:08:42 -07:00