Add experimental support for WeakRef

This commit adds experimental support for `WeakRef` to be used to automatically
free wasm objects instead of having to always call the `free` function manually.
Note that when enabled the `free` function for all exported objects is still
generated, it's just optionally invoked by the application.

Support isn't exposed through a CLI flag right now due to the early stages of
the `WeakRef` proposal, but the env var `WASM_BINDGEN_WEAKREF` can be used to
enable this generation. Upon doing so the output can then be edited slightly as
well to work in the SpiderMonkey shell and it looks like this is working!

Closes #704
This commit is contained in:
Alex Crichton
2018-08-15 17:52:26 -07:00
parent adcc0dd23e
commit 61491eafbf
2 changed files with 73 additions and 6 deletions

View File

@ -10,6 +10,7 @@ extern crate failure;
use std::any::Any;
use std::collections::BTreeSet;
use std::env;
use std::fmt;
use std::fs;
use std::mem;
@ -33,6 +34,9 @@ pub struct Bindgen {
typescript: bool,
demangle: bool,
keep_debug: bool,
// Experimental support for `WeakRefGroup`, an upcoming ECMAScript feature.
// Currently only enable-able through an env var.
weak_refs: bool,
}
enum Input {
@ -55,6 +59,7 @@ impl Bindgen {
typescript: false,
demangle: true,
keep_debug: false,
weak_refs: env::var("WASM_BINDGEN_WEAKREF").is_ok(),
}
}