diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index 4b6b4c5d..26b2b300 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -2866,6 +2866,20 @@ pub mod WebAssembly { #[wasm_bindgen(js_namespace = WebAssembly)] pub fn compile(buffer_source: &JsValue) -> Promise; + /// The `WebAssembly.instantiate()` function allows you to compile and + /// instantiate WebAssembly code. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate) + #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)] + pub fn instantiate_buffer(buffer: &[u8], imports: &Object) -> Promise; + + /// The `WebAssembly.instantiate()` function allows you to compile and + /// instantiate WebAssembly code. + /// + /// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate) + #[wasm_bindgen(js_namespace = WebAssembly, js_name = instantiate)] + pub fn instantiate_module(module: &Module, imports: &Object) -> Promise; + /// The `WebAssembly.validate()` function validates a given typed /// array of WebAssembly binary code, returning whether the bytes /// form a valid wasm module (`true`) or not (`false`). diff --git a/crates/js-sys/tests/wasm/WebAssembly.rs b/crates/js-sys/tests/wasm/WebAssembly.rs index 2d84dc4f..72ec451a 100644 --- a/crates/js-sys/tests/wasm/WebAssembly.rs +++ b/crates/js-sys/tests/wasm/WebAssembly.rs @@ -172,6 +172,17 @@ fn webassembly_instance() { assert!(Reflect::has(exports.as_ref(), &"exported_func".into())); } +#[wasm_bindgen_test(async)] +fn instantiate_module() -> impl Future { + let module = WebAssembly::Module::new(&get_valid_wasm()).unwrap(); + let imports = get_imports(); + let p = WebAssembly::instantiate_module(&module, &imports); + JsFuture::from(p) + .map(|inst| { + assert!(inst.is_instance_of::()); + }) +} + #[wasm_bindgen_test] fn memory_works() { let obj = Object::new();