Support asynchronous tests (#600)

* Tweak the implementation of heap closures

This commit updates the implementation of the `Closure` type to internally store
an `Rc` and be suitable for dropping a `Closure` during the execution of the
closure. This is currently needed for promises but may be generally useful as
well!

* Support asynchronous tests

This commit adds support for executing tests asynchronously. This is modeled
by tests returning a `Future` instead of simply executing inline, and is
signified with `#[wasm_bindgen_test(async)]`.

Support for this is added through a new `wasm-bindgen-futures` crate which is a
binding between the `futures` crate and JS `Promise` objects.

Lots more details can be found in the details of the commit, but one of the end
results is that the `web-sys` tests are now entirely contained in the same test
suite and don't need `npm install` to be run to execute them!

* Review tweaks

* Add some bindings for `Function.call` to `js_sys`

Name them `call0`, `call1`, `call2`, ... for the number of arguments being
passed.

* Use oneshots channels with `JsFuture`

It did indeed clean up the implementation!
This commit is contained in:
Alex Crichton
2018-08-01 15:52:24 -05:00
committed by GitHub
parent 4181afea45
commit eee71de0ce
34 changed files with 1167 additions and 333 deletions

View File

@ -214,7 +214,6 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
builder.rust_argument("this.a");
}
builder
.rust_argument("this.b")
.process(&closure.function)?
.finish("function", "this.f")
};
@ -225,18 +224,16 @@ impl<'a, 'b> Rust2Js<'a, 'b> {
let reset_idx = format!(
"\
let cb{0} = {js};\n\
cb{0}.f = wasm.__wbg_function_table.get(getGlobalArgument({f}));\n\
cb{0}.a = getGlobalArgument({a});\n\
cb{0}.b = getGlobalArgument({b});\n\
cb{0}.f = wasm.__wbg_function_table.get(getGlobalArgument({c}));\n\
let real = cb{0}.bind(cb{0});\n\
real.original = cb{0};\n\
idx{0} = getUint32Memory()[{0} / 4] = addHeapObject(real);\n\
",
abi,
js = js,
f = self.global_idx(),
a = self.global_idx(),
b = self.global_idx(),
c = self.global_idx(),
);
self.prelude(&format!(
"\