Commit Graph

419 Commits

Author SHA1 Message Date
Alex Crichton
02b7021053 Leverage new rustc wasm features
This commit leverages two new attributes in the Rust compiler,
`#[wasm_custom_section]` and `#[wasm_import_module]`. These two attributes allow
removing a lot of hacks found in wasm-bindgen and also allows removing the
requirement of `wasm-opt` to remove the unused data sections.

This does require two new nightly features but we already required the
`proc_macro` nightly feature and these will hopefully be stabilized before that
feature!
2018-03-24 10:36:19 -07:00
Alex Crichton
8e894fcfc5 Implement static imports
This allows importing static objects like `document`, `window`, or an arbitrary
JS object from a module
2018-03-21 08:09:59 -07:00
Alex Crichton
91295f4d16 Fix wasm sizes on nightly
Looks like the recent changes to `Vec::with_capacity` meant that our previous
codegen to avoid panics no longer avoids panics. Let's pick up the `try_reserve`
unstable feature for now and hopefully it'll be stabilized before the other
pieces in the future.
2018-03-20 15:19:45 -07:00
Alex Crichton
0970fa2998 Fix duplicated definition of a constant 2018-02-16 19:06:48 -08:00
Alex Crichton
f3c0fc369a Fix compatibility with LLD
Ensure the runtime library is always at least linked as it has important symbols
that we'll use later.
2018-02-10 10:06:56 -08:00
Alex Crichton
29771b574c Migrate from a macro to an attribute
This commit migrates from `wasm_bindgen!`-the-macro to
`#[wasm_bindgen]`-the-attribute. The actual mechanics of the macro are
relatively simple in just generating some shims here and there, but wrapping
everything in one huge macro invocation can often seem intimidating as it gives
off this feeling of "oh dear anything can happen here!" Using an attribute
should curb expectations much more greatly of "oh there's just some extra stuff
happening behind the scenes".

The usage is otherwise relatively straightforward and close to what it was
before, but check out the DESIGN.md/README.md changes for more info!
2018-02-08 10:18:16 -08:00
Alex Crichton
43ee52bcbf Change schemes for encoding custom type names
Store JSON a utf-32, map hashes of names to a `char` and store that name
in the map, and then do a reverse mapping when generating JS
2018-02-06 16:56:26 -08:00
Alex Crichton
e60aa6a990 Rename JsObject to JsValue
Let's reserve `JsObject` for something we actually know is an object
2018-02-06 15:04:46 -08:00
Alex Crichton
56b7fa453a Fix some class import methods and auto gc
The runtime functions are now moved to the `wasm-bindgen` crate and are
auto-gc'd if they don't end up actually being required.
2018-02-06 08:58:15 -08:00
Alex Crichton
d5ff725913 Greatly simplify handling of types in Rust
Push the compiler to do trait resolution to figure out what each type is bound
with in JS, and that way we can accept effectively all types (so long as they
implement a trait).
2018-02-06 07:56:14 -08:00
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
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
97be6d35ce Add get_mut to WasmRefCell 2017-12-21 12:28:30 -08:00
Alex Crichton
44a9555313 Extract null check throw to a separate function
Slightly smaller callsite!
2017-12-21 12:25:13 -08:00
Alex Crichton
91fddfd10f Improve consistency of prefixes 2017-12-19 20:00:25 -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
946e5317fe Support passing JS objects through Rust 2017-12-19 09:25:41 -08:00
Alex Crichton
2926e6e9f4 Initial commit 2017-12-14 19:31:01 -08:00