Commit Graph

625 Commits

Author SHA1 Message Date
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