js-sys: Add bindings for WebAssembly.instantiateStreaming

Part of #275
This commit is contained in:
Nick Fitzgerald
2018-09-06 14:47:37 -07:00
parent 021cbbab71
commit fb5e6e9c06
3 changed files with 29 additions and 0 deletions

View File

@ -31,6 +31,12 @@ function getImports() {
};
}
// Polyfill `WebAssembly.instantiateStreaming` for node.
if (!global.WebAssembly.instantiateStreaming) {
global.WebAssembly.instantiateStreaming =
(response, imports) => response.then(buf => WebAssembly.instantiate(buf, imports));
}
module.exports = {
getInvalidTableObject,
getTableObject,

View File

@ -183,6 +183,20 @@ fn instantiate_module() -> impl Future<Item = (), Error = JsValue> {
})
}
#[wasm_bindgen_test(async)]
fn instantiate_streaming() -> impl Future<Item = (), Error = JsValue> {
let response = Promise::resolve(&get_valid_wasm());
let imports = get_imports();
let p = WebAssembly::instantiate_streaming(&response, &imports);
JsFuture::from(p)
.map(|obj| {
assert!(
Reflect::get(obj.as_ref(), &"instance".into())
.is_instance_of::<WebAssembly::Instance>()
);
})
}
#[wasm_bindgen_test]
fn memory_works() {
let obj = Object::new();