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
This commit is contained in:
Alex Crichton
2017-12-19 19:50:06 -08:00
parent 5b079b8f60
commit d3387d591f
4 changed files with 170 additions and 15 deletions

View File

@ -389,6 +389,13 @@ impl Js {
imports.push_str("__wasm_bindgen_object_drop_ref: dropRef,\n");
}
if self.wasm_import_needed("__wbindgen_throw", m) {
self.expose_get_string_from_wasm();
imports.push_str("__wbindgen_throw: function(ptr: number, len: number) {
throw new Error(getStringFromWasm(ptr, len));
},\n");
}
let mut writes = String::new();
if self.exposed_globals.contains(&"memory") {
writes.push_str("memory = exports.memory;\n");