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

@ -1210,11 +1210,13 @@ impl ToTokens for ast::DictionaryField {
(quote! {
pub fn #name(&mut self, val: #ty) -> &mut Self {
use wasm_bindgen::JsValue;
::js_sys::Reflect::set(
let r = ::js_sys::Reflect::set(
self.obj.as_ref(),
&JsValue::from(stringify!(#name)),
&JsValue::from(val),
);
debug_assert!(r.is_ok(), "setting properties should never fail on our dictionary objects");
let _ = r;
self
}
}).to_tokens(tokens);