Commit Graph

278 Commits

Author SHA1 Message Date
Nick Fitzgerald
bce892b625 Add #[wasm_bindgen(assert_no_shim)] on imported functions for testing
This should not be used outside of wasm-bindgen's test suite.
2019-07-12 12:34:29 -07:00
Alex Crichton
e596ef596c Bump to 0.2.48 2019-07-11 15:02:39 -07:00
Nick Fitzgerald
1ba298548f Fix warning about unnecessary parens in generated code 2019-07-09 13:17:34 -07:00
Alex Crichton
a021a967b2 Remove the long-defunkt Stack trait
This was used oh-so-long ago but hasn't been used in a very long time
since then. It's served no purpose for a very long time now and I don't
think we have a plan for giving it a purpose any time soon, so let's
remove it.
2019-06-25 05:08:50 -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
6796bc6895 Communicate exceptions through global memory
Instead of allocating space on the stack and returning a pointer we
should be able to use a single global memory location to communicate
this error payload information. This shouldn't run into any reentrancy
issues since it's only stored just before returning to wasm and it's
always read just after returning from wasm.
2019-06-11 11:41:05 -07:00
Pauan
b205045424 Adding in AsRef impl for all wasm_bindgen types 2019-06-10 08:05:59 +02: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
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
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
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
773c6ff430 Bump to 0.2.44 2019-05-16 07:47:23 -07:00
Alex Crichton
578d59ebc0
Merge pull request #1440 from c410-f3r/getters
Getters/Setters for fields
2019-04-30 12:07:34 -05:00
Caio
470eea9fb0 Getters/Setters for fields 2019-04-30 10:26:03 -03:00
Alex Crichton
f2429be07f Bump to 0.2.43 2019-04-29 08:28:41 -07:00
Ingvar Stepanyan
3a7d384dc8 Generate bindings for indexed struct properties
This allows to export fields of tuple-like structs as indexed JS properties.
2019-04-17 12:56:14 +01:00
Alex Crichton
ff1addbbaa Run cargo fmt 2019-04-16 10:52:27 -07:00
Alex Crichton
c4776becbb Touch up descriptions of has_type 2019-04-12 10:54:36 -07:00
Ingvar Stepanyan
cb880bdbff Add customisable is_type_of 2019-04-12 17:23:42 +01:00
Alex Crichton
df8da56a6c Add PartialEq/Eq to many js-sys types
This commit adds `#[derive(PartialEq, Eq)]` to many types throughout
`js-sys`. These types are basically all based on `Object`, which means
that `Object.is` can be used for `PartialEq` and the `Eq` requirements
are upheld.

The macro has also been updated to internally store the deref target
instead of unconditionally storing `JsValue`, allowing `#[derive]` to
work a bit better in these situations.
2019-04-12 09:02:33 -07: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
e4400ac8b4 Improve error message for non-copy struct fields
Make sure the error message points to the type in question instead of to
the `#[wasm_bindgen]` macro which can be overly confusing!
2019-04-08 07:35:14 -07:00
Alex Crichton
778e497186 Generate r#async method names in web-sys
This is a new keyword in the 2018 edition!
2019-03-26 08:51:46 -07:00
Alex Crichton
a6fe0cefa8 Migrate all crates to the 2018 edition
Most of the CLI crates were already in the 2018 edition, and it turns
out that one of the macro crates was already in the 2018 edition so we
may as well move everything to the 2018 edition!

Always nice to remove those `extern crate` statements nowadays!

This commit also does a `cargo fmt --all` to make sure we're conforming
with style again.
2019-03-26 08:10:53 -07:00
Alex Crichton
c5d2b2d1fb
Merge pull request #1359 from konstin/reexporting_in_2018
Allow reexporting proc macro output in the 2018 edition
2019-03-26 10:08:46 -05:00
Alex Crichton
6edb40a807 Implement transitive support for NPM dependencies
This commit implements [RFC 8], which enables transitive and transparent
dependencies on NPM. The `module` attribute, when seen and not part of a
local JS snippet, triggers detection of a `package.json` next to
`Cargo.toml`. If found it will cause the `wasm-bindgen` CLI tool to load
and parse the `package.json` within each crate and then create a merged
`package.json` at the end.

[RFC 8]: https://github.com/rustwasm/rfcs/pull/8
2019-03-22 09:42:40 -07:00
Alex Crichton
6803c619bb Bump to 0.2.40 2019-03-21 17:08:48 -07:00
konstin
42c1cdd8bf
Merge branch 'master' into reexporting_in_2018 2019-03-18 21:38:18 +01:00
Alex Crichton
2177dee9e4
Merge pull request #1353 from alexcrichton/raw-module
Add a `raw_module` attribute to `#[wasm_bindgen]`
2019-03-18 12:48:14 -05:00
konstin
69bbf597af Allow reexporting proc macro output in the 2018 edition
Trying to use a proc macro from a 2018 edition crate in a 2018 edition crate that reexports wasm bindgen's output failed before this commit with "could not find `wasm_bindgen` in `{{root}}`".

This commit was made with 

rg " ::wasm_bindgen::" --files-with-matches | xargs sed -i 's/::wasm_bindgen::/wasm_bindgen::/g'
2019-03-18 10:43:48 +01:00
Alex Crichton
0d592fffb0 Add a raw_module attribute to #[wasm_bindgen]
This allows subverting the checks and resolution performed by the
`module` attribute added as part of [RFC 6] and has been discussed in #1343.

Closes #1343

[RFC 6]: https://github.com/rustwasm/rfcs/pull/6
2019-03-15 08:08:09 -07:00
alexlapa
1014bdb5df Merge remote-tracking branch 'upstream/master' into enable-rtc-rtp-transceiver 2019-03-14 13:24:24 -06:00
alexlapa
9178231b60 impl OptionFromWasmAbi and OptionIntoWasmAbi for ImportEnum, enable RTCRtpTransceiver.webidl, add add rtc_rtp_transceiver_direction test 2019-03-14 12:15:02 -06:00
Caio
59c1b2a565 Merge branch 'master' into arg-names 2019-03-14 09:30:14 -03:00
Caio
70f5373348 Preserve argument names 2019-03-14 08:46:42 -03:00
Alex Crichton
228f58dca3 Bump to 0.2.39 2019-03-13 11:02:27 -07:00
Caio
ded4fdf52d Remove PartialEq and Eq from Function 2019-03-07 15:00:55 -03:00
Alex Crichton
d6e3770350 Scope snippets within a crate
Use the same crate identifier for manually included snippets as well as
inline snippets to help with debugging.
2019-03-05 14:53:14 -08:00
Alex Crichton
f3f3ebee3a Remove unsafe usage in backend/src/encode.rs
Using `unsafe` was just a little too eager there so let's use an
off-the-shelf solution for solving the actual problem we have, which is
to allocate strings with a lifetime of `Interner` rather than
deduplicating strings.
2019-03-05 12:28:14 -08:00
Alex Crichton
93a1301c9f Don't explicitly hide _INCLUDED_FILES
It's already hidden from docs!
2019-03-05 12:17:42 -08:00
Alex Crichton
6283169a30 Paths are relative to CARGO_MANIFEST_DIR
The cwd is different for workspaces, so use the manifest env var
instead.
2019-03-05 08:00:47 -08:00
Alex Crichton
b762948456 Implement the local JS snippets RFC
This commit is an implementation of [RFC 6] which enables crates to
inline local JS snippets into the final output artifact of
`wasm-bindgen`. This is accompanied with a few minor breaking changes
which are intended to be relatively minor in practice:

* The `module` attribute disallows paths starting with `./` and `../`.
  It requires paths starting with `/` to actually exist on the filesystem.
* The `--browser` flag no longer emits bundler-compatible code, but
  rather emits an ES module that can be natively loaded into a browser.

Otherwise be sure to check out [the RFC][RFC 6] for more details, and
otherwise this should implement at least the MVP version of the RFC!
Notably at this time JS snippets with `--nodejs` or `--no-modules` are
not supported and will unconditionally generate an error.

[RFC 6]: https://github.com/rustwasm/rfcs/pull/6

Closes #1311
2019-03-05 08:00:47 -08:00
Alex Crichton
a659f27c07 Bump to 0.2.38 2019-03-04 09:11:23 -08:00
Alex Crichton
4181fb311a Add experimental support for the anyref type
This commit adds experimental support to `wasm-bindgen` to emit and
leverage the `anyref` native wasm type. This native type is still in a
proposal status (the reference-types proposal). The intention of
`anyref` is to be able to directly hold JS values in wasm and pass the
to imported functions, namely to empower eventual host bindings (now
renamed WebIDL bindings) integration where we can skip JS shims
altogether for many imports.

This commit doesn't actually affect wasm-bindgen's behavior at all
as-is, but rather this support requires an opt-in env var to be
configured. Once the support is stable in browsers it's intended that
this will add a CLI switch for turning on this support, eventually
defaulting it to `true` in the far future.

The basic strategy here is to take the `stack` and `slab` globals in the
generated JS glue and move them into wasm using a table. This new table
in wasm is managed at the fringes via injected shims. At
`wasm-bindgen`-time the CLI will rewrite exports and imports with shims
that actually use `anyref` if needed, performing loads/stores inside the
wasm module instead of externally in the wasm module.

This should provide a boost over what we have today, but it's not a
fantastic strategy long term. We have a more grand vision for `anyref`
being a first-class type in the language, but that's on a much longer
horizon and this is currently thought to be the best we can do in terms
of integration in the near future.

The stack/heap JS tables are combined into one wasm table. The stack
starts at the end of the table and grows down with a stack pointer (also
injected). The heap starts at the end and grows up (state managed in
linear memory). The anyref transformation here will hook up various
intrinsics in wasm-bindgen to the runtime functionality if the anyref
supoprt is enabled.

The main tricky treatment here was applied to closures, where we need JS
to use a different function pointer than the one Rust gives it to use a
JS function pointer empowered with anyref. This works by switching up a
bit how descriptors work, embedding the shims to call inside descriptors
rather than communicated at runtime. This means that we're accessing
constant values in the generated JS and we can just update the constant
value accessed.
2019-02-20 07:28:54 -08:00