Skip to content

Commit 624a14c

Browse files
committed
Add comments describing what the code segment is doing
1 parent 487fc30 commit 624a14c

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

crates/webidl/src/util.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,23 @@ impl<'src> FirstPassRecord<'src> {
297297
},
298298
};
299299

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>`
303317
!format!("{}", quote! { #ty })
304318
.replace(" ", "")
305319
.starts_with("Option<")

0 commit comments

Comments
 (0)