js-sys: Add exports getter to WebAssembly.Instance

Part of #275
This commit is contained in:
Nick Fitzgerald
2018-09-06 14:16:28 -07:00
parent cb2aa999c0
commit 8b5f5a7560
2 changed files with 16 additions and 1 deletions

View File

@ -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

View File

@ -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]