mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-22 01:01:34 +00:00
@ -2917,6 +2917,15 @@ pub mod WebAssembly {
|
|||||||
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
|
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance)
|
||||||
#[wasm_bindgen(catch, constructor, js_namespace = WebAssembly)]
|
#[wasm_bindgen(catch, constructor, js_namespace = WebAssembly)]
|
||||||
pub fn new(module: &Module, imports: &Object) -> Result<Instance, JsValue>;
|
pub fn new(module: &Module, imports: &Object) -> Result<Instance, JsValue>;
|
||||||
|
|
||||||
|
/// The `exports` readonly property of the `WebAssembly.Instance` object
|
||||||
|
/// prototype returns an object containing as its members all the
|
||||||
|
/// functions exported from the WebAssembly module instance, to allow
|
||||||
|
/// them to be accessed and used by JavaScript.
|
||||||
|
///
|
||||||
|
/// [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports)
|
||||||
|
#[wasm_bindgen(getter, method, js_namespace = WebAssembly)]
|
||||||
|
pub fn exports(this: &Instance) -> Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebAssembly.LinkError
|
// WebAssembly.LinkError
|
||||||
|
@ -157,13 +157,19 @@ fn runtime_error_inheritance() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen_test]
|
#[wasm_bindgen_test]
|
||||||
fn instance_constructor_and_inheritance() {
|
fn webassembly_instance() {
|
||||||
let module = WebAssembly::Module::new(&get_valid_wasm()).unwrap();
|
let module = WebAssembly::Module::new(&get_valid_wasm()).unwrap();
|
||||||
let imports = get_imports();
|
let imports = get_imports();
|
||||||
let instance = WebAssembly::Instance::new(&module, &imports).unwrap();
|
let instance = WebAssembly::Instance::new(&module, &imports).unwrap();
|
||||||
|
|
||||||
|
// Inheritance chain is correct.
|
||||||
assert!(instance.is_instance_of::<WebAssembly::Instance>());
|
assert!(instance.is_instance_of::<WebAssembly::Instance>());
|
||||||
assert!(instance.is_instance_of::<Object>());
|
assert!(instance.is_instance_of::<Object>());
|
||||||
let _: &Object = instance.as_ref();
|
let _: &Object = instance.as_ref();
|
||||||
|
|
||||||
|
// Has expected exports.
|
||||||
|
let exports = instance.exports();
|
||||||
|
assert!(Reflect::has(exports.as_ref(), &"exported_func".into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen_test]
|
#[wasm_bindgen_test]
|
||||||
|
Reference in New Issue
Block a user