Commit Graph

704 Commits

Author SHA1 Message Date
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
Alex Crichton
f3942229fe More reuse of a parity_wasm::Module in the test runner
This commit updates the test runner to only deserialize a `Module` once and then
directly pass it to the `wasm-bindgen` config, avoiding pulling in a public
dependency with the same strategy as the `wasm-gc-api` crate for now.

This reduces the runtime of this step for `wasm-bindgen-test-runner` from ~0.23s
to ~0.19s on my machine.
2018-07-25 15:49:50 -07:00
Alex Crichton
764302cfcc Reuse the same parity_wasm::Module instance for wasmi
Since `wasmi` already has a public dependency on `parity_wasm` let's just use
it! A `clone` is much faster than a serialize + parse, reducing a `wasm-bindgen`
invocation on my machine from 0.2s to 0.18s.
2018-07-25 15:42:56 -07:00
Alex Crichton
9b5d47f5e1 Avoid serializing/reparsing modules during gc
Currently the `wasm-gc-api` crate doesn't expose `parity_wasm::Module` as a
public dependency which means that whenever we want to run a GC (which is twice
per `wasm-bindgen` invocation) we have to serialize and reparse the module a
lot! The `wasm-bindgen` has to serialize, `wasm-gc` then parses, `wasm-gc` then
serializes, and `wasm-bindgen` then parses.

This commit sidesteps all of these operations by ensuring that we always use the
same `parity_wasm::Module` instance, even when multiple versions of the
`parity_wasm` crate are in use. We'll get a speed boost when they happen to
align (which they always should for `wasm-bindgen`), but it'll work even if they
aren't aligned (by going through serialization).

Concretely on my machine this takes a `wasm-bindgen` invocation from 0.5s to
0.2s, a nice win!
2018-07-25 15:42:07 -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
61fc8d2567 Js sys once over (#550)
* js-sys: Return `f64` instead of `Number`

* js-sys: remove trailing whitespace

* js-sys: Ensure that all imported types derive Clone and Debug

* js-sys: Imported functions should always take JS object arguments by-ref
2018-07-25 16:33:44 -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
Tyler Wilcock
cefe1681ab Implement Math.min() and Math.max() bindings (#542)
* Add Number.isNaN() binding

* Add binding for Math.hypot()

* Implement Math.min() and Math.max() bindings
2018-07-23 23:50:29 -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
Tyler Wilcock
5fddcf3868 Add Math.hypot binding (#538)
* Add Number.isNaN() binding

* Add binding for Math.hypot()
2018-07-23 09:11:03 -05:00
Marcin Baraniecki
de0ba29abc implements bindings for Object.is (#537)
* implements bindings for Object.is

* adds counterpart test cases for non-equal values
2018-07-22 12:42:10 -05:00
Alex Crichton
82c2dfa7b2
Bump to 0.2.13 (#536) 2018-07-21 23:10:47 -05:00
Alex Crichton
6679ddfefc Move final js-sys test to a headless suite
Hopefully this doesn't need to get too large over time!
2018-07-21 20:09:45 -07:00
Alex Crichton
59c04e26d4 Port Reflect tests to wasm 2018-07-21 20:07:55 -07:00
Alex Crichton
906cd7adcc Remove usage of wasm_import_module feature
This is now stabilized! Also tweak usage of it to the stable version.
2018-07-21 19:00:40 -07:00
Sendil Kumar
2ef4b74ca6 add unescape 2018-07-21 23:06:36 +02:00
Tyler Wilcock
b7acb0785d Add Number.isNaN() binding (#532) 2018-07-21 15:19:30 -05:00
Alex Crichton
2da77fb8b0 Merge the cli and test-runner packages
Shouldn't be any need to have them versioned separately!
2018-07-20 22:42:36 -07:00
Alex Crichton
2e5cc810c8 Migrate tests for global functions to wasm 2018-07-20 17:45:00 -07:00
Alex Crichton
5f87ed4cef Port WebAssembly tests to wasm 2018-07-20 17:09:50 -07:00
Alex Crichton
9f7eea1e75 Port WeakSet tests to wasm 2018-07-20 17:07:00 -07:00
Alex Crichton
1d1df09e60 Port WeakMap tests to wasm 2018-07-20 17:01:26 -07:00
Alex Crichton
b667cafb63 Port TypedArray tests to wasm 2018-07-20 16:31:29 -07:00
Alex Crichton
df3530a9c2 Port Symbol and SetIterator tests to wasm 2018-07-20 16:19:10 -07:00
Alex Crichton
54abca7344 Port Set tests to wasm 2018-07-20 15:44:15 -07:00
Alex Crichton
ad86c52b02 Port Proxy tests to wasm 2018-07-20 15:35:15 -07:00
Alex Crichton
01ff04d85c Port Object tests to wasm 2018-07-20 15:23:56 -07:00
Alex Crichton
fb6041cf3b Port Number tests to wasm 2018-07-20 14:35:44 -07:00
Alex Crichton
627ddcb192 Port Math tests to wasm 2018-07-20 14:21:29 -07:00
Alex Crichton
230f923fdb Port MapIterator tests to wasm 2018-07-20 13:57:18 -07:00
Alex Crichton
2c9a606c3d Port Map tests to wasm 2018-07-20 13:46:22 -07:00
Alex Crichton
f3e34d854d Port JsString tests to wasm 2018-07-20 13:35:46 -07:00
Alex Crichton
d76f619298 Port Intl tests to wasm 2018-07-20 13:00:44 -07:00
Alex Crichton
067de51e57 Port Generator tests to wasm 2018-07-20 12:56:32 -07:00
Alex Crichton
f3d4a20ec7 Change Function::apply to catch the result
We don't know whether it'll throw or not!
2018-07-20 12:44:21 -07:00
Alex Crichton
75215134a5 Migrate Function tests to wasm 2018-07-20 12:43:07 -07:00
Alex Crichton
347c1daad9 Tweak instructions in js-sys/src/lib.rs 2018-07-20 12:27:03 -07:00
Alex Crichton
20e9267775 Port Error tests to wasm 2018-07-20 12:21:41 -07:00
Alex Crichton
cc8e7edd83 Revert "Explicitly ignore "Exposed" attributes"
This reverts commit 81150492a5.
2018-07-20 12:15:25 -07:00
Alex Crichton
601b138296 Port Date tests to wasm 2018-07-20 12:07:41 -07:00
Alex Crichton
81150492a5 Explicitly ignore "Exposed" attributes
It looks like these are primarily targeted at informing whether functionality is
either on web workers, windows, or both. For now we'll generate the same
bindings regardless, and users will need to be proactive about what they're
using. In that case there shouldn't be any need for us to process these, so
avoid warning about them!
2018-07-20 12:07:39 -07:00
Alex Crichton
efd6b2abac Migrate Array tests to wasm-bindgen-test 2018-07-20 11:48:57 -07:00
Alex Crichton
f8d336d711
Add a test harness to directly execute wasm tests (#524)
* Add a test harness to directly execute wasm tests

This commits adds a few new crates and infrastructure to enable comands like:

    cargo test --target wasm32-unknown-unknown

The intention here is to make it as low-friction as possible to write wasm tests
and also have them execute in a reasonable amount of time. Eventually this is
also hopefully enough support to do things like headless testing!

For now though this is defintely MVP status rather than fully fleshed out.
There's some more information at `crates/test/README.md` about how it works and
how to use it, but for now this is mainly intended to play around with locally
in this repository for our own tests.

* Port a numbe of `js-sys` tests to the new test framework

This commit ports a number of existing tests for the `js-sys` crate over to the
new test framework created in the previous commit, showing off how they can be
executed as well as drastictlly simplifying the tests themselves! This is
intended to be a proof of concept for now which we can refine over time. This
should also show off that it's possible to incrementally move over to the new
test framework.
2018-07-20 13:47:49 -05:00
Alex Crichton
9753f9150b
Allow renaming exported functions into JS (#525)
Support the `js_name` attribute on exports as well as imports to allow exporting
types as camelCase instead of snake_case, for example.

Closes #221
2018-07-20 12:01:28 -05:00
Richard Dodd (dodj)
ff1eb345e0 Link to docs in README. (#522) 2018-07-20 10:41:07 -05:00
T. Nagasawa
bec1c95b5c bindings for to_locale_XXX_case (#523) 2018-07-20 09:03:29 -05:00
Alex Crichton
2d70a51370 Publication cleanup 2018-07-19 13:03:52 -07:00
Alex Crichton
aa348f963f
Bump to 0.2.12 (#515)
* Bump to 0.2.12

* Update all version numbers and deps
* Update all listed authors to `["The wasm-bindgen Developers"]`
* Update `repository` links to specific paths for each crate
* Update `homepage` links to the online book
* Update all links away from `alexcrichton/wasm-bindgen`
* Add `#[doc]` directives for HTML URLs

* Update more version requirements

* Fill out CHANGELOG
2018-07-19 14:57:04 -05:00
Alex Crichton
cbeb301371
Add support for optional slice types (#507)
* Shard the `convert.rs` module into sub-modules

Hopefully this'll make the organization a little nicer over time!

* Start adding support for optional types

This commit starts adding support for optional types to wasm-bindgen as
arguments/return values to functions. The strategy here is to add two new
traits, `OptionIntoWasmAbi` and `OptionFromWasmAbi`. These two traits are used
as a blanket impl to implement `IntoWasmAbi` and `FromWasmAbi` for `Option<T>`.

Some consequences of this design:

* It should be possible to ensure `Option<SomeForeignType>` implements to/from
  wasm traits. This is because the option-based traits can be implemented for
  foreign types.
* A specialized implementation is possible for all types, so there's no need for
  `Option<T>` to introduce unnecessary overhead.
* Two new traits is a bit unforutnate but I can't currently think of an
  alternative design that works for the above two constraints, although it
  doesn't mean one doesn't exist!
* The error messages for "can't use this type here" is actually halfway decent
  because it says these new traits need to be implemented, which provides a good
  place to document and talk about what's going on here!
* Nested references like `Option<&T>` can't implement `FromWasmAbi`. This means
  that you can't define a function in Rust which takes `Option<&str>`. It may be
  possible to do this one day but it'll likely require more trait trickery than
  I'm capable of right now.

* Add support for optional slices

This commit adds support for optional slice types, things like strings and
arrays. The null representation of these has a pointer value of 0, which should
never happen in normal Rust. Otherwise the various plumbing is done throughout
the tooling to enable these types in all locations.

* Fix `takeObject` on global sentinels

These don't have a reference count as they're always expected to work, so avoid
actually dropping a reference on them.

* Remove some no longer needed bindings

* Add support for optional anyref types

This commit adds support for optional imported class types. Each type imported
with `#[wasm_bindgen]` automatically implements the relevant traits and now
supports `Option<Foo>` in various argument/return positions.

* Fix building without the `std` feature

* Actually fix the build...

* Add support for optional types to WebIDL

Closes #502
2018-07-19 14:44:23 -05:00
Alex Crichton
6eef5f7b52
Move the js module to a js_sys crate (#512)
* Move the `js` module to a `js_sys` crate

* Update js-sys tests to pass again

* Update binding_to_unimplemented_apis_doesnt_break_everything

Remove its dependency on the `js` module

* Update metadata for js-sys

* Fix the `closures` example
2018-07-19 14:30:58 -05:00
Alex Crichton
4eaa1a5639 Add support for more slice types in WebIDL
Add support for the primitive type arrays, and additionally switch `ByteString`
to `String` instead of `Vec<u8>` according to the online documentation.
2018-07-19 08:46:45 -07:00
Jonathan Kingston
4013fd90a7 Implementing Element in web-sys (#508) 2018-07-19 10:46:26 -05:00
Alex Crichton
a949482e3a
Remove usage of #[wasm_custom_section] (#509)
This has been stabilized on nightly as `#[link_section]`, so no need for an
unstable attribute any more. Yay!
2018-07-19 08:57:18 -05:00
Alex Crichton
9b6804a01b
Translate ByteString in WebIDL to [u8] (#505)
In arguments take `&[u8]` and in return value return `Vec<u8>`. Should help fill
out a few more APIs on `Header` and `Response`!
2018-07-18 17:59:24 -05:00
Ben Merritt
478e3fcedf Add basic support for [NoInterfaceObject] attribute (#497) 2018-07-18 00:23:17 -05:00
Alex Crichton
bf64f74cab
Fix symbol conflicts defined in two crates (#496)
Not a lot of attention has been paid to dealing with conflicts of symbols
between crates and different `#[wasm_bindgen]` blocks. This commit starts to fix
this issue by unblocking #486 which first ran into this. Currently there's a bug
where if two independent crates bind the same JS API they'll generate the same
symbol which causes conflicts for things like LTO or linking in general.

This commit starts to add a "salt" to all symbols generated by `wasm-bindgen`
(these are all transparent to the user) to ensure that each crate's invocations
are kept apart from one another and using the correct bindings.
2018-07-17 18:24:48 -05:00
Richard Dodd (dodj)
9d27b44a4a Fix extra-traits feature (#491) 2018-07-17 10:28:44 -05:00
Alex Crichton
ed05c7b945
Fix compile on latest nightly (#489) 2018-07-17 09:11:30 -05:00
Alex Crichton
e1e80a9b7e Work around #483
This commit adds a hack to the `wasm-bindgen` CLI tool to work around #483 which
is present on nightly Rust with the recent LLVM upgrade. Hopefully this'll carry
us forward until the [upstream bug][1] is fixed.

Closes #483

[1]: https://bugs.llvm.org/show_bug.cgi?id=38184
2018-07-16 13:44:41 -07:00
Stephan Wolski
4cc069bd01 Clean up Some Clippy Warnings (#478)
* clippy: it is more idiomatic to loop over references to containers instead of using explicit iteration methods

* clippy: useless use of `format!`

* clippy: if/else is an expression

* clippy: use of  followed by a function call

* clippy: large size difference between variants

* clippy: redundant closure

* Revert "clippy: large size difference between variants"

This reverts commit 7e2e660dd4.

* Revert "clippy: it is more idiomatic to loop over references to containers instead of using explicit iteration methods"

This reverts commit 5c4804f790.
2018-07-15 11:43:55 -05:00
Julius Rakow
51b9eb81e8
split const integers into signed and unsigned 2018-07-14 22:48:37 +02:00
Nick Fitzgerald
1e32e91877
Merge pull request #460 from ohanar/webidl_partial_mixins
webidl: add support for partial interfaces and mixins
2018-07-14 13:46:54 -07:00
Alex Crichton
d7a05129ac
Improve documentation around link_this_library (#471)
I've started noticing this in non-LTO builds and initially tried to remove it. I
was unsuccessful but decided to better document my adventures to hopefully
improve future onlookers!
2018-07-14 11:04:47 -05:00
Julius Rakow
e49e02cc88 web-sys: only try to build webidl files (#474) 2018-07-14 11:04:20 -05:00
R. Andrew Ohana
80384d8da9 address my comments for #470 2018-07-13 22:36:51 -07:00
R. Andrew Ohana
0c908bb951 Merge remote-tracking branch 'origin/master' into webidl_partial_mixins 2018-07-13 22:32:16 -07:00
R. Andrew Ohana
d5fee8d5d1 webidl: move first pass logic to new module
I also updated it so that it is modeled in the same
extensible way as the WebidlParse trait.
2018-07-13 21:46:36 -07:00
R. Andrew Ohana
696678b8cc
Merge pull request #470 from jrakow/webidl-const
Support WebIDL constants
2018-07-13 21:12:46 -07:00
Nick Fitzgerald
1c44408d46
Merge pull request #466 from alexcrichton/rm-debug
Remove debug sections by default
2018-07-13 13:38:53 -07:00
Julius Rakow
9ebd8bc790
webidl: add float const test 2018-07-13 19:59:59 +02:00
Julius Rakow
473ac6d2ee
webidl: add int const test 2018-07-13 19:59:52 +02:00
Julius Rakow
88f0e84f6c
webidl: add bool const test 2018-07-13 19:59:44 +02:00
Julius Rakow
b23b9cce5b
webidl: add empty constant test file 2018-07-13 19:59:37 +02:00
Julius Rakow
e35129445d
webidl: translate webidl const to backend const 2018-07-13 19:59:27 +02:00
Julius Rakow
862e4c50f6
backend: add const to ast 2018-07-13 19:59:21 +02:00
Julius Rakow
63598721ca
rustfmt 2018-07-13 19:59:13 +02:00
Michael Hoffmann
1007449a17 Enable Headers interface part of fetch API (#463) 2018-07-13 12:11:06 -05:00
Alex Crichton
133706fc5c Remove debug sections by default
The changes on master Rust insert debug sections now (yay!) but this means that
wasm binaries by default pick up debug sections from the standard library, so
let's remove them by default in wasm-bindgen unless `--debug` is passed
2018-07-13 08:12:12 -07:00
R. Andrew Ohana
5b952f2081 webidl: add support for partial interfaces and mixins
This is a major change to how webidl is processed. This adds
a two phase process, where the first phase records the names of
various types and indexes the mixins (and might do more in the
future). The actual program building happens in the second phase.

As part of this, this also makes it so that interface objects
are passed by reference, rather than by value. The spec isn't
exactly clear on this, but Mozilla's C++ reflection suggestions
seem to indicate that they should be passed by reference (see
https://developer.mozilla.org/en-US/docs/Mozilla/WebIDL_bindings).
2018-07-11 19:25:16 -07:00
Stephan Wolski
5520da1ef6
webidl: update enum test to unwrap constructor results
Update the enum test to match the new constructor return values
2018-07-11 16:17:56 -04:00
Stephan Wolski
fac73a2ea4
webidl: make from_js_value visible for enums
Make from_js_value match the visibility of the enum it's associated with
2018-07-11 15:36:41 -04:00
Stephan Wolski
4c7b130872
Merge branch 'master' into feat/basic-enum-support 2018-07-11 15:34:00 -04:00
Nick Fitzgerald
f8949acbe0
Merge pull request #457 from fitzgen/turn-throws-extended-attribute-into-catch
webidl: Turn the `[Throws]` extended attributes into `Result<T, JsValue>`
2018-07-11 11:37:57 -07:00
Nick Fitzgerald
3cdb6ef03a webidl: Turn the [Throws] extended attributes into Result<T, JsValue>
This sets the `catch` flag on the emitted AST when an operation/attribute has
the `[Throws]` extended attribute on it.

Additionally, constructors aren't annotated with `[Throws]` but can still throw
exceptions, so we must conservatively assume *every* constructor can throw an
error.
2018-07-11 11:07:03 -07:00
Michael Hoffmann
77b86f481e Add helper function to preconfigure project for web-sys (#455) 2018-07-11 09:27:27 -05:00
Stephan Wolski
6608828d72
webidl: use JSValue::from in IntoWasmAbi for enums 2018-07-10 20:28:34 -04:00
Stephan Wolski
c56b1b0189
webidl: replace From trait with from_js_value method for enums
* Remove From<JSValue> for ENUM
* Add `from_js_value` method which returns an Option<ENUM>
2018-07-10 20:28:34 -04:00
Stephan Wolski
a981dfd507
webidl: initial enum support
Add enum support to the WebIDL interface generator.
2018-07-10 20:28:34 -04:00
Nick Fitzgerald
eabbe0e56e
Merge pull request #452 from brisad/add-fetch-api-response
Add Response interface part of fetch API
2018-07-10 15:22:12 -07:00
Michael Hoffmann
717e260a99 Add Response interface part of fetch API 2018-07-10 23:49:14 +02:00
Nick Fitzgerald
92dd8e859f Move webidl tests to the webidl crate's test suite (#451)
* webidl: Remove exact-output tests

These have not been as effective, nor as easy to write and maintain, as the
project()-based integration tests.

* tests: Move webidl tests into the webidl crate's test suite
2018-07-10 16:17:33 -05:00
Robert Masen
1d826e96de fix reformatting for new syntax 2018-07-10 08:42:35 -05:00
Robert Masen
c7d98b9ee1 add js doc @param and @returns annotations 2018-07-10 08:42:34 -05:00
Nick Fitzgerald
f2f2d7231a
Create the web-sys crate mechanically from WebIDL (#409)
* Create a new `web-sys` crate

This will eventually contain all the WebIDL-generated bindings to Web APIs.

* ci: Test the new `web-sys` crate in CI

* web-sys: Add a small README

* web-sys: Vendor all the WebIDL files from mozilla-central

* backend: Add a pass to remove AST items that use undefined imports

This is necessary for the WebIDL frontend, which can't translate many WebIDL
constructs into equivalent wasm-bindgen AST things yet. It lets us make
incremental progress: we can generate bindings to methods we can support right
now even though there might be methods on the same interface that we can't
support yet.

* webidl: Add a bunch of missing semicolons

* webidl: Make parsing private

It was only `pub` so that we could test it, but we ended up moving towards
integration tests rather than unit tests that assert particular ASTs are parsed
from WebIDL files.

* webidl: Remove uses of undefined import types

* test-project-builder: Build projects in "very verbose" mode

This helps for debugging failing WebIDL-related tests.

* test-project-builder: Add more profiling timers

* test-project-builder: Detect when webpack-dev-server fails

Instead of going into an infinite loop, detect when webpack-dev-server fails to
start up and early exit the test.

* webidl: Specify version for dev-dependency on wasm-bindgen-backend

Instead of only a relative path.

* guide: Add section about contributing to `web-sys`

* WIP enable Event.webidl

Still need to fix and finish the test.

* Update expected webidl output

* Start out a test's status as incomplete

That way if we don't fill it in the error message doesn't look quite so bizarre

* Fix onerror function in headless mode

Otherwise we don't see any output!

* Fix package.json/node_modules handling in project generation

Make sure these are looked up in the git project root rather than the crate root

* Avoid logging body text

This was meant for debugging and is otherwise pretty noisy

* Fix a relative path

* More expected test fixes

* Fix a typo

* test-project-builder: Allow asynchronous tests

* webidl: Convert [Unforgeable] attributes into `#[wasm_bindgen(structural)]`

Fixes #432

* test-project-builder: Print generated WebIDL bindings for debugging purposes

Helps debug bad WebIDL bindings generation inside tests.

* When we can't find a descriptor, say which one can't be found

This helps when debugging things that need to become structural.

* web-sys: Test bindings for Event

* ci: Use `--manifest-path dir` instead of `cd dir && ...`

* web-sys: Just move .webidl files isntead of symlinking to enable them

* tests: Polyfill Array.prototype.values for older browsers in CI

* test-project-builder: Don't panic on poisoned headless test mutex

We only use it to serialize headless tests so that we don't try to bind the port
concurrently. Its OK to run another headless test if an earlier one panicked.

* JsValue: Add {is,as}_{object,function} methods

Allows dynamically casting values to `js::Object` and `js::Function`.

* tidy: Fix whitespace and missing semicolons

* Allow for dynamic feature detection of methods

If we create bindings to a method that doesn't exist in this implementation,
then it shouldn't fail until if/when we actually try and invoke that missing
method.

* tests: Do feature detection in Array.prototype.values test

* Add JsValue::{is_string, as_js_string} methods

And document all the cast/convert/check methods for js value.

* eslint: allow backtick string literals

* Only generate a fallback import function for non-structural imports
2018-07-09 16:35:25 -07:00
Alex Crichton
ade4561eba Don't unwrap mutex lock in headless testing
We don't worry about poisoning and it causes too many test failures if it's
turned on!
2018-07-09 14:55:55 -07:00
Nick Fitzgerald
2b5dd430a8
Merge pull request #428 from alexcrichton/missing-docs
Fix some cases with `#[deny(missing_docs)]`
2018-07-09 11:01:05 -07:00
Alex Crichton
331a86a07a Simplify the reset_indentation function
This should fix a stack overflow reported on IRC by ensuring that the function
isn't recursive
2018-07-09 09:10:26 -07:00
Alex Crichton
b4c7a5c1e1 Fix some cases with #[deny(missing_docs)]
Generated functions by wasm-bindgen should either be `#[doc(hidden)]` or include
the docs on the original item!

Closes #425
2018-07-09 08:49:16 -07:00
Alex Crichton
3c38ba258c Fix tests 2018-07-09 08:49:00 -07:00