Commit Graph

2621 Commits

Author SHA1 Message Date
Alex Crichton
68c5233f80 First refactor for WebIDL bindings
This commit starts the `wasm-bindgen` CLI tool down the road to being a
true polyfill for WebIDL bindings. This refactor is probably the first
of a few, but is hopefully the largest and most sprawling and everything
will be a bit more targeted from here on out.

The goal of this refactoring is to separate out the massive
`crates/cli-support/src/js/mod.rs` into a number of separate pieces of
functionality. It currently takes care of basically everything
including:

* Binding intrinsics
* Handling anyref transformations
* Generating all JS for imports/exports
* All the logic for how to import and how to name imports
* Execution and management of wasm-bindgen closures

Many of these are separable concerns and most overlap with WebIDL
bindings. The internal refactoring here is intended to make it more
clear who's responsible for what as well as making some existing
operations much more straightforward. At a high-level, the following
changes are done:

1. A `src/webidl.rs` module is introduced. The purpose of this module is
   to take all of the raw wasm-bindgen custom sections from the module
   and transform them into a WebIDL bindings section.

  This module has a placeholder `WebidlCustomSection` which is nowhere
  near the actual custom section but if you squint is in theory very
  similar. It's hoped that this will eventually become the true WebIDL
  custom section, currently being developed in an external crate.

  Currently, however, the WebIDL bindings custom section only covers a
  subset of the functionality we export to wasm-bindgen users. To avoid
  leaving them high and dry this module also contains an auxiliary
  custom section named `WasmBindgenAux`. This custom section isn't
  intended to have a binary format, but is intended to represent a
  theoretical custom section necessary to couple with WebIDL bindings to
  achieve all our desired functionality in `wasm-bindgen`. It'll never
  be standardized, but it'll also never be serialized :)

2. The `src/webidl.rs` module now takes over quite a bit of
   functionality from `src/js/mod.rs`. Namely it handles synthesis of an
   `export_map` and an `import_map` mapping export/import IDs to exactly
   what's expected to be hooked up there. This does not include type
   information (as that's in the bindings section) but rather includes
   things like "this is the method of class A" or "this import is from
   module `foo`" and things like that. These could arguably be subsumed
   by future JS features as well, but that's for another time!

3. All handling of wasm-bindgen "descriptor functions" now happens in a
   dedicated `src/descriptors.rs` module. The output of this module is
   its own custom section (intended to be immediately consumed by the
   WebIDL module) which is in theory what we want to ourselves emit one
   day but rustc isn't capable of doing so right now.

4. Invocations and generations of imports are completely overhauled.
   Using the `import_map` generated in the WebIDL step all imports are
   now handled much more precisely in one location rather than
   haphazardly throughout the module. This means we have precise
   information about each import of the module and we only modify
   exactly what we're looking at. This also vastly simplifies intrinsic
   generation since it's all simply a codegen part of the `rust2js.rs`
   module now.

5. Handling of direct imports which don't have a JS shim generated is
   slightly different from before and is intended to be
   future-compatible with WebIDL bindings in its full glory, but we'll
   need to update it to handle cases for constructors and method calls
   eventually as well.

6. Intrinsic definitions now live in their own file (`src/intrinsic.rs`)
   and have a separated definition for their symbol name and signature.
   The actual implementation of each intrinsic lives in `rust2js.rs`

There's a number of TODO items to finish before this merges. This
includes reimplementing the anyref pass and actually implementing import
maps for other targets. Those will come soon in follow-up commits, but
the entire `tests/wasm/main.rs` suite is currently passing and this
seems like a good checkpoint.
2019-06-05 07:52:14 -07:00
Alex Crichton
b11b6dfe5d
Merge pull request #1573 from not-an-aardvark/implement-flat-and-flatmap
Add Array#flat and Array#flatMap to js-sys (fixes #1454)
2019-06-04 09:59:40 -05:00
Teddy Katz
5c5c13cf9e
Add Array#flat and Array#flatMap to js-sys (fixes #1454) 2019-06-03 18:32:58 -04:00
Nick Fitzgerald
6ac61b5feb
Merge pull request #1572 from alexcrichton/dictionary-fields
Fix small issues around web-sys dictionaries
2019-06-03 13:49:20 -07:00
Alex Crichton
117928f0c0 Add doc comments to web-sys dictionaries/fields
This commit ensures that web-sys generated dictionaries and fields all
have comments like interfaces do, indicating a bare minimum of what's
happening as well as the required features to enable the API.
2019-06-03 13:18:38 -07:00
Alex Crichton
877c31cdc8 web-sys: Don't remove dictionaries if required fields are removed
This commit updates the conditional binding generation for dictionaries
to ensure that a dictionary is not entirely removed if any of its
required fields are removed. If a required field is removed, however, it
cannot be constructed, so the constructor is removed.
2019-06-03 12:57:21 -07:00
Alex Crichton
618b5d3531
Merge pull request #1571 from alexcrichton/less-warnings
Use `dyn` with all trait objects
2019-06-03 11:54:29 -05: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
Alex Crichton
f3adee7056 Squash warnings about unused variables
Make sure when compiling for non-wasm targets we don't issue tons of
warnings about unused variables which can't be squashed.
2019-06-03 08:25:07 -07:00
Alex Crichton
c876bd6268
Merge pull request #1570 from DiamondLovesYou/master
Support 8 argument closures.
2019-06-03 09:36:41 -05:00
Alex Crichton
9884c79bd9
Merge pull request #1546 from ibaryshnikov/websockets-example
added websockets example
2019-06-03 09:33:39 -05:00
ibaryshnikov
cbedf0bba0 added websockets example to the guide 2019-06-01 16:17:50 +03:00
ibaryshnikov
e16bb9cd38 exclude websockets from being built using npm 2019-06-01 15:40:32 +03:00
ibaryshnikov
6825da384f added websockets example 2019-06-01 15:40:32 +03:00
Richard Diamond
03218d9d3c Support 8 argument closures. 2019-06-01 04:19:26 -05:00
Alex Crichton
ad68436cc9 Looks like webassembly-js-api package no longer needed!
Closes #1565
2019-05-30 07:40:26 -07:00
Alex Crichton
2d13589c56
Merge pull request #1561 from xtuc/chore-upgrade-wasm-pack-plugin
update wasm-pack-plugin to 0.4.1
2019-05-30 09:01:43 -05: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
Alex Crichton
cd724cb274
Merge pull request #1560 from devsnek/clean/linting
Run fmt and clippy
2019-05-28 12:15:07 -05:00
Gus Caplan
2cc40a27d2
Run fmt and clippy 2019-05-28 09:52:44 -05:00
Alex Crichton
dfcaabc738
Merge pull request #1557 from devsnek/new-weakref
Rewrite weakrefs to use current proposal
2019-05-28 09:12:47 -05:00
Alex Crichton
2a665a92fd Fix compile errors on nightly 2019-05-28 07:05:52 -07:00
Alex Crichton
39b5f1845d Fix a warning 2019-05-28 07:03:42 -07:00
Alex Crichton
2d22fa4f03
Merge pull request #1556 from noelyoo/fix-docs-link
docs: update docs link
2019-05-28 08:25:07 -05:00
Gus Caplan
66ade77720
Rewrite weakrefs to use current proposal 2019-05-26 09:30:33 -05:00
noelyoo
f3ec734310 docs: update docs link 2019-05-26 16:43:00 +09:00
Nick Fitzgerald
62b313d695 Fix README's badges 2019-05-23 14:27:16 -07:00
Nick Fitzgerald
c7b41d03a6 Add standard WG header to README 2019-05-23 14:24:29 -07:00
Nick Fitzgerald
6f8de177e3
Merge pull request #1553 from fitzgen/guide-serde-wasm-bindgen
Add note to the guide about `serde-wasm-bindgen`
2019-05-23 14:15:03 -07:00
Nick Fitzgerald
2a896dbeb3 Also mention that serde-wasm-bindgen supports more types than JSON does 2019-05-23 14:14:21 -07:00
Nick Fitzgerald
90f1866ddd Add note to the guide about serde-wasm-bindgen 2019-05-22 09:39:08 -07:00
Nick Fitzgerald
5233139b31
Update README.md sample code to 2018 edition 2019-05-21 19:22:34 -07:00
Alex Crichton
9b04fe9e45
Merge pull request #1545 from infinity0/master
Work around rust-lang/rust#58516
2019-05-21 08:58:59 -05:00
Ximin Luo
81fb2d97d3 Work around rust-lang/rust#58516 2019-05-20 20:18:24 -07:00
Alex Crichton
bc5f73e3d2
Merge pull request #1550 from alexcrichton/more-better-errors
Improve diagnostics with missing trait implementations
2019-05-20 13:04:46 -05:00
Alex Crichton
b96186e9a6
Merge pull request #1549 from alexcrichton/bump
Bump to 0.2.45
2019-05-20 12:50:42 -05:00
Alex Crichton
2cbb8b8a69 Improve diagnostics with missing trait implementations
Rejigger a few spans, work around an odd rustc issue, and hopefully
produce higher quality error messages!

Closes #1528
2019-05-20 10:49:36 -07:00
Alex Crichton
a02d210d5c Catch more errors on non-wasm32 platforms
This commit tweaks the codegen for imported functions and such (anything
that relies on some imported intrinsic or function filled in by the CLI)
to share as much code as possible on non-wasm32 platforms. This should
help us catch more errors before compiling to wasm and also just make it
easier to write UI tests!

For example a UI test previously couldn't be written for #1528 but now
it can be, and one is include (although the error message is quite bad).
2019-05-20 10:16:25 -07:00
Alex Crichton
137bbdf2e3 Bump to 0.2.45 2019-05-20 09:44:03 -07:00
Alex Crichton
f23b867179
Merge pull request #1544 from ibaryshnikov/master
expose forget to wasm
2019-05-20 11:33:10 -05:00
Alex Crichton
a68cdc594d Add a test that Callback::forget works 2019-05-20 09:32:37 -07:00
Alex Crichton
4049803c39
Merge pull request #1548 from lzubiaur/fix-heap-closure-example
Fix closure example compilation errors
2019-05-20 09:23:06 -05:00
lzubiaur
c043a952a2 Fix closure example compilation errors 2019-05-20 16:40:22 +09:00
ibaryshnikov
805738608d expose forget to wasm 2019-05-19 14:42:53 +03:00
Nick Fitzgerald
0cbdea5fa9
Merge pull request #1542 from fitzgen/update-walrus
Update dependencies and use new walrus custom sections APIs
2019-05-17 15:21:35 -07:00
Nick Fitzgerald
d422436487 Update dependencies and use new walrus custom sections APIs 2019-05-17 14:58:50 -07:00
Alex Crichton
fb42e47ba7
Merge pull request #1541 from RReverser/rm-wasm-bindgen-test-unsafe
Remove unsafe from #[wasm_bindgen_test] output
2019-05-17 10:42:35 -05:00
Ingvar Stepanyan
cce12bfe16 Remove unsafe from #[wasm_bindgen_test] output
This is not necessary because references are FFI-safe and compatible with corresponding pointers, so we can just use them directly as an input.

Fixes #1540.
2019-05-17 15:52:26 +01:00