Commit Graph

259 Commits

Author SHA1 Message Date
Alex Crichton
88618116ac
Add support for #[wasm_bindgen] on async fn (#1754)
This commit adds support to attach `#[wasm_bindgen]` on an `async fn`
which will change the return value into a `Promise` in JS. This in
theory has the exact same semantics as an `async` function in JS where
you call it with all the arguments, nothing happens and you get a
promise back, and then later the promise actually resolves.

This commit also adds a helper trait, `IntoJsResult`, to allow `async`
functions with multiple kinds of return values instead of requiring
everything to be `Result<JsValue, JsValue>`.
2019-09-06 13:47:16 -05:00
Alex Crichton
3c887c40b7
Default all async support to std::future (#1741)
This commit defaults all crates in-tree to use `std::future` by default
and none of them support the crates.io `futures` 0.1 crate any more.
This is a breaking change for `wasm-bindgen-futures` and
`wasm-bindgen-test` so they've both received a major version bump to
reflect the new defaults. Historical versions of these crates should
continue to work if necessary, but they won't receive any more
maintenance after this is merged.

The movement here liberally uses `async`/`await` to remove the need for
using any combinators on the `Future` trait. As a result many of the
crates now rely on a much more recent version of the compiler,
especially to run tests.

The `wasm-bindgen-futures` crate was updated to remove all of its
futures-related dependencies and purely use `std::future`, hopefully
improving its compatibility by not having any version compat
considerations over time. The implementations of the executors here are
relatively simple and only delve slightly into the `RawWaker` business
since there are no other stable APIs in `std::task` for wrapping these.

This commit also adds support for:

    #[wasm_bindgen_test]
    async fn foo() {
        // ...
    }

where previously you needed to pass `(async)` now that's inferred
because it's an `async fn`.

Closes #1558
Closes #1695
2019-09-05 11:18:36 -05:00
Alex Crichton
4e19ead71b
Fix the wasm2js example (#1750)
This needed and update now that we're explicitly importing `*.wasm` to
import `*.js` instead. Additionally this was moved over to the `web`
target to avoid needing Webpack

Closes #1743
2019-09-03 16:05:23 -04:00
Darin Morrison
0eba2efe45 Fix warnings in raytrace-parallel example 2019-08-27 12:40:58 -07:00
Sven Sauleau
312f5d6dca chore: upgrade @wasm-tool/wasm-pack-plugin to 1.0.1 2019-08-27 18:20:24 +01:00
Alex Crichton
c2daa4f63c Bump to 0.2.50 2019-08-19 04:21:27 -07:00
Alex Crichton
c1d4fddeac Bump to 0.2.49 2019-08-14 08:32:02 -07:00
Alex Crichton
1d0c333a2b Run cargo fmt over all code 2019-08-12 11:28:37 -07:00
Benjamin Lee
50683f0c3c
Removed unnecessary dereference in Store::find
Prefer no dereference when it is not needed.
`todo` has type `&&Item`. Argument needs to be `&Item`, but this is converted via deref coercion.
2019-08-06 20:34:39 -07:00
Benjamin Lee
af922fb670
Fixup styling in sync_local_storage
- `storage_string` is already a `JsString`, calling `to_string` is redundant

- `as_str` is not required, so it is more idiomatic to just use a borrow.
2019-08-06 09:27:09 -07:00
Benjamin Lee
fffcc5ef35
Makes code clearing by providing code symmetry.
```            
child.push(&JsValue::from(&item.title));
child.push(&JsValue::from(item.completed));
child.push(&JsValue::from(&item.id));
```
Parallel syntax makes it easier to see that each iteration intends to push each of `item`'s fields to `child`.
2019-08-05 23:16:53 -07:00
Benjamin Lee
09b37b4a43
Removed unnecessary and confusing clone of String 2019-08-05 22:59:53 -07:00
Alex Crichton
0dbf4294c2
Merge pull request #1702 from UnHumbleBen/patch-2
Fixes description of Closure lifetime in comments.
2019-08-05 10:15:23 -05:00
Benjamin Lee
89067c1ddf
Updated description for single closure 2019-08-04 20:22:41 -07:00
Benjamin Lee
af4622ff3d
Fixes description of Closure lifetime in comments. 2019-08-04 11:01:13 -07:00
Benjamin Lee
b978531536
Use idiomatic syntax of Rc::clone() 2019-08-03 19:52:14 -07:00
Alex Crichton
8cb792474c Fully update threading support for LLVM 9
Support has landed in rust-lang/rust for full support for LLVM 9's
interpretation of WebAssembly threads. This commit updates our thread
transformation pass to take all this into account, namely:

* The threadign pass now runs by default and is keyed on whether memory
  is shared, not off an env var.
* TLS is initialized in addition to memory on each thread.
* Stack pointer finding is tweaked to account for the TLS base also
  being a mutable global.
* The build of the parallel raytrace example was updated to use today's
  nightly.
2019-07-30 09:17:23 -07:00
Alex Crichton
9f77f8dd00 Update parallel raytrace example to use futures
Use the atomics support now implemented!
2019-07-18 10:13:34 -07:00
ibaryshnikov
6ab1a49a41 moved lib.rs to stable.rs in wasm-bindgen-futures, updated during review 2019-07-17 00:58:05 +03:00
ibaryshnikov
16c6bdc966 moved threadsafe futures implementation to a separate file, made updates after review 2019-07-17 00:48:00 +03:00
Alex Crichton
e596ef596c Bump to 0.2.48 2019-07-11 15:02:39 -07:00
Pauan
92a464d48e Updating a couple examples 2019-06-25 21:42:20 +02:00
Alex Crichton
b601c3fb2e Revert add example to what was originally intended
Remove stray debugging code added in the meantime.
2019-06-25 04:51:52 -07:00
Alex Crichton
e0ef329e17
Merge pull request #1594 from alexcrichton/webidl-for-realz
Second large refactor for WebIDL bindings
2019-06-25 08:21:24 +02:00
Alex Crichton
04aea4e9ab Use view instead of subarray in WebGL example
Pointed out in #1615!
2019-06-23 08:29:47 -07:00
Alex Crichton
3cc30843e3 Second large refactor for WebIDL bindings
This commit is the second, and hopefully last massive, refactor for
using WebIDL bindings internally in `wasm-bindgen`. This commit actually
fully executes on the task at hand, moving `wasm-bindgen` to internally
using WebIDL bindings throughout its code generation, anyref passes,
etc. This actually fixes a number of issues that have existed in the
anyref pass for some time now!

The main changes here are to basically remove the usage of `Descriptor`
from generating JS bindings. Instead two new types are introduced:
`NonstandardIncoming` and `NonstandardOutgoing` which are bindings lists
used for incoming/outgoing bindings. These mirror the standard
terminology and literally have variants which are the standard values.
All `Descriptor` types are now mapped into lists of incoming/outgoing
bindings and used for process in wasm-bindgen. All JS generation has
been refactored and updated to now process these lists of bindings
instead of the previous `Descriptor`.

In other words this commit takes `js2rust.rs` and `rust2js.rs` and first
splits them in two. Interpretation of `Descriptor` and what to do for
conversions is in the binding selection modules. The actual generation
of JS from the binding selection is now performed by `incoming.rs` and
`outgoing.rs`. To boot this also deduplicates all the code between the
argument handling of `js2rust.rs` and return value handling of
`rust2js.rs`. This means that to implement a new binding you only need
to implement it one place and it's implemented for free in the other!

This commit is not the end of the story though. I would like to add a
mdoe to `wasm-bindgen` that literally emits a WebIDL bindings section.
That's left for a third (and hopefully final) refactoring which is also
intended to optimize generated JS for bindings.

This commit currently loses the optimization where an imported is hooked
up by value directly whenever a shim isn't needed. It's planned that
the next refactoring to emit a webidl binding section that can be added
back in. It shouldn't be too too hard hopefully since all the
scaffolding is in place now.

cc #1524
2019-06-20 19:16:10 -07:00
Alex Crichton
d71ab78fc6 Bump to 0.2.47 2019-06-19 11:14:37 -07:00
Alex Crichton
8fc0a38402 Bump to 0.2.46 2019-06-14 11:44:58 -07:00
Alex Crichton
eafc6024cc Rewrite the parallel raytracing example with rayon
One of the best parts about concurrency in Rust is using `rayon` and how
easy it makes parallelization of tasks, so it's the ideal example for
parallel Rust on the web! Previously we've been unable to use `rayon`
because there wasn't a way to customize how rayon threads themselves are
spawned, but [that's now being developed for us][rayon]!

This commit uses that PR to rewrite the `raytrace-parallel` example in
this repository. While not a perfect idiomatic representation of using
`rayon` I think this is far more idiomatic than the previous iteration
of `raytrace-parallel`! I'm hoping that we can continue to iterate on
this, but otherwise show it off as a good example of parallel Rust on
the web.

[rayon]: https://github.com/rayon-rs/rayon/pull/636
2019-06-13 06:48:53 -07:00
ibaryshnikov
8ace8287ff added default module path inside init function when target is web 2019-06-08 01:27:35 +03:00
Alex Crichton
81fbc642f4 Don't pass strings in raytrace-parallel example
Make sure to explicitly parse strings to numbers
2019-06-05 07:52:14 -07:00
Alex Crichton
82467f9793 Use dyn with all trait objects
Fixes new warnings showing up on nightly nowadays.
2019-06-03 08:28:55 -07:00
ibaryshnikov
cbedf0bba0 added websockets example to the guide 2019-06-01 16:17:50 +03:00
ibaryshnikov
6825da384f added websockets example 2019-06-01 15:40:32 +03:00
Sven Sauleau
546f65e2f3 chore: bump again 2019-05-29 17:37:37 +01:00
Sven Sauleau
e65791d5c1 fix: remove css modification 2019-05-29 17:10:43 +01:00
Sven Sauleau
f63238ee24 chore: update wasm-pack-plugin to 0.4.1 2019-05-29 17:09:26 +01:00
noelyoo
f3ec734310 docs: update docs link 2019-05-26 16:43:00 +09:00
Alex Crichton
137bbdf2e3 Bump to 0.2.45 2019-05-20 09:44:03 -07:00
Alex Crichton
773c6ff430 Bump to 0.2.44 2019-05-16 07:47:23 -07:00
Sven Sauleau
98de4d7098
Update webpack.config.js 2019-05-01 17:43:50 +02:00
Alex Crichton
f2429be07f Bump to 0.2.43 2019-04-29 08:28:41 -07:00
Alex Crichton
cd7aa717c5
Merge pull request #1467 from RReverser/tuple-structs
Generate bindings for indexed struct properties
2019-04-26 09:21:36 -05:00
Alex Crichton
03299a73b4 Fix raytrace example by using an older nightly
Unfortunately xargo is currently broken against master Rust, so let's
pin to an older nightly while that's sorted out
2019-04-25 19:47:59 -07:00
Ingvar Stepanyan
a0a3a1446d Include props usage in exported_types example 2019-04-24 20:30:31 +01:00
Alex Crichton
df6e15e3ab Bump to 0.2.42 2019-04-11 07:39:45 -07:00
Alex Crichton
02394724ea Bump to 0.2.41 2019-04-10 10:53:32 -07:00
Alex Crichton
b6d041e4d5 Remove debugging code accidentally added in #1416 2019-04-08 07:49:58 -07:00
Alex Crichton
44738e049a Add warnings about UTF-16 vs UTF-8 strings
This commit aims to address #1348 via a number of strategies:

* Documentation is updated to warn about UTF-16 vs UTF-8 problems
  between JS and Rust. Notably documenting that `as_string` and handling
  of arguments is lossy when there are lone surrogates.

* A `JsString::is_valid_utf16` method was added to test whether
  `as_string` is lossless or not.

The intention is that most default behavior of `wasm-bindgen` will
remain, but where necessary bindings will use `JsString` instead of
`str`/`String` and will manually check for `is_valid_utf16` as
necessary. It's also hypothesized that this is relatively rare and not
too performance critical, so an optimized intrinsic for `is_valid_utf16`
is not yet provided.

Closes #1348
2019-04-05 08:11:50 -07:00
Alex Crichton
faf49c7d56 Reorganize the import_js example 2019-03-25 13:49:29 -07:00