js-sys: Catch exceptions thrown in Reflect APIs

Proxies passed to Reflect APIs can throw for any of these operations and it is a
bit of a mess.
This commit is contained in:
Nick Fitzgerald
2018-09-25 11:55:28 -07:00
parent 6edb871c36
commit e3d2ea2628
10 changed files with 171 additions and 92 deletions

View File

@ -178,7 +178,7 @@ fn webassembly_instance() {
// Has expected exports.
let exports = instance.exports();
assert!(Reflect::has(exports.as_ref(), &"exported_func".into()));
assert!(Reflect::has(exports.as_ref(), &"exported_func".into()).unwrap());
}
#[wasm_bindgen_test(async)]
@ -201,6 +201,7 @@ fn instantiate_streaming() -> impl Future<Item = (), Error = JsValue> {
.map(|obj| {
assert!(
Reflect::get(obj.as_ref(), &"instance".into())
.unwrap()
.is_instance_of::<WebAssembly::Instance>()
);
})
@ -209,7 +210,7 @@ fn instantiate_streaming() -> impl Future<Item = (), Error = JsValue> {
#[wasm_bindgen_test]
fn memory_works() {
let obj = Object::new();
Reflect::set(obj.as_ref(), &"initial".into(), &1.into());
Reflect::set(obj.as_ref(), &"initial".into(), &1.into()).unwrap();
let mem = WebAssembly::Memory::new(&obj).unwrap();
assert!(mem.is_instance_of::<WebAssembly::Memory>());
assert!(mem.is_instance_of::<Object>());