Commit Graph

477 Commits

Author SHA1 Message Date
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
7f8d510f3d Move unused_imports_not_generated test to wasm 2018-08-06 11:28:08 -07:00
Alex Crichton
0fbdc7682c Remove stray file no longer needed 2018-08-06 11:10:19 -07:00
Alex Crichton
0a2399a7f1 Migrate #![no_std] tests to wasm
This required getting a little creative in a few places, but otherwise these
tests shouldn't need the test builder any more.
2018-08-06 11:08:35 -07:00
Alex Crichton
005f7eb9fa Migrate rest of dependencies test to wasm 2018-08-06 10:42:08 -07:00
Alex Crichton
28036db262 Move node test over to wasm 2018-08-06 10:06:45 -07:00
Alex Crichton
59d4c5a06a Remove dependencies_work test
The fact that `web-sys` works at all obviates the need for this test!
2018-08-06 10:00:01 -07:00
Alex Crichton
d978878d86 Remove add_headless test
We've got tons of other headless tests, no need for this particular one to stick
around!
2018-08-06 09:59:05 -07: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
Alex Crichton
3c52a82213 Remove unused import 2018-08-06 09:55:45 -07:00
Alex Crichton
c83e498f52 Move non-wasm test to an actual non-wasm test 2018-08-06 09:55:20 -07:00
Alex Crichton
8513858973 Move $-renaming tests to wasm 2018-08-06 09:51:29 -07:00
Alex Crichton
0bdb31d41e Migrate the serde-serialize test to wasm 2018-08-06 09:43:55 -07:00
Alex Crichton
4661588171 Move most of the "simple" test to the wasm suite 2018-08-06 09:21:41 -07:00
Michael Hoffmann
21c36d3902 Allow js_name attribute to accept a string 2018-08-06 09:06:00 -05:00
Alex Crichton
b4601295d0 Migrate most import tests to wasm 2018-08-05 12:35:47 -05:00
Alex Crichton
66d51f13ee Migrate the import_class to wasm 2018-08-05 12:35:47 -05:00
Anton Danilkin
654bb9b683 Port tests that use only basic features 2018-08-04 22:25:29 -05:00
Alex Crichton
57fd1dedd6 Migrate wasm-bindgen classes test to wasm 2018-08-04 15:09:43 -05:00
Alex Crichton
df7bcc4e03 Migrate wasm-bindgen char test to wasm 2018-08-04 15:09:43 -05:00
Anton Danilkin
61b3d52dc9 Rename the test 2018-08-03 15:59:27 -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
3d9401aca6 Fix JS style 2018-08-03 15:59:27 -05:00
Anton Danilkin
81cbb2e26d Migrate the test 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
88db12669f Add support for Option<&T> in imported argument lists
Closes #619
2018-08-02 22:40:42 -07:00
Alex Crichton
fe51cf9857 Add tests for by-value options 2018-08-02 22:23:11 -07: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
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
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
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
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
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
data-pup
32fa5724dd Set.prototype.forEach and Array.prototype.forEach (#504)
* Array.prototype.forEach binding.

* Set.prototype.forEach binding.
2018-07-18 13:32:07 -05:00
data-pup
f0dcdc249c Map.prototype.forEach binding. (#501) 2018-07-18 10:30:52 -05:00
Sendil Kumar N
bc474aceba Expose math.random, string.endswith, string.normalize, string.repeat, escape() JSBindings (#499)
* add math.random

* add ends with

replace length with variable

* add normalize

* add repeat

* add escape
2018-07-18 09:56:15 -05:00
Craig Disselkoen
a05d930a38 Bindings for TypedArray subclasses (#486)
* Bindings for TypedArray subclasses

* Fill with Rust values rather than JsValues
2018-07-17 18:24:56 -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
data-pup
c26caf6354 String - padEnd, padStart (#493) 2018-07-17 16:56:16 -05:00
data-pup
5f2f30dba1 String - lastIndexOf (#490) 2018-07-17 12:12:36 -05:00
Alex Crichton
ed05c7b945
Fix compile on latest nightly (#489) 2018-07-17 09:11:30 -05:00
Tomohide Takao
babc2134e1 Remove target_args from Array.find_index() (#479) 2018-07-14 23:10:27 -05:00
R. Andrew Ohana
16cbca74e2 deal with yet another locale/platform issue (#480)
This test fails on my system. As previously decided, until we can
figure out a better solution for this issue, for now we just check
to make sure the output is a non-empty string.
2018-07-14 22:45:49 -05:00
Tomohide Takao
7a7bc6d22e Bindings for Array.prototype.toLocaleString() 2018-07-14 19:45:22 +09:00
Tomohide Takao
f5035c3841 Bindings for Array.prototype.findIndex() 2018-07-14 19:33:48 +09:00
Tomohide Takao
a7deb69e80 Bindings for Array.prototype.reduce(Right) 2018-07-12 23:53:26 +09:00
Liigo Zhuang
e666371ae3 some fix 2018-07-12 10:11:44 +08:00
Liigo Zhuang
823e5a4fd9 fix test 2018-07-12 09:55:34 +08:00
Liigo Zhuang
79f53b567b js::DataView binding 2018-07-12 09:55:33 +08:00
T. Nagasawa
5ce424e57b bindings for Date.prototype.setUTCXXX() (#456) 2018-07-11 09:27:59 -05:00
Tomohide Takao
d7857da262 binding for Array.prototype.map() 2018-07-11 07:20:52 +09: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
Nick Fitzgerald
42938792c7
Merge pull request #430 from FreeMasen/js_docs
Js docs
2018-07-10 10:08:41 -07:00
Nick Fitzgerald
7200d36fb6
Merge pull request #438 from toVersus/js_date
bindings for Date.setXXX
2018-07-10 10:04:36 -07:00
Satoshi Amemiya
8be0a98386 Add support for methods of Symbol (#437) 2018-07-10 09:46:05 -05:00
toversus
d2feddcf90 fix to have no impact on timezones difference 2018-07-10 23:31:25 +09:00
Robert Masen
c7d98b9ee1 add js doc @param and @returns annotations 2018-07-10 08:42:34 -05:00
toversus
91d6ae5f04 binding for Date.prototype.setTime() 2018-07-10 21:46:44 +09:00
toversus
c185897eff binding for Date.prototype.setSeconds() 2018-07-10 21:45:33 +09:00
toversus
609d457301 binding for Date.prototype.setMonth() 2018-07-10 21:27:12 +09:00
toversus
a81827caf9 binding for Date.prototype.setMinutes() 2018-07-10 21:20:18 +09:00
toversus
11a58a1bd0 binding for Date.prototype.setMilliseconds() 2018-07-10 20:55:45 +09:00
toversus
524628e1e1 binding for Date.prototype.setHours() 2018-07-10 20:51:39 +09:00
toversus
d555b7f068 binding for Date.prototype.setFullYear() 2018-07-10 20:45:25 +09:00
toversus
1a8da45340 binding for Date.prototype.setDate() 2018-07-10 20:38:54 +09: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
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
Michael Hoffmann
bae324c951 Add Array.prototype.values binding (#395) 2018-07-09 12:42:30 -05:00
Nick Fitzgerald
21cb50ef05
Merge pull request #412 from matiasinsaurralde/intl
Add bindings for `Intl`
2018-07-09 10:31:22 -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
Liigo Zhuang
bfec9e6401 bindings for parseInt/parseFloat (#384)
* parseInt, parseFloat, JsValue::is_nan

* Number.parseInt, Number.parseFloat

* remove `JsValue::is_nan`

* parse_int/float returns f64
2018-07-09 08:59:54 -05:00
toversus
5bfde7778d binding for Date.prototype.getUTCSeconds() 2018-07-09 18:20:04 +09:00
toversus
15d9f743ec binding for Date.prototype.getUTCMonth() 2018-07-09 18:08:38 +09:00
toversus
2e85bbd9e0 binding for Date.prototype.getUTCMinutes() 2018-07-09 18:04:20 +09:00
toversus
c260ac7c3e binding for Date.prototype.getUTCMilliseconds() 2018-07-09 17:59:15 +09:00
toversus
6aa3661e11 binding for Date.prototype.getUTCHours() 2018-07-09 17:54:19 +09:00
toversus
975818a1f6 binding for Date.prototype.getUTCFullYear() 2018-07-09 17:50:13 +09:00
toversus
ea19848691 binding for Date.prototype.getUTCDay() 2018-07-09 17:46:21 +09:00
toversus
792baefc22 binding for Date.prototype.getUTCDate() 2018-07-09 17:42:30 +09:00
toversus
d3a17d4014 binding for Date.prototype.getTimezoneOffset() 2018-07-09 17:38:38 +09:00
Alexander Kryvomaz
6758525980 bindings for isFinite(), Number.isFinite() and Number.isSafeInteger() (#420)
* bindings for isFinite()

* bindings for Number.isFiniter(), refactoring of Number.isInteger()

* bindings for Number.isSafeInteger()
2018-07-08 10:03:10 -05:00
Alex Crichton
791e69a5c0
Generate normal Rust functions for imported bindings (#410)
* Generate normal Rust functions for imported bindings

No need to use the C ABI, it just mixes up the documentation!

* Update expected webidl output
2018-07-07 12:20:42 -05:00
T. Nagasawa
056b45aeed bindings for Date.parse and Date.getXXX (#414)
* binding for Date.prototype.getHours()

* binding for Date.prototype.getMilliseconds()

* binding for Date.prototype.getMinutes()

* binding for Date.prototype.getMonth()

* binding for Date.prototype.getSeconds()

* binding for Date.prototype.getTime()

* binding for Date.parse()
2018-07-07 12:09:46 -05:00
Matias Insaurralde
8352b4610f
Add bindings for Intl.getCanonicalLocales 2018-07-07 08:00:22 -04:00
Alex Crichton
ef807a8068 Tweak some docs and fixup some symbol tests 2018-07-06 20:00:53 -07:00
Nick Fitzgerald
a526be9baf
Merge pull request #401 from rail44/support-symbol
Add support for static props of Symbol
2018-07-06 09:15:36 -07:00
Marcin Baraniecki
83a7d5bfdc
Merge pull request #399 from alexcrichton/jsvalue-debug
Implement `Debug for JsValue`
2018-07-06 13:36:17 +02:00
Marcin Baraniecki
c9f4a266b0
Merge pull request #386 from jannikkeye/bindings-reflect
Reflect.xx bindings
2018-07-06 13:34:59 +02:00
Marcin Baraniecki
f7dc819289
Merge pull request #387 from Hywan/webassembly
feat(js) Implement the `WebAssembly.validate` binding.
2018-07-06 13:33:37 +02:00
Ivan Enderlin
b4bf8fbfba
test(js) New WebAssembly.validate_with_invalid_input test case. 2018-07-06 10:41:51 +02:00
Ivan Enderlin
d1955c91b7
test(js) Don't unwrap to false. 2018-07-06 10:41:32 +02:00
Satoshi Amemiya
6e4948d983 Add support for static props of Symbol 2018-07-06 17:07:43 +09:00
Jannik Keye
2022b44416 fix: convert tests to plain js 2018-07-06 09:41:08 +02:00
Jannik Keye
99d66ad6ed merge master 2018-07-06 09:31:58 +02:00
Sendil Kumar N
a65b6c7003
Merge pull request #397 from ZerothLaw/Issue275/ArrayFind
Issue #275: Added Array.prototype.find binding
2018-07-06 09:22:46 +02:00
Sendil Kumar N
142d7377e2
Merge pull request #400 from alexcrichton/derive-import
Forward attributes on `type` declaration to definition
2018-07-06 09:21:01 +02:00
Satoshi Amemiya
1bcfcaf1ed TypeScript is no longer enabled 2018-07-06 15:41:07 +09:00
Satoshi Amemiya
bd068207a1 Fix test of Symbol.hasInstance 2018-07-06 14:57:22 +09:00