Commit Graph

1008 Commits

Author SHA1 Message Date
Alex Crichton
40b68c66d9 Fix a bug in coalescing types with GC
When a duplicate type is found is should no longer be considered used!
2018-10-30 15:45:21 -07:00
Alex Crichton
31c11f0781 GC passive segments
We statically know which passive segments are actually used, so let's be
sure to gc them!
2018-10-29 16:49:02 -07:00
Alex Crichton
91d68a0012 Add tests for the wasm-gc crate
This commit adds a test harness and the beginnings of a test suite for
the crate that performs GC over a wasm module. This crate historically
has had zero tests because it was thought that it would no longer be
used once LLD landed with `--gc-sections`, but `wasm-bindgen` has come
to rely more and more on `wasm-gc` for various purposes.

The last release of `wasm-bindgen` was also released with a bug in the
recently refactored support in the `wasm-gc` crate, providing a perfect
time and motivation to start writing some tests!

All tests added here are `*.wat` files which contain the expected output
after the gc pass is executed. Tests are automatically updated with
`BLESS_TESTS=1` in the environment, which is the expected way to
generate the output for each test.
2018-10-29 15:49:35 -07:00
Alex Crichton
6dfbb4be89 Bump to 0.2.27 2018-10-29 14:30:33 -07:00
Alex Crichton
b1d92aecac
Merge pull request #995 from alexcrichton/gc-too-aggressive
Assume all data/element/table/memory segments needed
2018-10-29 14:16:59 -07:00
Alex Crichton
a0a9ed4686
Merge pull request #986 from alexcrichton/gc-types
Eliminate duplicate types in the type section
2018-10-29 14:11:58 -07:00
Alex Crichton
d172c20b76 Assume all data/element/table/memory segments needed
wasm-gc is in dire need of a better test suite, so I'll work on that
before attempting to de-pessimize this.

Closes #994
2018-10-29 14:06:06 -07:00
Alex Crichton
7fad2bf0c8 Bump to 0.2.26 2018-10-29 12:56:37 -07:00
Alex Crichton
27001a226d Eliminate duplicate types in the type section
This commit updates the `wasm-gc` pass of wasm-bindgen to eliminate
duplicate types in the type section, effectively enabling a gc of the
type section itself. The main purpose here is ensure that code generated
by `wasm-bindgen` itself doesn't have to go too far out of its way to
deduplicate at generation time, but rather it can rely on the gc pass to
clean up.

Note that this currently depends on paritytech/parity-wasm#231, but this
can be updated if that ends up not landing.
2018-10-29 12:04:11 -07:00
Alex Crichton
fab5c795ae Add gc support for locals in functions
This commit adds support for running a gc pass over locals in a
function. This will remove dead local declarations for a function
(completely unused) as well as compact existing entries to ensure that
we don't have two local declarations of the same type.

While this was initially intended for some future support of emitting
shims in `wasm-bindgen`, it turns out this pass is firing quite a lot
over existing functions generated by LLVM. Looks like we may see benefit
from this today with slightly smaller wasm binaries!
2018-10-29 10:10:23 -07:00
Nick Fitzgerald
1ec68009e8
Merge pull request #985 from alexcrichton/differeng-gc
Restructure internals of `wasm-gc`
2018-10-29 10:45:53 +01:00
Nick Fitzgerald
73740ba6ab
Merge pull request #984 from alexcrichton/more-gc
Discard internal LLD symbols during gc
2018-10-29 10:44:50 +01:00
Alex Crichton
aa963db854 Fix WebDriver compat with Safari
They've made a few breaking changes in the most recent version, so let's
support that plus the old protocol for now!

Closes #983
2018-10-28 12:44:05 -07:00
Alex Crichton
4407a791c2 Discard internal LLD symbols during gc
These don't seem to be widely used and they're not needed by
wasm-bindgen itself, so let's remove the symbols by default and
optionally in the future we can add an option to retain them.
2018-10-28 10:11:02 -07:00
Alex Crichton
a0fc095407 Restructure internals of wasm-gc
This commit restructures some of the internals of `wasm-gc` now that
I've actually got a better grasp on the wasm format and what all the
ownership edges look like. This shouldn't actually result in any
user-facing changes, but should make us be a bit more compatible with
operations in the future.

Memories/tables/elements/segments are no longer considered automatic
roots but rather need to be rooted by something else to prevent a gc.
For example an element section is gc'd along with a table if the table
is never referenced, along with data segments as well if the memory
isn't referenced.

Additionally all index sets now don't contained offseted indices, but
rather everything is always stored relative to the "index space" to
ensure consistency.

This should make it a bit easier to add future items to gc!
2018-10-28 10:10:51 -07:00
Alex Crichton
c8f2f77480
Merge pull request #954 from alexcrichton/fix-futures
Defer future execution to the next event loop tick
2018-10-23 16:40:31 +02:00
Alex Crichton
a1da85a24b Defer future execution to the next event loop tick
Previously whenever a future readiness notification came in we would
immediately start polling a future. This ends up having two downsides,
however:

* First, the stack depth may run a risk of getting blown. There's no
  recursion limit to defer execution to later, which means that if
  futures are always ready we'll keep making the stack deeper.

* Second, and more worrisome in the near term, apparently future
  adapaters in the `futures` crate (namely the unsync oneshot channel)
  doesn't actually work if you immediately poll on readiness. This may
  or may not be a bug in the `futures` crate but it's good to fix it
  here anyway.

As a result whenever a future is ready to get polled again we defer its
polling to the next turn of the event loop. This should ensure that the
current call stack is always drained and we're effectively enqueueing
the future to be polled in the near future.
2018-10-23 07:12:54 -07:00
Alex Crichton
cb170ef94f
Merge pull request #972 from alexcrichton/bulk-memory
Implement support for WebAssembly threads
2018-10-23 11:30:59 +02:00
Alex Crichton
25b26f41e7 Implement support for WebAssembly threads
... and add a parallel raytracing demo!

This commit adds enough support to `wasm-bindgen` to produce a workable
wasm binary *today* with the experimental WebAssembly threads support
implemented in Firefox Nightly. I've tried to comment what's going on in
the commits and such, but at a high level the changes made here are:

* A new transformation, living in a new `wasm-bindgen-threads-xform`
  crate, prepares a wasm module for parallel execution. This performs a
  number of mundane tasks which I hope to detail in a blog post later on.
* The `--no-modules` output is enhanced with more support for when
  shared memory is enabled, allowing passing in the module/memory to
  initialize the wasm instance on multiple threads (sharing both module
  and memory).
* The `wasm-bindgen` crate now offers the ability, in `--no-modules`
  mode, to get a handle on the `WebAssembly.Module` instance.
* The example itself requires Xargo to recompile the standard library
  with atomics and an experimental feature enabled. Afterwards it
  experimentally also enables threading support in wasm-bindgen.

I've also added hopefully enough CI support to compile this example in a
builder so we can upload it and poke around live online. I hope to
detail more about the technical details here in a blog post soon as
well!
2018-10-23 01:20:18 -07:00
Alex Crichton
cb9c9fb011 Shrink binary size of distributed wasm-bindgen
This shaves a little over 2MB off the download locally for Linux,
removing debuginfo (which no one's probably gonna use anyway) as well as
switching from jemalloc to the system allocator.
2018-10-17 19:15:09 -07:00
Alex Crichton
ab8be88e7b
Merge pull request #970 from alexcrichton/more-new
Bind more Typed Array constructors in `js-sys`
2018-10-17 09:57:47 -05:00
Alex Crichton
a4a2ec605d Update parity-wasm
Bring in some support for bulk-memory-operations instructions
2018-10-16 14:04:40 -07:00
Alex Crichton
9effb7c707 Bind more Typed Array constructors in js-sys
Bind `new Int8Array(length)`, `new Int8Array(buffer, offset)` and `new
Int8Array(buffer, offset, length)`.
2018-10-16 11:16:22 -07:00
Alex Crichton
34b75c35b2 Allow passing a WebAssembly.Module in --no-modules
I've noticed this in a few cases where it's sometimes easy to have a
`WebAssembly.Module` on-hand for the `--no-modules` mode where you don't
want to necessarily `fetch`. This commit changes the exported
initialization function in `--no-modules` mode to support both!
2018-10-16 10:48:07 -07:00
Nick Fitzgerald
0b59657603
Merge pull request #945 from alexcrichton/remove-json
Don't use JSON for custom section format
2018-10-16 05:49:00 -07:00
Joni Katajamäki
83f9f54b04 Fix getFloat64 comments 2018-10-15 16:24:49 +03:00
Joni Katajamäki
968b5e0154 Add overloads with endianness parameter to DataView gets and sets 2018-10-15 14:32:17 +03:00
Alex Crichton
f749c7cf95 Don't use JSON for custom section format
This commit migrates away from using Serde for the custom section in
wasm executables. This is a refactoring of a purely-internal data
structure to `wasm-bindgen` and should have no visible functional change
on users.

The motivation for this commit is two fold:

* First, the compile times using `serde_json` and `serde_derive` for the
  syntax extension isn't the most fun.
* Second, eventually we're going to want to stablize the layout of the
  custom section, and it's highly unlikely to be json!

Primarily, though, the intention of this commit is to improve the
cold-cache compile time of `wasm-bindgen` by ensuring that for new users
this project builds as quickly as possible. By removing some heavyweight
dependencies from the procedural macro, `serde`, `serde_derive`, and
`serde_json`, we're able to get a pretty nice build time improvement for
the `wasm-bindgen` crate itself:

|             | single-core build | parallel build |
|-------------|-------------------|----------------|
| master      |             36.5s |          17.3s |
| this commit |             20.5s |          11.8s |

These are't really end-all-be-all wins but they're much better
especially on the spectrum of weaker CPUs (in theory modeled by the
single-core case showing we have 42% less CPU work in theory).
2018-10-12 11:23:00 -07:00
Alex Crichton
13cac2d0c4 Fix generated shims if APIs don't exist
This commit fixes instantiation of the wasm module even if some of the
improted APIs don't exist. This extends the functionality initially
added in #409 to attempt to gracefully allow importing values from the
environment which don't actually exist in all contexts. In addition to
nonexistent methods being handled now entire nonexistent types are now
also handled.

I suspect that eventually we'll add a CLI flag to `wasm-bindgen` to say
"I assert everything exists, don't check it" to trim out the extra JS
glue generated here. In the meantime though this'll pave the way for a
wasm-bindgen shim to be instantiated in both a web worker and the main
thread, while using DOM-like APIs only on the main thread.
2018-10-10 17:46:51 -07:00
Alex Crichton
e03e40451e
Merge pull request #955 from alexcrichton/non-send
Ensure that `JsValue` isn't considered `Send`
2018-10-10 17:41:49 -07:00
Alex Crichton
41d3a08028
Merge pull request #958 from alexcrichton/no-global-cache
js_sys: Use a thread local to cache `global()`
2018-10-10 17:41:41 -07:00
Alex Crichton
e0b73abc7e
Merge pull request #957 from alexcrichton/promise-clone
js_sys: Add `#[derive(Clone, Debug)]` to `Promise`
2018-10-10 16:52:57 -07:00
Alex Crichton
e72ae12e77
Merge pull request #956 from alexcrichton/js-sys-typed-array-slice
js-sys: Add bindings for `TypedArray.slice`
2018-10-10 16:52:39 -07:00
Alex Crichton
4993e45fd9 Squash a few warnings that snuck in by accident 2018-10-10 16:09:24 -07:00
Alex Crichton
105a6bc853 js_sys: Use a thread local to cache global()
When we add threads it's not actually valid to have a global cache as
the index is only valid on one thread! Instead let's use a per-thread
cache using `thread_local!` which compiles to basically the same code as
before for single-threaded wasm.
2018-10-10 16:01:32 -07:00
Alex Crichton
e9fa209dcf js_sys: Add #[derive(Clone, Debug)] to Promise
I think we just forgot this from earlier!
2018-10-10 15:58:47 -07:00
Alex Crichton
f9d2dbd0b6 js-sys: Add bindings for TypedArray.slice
This commit adds support for the `slice` function on all `TypedArray`
instances. The `slice` function is similar to `subarray` except that it
actually copies the data, whereas `subarray` just returns a different
view into data.
2018-10-10 15:57:00 -07:00
Alex Crichton
e46537e6c2 Ensure that JsValue isn't considered Send
The `JsValue` type wraps a slab/heap of js objects which is managed by
the wasm-bindgen shim, and everything here is not actually able to cross
any thread boundaries. When wasm actually has threads, for example, each
thread will have to have its own slab of objects generated by
wasm-bindgen, and indices in one slab aren't valid in any other slabs.

This is technically a breaking change because `JsValue` was previously
`Send` and `Sync`, but I'm hoping that in practice this isn't actually a
breaking change because nothing in wasm can be using threads which in
theory shouldn't activate the `Send` and/or `Sync` bounds.
2018-10-10 15:47:07 -07:00
Nick Fitzgerald
dd82a3e134 Bump to 0.2.25 2018-10-10 13:19:40 -07:00
Alex Crichton
f6cb73442a Fix bindings for classes only referenced through struct fields
The bindings generation for a class would accidentally omit the `__wrap`
function if it was only discovered very late in the process that
`__wrap` was needed, after we'd already passed the point where we needed
to have decided that.

This commit moves struct field generation of bindings much earlier in
the binding generation process which should ensure everything is all
hooked up by the time we generate the classes themselves.

Closes #949
2018-10-10 10:21:19 -07:00
Alex Crichton
1410b5253d
Merge pull request #944 from alexcrichton/windows-slash
Fix web-sys build on some Windows builds
2018-10-08 12:46:44 -07:00
Alex Crichton
18deb5e848 Fix web-sys build on some Windows builds
The official pathname separator on Windows is `\` instead of `/`, but
we've been unconditionally using `/`. This typically works on Windows
because Cargo's default `OUT_DIR` listing is a normal `C:\...` path
which works with either `/` or `\`. If, however, a user sets
`CARGO_TARGET_DIR` to a UNC-style path like `\\?\C:\...` then `/` is
*not* the same as `\`, but rather `/` is interpreted as part of the file
name (to allow file names with `/` in the name).

Let's bypass all this and just use a build script output env var.

Closes #943
2018-10-08 10:19:43 -07:00
Alex Crichton
79e4324a3b Update parity-wasm dependency
While doing this, make `parity-wasm` a public dependency of all crates
instead of using the `Any` trick as that's not really needed any more.
2018-10-08 10:01:53 -07:00
Alex Crichton
4750927f11 Import the wasm-gc-api crate into this repository
The `wasm-bindgen` crate is effectively the only user of this crate now
that the `wasm-gc` tool has been deprecated. It's also much easier to
keep it in this repository as it's easier to sync changes to
`parity-wasm`. I'd also like to start refactoring out utilities for
managing a `parity_wasm::Module` to share between this crate and the
other CLI support code.
2018-10-05 14:21:59 -07:00
Alex Crichton
c210ccd596 Bump to 0.2.24 2018-10-05 09:53:19 -07:00
Alex Crichton
7eb49acf0d Allow passing extra args to node in test runner
This can be useful for enabling experimental features
2018-10-04 22:20:23 -07:00
Nick Fitzgerald
7ea3ee60b7
Merge pull request #927 from alexcrichton/fix-browser
Fix the `no_modules` example by fixing `--browser`
2018-10-03 16:34:31 -07:00
Alex Crichton
3f357f46eb Fix the no_modules example by fixing --browser
Recent refactorings forgot a case of emitting code for
`cachedTextDecoder`!
2018-10-03 15:54:57 -07:00
Alex Crichton
9eaba6e28b Filter only for RustDeprecated in attrs
Previously any string-related attribute would emit a deprecation
warning!

cc #925
2018-10-03 15:44:58 -07:00
Alex Crichton
84bda02bbf
Merge pull request #923 from alexcrichton/extends-path
Parse `Path`s in `extends` attributes
2018-10-03 10:38:50 -07:00
Alex Crichton
5df8e20815 Parse Paths in extends attributes
Closes #916
2018-10-03 09:14:23 -07:00
Alex Crichton
4a5e13b08b
Merge pull request #920 from alexcrichton/fix-borrow-mut
Fix exporting structs with `BorrowMut` in scope
2018-10-03 09:09:36 -07:00
Alex Crichton
05742177c2
Merge pull request #921 from alexcrichton/fix-typescript
Fix TypeScript for generated constructors
2018-10-03 09:09:23 -07:00
Alex Crichton
32fd1227e4
Merge pull request #910 from alexcrichton/fix-text-encoder-edge
Fix polyfill of `TextEncoder` and `TextDecoder`
2018-10-03 00:07:30 -07:00
Alex Crichton
157750fd99 Fix TypeScript for generated constructors
It accidentally had a stray colon!

Closes #917
2018-10-03 00:00:54 -07:00
Alex Crichton
32b62b4358 Fix exporting structs with BorrowMut in scope
Apparently the codegen wasn't precise enough such that a trait import
could cause method resolution to go awry!

Closes #919
2018-10-02 23:56:15 -07:00
Alex Crichton
332beecabe Add a number of #[inline] annotation through crates
Adding `#[inline]` will typically improve codegen for optimized builds
without LTO (so far the majority in practice) by allowing functions that
otherwise couldn't be inlined across codegen units to get inlined
across codegen units.

Right now `wasm-bindgen` has a lot of functions that are very small and
delegate to other functions, but aren't otherwise candidates for
inlining because they're concrete.

I was poking around in release-mode wasm recently and noticed an
alarming number of functions for tiny pieces of functionality, which
motivates this patch!
2018-10-01 15:31:09 -07:00
Alex Crichton
9c085dc0f5
Merge pull request #914 from alexcrichton/rename-polyfill
Rename `polyfill` to `vendor_prefix`
2018-10-01 14:47:07 -07:00
Alex Crichton
f75349262a Rename polyfill to vendor_prefix
cc #906
2018-10-01 14:45:30 -07:00
Alex Crichton
8e7238d15f Fix test --release
Unfortuantely we need to do some linking trickery to make sure a custom
section is correctly pulled in...
2018-10-01 14:44:21 -07:00
Alex Crichton
a7e9da0a81
Merge pull request #879 from alexcrichton/closure-zst
Improve codegen for `Closure<T>`
2018-10-01 14:41:13 -07:00
Alex Crichton
bb7271aa43 Fix our WebIDL for Safari
This commit employs the strategy described in #908 to apply a
non-breaking change to fix WebIDL to be compatible with all browsers,
including Safari.

The problem here is that `BaseAudioContext` and `AudioScheduledSourceNode`
are not types in Safari, but they are types in Firefox/Chrome. The fix
here was to move the contents of these two interfaces into mixins, and
then include the mixins in all classes which inherit from these two
classes. That should have the same effect as defining the methods
inherently on the original interface.

Additionally a special `[RustDeprecated]` attribute to WebIDL was added
to signify interfaces this has happened to. Currently it's directly
tailored towards this case of "this intermediate class doesn't exist in
all browsers", but we may want to refine and extend the deprecation
message over time.

Although it's possible we could do this as a breaking change to
`web-sys` I'm hoping that we can do this as a non-breaking change for
now and then eventually on the next breaking release batch all these
changes together, deleting the intermediate classes. This is also
hopefully a good trial run for how stable web-sys can be when it's
actually stable!

cc #897
cc #908
2018-10-01 12:24:37 -07:00
Nick Fitzgerald
0a48d2bc29 web-sys: allow unused import warning
This import is only used if some features get used and it is way easier to just
quiet the warning when those features aren't used than to try and `cfg` this
import.
2018-10-01 09:53:03 -07:00
Alex Crichton
717cfa303d Fix polyfill of TextEncoder and TextDecoder
This commit does a few things, including:

* Fixing the generated JS of `wasm-bindgen` to allow polyfills to work.
  (a minor tweak of the generated JS)

* All examples are updated to include a Webpack-specific polyfill for
  these two types to get examples working in Edge.

* A new page has been added to the guide about supported browsers. This
  mentions known caveats like IE 11 requiring `wasm2js` as well as
  documenting some `TextEncoder` and `TextDecoder` workarounds for Edge.

Closes #895
2018-09-30 10:16:20 -07:00
Alex Crichton
8ba41cce6e Improve codegen for Closure<T>
This commit improves the codegen for `Closure<T>`, primarily for ZST
where the closure doesn't actually capture anything. Previously
`wasm-bindgen` would unconditionally allocate an `Rc` for a fat pointer,
meaning that it would always hit the allocator even when the `Box<T>`
didn't actually contain an allocation. Now the reference count for the
closure is stored on the JS object rather than in Rust.

Some more advanced tests were added along the way to ensure that
functionality didn't regress, and otherwise the calling convention for
`Closure` changed a good deal but should still be the same user-facing.
The primary change was that the reference count reaching zero may cause
JS to need to run the destructor. It simply returns this information in
`Drop for Closure` and otherwise when calling it now also retains a
function pointer that runs the destructor.

Closes #874
2018-09-29 07:00:53 -07:00
Alex Crichton
230b8f61fd Fix WebIDL mixin attributes on Window
Previously the "container attribute" were set to the attributes of the
mixin itself, but we want the container attributes to be that of the
type which includes the mixin (like `Window`) as those attributes
contain information about whether or not bindings are `structural`.

The end result with this is that the `structural` tag is now used for
properties on `Window`, correctly generating setters/getters.

Closes #904
2018-09-28 21:41:48 -07:00
Alex Crichton
3c14f7a6eb Implement a polyfill attribute for imports
Allow using imported APIs under alternative names, such as prefixed
names, for web APIs when the exact API differs across browsers.
2018-09-28 13:43:00 -07:00
Alex Crichton
7447c30ba4
Merge pull request #903 from alexcrichton/doc-constructors
Add more documentation to `web-sys` constructors
2018-09-27 13:51:07 -07:00
Alex Crichton
f3dd28e294 Add more documentation to web-sys constructors
Closes #899
2018-09-27 12:35:46 -07:00
Alex Crichton
fd1a00db76 Escape HTML text in browser failure messages
When browser tests fail we're appending to `innerHTML`, which means that
we need to escape some characters for all to show up!

Closes #898
2018-09-27 12:21:41 -07:00
Alex Crichton
65fc8228f1 Remove a stray script 2018-09-27 12:21:41 -07:00
Alex Crichton
7ecf4aae87 cargo +nightly fmt --all
Rustfmt all the things!
2018-09-26 08:26:00 -07:00
Alex Crichton
18e089fa85 Add some Cargo metadata for web-sys 2018-09-26 08:07:33 -07:00
Nick Fitzgerald
4c766c5c7a Start web-sys at 0.3.0 2018-09-26 07:37:51 -07:00
Nick Fitzgerald
f834a427d7 Bump to version 0.2.23 (and js-sys and wasm-bindgen-futures to 0.3.0) 2018-09-26 07:31:54 -07:00
Nick Fitzgerald
ee0e4bc089
Merge pull request #887 from fitzgen/iterating-over-js-values
Iterating over js values
2018-09-25 16:04:50 -07:00
Nick Fitzgerald
7db28b4548 js-sys: run rustfmt 2018-09-25 14:30:26 -07:00
Nick Fitzgerald
f9cd329b14 js-sys: Add js_sys::try_iter for iterating over any JsValue
Fixes #776
2018-09-25 14:30:26 -07:00
Nick Fitzgerald
e3d2ea2628 js-sys: Catch exceptions thrown in Reflect APIs
Proxies passed to Reflect APIs can throw for any of these operations and it is a
bit of a mess.
2018-09-25 14:30:26 -07:00
Alex Crichton
9b99ebfc87
Merge pull request #886 from alexcrichton/tweak-features
Update and improve crate features in `web-sys`
2018-09-25 12:26:45 -07:00
Alex Crichton
97cceebe7e Update and improve crate features in web-sys
* Regenerate the list of features for the crate given recent
  improvements, enabling some more types to be bound.
* Add feature gates for the `css` and `console` namespaces (modules),
  gating the APIs by default. Now `web_sys` has zero APIs unless they're
  requested.
* Improved the "required feature" documentation for `struct` types to
  not list parent classes and mention just the `struct` type instead.
2018-09-25 11:27:22 -07:00
Nick Fitzgerald
6edb871c36 js-sy: Add a doc comment for js_sys::IntoIter 2018-09-25 11:21:56 -07:00
Nick Fitzgerald
dc22965e71 js-sys: Add doc comment for js_sys::Iter 2018-09-25 11:21:56 -07:00
Nick Fitzgerald
2c62795a8d
Merge pull request #880 from alexcrichton/better-link-mem-intrinsics
Improve `link_mem_intrinsics` hack
2018-09-24 17:20:54 -07:00
Alex Crichton
b256b98e38 Improve link_mem_intrinsics hack
Previously the `link_mem_intrinsics` hack actually had a runtime
overhead by storing a value into a global location, but it turns out we
can actually use a non-inlined function call as part of the *descriptor*
which requires this to be in the final binary, but we'll end up snip'ing
the value at the end.

All in all this should mean that it's not a zero-overhead solution for
linking these intrinsics! The `#[wasm_bindgen]` attribute already has
other problems if the descriptors don't show up, so that's the least of
our issues!
2018-09-24 15:43:04 -07:00
Alex Crichton
7b495468f6 Implement support for Uint8ClampedArray
This commit implements support for binding APIs that take
`Uint8ClampedArray` in JS. This is pretty rare but comes up in a
`web-sys` binding or two, and we're now able to bind these APIs instead
of having to omit the bindings.

The `Uint8ClampedArray` type is bound by using the `Clamped` marker
struct in Rust. For example this is declaring a JS API that takes
`Uint8ClampedArray`:

    use wasm_bindgen::Clamped;

    #[wasm_bindgen]
    extern {
        fn takes_clamped(a: Clamped<&[u8]>);
    }

The `Clamped` type currently only works when wrapping the `&[u8]`, `&mut
[u8]`, and `Vec<u8>` types. Everything else will produce an error at
`wasm-bindgen` time.

Closes #421
2018-09-24 13:58:37 -07:00
Alex Crichton
b91817f181 Remove no-longer-needed math bindings
All these functions are now provided by upstream compiler-builtins, so
there's no need for us to be binding them automatically. The remaining
`Math_*` functions are also no longer needed on nightly after
https://github.com/rust-lang/rust/pull/54257 but that PR isn't on beta,
so we'll need to leave these here for awhile while beta rides the trains
2018-09-24 10:42:04 -07:00
Alex Crichton
c5d3ca9c00
Merge pull request #862 from alexcrichton/more-types
Enable union types without interfaces in WebIDL
2018-09-24 10:00:26 -07:00
Alex Crichton
d098d3cf28 Enable union types without interfaces in WebIDL
Bind them all as `JsValue` as that's the "least common ancestor" we can
work with. Fixes up one location in WebIDL where `Option<JsValue>`
arose as we haven't implemented that.

Closes #817
2018-09-24 09:33:22 -07:00
Alex Crichton
9a1fa5a81b
Merge pull request #870 from alexcrichton/no-constructor-token
Remove the need for a `ConstructorToken`
2018-09-21 21:40:08 -07:00
Alex Crichton
75f005be23 Support #[wasm_bindgen(setter, js_name = ...)]
Previously we'd require the explicit `js_name` to *also* start with
`set_`, but when explicitly specified it shouldn't be mangled at all!

Closes #584
2018-09-21 17:54:26 -07:00
Alex Crichton
3f85d7db9f Remove the need for a ConstructorToken
This commit removes the need for an injected `ConstructorToken` type and
also cleans up the story we have for generating constructors a bit.
After this commit a `constructor()` is omitted entirely if we're in
non-debug mode and there's no actual listed constructor. Additionally we
don't deal with splat arguments and rerouting constructors, Nick was
kind enough to enlighten me about `Object.create` which is creating an
instance without running the constructor!

Instances of an exported type are now created through one of two
methods:

* If `#[wasm_bindgen(constructor)]` is present, then a `constructor` is
  generated with the appropriate signature. If a constructor is not
  present and we're in debug mode, a throwing constructor is generated.
  If we're in release mode and there's no constructor, no constructor is
  generated.

* Otherwise if a binding returns an instance of a type (or otherwise
  needs to manfuacture an instance, then it will cause an internal
  `__wrap` function to be generated. This function will use
  `Object.create` to create an instance without running the constructor.

This should ideally clean up our generated JS for classes quite a bit,
making it much more lean-and-mean!
2018-09-21 17:42:06 -07:00
Alex Crichton
534cceafc8 Improve error message for infer_setter_property
If the setter doesn't start with `set_*` then we currently panic, but
panicking is bad! Instead let's thread through structured errors to make
sure they make their way to the top
2018-09-21 17:29:50 -07:00
Alex Crichton
ab3688d01a Only generate JS null checks in debug mode
In non-debug mode Rust is already checking these pointers, so let's only
generate the relevant code in debug mode.
2018-09-21 16:10:02 -07:00
Alex Crichton
51ec485c94 Bump to 0.2.22 2018-09-21 13:41:58 -07:00
Alex Crichton
ebe73a537c
Merge pull request #866 from alexcrichton/fix-lto
More conservatively patch closure descriptors
2018-09-21 13:35:16 -07:00
Alex Crichton
a117c057fb More conservatively patch closure descriptors
Previously `wasm-bindgen` would take its `breaks_if_inlined` shims and
attempt to remove them entirely, replacing calls to `breaks_if_inlined`
to the imported closure factories. This worked great in that it would
remove the `breaks_if_inlined` funtion entirely, removing the "cost" of
the `#[inline(never)]`.

Unfortunately as #864 discovered this is "too clever by half". LLVM's
aggressive optimizations won't inline `breaks_if_inlined`, but it may
still change the ABI! We can't replace calls to `breaks_if_inlined` if
the signature changes, because the function its calling has a fixed signature.

This commit cops out a bit and instead of replacing calls to
`breaks_if_inlined` to the imported closure factories, we instead
rewrite calls to `__wbindgen_describe_closure` to the closure factories.
This means that the `breaks_if_inlined` shims do not get removed. It
also means that the closure factory shims have a third and final
argument (what would be the function pointer of the descriptor function)
which is dead and unused.

This should be a functional solution for now and let us iterate on a
true fix later on (if needed). For now the cost of this
`#[inline(never)]` and the extra unused argument should be quite small.

Closes #864
2018-09-21 13:34:59 -07:00
Nick Fitzgerald
c517b00825
Merge pull request #861 from alexcrichton/less-moz
Purge a number of Mozilla-specific WebIDL
2018-09-21 09:57:12 -07:00
Ivan Enderlin
54b2482d03
doc(readme) Add links to doc & clean
This patch adds a link to the crate's documentation. It also removes a reference to #275, which is closed now.
2018-09-21 10:08:11 +02:00
Alex Crichton
a2d6a8ff53 Use anyref helper to reduce some code duplication 2018-09-20 17:26:49 -07:00