Commit Graph

1654 Commits

Author SHA1 Message Date
Alex Crichton
efacd8b74d
Merge pull request #1514 from ibaryshnikov/threadsafe-futures
Threadsafe futures
2019-07-19 09:38:04 -05:00
Pauan
ed778f5eb2 Adding in PartialEq and Eq to web-sys types 2019-07-18 23:12:49 +02:00
Alex Crichton
b13f757e90 Shared more betwee legacy with/without atomics 2019-07-18 14:11:59 -07:00
Alex Crichton
be294c8248 Remove a debugging statement 2019-07-18 14:04:45 -07:00
Alex Crichton
c8451d6f3e Rename some files
* Use "legacy" instead of "stable" since `futures 0.1` is quicly
  becoming "legacy"
* Rename "atomics" to "legacy_atomics" to leave room for the
  libstd-based futures atomics version.
* Rename "polyfill" to "wait_async_polyfill" to specify what it's
  polyfilling.
2019-07-18 14:00:45 -07:00
Alex Crichton
d590a9e053 Deduplicate JsFuture definitions
Turns out it's the exact same for both before and after atomics, so
let's use the same definition!
2019-07-18 13:59:14 -07:00
Alex Crichton
cde9684e4b Clean up atomics/futures + polyfill
* Remove now-unneeded `State` enum
* Remove timeout argument from polyfill since we don't need it
* Call `Atomics.waitAsync` if it's available instead of using our polyfill
* Remove some extraneous dead code from the polyfill
* Add a `val: i32` argument to the polyfill
* Simplify the flow of futures with `Package` since `waitAsync` handles
  all the heavy lifting for us.
* Remove `Arc<Package>` and just use `Package`
* Remove `RefCell` from inside of `Package` now that it is no longer
  needed.
2019-07-18 13:55:54 -07:00
Pauan
c3676bc6f9 Removing unneeded if statement 2019-07-18 21:51:29 +02:00
Pauan
adf21fe6cb Removing unneeded size argument 2019-07-18 21:51:29 +02:00
Pauan
cc6ec867f7 Fixing compile errors 2019-07-18 21:51:28 +02:00
Pauan
1723e9d024 More simplifications 2019-07-18 21:51:28 +02:00
Pauan
1e4cac9c95 Simplifying the output 2019-07-18 21:51:28 +02:00
Pauan
2ee4c54f00 Changing to use WasmSlice for the caching 2019-07-18 21:51:28 +02:00
Pauan
86a8842f24 Changing IntoWasmAbi to use interning 2019-07-18 21:51:28 +02:00
Pauan
6767371ca7 Initial interning implementation 2019-07-18 21:51:28 +02:00
Alex Crichton
d122bbca13 Emit a compiler error with futures 0.3 and atomics
Not implemented yet, and the one there doesn't work with atomics! (we'll
get around to this soon-ish)
2019-07-18 10:13:05 -07:00
ibaryshnikov
02be3690cf removed AtomicBool from Waker struct 2019-07-17 01:52:55 +03:00
ibaryshnikov
45d2c7ce93 updated to the latest master 2019-07-17 01:24:44 +03:00
ibaryshnikov
cbaa1d302a added documentation comment for a stable version of wasm-bindgen-futures 2019-07-17 00:58:05 +03: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
221dc732af updated default timeout and wait_async signature in wasm-bindgen-futures 2019-07-17 00:48:00 +03:00
ibaryshnikov
06c783d5e3 placed web-sys dependency behind a feature flag in wasm-bindgen-futures 2019-07-17 00:48:00 +03:00
ibaryshnikov
16c6bdc966 moved threadsafe futures implementation to a separate file, made updates after review 2019-07-17 00:48:00 +03:00
ibaryshnikov
e466e1a6f1 moved threadsafe futures behind a flag 2019-07-17 00:48:00 +03:00
ibaryshnikov
2fdfe79574 added polyfill implementation in rust 2019-07-17 00:48:00 +03:00
ibaryshnikov
c01575c1bc typo fixed in Atomics docs 2019-07-17 00:48:00 +03:00
ibaryshnikov
d1d3021271 added polyfill for Atomics.wait and used it to notify futures 2019-07-17 00:48:00 +03:00
Nick Fitzgerald
8fd5f4ed6a Check for use-after-move in JS glue when --debug is enabled again
Fixes #1669
2019-07-16 13:35:59 -07:00
Julien Cretin
170ce683d8 Add missing Element::get_elements_by_* methods 2019-07-15 19:47:09 +02:00
Nick Fitzgerald
a48a0aeb93
Merge pull request #1654 from fitzgen/no-import-shims
Skip generating JS import shims when unnecessary
2019-07-15 10:13:11 -07:00
Nick Fitzgerald
31ca527523 Bump wasm-webidl-bindings dep to 0.1.2 2019-07-15 09:35:22 -07:00
Nick Fitzgerald
afb33e5cf4 Assert that a bunch more function signatures don't require JS glue 2019-07-12 12:34:29 -07:00
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
4f86653e0d Fix parsing of final on Nightly Rust
This fixes an issue also reported to upstream (rust-lang/rust#62628) to
ensure that we parse the `final` attribute as either `r#final` or
`final`, since now the compiler is giving us `r#final` and we were
previously only accepting `final`.

The parsing here was a bit wonky, but this setup ended up working!
2019-07-12 10:05:11 -07:00
Nick Fitzgerald
2d0866da9a cli-support: rustfmt 2019-07-11 15:44:16 -07:00
Nick Fitzgerald
d5d3e46334 cli-support: Skip generating JS shims for imports when unnecessary
After this change, any import that only takes and returns ABI-safe numbers (signed
integers less than 64 bits and unrestricted floating point numbers) will be a
direct import, and will not have a little JS shim in the middle.

We don't have a great mechanism for testing the generated bindings' contents --
as opposed to its behavior -- but I manually verified that everything here does
the Right Thing and doesn't have a JS shim:

```rust
\#[wasm_bindgen]
extern "C" {
    fn trivial();

    fn incoming_i32() -> i32;
    fn incoming_f32() -> f32;
    fn incoming_f64() -> f64;

    fn outgoing_i32(x: i32);
    fn outgoing_f32(y: f32);
    fn outgoing_f64(z: f64);

    fn many(x: i32, y: f32, z: f64) -> i32;
}
```

Furthermore, I verified that when our support for emitting native `anyref` is
enabled, then we do not have a JS shim for the following import, but if it is
disabled, then we do have a JS shim:

```rust
\#[wasm_bindgen]
extern "C" {
    fn works_when_anyref_support_is_enabled(v: JsValue) -> JsValue;
}
```

Fixes #1636.
2019-07-11 15:44:16 -07:00
Nick Fitzgerald
f2a4694c69 cli-support: Fix copy-pasted error message
This error case is for an invalid free function, not an invalid constructor.
2019-07-11 15:44:16 -07:00
Nick Fitzgerald
21fe8dc706 cli-support: Fix typo in comment 2019-07-11 15:44:16 -07:00
Alex Crichton
e596ef596c Bump to 0.2.48 2019-07-11 15:02:39 -07:00
dependabot-preview[bot]
ce40388a7f
Update weedle requirement from 0.9 to 0.10
Updates the requirements on [weedle](https://github.com/rustwasm/weedle) to permit the latest version.
- [Release notes](https://github.com/rustwasm/weedle/releases)
- [Commits](https://github.com/rustwasm/weedle/compare/0.9.0...0.10.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-07-11 10:07:41 +00:00
Nick Fitzgerald
d02e115fd4
Merge pull request #1650 from alexcrichton/less-csp
Use static accessors if possible to get global object
2019-07-10 09:37:56 -07:00
Alex Crichton
b64f5c0ad8
Merge pull request #1649 from alexcrichton/fix-futures
Update futures implementation to not destroy callbacks
2019-07-10 11:02:43 -05:00
Nick Fitzgerald
6cb659d5ac Fix warning about dead code when testing on non-wasm32 targets
There are functions that are only used on wasm32 targets, but `cfg`ing them is
more work than just making the modules public, and this is just a testing crate.
2019-07-09 13:17:52 -07:00
Nick Fitzgerald
1ba298548f Fix warning about unnecessary parens in generated code 2019-07-09 13:17:34 -07:00
Alex Crichton
d32b6a916c Update futures implementation to not destroy callbacks
JS engines guarantee that at least one of our `then` callbacks are
invoked, so that means if we destroy them prematurely they're guaranteed
to log an exception to the console! Instead to prevent exceptions from
happening tweak how the completion callbacks for JS futures are managed
and ensure that the closures stay alive until they're invoked later.

Closes #1637
2019-07-09 11:14:26 -07:00
Alex Crichton
0b08bba0c7 Use static accessors if possible to get global object
Previously we always used `Function('return this')` but this triggers
CSP errors since it's basically `eval`. Instead this adds a few
preflight checks to look for objects like `globalThis`, `self`, etc.
Currently we don't have a `#[wasm_bindgen]` function annotation to
import a bare global field like `self`, but we test accesses with
`self.self` and `globalThis.globalThis`, catching errors to handle any
issues.

Closes #1641
2019-07-08 13:28:06 -07:00
Alex Crichton
604c036111
Merge pull request #1645 from derekdreery/fix_futures_0_3_hack
Add in (unsafe and incorrect) impls of Send/Sync that are now required.
2019-07-08 12:04:43 -05:00
ibaryshnikov
8f52f10aea added explicit extension for imported .wasm file for --target bundler 2019-07-08 03:50:17 +03:00
Richard Dodd
2541507789 Add in (unsafe and incorrect) impls of Send/Sync that are now required. 2019-07-06 16:30:29 +01:00
dakom
f27de49989 whitelist slices for webgl2 uniformNuiv 2019-07-03 23:32:00 +03:00
Thomas
0ee7236698 Define is_truthy in terms of is_falsy 2019-07-02 19:06:44 +02:00
Thomas
e61f691e0b Add is_truthy, is_falsy 2019-07-02 18:44:06 +02:00
Samuel Warfield
367a56eb25 Test are fully implemented 2019-06-28 14:14:27 -06:00
Samuel Warfield
06d0704cf8 Added tests for bind1() 2019-06-28 12:03:45 -06:00
Samuel Warfield
caa86a07a0 Attempted to tackle #1622 2019-06-27 15:48:18 -06:00
Alex Crichton
792ab403a1
Merge pull request #1625 from alexcrichton/less-return-ptr
Remove `__wbindgen_global_argument_ptr` intrinsic
2019-06-26 13:36:57 +02:00
Pauan
497c5ed423 Removing TODOs 2019-06-25 21:42:20 +02:00
Pauan
b9fd30b49e Adding in TODO note 2019-06-25 21:42:20 +02:00
Pauan
8cb9b88acb Adding in unit tests for From impl 2019-06-25 21:42:20 +02:00
Pauan
86937b9dba Adding in From impl for TypedArrays 2019-06-25 21:42:20 +02:00
Alex Crichton
b9c27b93a5 Update all non-mutable slices into Rust to use AllocCopy
This commit migrates all non-mutable slices incoming into Rust to use
the standard `AllocCopy` binding instead of using a custom `Slice`
binding defined by `wasm-bindgen`. This is done by freeing the memory
from Rust rather than freeing the memory from JS. We can't do this for
mutable slices yet but otherwise this should be working well!
2019-06-25 05:44:32 -07:00
Alex Crichton
eb550f5b4f Remove __wbindgen_global_argument_ptr intrinsic
We don't actually need this since we can simply pass in a number like 8
for the return pointer all the time. There's no need to allocate more
space in static data for a return pointer tha may not even get used!
2019-06-25 05:24:08 -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
597d66ab87 Update git repo for wasm-webidl-bindings 2019-06-25 01:16:00 -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
2e03961ca1 Be sure to GC our imports as well as the module
After a module goes through its primary GC pass we need to look over the
set of remaining imports and use that to prune the set of imports that
we're binding.

Closes #1613
2019-06-23 08:16:11 -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
9b8191efb1
Merge pull request #1605 from c410-f3r/getters-check
Forbid duplicated getter/setter names in fields and methods
2019-06-19 13:11:17 -05:00
Alex Crichton
c9ee88bda3 Preserve the function table during early gc passes
Recent refactorings of wasm-bindgen have inserted multiple `gc` passes
executed by walrus. In these passes though the function table was being
removed a bit too aggressively because it's not exported by LLD and it's
only later that we realize we need to export it.

To handle this case we add synthetic and temporary exports of the
function table and these exports are removed just after the GC pass in
question.

Closes #1603
2019-06-18 11:04:17 -07:00
Alex Crichton
8d90655f98
Merge pull request #1602 from alexcrichton/more-immutable
Handle more slice types in `flag_slices_immutable`
2019-06-18 11:04:09 -07:00
Alex Crichton
1aa6773c47
Merge pull request #1604 from marienz/link-utils-mixin
Make HTMLHyperlinkElementUtils a mixin, not a NoInterfaceObject
2019-06-17 16:56:21 -07:00
Caio
597b697017 Forbid duplicated getter/setter names in fields and methods 2019-06-17 15:09:39 -03:00
Alex Crichton
3361e02caf
Merge pull request #1601 from c410-f3r/unnecessary-result
Remove unnecessary Result return
2019-06-17 09:37:05 -05:00
Caio
af1f051e9b Typo 2019-06-17 11:36:51 -03:00
Alex Crichton
b5da08c6a0
Merge pull request #1598 from Pauan/fix-futures
Fixing panic if the Future wakes up after returning Poll::Ready
2019-06-17 09:36:24 -05:00
Marien Zwart
46e3cd5aa2 Make HTMLHyperlinkElementUtils a mixin, not a NoInterfaceObject
Commit b8afa0abde converted several interfaces
from NoInterfaceObject to mixins. It looks like it missed
HTMLHyperlinkElementUtils: it did update the interfaces that use
HTMLHyperlinkElementUtils (from "implements" to "includes"), but did not mark
HTMLHyperlinkElementUtils as a mixin.

Fix it, which makes HtmlAnchorElement gain useful functions like `set_href`.
2019-06-18 00:25:56 +10:00
Alex Crichton
379cad047a
Merge pull request #1599 from marienz/typescript-init
Make the argument to init optional in the Typescript declaration too
2019-06-17 07:32:09 -05:00
Alex Crichton
3b06e58c9e Handle more slice types in flag_slices_immutable
Should address the latest comment on #1539
2019-06-17 05:30:10 -07:00
Caio
00d47c1958 Remove unnecessary Result return 2019-06-16 22:24:27 -03:00
Caio
62681425b0 Update repository url 2019-06-16 19:52:11 -03:00
Marien Zwart
1b91457200 Make the argument to init optional in the Typescript declaration too
Commit 8ace8287ff made the argument to the
generated init() function optional (when the target is "web"), but it is still
marked as required in the generated .d.ts file.

Fix the generated declaration to match the function definition again.
2019-06-16 21:34:31 +10:00
Pauan
5a1dfdf2ab Fixing panic if the Future wakes up after returning Poll::Ready 2019-06-15 15:08:34 +02:00
Alex Crichton
8fc0a38402 Bump to 0.2.46 2019-06-14 11:44:58 -07:00
Alex Crichton
83a3f5d44a Run cargo fmt --all 2019-06-13 08:30:06 -07:00
Alex Crichton
1c558fac92
Merge pull request #1592 from alexcrichton/explicit-self
Include self-pointer in `Function` descriptions
2019-06-11 17:11:58 -05:00
Alex Crichton
80c75df166
Merge pull request #1590 from alexcrichton/intrinsics
Correct some intrinsic signatures
2019-06-11 14:53:22 -05:00
Alex Crichton
754328bef2
Merge pull request #1589 from alexcrichton/clamped
Remove the `Clamped` descriptor type
2019-06-11 14:53:15 -05:00
Alex Crichton
afbd7d3ff8 Include self-pointer in Function descriptions
Previously a `Function` didn't actually take into account the self
pointer and instead left it as an implicit argument. This instead
ensures that there's a `Descriptor::I32` type inside of a `Function`
description that we have to later skip, and this should not only make
the anyref pass correct for Rust exports but it should also make it more
accurate for future webidl transformations.
2019-06-11 12:51:53 -07:00
Alex Crichton
ce4cc317e8 Correct some intrinsic signatures
While this doesn't currently cause issues in the upcoming webidl
refactor this is actually being asserted and causes verification issues
if the types don't align!

These are basically just mistakes from the original implementation of
this module, but this doesn't actually fix a known bug today.
2019-06-11 11:56:08 -07:00
Alex Crichton
621fc9c440 Remove the Clamped descriptor type
This is just a bit too general to work with and is pretty funky. Instead
just tweak `Clamped<&[u8]>` to naturally generate a descriptor for
`Ref(Slice(ClampedU8))`, requiring fewer gymnastics when interpreting
descriptors.
2019-06-11 11:52:13 -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
Alex Crichton
535aa3193c Attempt to fix compilation issues on CI
Can't reproduce the errors on Azure locally, but hopefully tweaking
generated code can get things to work.
2019-06-10 08:47:19 -07:00
Alex Crichton
c3e0edd956
Merge pull request #1586 from alexcrichton/no-web-sys
Make `env_logger` an optional dependency
2019-06-10 10:47:14 -05:00
Alex Crichton
a7726545ac
Merge pull request #1579 from ibaryshnikov/default-init-module
added default module path inside init function when target is web
2019-06-10 10:40:38 -05:00
Alex Crichton
5cf8224d99 Make env_logger an optional dependency
Only used during development no need to pull in its set of features when
typically compiled as a dependency of other crates!

Closes #1580
2019-06-10 07:12:44 -07:00
Pauan
b205045424 Adding in AsRef impl for all wasm_bindgen types 2019-06-10 08:05:59 +02:00
ibaryshnikov
8ace8287ff added default module path inside init function when target is web 2019-06-08 01:27:35 +03:00
Caio
e7e8ae1877 Fix getter and setter 2019-06-06 16:11:51 -03:00
Alex Crichton
59e773f5ec Update walrus 2019-06-05 11:08:04 -07:00
Alex Crichton
bf1a31e139 Don't generate a free function shim for classes
This was once required due to flavorful management of the `WeakRef`
proposal but nowadays it's simple enough that we don't need to refactor
it out here.
2019-06-05 07:52:14 -07:00
Alex Crichton
6e8c3e88f8 Directly import __wrap functions if possible
These can have similar optimizations as importing a value directly.
2019-06-05 07:52:14 -07:00
Alex Crichton
c22b907e7f Touch up some comments 2019-06-05 07:52:14 -07:00
Alex Crichton
ee426c03a9 Ensure that generated JS is deterministic
Iteration order of hash maps is nondeterministic, so add a `sorted_iter`
function and then use that throughout whenever iteration order of a hash
map would affect the generated JS.
2019-06-05 07:52:14 -07:00
Alex Crichton
cfd3e0406f Split symbol intrinsics into two
This allows using WebIDL bindings types to describe both of them instead
of having a custom ABI, allowing for more direct and rich bindings
eventually!
2019-06-05 07:52:14 -07:00
Alex Crichton
6f727d7c13 Refactor the module name slightly in gen_init 2019-06-05 07:52:14 -07:00
Alex Crichton
4eafaeae2d Handle the function table export on-demand
Don't delay processing until `finalize`, but instead process it as soon
as it's requested to avoid doing too much logic in `finalize`.
2019-06-05 07:52:14 -07:00
Alex Crichton
71209686e9 Use unwrap_call instead of an explicit match 2019-06-05 07:52:14 -07:00
Alex Crichton
c7021ba307 Update crates/cli-support/src/js/mod.rs
Co-Authored-By: Nick Fitzgerald <fitzgen@gmail.com>
2019-06-05 07:52:14 -07:00
Alex Crichton
3b5e3edd18 Fix anyref closure transformations
* Catch all closures by walking all `Descriptor` values and looking for
  either `Function` or `Closure`.
* Update the correct arguments for wasm by ensuring that the closure
  modifications skip the first two arguments.
2019-06-05 07:52:14 -07:00
Alex Crichton
b51df39bc9 Reimplement anyref processing and passes
This commit reimplements the `anyref` transformation pass tasked with
taking raw rustc output and enhancing the module to use `anyref`. This
was disabled in the previous commits during refactoring, and now the
pass is re-enabled in the manner originally intended.

Instead of being tangled up in the `js/mod.rs` pass, the anyref
transformation now happens locally within one module,
`cli-support/src/anyref.rs`, which exclusively uses the output of the
`webidl` module which produces a WebIDL bindings section as well as an
auxiliary wasm-bindgen specific section. This makes the anyref transform
much more straightforward and local, ensuring that it doesn't propagate
elsewhere and can be a largely local concern during the transformation.

The main addition needed to support this pass was detailed knowledge of
the ABI of a `Descriptor`. This knowledge is already implicitly
hardcoded in `js2rust.rs` and `rust2js.rs` through the ABI shims
generated. This was previously used for the anyref transformation to
piggy-back what was already there, but as a separate pass we are unable
to reuse the knowledge in the binding generator.

Instead `Descriptor` now has two dedicated methods describing the
various ABI properties of a type. This is then asserted to be correct
(all the time) when processing bindings, ensuring that the two are kept
in sync.
2019-06-05 07:52:14 -07:00
Alex Crichton
55fc5367a5 Fix a typo in the JsvalEq intrinsic
This is supposed to be `===`, not `==`.
2019-06-05 07:52:14 -07:00
Alex Crichton
cbd4b87d08 Fix handling imported memories
Need to make sure we update the import itself and configure the value on
the import object!
2019-06-05 07:52:14 -07:00
Alex Crichton
b4c395bd6e Fix an inverted condition for catch_and_throw 2019-06-05 07:52:14 -07:00
Alex Crichton
edd1469d21 Include docs in generated JS getters/setters 2019-06-05 07:52:14 -07:00
Alex Crichton
cba1e70077 Fix TypeScript output for fields 2019-06-05 07:52:14 -07:00
Alex Crichton
ff0a50e31e Fix failing interpreter tests 2019-06-05 07:52:14 -07:00
Alex Crichton
346868f78b Fix a failing CLI test 2019-06-05 07:52:14 -07:00
Alex Crichton
22b26db911 Use delete_typed to improve some ergonomics 2019-06-05 07:52:14 -07:00
Alex Crichton
e8e84a3f9c Remove __exports map on the web target
This is no longe rneeded now that we precisely track what needs to be
exported for an imported item, so all the imports are hooked up
correctly elsewhere without the need for the `__exports` map.
2019-06-05 07:52:14 -07:00
Alex Crichton
3e28e6ea46 Fix web, no-modules, and bundler output types
Make sure the wasm import definition map is hooked up correctly!
2019-06-05 07:52:14 -07:00
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
Teddy Katz
5c5c13cf9e
Add Array#flat and Array#flatMap to js-sys (fixes #1454) 2019-06-03 18:32:58 -04: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
ad68436cc9 Looks like webassembly-js-api package no longer needed!
Closes #1565
2019-05-30 07:40:26 -07: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
Gus Caplan
66ade77720
Rewrite weakrefs to use current proposal 2019-05-26 09:30:33 -05: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
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
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
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
dakom
ae2aba094c whitelist uniforms with Int32List 2019-05-17 09:59:28 +03:00
lqd
ca0008174a Update weedle to version 0.9 2019-05-16 18:52:25 +02:00
Alex Crichton
773c6ff430 Bump to 0.2.44 2019-05-16 07:47:23 -07:00
Alex Crichton
5d97b358a2
Merge pull request #1534 from alexcrichton/trybuild
Migrate to `trybuild` from `compiletest`
2019-05-15 16:57:57 -05:00
Alex Crichton
4cc730fc41 Migrate to trybuild from compiletest
This migrates our UI tests to the recently published `trybuild` crate
which should hopefully be a bit more robust than `compiletest` over
time!
2019-05-15 14:47:22 -07:00
Huston Bokinsky
e728a7ee9e Enable text area selectionStart and selectionEnd calls. 2019-05-14 14:58:06 -07:00
Alex Crichton
827810fa1b
Merge pull request #1483 from dbrgn/typescript-optional-args
Fix optional arguments in TypeScript
2019-05-14 12:39:35 -05:00
Ingvar Stepanyan
716ed0d891 Hotfix for double encodeInto call
This was a regression introduced in the last commit of https://github.com/rustwasm/wasm-bindgen/pull/1470, which might make Unicode strings 2x slower to pass.
2019-05-14 14:14:34 +01:00
Alex Crichton
15defcfd3a Add a debug assert and more tests 2019-05-13 08:12:32 -07:00
Ingvar Stepanyan
0c681ee2ba Fix offset to arg comparison 2019-05-10 15:31:59 +01:00
Ingvar Stepanyan
7418cec613 Reduce reallocation sizes 2019-05-10 14:44:49 +01:00
Ingvar Stepanyan
57b1a57c5e Speed up passing ASCII-only strings to WASM
Some speed up numbers from my string-heavy WASM benchmarks:
 - Firefox + encodeInto: +45%
 - Chrome + encodeInto: +80%
 - Firefox + encode: +29%
 - Chrome + encode: +62%

Note that this helps specifically with case of lots of small ASCII strings, in case of large strings there is no measurable difference in either direction.
2019-05-10 14:40:59 +01:00
Nick Fitzgerald
befefe0da6
Merge pull request #1521 from fitzgen/anyref-heap-live-count
Utility for counting the number of live JsValues in the wasm-bindgen heap
2019-05-09 16:22:06 -07:00
Nick Fitzgerald
450c9234ad Add the anyref_heap_live_count function
This is useful for debugging and writing tests that assert various operations do
not leak `JsValue`s.
2019-05-09 15:57:21 -07:00
Chris Trevino
9b5de9f88d update init test 2019-05-09 11:12:45 -07:00
Chris Trevino
2850cfc78e update init function export 2019-05-09 11:01:45 -07:00
Danilo Bargen
608a819c0b fixup! Fix optional arguments in TypeScript
Update tests
2019-05-09 18:36:47 +02:00
Danilo Bargen
d9c559f2ca fixup! Fix optional arguments in TypeScript
Apply feedback about omittable and non-omittable arguments. Thanks
@rhysd!
2019-05-09 18:22:47 +02:00
Danilo Bargen
2384af21c1 Fix optional arguments in TypeScript 2019-05-09 18:09:29 +02:00
Alex Crichton
d139228a34
Merge pull request #1508 from RSSchermer/master
Add `bufferSubData` and `clearBuffer[fiuv]` to immutable slice whitelist
2019-05-08 07:14:27 -07:00
Alex Crichton
a85335dee9
Merge pull request #1507 from Pauan/futures-0.3
Adding in Futures 0.3 support to wasm-bindgen-futures
2019-05-06 10:23:30 -05:00
Pauan
c00262f210 Fixing some nits 2019-05-04 09:28:54 +02:00
Pauan
6c58afda01 Addressing feedback 2019-05-04 09:17:29 +02:00
Alex Crichton
9d33dd8717 Remove unused statements in web-sys build script 2019-05-03 14:59:35 -07:00
Alex Crichton
d6a6fdfcc7 Don't assert rustfmt succeeds
Not all environments have it so only run it and hope it succeeds.
2019-05-03 14:59:01 -07:00
Alex Crichton
a7b85362ce
Merge pull request #1506 from alexcrichton/fix-same-name
Fix importing and exporting the same name
2019-05-03 11:29:44 -05:00
Alex Crichton
3d43d6e5e8 Fix importing and exporting the same name
Run exports through the same identifier generation as imports to ensure
that everything gets a unique identifier and then just make sure all the
appropriate wires are hooked up when dealing with exports and imports.

Closes #1496
2019-05-03 07:15:20 -07:00
Alex Crichton
5a017c1e22 Update walrus dependency 2019-05-03 07:12:28 -07:00
RSSchermer
15e5162275 Add bufferData and clearBuffer to immutable slice whitelist 2019-05-02 18:19:31 +02:00
Pauan
69d7dc24b1 Adding in Futures 0.3 support 2019-05-02 13:48:44 +02:00
Alex Crichton
358ee18ab2
Merge pull request #1466 from fitzgen/log-stacks
Log stacks of imported JS functions that throw but aren't marked `catch`
2019-05-01 16:51:50 -05:00
Alex Crichton
22eb34d9ab Fix direct imports in --target web
Currently the import object constructed for the `--target web` output
only ever includes the current module as an one of the modules included.
With `wasm-bindgen`'s optimization to import directly from modules,
however, it's possible to have more modules imported from in the
generated wasm file. This commit ensures that the imports are hooked up
in the `--target web` es6 emulation mode, ensuring there aren't
extraneous errors about import objects.
2019-05-01 13:53:59 -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
Alex Crichton
60bb68649b
Merge pull request #1490 from RReverser/deprecate-custom-try-from
Recommend to use dyn_ref on funcs and strings
2019-04-29 09:08:00 -05:00
Caio
0c4cdefd07 Rustfmt 2019-04-29 09:45:23 -03:00
Alex Crichton
36c0a1347d
Merge pull request #1492 from RReverser/function-new-with-args
Add bindings for `new Function(args, body)`
2019-04-26 12:05:46 -05:00
Ingvar Stepanyan
814f576b1d Add bindings for new Function(args, body)
We don't support variadic args in front, but, luckily for us, `new Function` accepts comma-separated args as a single string as well (see updated JSON test for an example).
2019-04-26 17:42:23 +01:00
Ingvar Stepanyan
85eea18658 Adds missing variadic bindings for string methods
- `JsString::from_code_point` - allows to create JS strings using slice of codes in WASM memory.
 - `JsString::from_char_code` - same as above, but also uses updated signature with `u16` instead of `u32` (partially helps with #1460 at least for the new binding).
2019-04-26 16:57:34 +01:00
Ingvar Stepanyan
ccc99cd047 Recommend to use dyn_ref on funcs and strings
Now that functions and strings work properly with custom typechecks, these custom methods seem obsolete, so I'd recommend to use standard dyn_ref instead.
2019-04-26 15:50:08 +01:00
Alex Crichton
26f9d86f62
Merge pull request #1487 from ibaryshnikov/shared_array_buffer_tests
Added tests for SharedArrayBuffer
2019-04-26 09:38:16 -05: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
Kevin Gibbons
70480ad29d fix test 2019-04-25 21:21:17 -07:00
Kevin Gibbons
a32d2553fc js-sys: add Object.fromEntries 2019-04-25 20:52:29 -07:00
Alex Crichton
26df24ae6a
Merge pull request #1484 from alexcrichton/new-node
Upgrade version of node.js used on Azure
2019-04-25 22:14:31 -05:00
ibaryshnikov
af22a26880 added tests for SharedArrayBuffer 2019-04-26 10:59:06 +08:00
Alex Crichton
7e512ba187
Merge pull request #1463 from ibaryshnikov/atomics-support
added Atomics and SharedArrayBuffer
2019-04-25 21:48:55 -05:00
Alex Crichton
4156a37856
Merge pull request #1485 from alexcrichton/missing-vector-len
Add missing `expose_wasm_vector_len`
2019-04-25 21:48:09 -05:00
Alex Crichton
dea5bad698 Fix test for node 12 2019-04-25 19:30:32 -07:00
Alex Crichton
21205eccf2 Add missing expose_wasm_vector_len
Found through some testing I did awhile back!
2019-04-25 19:21:13 -07:00
ibaryshnikov
b05ae44a8c changed f64 to i32 in static methods of Atomics, changed static_method_of to js_namespace, set typed_array type to Int32Array in notify and wait methods 2019-04-26 01:56:58 +08:00
ibaryshnikov
58245b0587 changed String to JsString in Atomics::wait 2019-04-26 00:02:19 +08:00
ibaryshnikov
de2c2cf26c fixed Atomics::wait and Atomics::wait_with_timeout return type 2019-04-25 19:18:31 +08:00
Ingvar Stepanyan
680a6bbb0c Remove PartialEq<char> for JsString for now
This seems to spark controversy, so removing for now but should be easy enough to still add in the future.
2019-04-24 13:40:18 +01:00
ibaryshnikov
0759bfa7e2 f32 changed to f64 in Atomics 2019-04-24 00:27:15 +08:00
ibaryshnikov
f1eaefdf0d fixed value types in Atomics methods 2019-04-24 00:25:25 +08:00
ibaryshnikov
1071457c3d added SharedArrayBuffer and Atomics to js-sys 2019-04-24 00:01:15 +08:00
Ingvar Stepanyan
bc4a98d146 Add JsString <-> char conversions
These are pretty common and already supported via ABI conversions, yet pretty easy to get wrong when converting them manually.

Fixes #1363.
2019-04-23 15:54:06 +01:00
Laurențiu Nicola
04a78badc5 Implement Debug for JsFuture 2019-04-20 09:41:59 +03:00
Alex Crichton
7decb133f0
Merge pull request #1472 from c410-f3r/ts-methods
TS: Add docs for methods
2019-04-18 09:07:33 -07:00
Caio
59fd11b31c TS: Add docs for methods 2019-04-17 18:41:20 -03:00
Nick Fitzgerald
805aaa2273 Log stacks of imported JS functions that throw but are not marked catch
Particularly useful in our tests, where we don't have the regular console
logging with post-facto object inspection, and instead need to provide all this
info up front.
2019-04-17 13:16:48 -07:00
Ingvar Stepanyan
d7650863ab Fix or suppress {primitive}::new warnings in tests
Constructing boxed primitives was deprecated in #1447.

Some tests have been still using these methods, so this PR either updates them to use newly added {primitive}::from implementations or adds `#[allow(deprecated)]` where necessary.
2019-04-17 18:25:45 +01: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
79f370deef Add env vars to filter wasm-bindgen-test-runner tests
This is intended to handle #1458 and #822. These issues stem from
behavior where:

    wasm-pack test --node

will actually run both Node.js and browser tests! Two new env vars are
read here, `WASM_BINDGEN_TEST_ONLY_{NODE,WEB}`, which control which
tests are executed by `wasm-bindgen-test-runner`. The intention is that
these will be set by `wasm-pack` to configure which tests are run, and
if test suites are skipped due to the env vars we'll print an
informational message indicating how they can be run.

Closes #822
Closes #1458
2019-04-16 10:42:16 -07:00
Alex Crichton
18746ecf4a
Merge pull request #1461 from alexcrichton/rustfmt-web-sys
Format web-sys bindings by default
2019-04-15 12:36:28 -05:00
Alex Crichton
3ab9bb192a
Merge pull request #1449 from alexcrichton/no-interface-objects
Support [NoInterfaceObject] in `web-sys`
2019-04-15 12:36:14 -05:00
Alex Crichton
01a52233d3 Support [NoInterfaceObject] in web-sys
This commit enables `[NoInterfaceObject]` annotated interfaces in
`web-sys`. The `NoInterfaceObject` attribute means that there's not
actually a JS class for the object, but all of its properties and such
can still be accessed structually and invoked. This should help provide
more bindings for some more common types on the web!

Note that this builds on recent features to ensure that `dyn_into` and
friends always fail for `NoInterfaceObject` objects because they don't
actually have a class.

Closes #893
Closes #1257
Closes #1315
2019-04-15 10:36:01 -07:00
Alex Crichton
fd4f0b6508 Format web-sys bindings by default
This commit switches to executing `rustfmt` by default on
`web-sys`-generated bindings. This improves situations like "view
source" in Rustdoc as well as the IDE interactive debugging experience.

This was initially disabled by default because `rustfmt` took so long to
execute, but nowadays `web-sys` is by default much smaller so there's
much less need to avoid running `rustfmt` in fear of it taking too
long.

Closes #1457
2019-04-15 08:33:02 -07:00
Alex Crichton
526b253b47
Merge pull request #1451 from RReverser/more-static-namespaces
Transform Math, Reflect and JSON into static namespaces
2019-04-15 09:41:40 -05:00
Alex Crichton
7ee4906661
Merge pull request #1410 from alexlapa/add-wasm-bindgen-skip-attr
Add wasm_bindgen(skip) attribute
2019-04-15 09:31:01 -05:00
Ingvar Stepanyan
ed45ca72da Fix more DataView documentation mistakes
I fixed few copy-paste mistakes in https://github.com/rustwasm/wasm-bindgen/pull/1372, but haven't noticed that they go even deeper :(
2019-04-15 14:31:23 +01:00
alexlapa
00c4dd9b6f Merge branch 'master' into add-wasm-bindgen-skip-attr 2019-04-14 23:43:21 +03:00
Ingvar Stepanyan
62b7d3e3c4 Transform JSON into a namespace 2019-04-13 02:22:19 +01:00
Ingvar Stepanyan
75c2971ab9 Transform Reflect into a namespace 2019-04-13 02:21:33 +01:00
Ingvar Stepanyan
fe939bc911 Transform Math into a namespace 2019-04-13 02:20:24 +01:00
Ingvar Stepanyan
2f524ee494 Leverage new is_type_of for iterator protocol
Treats any object of shape `{ next: function }` as an iterator via new `is_type_of` method. This is consistent with JavaScript iteration protocol which we already respect.

Also fixes a minor issue that `is_function` was unnecessarily called twice (once explicitly and once as part of `dyn_into` which now does the same check).
2019-04-12 20:30:41 +01: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
ba1f67d854 Remove some unnecessary unsafe in js-sys 2019-04-12 09:02:39 -07: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
018b9b4e09 Fix compile of js-sys 2019-04-12 08:54:23 -07:00
Alex Crichton
ba88ae8b64 Improve Boolean/Number/JsString consistency
* Ensure `PartialEq` is implemented from these types to native Rust types
* Implement `From` between these type and native Rust types
* Deprecated `Number::new` and `Boolean::new` to discourage use of the
  object forms, recommending the `from` constructors instead.

Closes #1446
2019-04-12 08:50:29 -07:00
Alex Crichton
df6e15e3ab Bump to 0.2.42 2019-04-11 07:39:45 -07:00
Alex Crichton
3906e4066d Fix a bug using encodeInto truncating strings
The last write accidentally wasn't accounted for in the returned length
of the string and we unfortunately don't have any test coverage of
`encodeInto` since it requires Firefox nightly right now (and doesn't
work in Node yet).

Closes #1436
2019-04-11 07:25:27 -07:00
Alex Crichton
02394724ea Bump to 0.2.41 2019-04-10 10:53:32 -07:00
Alex Crichton
7e5e401076 Add an accessor for the function table
This commit adds an intrinsics to the `wasm_bindgen` crate which
accesses the `WebAssembly.Table` which is the function table of the
module. Eventually the thinking is that a module would import its own
function table via native wasm functionality (via `anyref` and such),
but until that's implemented let's add a binding for it ourselves!

Closes #1427
2019-04-08 10:40:46 -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
16745edf3f
Merge pull request #1416 from alexcrichton/js-string-valid-utf16
Add warnings about UTF-16 vs UTF-8 strings
2019-04-05 10:12:32 -05: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
Nick Fitzgerald
dff9b9b1e3 Don't put anything before ES module imports
Because of some incorrect use of `js.push_str(..)`, we could sometimes emit code
before the ES modules imports, which is syntactically invalid:

    const __exports = {};
    import { Thing } from '...'; // Syntax error!

This has been fixed by making sure that the correct `imports` or `imports_post`
string is built up. We now also assert that the `js` string is empty at the
location where we add imports if we're using ES modules.
2019-04-04 15:53:43 -07:00
Alex Crichton
f48fdec21e Fix imported usage of wasm_bindgen macro
Make sure it refers to `__wasm_bindgen_class_marker` via an absolute
path!

Closes #1422
2019-04-04 09:56:16 -07:00
Alex Crichton
e3473f5e9e Fix instantiation with a Module
This commit fixes the `init` function when passed a
`WebAssembly.Module`. Upon closer reading of the [spec] we see there's
two possible return values from `WebAssembly.instantiate`. If passed a
`Module`, it will return only the `Instance`. If passed a buffer source,
though, it'll return an object with the module/instance.

The fix here is to check the result value is an `Instance`, and if so
assume the input must have been a module so it's paired up in the
output.

Closes #1418

[spec]: http://webassembly.github.io/spec/js-api/index.html#webassembly-namespace
2019-04-02 14:19:24 -07:00
Alex Crichton
fa674df109
Merge pull request #1412 from c410-f3r/init-ts
Add TS type for init fn
2019-04-02 15:46:34 -05:00
Caio
b6317e3f24 Add TS type for init fn 2019-04-01 19:45:53 -03:00
Ingvar Stepanyan
2f28b8b80e Optimise encodeInto reallocations
Instead of doubling the size on each iteration, use precise upper limit (3 * JS length) if the string turned out not to be ASCII-only. This results in maximum of 1 reallocation instead of O(log N).

Some dummy examples of what this would change:
 - 1000 of ASCII chars: no change, allocates 1000 bytes and bails out.
 - 1000 ASCII chars + 1 '😃': before allocated 1000 bytes and reallocated to 2000; now allocates 1000 bytes and reallocates to 1006.
 - 1000 of '😃' chars: before allocated 1000 bytes, reallocated to 2000, finally reallocated again to 4000; now allocates 1000 bytes and reallocates to 4000 right away.

Related issue: #1313
2019-04-01 13:08:08 +01:00
alexlapa
1dcf468c9d add wasm_bindgen(skip) attr to disable getters and setters exposure of pub fields 2019-03-30 05:09:02 +02:00
Alex Crichton
1121393203
Merge pull request #1403 from RReverser/expose-constructor
Add `constructor` property to `Object`
2019-03-28 10:55:22 -03:00
Alex Crichton
0160f6af45 Fix handling of u32 between Rust and JS
All numbers in WebAssembly are signed and then each operation on them
may optionally have an unsigned version. This means that when we pass
large signed numbers to JS they actually show up as large negative
numbers even though JS numbers can faithfully represent the type.

This is fixed by adding `>>>0` in a few locations in the generated
bindings to coerce the JS value into an unsigned value.

Closes #1388
2019-03-27 13:37:14 -07:00
Ingvar Stepanyan
db17e9d2a7 Add constructor property to Object 2019-03-27 14:25:55 +00:00
Ingvar Stepanyan
a5f5c7a9e8 Consistently expose is_like_none
Aside from visual deduplication, this actually fixes a bug in js2rust.rs where it didn't call `expose_is_like_none` but used `isLikeNone` inside of `arg.get_64()` branch.
2019-03-26 18:53:55 +00:00
Alex Crichton
72672ff42a
Merge pull request #1397 from RReverser/option-char-abi
Simplify ABI for Option<char>
2019-03-26 13:50:59 -05:00
Ingvar Stepanyan
5f742ca4c4 Simplify ABI for Option<char>
Flatten None to a special u32 value instead of using an intermediate pointer.
2019-03-26 18:12:24 +00: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