Commit Graph

2199 Commits

Author SHA1 Message Date
1424c4987d Branch was merged quickly! 2018-04-17 11:51:55 -07:00
9a6a15f605 Fix compilation and support on 32-bit targets 2018-04-17 11:42:10 -07:00
f80a7067a0 Use a struct instead of a bool variant
Helps it be a bit more readable!
2018-04-17 11:29:03 -07:00
0e032955fb Use a length accessor instead of byteLength
This way we should be naturally compatible with normal JS arrays that get passed
in as well!

Closes #133
2018-04-16 13:50:21 -07:00
bd755c0378 Merge pull request #135 from rustwasm/doc-describ
Update DESIGN.md on recent closure/conversion changes
2018-04-16 15:33:02 -05:00
efb64b87d4 Extract Rust2Js like Js2Rust was extracted
Along the way clean up a lot of the formatting of the auto-generated code to
make it a bit prettier by default.
2018-04-16 13:31:56 -07:00
49ead6a0d0 I think incremental shoudl be fixed now! 2018-04-16 10:38:26 -07:00
b45ab77972 Update DESIGN.md on recent closure/conversion changes
Hopefully covering a lot of the groundwork done for closures in case anyone's
curious down the road!
2018-04-16 08:30:16 -07:00
5efde3abe9 Be sure to generate classes for empty structs
Closes #131
2018-04-16 08:05:18 -07:00
f61e12af91 Merge pull request #134 from rustwasm/better-formatting
Work a little harder to better format the output JS
2018-04-16 09:59:41 -05:00
f8ecf912c7 Clean up the generated JS a bit 2018-04-16 07:56:55 -07:00
d96e7309ad Format generated JS of export shims nicer
Apply a few indents and a few strategic slashes to make it look a bit nicer
2018-04-16 07:56:05 -07:00
1c11c46f49 Merge pull request #132 from rustwasm/closure-more-fun-types
Support closures with "rich" arguments
2018-04-16 09:52:19 -05:00
c64f178543 Support closures with "rich" arguments
This commit adds support for closures with arguments like strings and such. In
other words, closures passed to JS can now have the same suite of arguments as
all functions that can be exported from Rust, as one might expect!

At this time due to the way trait objects work closures still cannot use types
with references like `&str`, but bare values like `String` or `ImportedType`
should work just fine.

Closes #104
2018-04-16 07:51:51 -07:00
c1df44189e Merge pull request #127 from konstin/new
Support `new Foo(...)` to fix #115
2018-04-16 09:49:19 -05:00
f63635fce9 Fix merge-breakage 2018-04-15 15:36:59 +02:00
3999642f66 Merge remote-tracking branch 'upstream/master' into new 2018-04-15 01:50:23 +02:00
770d7365c4 Fix compilation and docs
The compilation part is effectively a cherry pick from master
2018-04-15 01:39:43 +02:00
f45ce1f239 Do only use ConstructorToken when needed
Also removing some effectively dead code
2018-04-15 01:29:09 +02:00
0e6325d833 Overhaul the conversion traits
This commit overhauls the conversion traits used for types crossing the Rust/JS
boundary. Previously there were a few ad-hoc traits but now there've been
slightly reduced and decoupled.

Conversion from Rust values to JS values is now exclusively done through
`IntoWasmAbi` with no special treatment for references. Conversion from JS to
Rust is a bit trickier as we want to create references in Rust which have
implications in terms of safety. As a result there are now three traits for
this, `FromWasmAbi`, `RefFromWasmAbi`, and `RefMutFromWasmAbi`. These three
traits are implemented for various types and specially dispatched to depending
on the type of argument in the code generator.

The goal of this commit is to lay the groundwork for using these traits in
closures with straightforward-ish definitions.
2018-04-14 12:01:07 -07:00
9976971e7e Fix CI 2018-04-14 11:34:37 -07:00
70f2d7daab Merge pull request #128 from rustwasm/fnmut-stack
Add support for mutable stack closures
2018-04-14 13:25:39 -05:00
d87e07f45e Update docs 2018-04-14 11:19:17 -07:00
e87b32fb22 Allow arbitratry constructor names 2018-04-14 11:19:17 -07:00
32ab5a5644 Suppport for javascript constructors
This is a conservative version where the function used for the constructor must be called `new`
2018-04-14 11:19:17 -07:00
a8d6ca3d62 Add support for mutable stack closures
This commit adds support for passing `&mut FnMut(..)` to JS via imports. These
closures cannot be invoked recursively in JS (they invalidate themselves while
they're being invoked) and otherwise work the same as `&Fn(..)` closures.

Closes #123
2018-04-14 11:16:16 -07:00
3305621012 Overhaul how type information gets to the CLI
This commit is a complete overhaul of how the `#[wasm_bindgen]` macro
communicates type information to the CLI tool, and it's done in a somewhat...
unconventional fashion.

Today we've got a problem where the generated JS needs to understand the types
of each function exported or imported. This understanding is what enables it to
generate the appropriate JS wrappers and such. We want to, however, be quite
flexible and extensible in types that are supported across the boundary, which
means that internally we rely on the trait system to resolve what's what.

Communicating the type information historically was done by creating a four byte
"descriptor" and using associated type projections to communicate that to the
CLI tool. Unfortunately four bytes isn't a lot of space to cram information like
arguments to a generic function, tuple types, etc. In general this just wasn't
flexible enough and the way custom references were treated was also already a
bit of a hack.

This commit takes a radical step of creating a **descriptor function** for each
function imported/exported. The really crazy part is that the `wasm-bindgen` CLI
tool now embeds a wasm interpreter and executes these functions when the CLI
tool is invoked. By allowing arbitrary functions to get executed it's now *much*
easier to inform `wasm-bindgen` about complicated structures of types. Rest
assured though that all these descriptor functions are automatically unexported
and gc'd away, so this should not have any impact on binary sizes

A new internal trait, `WasmDescribe`, is added to represent a description of all
types, sort of like a serialization of the structure of a type that
`wasm-bindgen` can understand. This works by calling a special exported function
with a `u32` value a bunch of times. This means that when we run a descriptor we
effectively get a `Vec<u32>` in the `wasm-bindgen` CLI tool. This list of
integers can then be parsed into a rich `enum` for the JS generation to work
with.

This commit currently only retains feature parity with the previous
implementation. I hope to soon solve issues like #123, #104, and #111 with this
support.
2018-04-14 11:15:28 -07:00
eb9a6524b9 Bump to 0.2.2 0.2.2 2018-04-13 07:50:24 -07:00
5d52bf81c5 Document --no-modules in the README 2018-04-13 07:47:16 -07:00
8854936599 Tweak initialization with --no-modules
* Have the global `wasm_bindgen` variable be a function which runs
  initialization rather than exporting an `init` function.
* Save off the wasm object on `wasm_bindgen.wasm` so the memory can be accessed
* Tidy up the code slightly
2018-04-13 07:44:35 -07:00
98016324f7 Merge branch 'umd' of https://github.com/csharad/wasm-bindgen 2018-04-13 07:34:27 -07:00
85c9f2319c Expose on window.wasm_bindgen 2018-04-13 14:25:27 +05:45
ffdb8a6a32 Simplified the preamble 2018-04-12 10:31:13 +05:45
b9b8756cd0 Demangle Rust symbols by default 2018-04-11 11:43:18 -07:00
aa6487b6f1 panic when modules used 2018-04-11 14:22:20 +05:45
8c935d5d94 Change flag to --no-modules 2018-04-11 13:59:58 +05:45
d1a4bffb3a Looks like opt-level=s may be better
With opt-level=z not enough functions were inlined to eliminate more code!
2018-04-10 07:41:40 -07:00
db15a898cb Merge pull request #117 from markandrus/fix-require-from-different-directory
Call fs.readFileSync with __dirname
2018-04-10 08:58:55 -05:00
0aef97215c Call fs.readFileSync with __dirname
Node's fs APIs resolve relative paths relative to the current working directory:

https://nodejs.org/api/fs.html#fs_file_paths

This creates a problem if you try to require the wasm-bindgen-generated
JavaScript from a different directory. For example, if you have

  build/foo.js
  build/foo_bg.js
  build/foo_bg.wasm

and another script, script/index.js, that requires build/foo.js. We can instead
use __dirname to get the correct path to the file.
2018-04-09 17:38:22 -07:00
656d69816d Move all tests to the same suite
Nowadays the compile times are mitigated with incremental compilation and
otherwise it's much more ergonomic to run only one test if they're all in the
same suite.
2018-04-09 15:32:06 -07:00
60ac57331b Bump to 0.2.1 0.2.1 2018-04-09 15:18:39 -07:00
a558fa49a0 Fix closures example build script 2018-04-09 15:02:20 -07:00
6b49af8234 Build releases with nightly on CI 2018-04-09 14:42:47 -07:00
071f3637fa Build closures example on Travis 2018-04-09 14:41:24 -07:00
aaff0be441 Fix closure tests 2018-04-09 14:40:01 -07:00
ee93122c5b Merge pull request #101 from rustwasm/closures
Initial support for closures
2018-04-09 16:36:01 -05:00
a3e5485b86 Add examples/documentation for closures 2018-04-09 14:34:21 -07:00
176060cc8a Aggressively optimize for size in release mode 2018-04-09 14:34:21 -07:00
66bdd92fa2 More aggressively gc module
As soon as we've removed unneeded exports immediately run a gc pass to ensure
that we don't bind functions in JS that don't actually end up getting needed.
2018-04-09 14:34:21 -07:00
f7f0d578e7 Support long-lived closures
Docs coming soon!
2018-04-09 14:34:21 -07:00