mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-05-13 14:21:22 +00:00
parent
021cbbab71
commit
fb5e6e9c06
@ -2880,6 +2880,15 @@ pub mod WebAssembly {
|
|||||||
#[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
|
#[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)]
|
||||||
pub fn instantiate_module(module: &Module, imports: &Object) -> Promise;
|
pub fn instantiate_module(module: &Module, imports: &Object) -> Promise;
|
||||||
|
|
||||||
|
/// The `WebAssembly.instantiateStreaming()` function compiles and
|
||||||
|
/// instantiates a WebAssembly module directly from a streamed
|
||||||
|
/// underlying source. This is the most efficient, optimized way to load
|
||||||
|
/// wasm code.
|
||||||
|
///
|
||||||
|
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming)
|
||||||
|
#[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiateStreaming)]
|
||||||
|
pub fn instantiate_streaming(response: &Promise, imports: &Object) -> Promise;
|
||||||
|
|
||||||
/// The `WebAssembly.validate()` function validates a given typed
|
/// The `WebAssembly.validate()` function validates a given typed
|
||||||
/// array of WebAssembly binary code, returning whether the bytes
|
/// array of WebAssembly binary code, returning whether the bytes
|
||||||
/// form a valid wasm module (`true`) or not (`false`).
|
/// form a valid wasm module (`true`) or not (`false`).
|
||||||
|
@ -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 = {
|
module.exports = {
|
||||||
getInvalidTableObject,
|
getInvalidTableObject,
|
||||||
getTableObject,
|
getTableObject,
|
||||||
|
@ -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]
|
#[wasm_bindgen_test]
|
||||||
fn memory_works() {
|
fn memory_works() {
|
||||||
let obj = Object::new();
|
let obj = Object::new();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user