Commit Graph

77 Commits

Author SHA1 Message Date
Alex Crichton
c51a342cb3 Rewrite wasm-bindgen with ES6 modules in mind
This commit is a mostly-rewrite of the `wasm-bindgen` tool. After some recent
discussions it's clear that the previous model wasn't quite going to cut it, and
this iteration is one which primarily embraces ES6 modules and the idea that
this is a polyfill for host bindings.

The overall interface and functionality hasn't changed much but the underlying
technology has now changed significantly. Previously `wasm-bindgen` would emit a
JS file that acted as an ES6 module but had a bit of a wonky interface. It
exposed an async function for instantiation of the wasm module, but that's the
bundler's job, not ours!

Instead this iteration views each input and output as a discrete ES6 module. The
input wasm file is interpreted as "this *should* be an ES6 module with rich
types" and the output is "well here's some ES6 modules that fulfill that
contract". Notably the tool now replaces the original wasm ES6 module with a JS
ES6 module that has the "rich interface". Additionally a second ES6 module is
emitted (the actual wasm file) which imports and exports to the original ES6
module.

This strategy is hoped to be much more amenable to bundlers and controlling how
the wasm itself is instantiated. The emitted files files purely assume ES6
modules and should be able to work as-is once ES6 module integration for wasm is
completed.

Note that there aren't a ton of tools to pretend a wasm module is an ES6 module
at the moment but those should be coming soon! In the meantime a local
`wasm2es6js` hack was added to help make *something* work today. The README has
also been updated with instructions for interacting with this model.
2018-01-29 21:50:01 -08:00
Alex Crichton
b38c273ee5 Add an --output-js flag
This'll output just vanilla JS rather than TypeScript!

Closes #8
2018-01-24 19:15:34 -08:00
Alex Crichton
0b81185c99 Expose primitive information about JsObject
Adds bindings for wbindgen to fill in via JS bindings to read the various
primitive properties of a JS value.
2017-12-31 15:45:47 -08:00
Alex Crichton
4151461ab9 Expose construction of a JsObject as a string
Start fleshing out the `JsObject` API!
2017-12-31 14:44:44 -08:00
Alex Crichton
bef908a9b1 Add an option to "uglify" imports
This commit adds an option to "uglify" the wasm module's imports/exports so
those which are controlled by bindgen are renamed to a shorter (probably one
letter) names. This'll hopefully help cut down on both the wasm size slightly
and also the generated JS as the glue we're talking to wasm over won't require
such large names all the time.
2017-12-24 15:32:40 -08:00
Alex Crichton
6aacff6a80 Further optimize non-debug output
Remove a bunch of exception throws in favor of type casts in TypeScript and
remove some type assertions as well that TypeScript should uphold.
2017-12-20 13:24:18 -08:00
Alex Crichton
b548239e02 Don't generate code for dead imports 2017-12-20 11:34:53 -08:00
Alex Crichton
5e80b082a9 Allow imports to return JS objects 2017-12-20 10:44:08 -08:00
Alex Crichton
294c5e147b Support passing booleans back and forth 2017-12-20 10:22:18 -08:00
Alex Crichton
5fe842e9bd Allow extra exports not part of wasm-bindgen
Currently throw them all in an interface under `extra` in the main exports
interface. May change in the future...
2017-12-20 08:11:06 -08:00
Alex Crichton
a12a8f414c Support imports outside of wasm_bindgen! 2017-12-20 07:58:41 -08:00
Alex Crichton
66ae545bff Add support for raw pointers in Rust 2017-12-20 07:35:14 -08:00
Alex Crichton
d3387d591f Start optimizing code size:
* Use a bundled custom `WasmRefCell` instead of the one in the standard library.
  This one primarily doesn't panic via libstd which means that its code
  footprint is much smaller.
* Add a `throw` function to `wasm_bindgen`-the-crate which can be used to throw
  an exception in JS from Rust. This is useful as a cheap way to throw an
  exception code-wise (little code bloat) and it's also a great way of reporting
  error messages to JS!
* Cut down on the code size of `__wbindgen_malloc` by aborting on huge requests
  earlier.
* Use a custom `assert_not_null` function which delegates to `throw` to test for
  incoming null pointers
2017-12-19 19:53:55 -08:00
Alex Crichton
85cdb51719 Generate TypeScript by default instead of JS
This is what's needed in the immediate future anyway, so let's do that!
2017-12-19 19:06:48 -08:00
Alex Crichton
946e5317fe Support passing JS objects through Rust 2017-12-19 09:25:41 -08:00
Alex Crichton
eda9beae25 Get imports working in a basic capacity 2017-12-18 21:43:16 -08:00
Alex Crichton
1ffcb90d2d Ensure class arguments have the expected type 2017-12-18 19:01:37 -08:00
Alex Crichton
ebc97438e7 Add a test that two mutable borrows is not ok 2017-12-18 16:24:31 -08:00
Alex Crichton
eebe8b21a2 Fix generation for a fn with two string args 2017-12-18 16:13:37 -08:00
Alex Crichton
62808e8d99 Add some tests for exceptions 2017-12-18 14:44:09 -08:00
Alex Crichton
6593b5ef69 Classes are now working! 2017-12-18 14:31:01 -08:00
Alex Crichton
7c510a8a7e Start adding support for classes 2017-12-18 12:39:14 -08:00
Alex Crichton
2225942000 Test two macro invocations 2017-12-14 21:56:40 -08:00
Alex Crichton
1b4f10217c Start handling strings 2017-12-14 21:55:21 -08:00
Alex Crichton
d5897c6e56 Test the eventual desired interface 2017-12-14 20:07:26 -08:00
Alex Crichton
d2d9f6be11 Avoid registry/git repo updates in tests
Use the main lockfile as a template, also print out how long each
command takes.
2017-12-14 19:36:41 -08:00
Alex Crichton
2926e6e9f4 Initial commit 2017-12-14 19:31:01 -08:00