@@ -297,9 +297,23 @@ impl<'src> FirstPassRecord<'src> {
297
297
} ,
298
298
} ;
299
299
300
- let is_indexing_getter_to_fix = is_indexing_getter && // exclude non index getters.
301
- !catch && // exclude indexing getters that return `Result<T, JsValue>`.
302
- if let Some ( ref ty) = ret { // exclude indexing getters that return `Option<T>`.
300
+ // Some WebIDL indexing getters (e.g. __widl_f_get_DOMStringMap) return
301
+ // `undefined` although the WebIDL specification does not explicitly
302
+ // state so, which causes uncaught runtime exceptions
303
+ // (rustwasm/wasm-bindgen#1756). To fix this, we check the return
304
+ // types of the generated Rust bindings for indexing getters, and
305
+ // ensure that they are wrapped as either `Result<T, JsValue>` or
306
+ // `Option<T>`. For indexing getters with an unwrapped return type, we
307
+ // convert their return types to `Option<T>`.
308
+ //
309
+ // Here we compute the `is_indexing_getter_to_fix` flag that tells us
310
+ // whether the binding function we are generating is for an indexing
311
+ // getter and its return type is not originally wrapped (i.e. neither
312
+ // `Result<T, JsValue>` nor `Option<T>`) thus needing the conversion
313
+ // to `Option<T>`.
314
+ let is_indexing_getter_to_fix = is_indexing_getter && // exclude non indexing getters
315
+ !catch && // exclude indexing getters that return `Result<T, JsValue>`
316
+ if let Some ( ref ty) = ret { // exclude indexing getters that return `Option<T>`
303
317
!format ! ( "{}" , quote! { #ty } )
304
318
. replace ( " " , "" )
305
319
. starts_with ( "Option<" )
0 commit comments