@@ -3,6 +3,7 @@ use std::ptr;
3
3
4
4
use heck:: { CamelCase , ShoutySnakeCase , SnakeCase } ;
5
5
use proc_macro2:: { Ident , Span } ;
6
+ use quote:: quote;
6
7
use syn;
7
8
use wasm_bindgen_backend:: ast;
8
9
use wasm_bindgen_backend:: util:: { ident_ty, leading_colon_path_ty, raw_ident, rust_ident} ;
@@ -227,6 +228,7 @@ impl<'src> FirstPassRecord<'src> {
227
228
idl_arguments : impl Iterator < Item = ( & ' a str , & ' a IdlType < ' src > ) > ,
228
229
ret : & IdlType < ' src > ,
229
230
kind : ast:: ImportFunctionKind ,
231
+ is_indexing_getter : bool ,
230
232
structural : bool ,
231
233
catch : bool ,
232
234
variadic : bool ,
@@ -294,9 +296,24 @@ impl<'src> FirstPassRecord<'src> {
294
296
}
295
297
} ,
296
298
} ;
297
- let js_ret = ret. clone ( ) ;
299
+
300
+ let is_indexing_getter_to_fix = is_indexing_getter && // exclude non index getters.
301
+ !catch && // exclude indexing getters that return `Result<T>`.
302
+ if let Some ( ref ty) = ret { // exclude indexing getters that return `Option<T>`.
303
+ !format ! ( "{}" , quote! { #ty } )
304
+ . replace ( " " , "" )
305
+ . starts_with ( "Option<" )
306
+ } else {
307
+ false
308
+ } ;
309
+
310
+ let mut js_ret = ret. clone ( ) ;
298
311
let ret = if catch {
299
312
Some ( ret. map_or_else ( || result_ty ( unit_ty ( ) ) , result_ty) )
313
+ } else if is_indexing_getter_to_fix {
314
+ let ret = Some ( ret. map_or_else ( || option_ty ( unit_ty ( ) ) , option_ty) ) ;
315
+ js_ret = ret. clone ( ) ;
316
+ ret
300
317
} else {
301
318
ret
302
319
} ;
@@ -349,6 +366,7 @@ impl<'src> FirstPassRecord<'src> {
349
366
None . into_iter ( ) ,
350
367
& ret,
351
368
kind,
369
+ false ,
352
370
is_structural ( attrs. as_ref ( ) , container_attrs) ,
353
371
throws ( attrs) ,
354
372
false ,
@@ -379,6 +397,7 @@ impl<'src> FirstPassRecord<'src> {
379
397
Some ( ( name, & field_ty) ) . into_iter ( ) ,
380
398
& IdlType :: Void ,
381
399
kind,
400
+ false ,
382
401
is_structural ( attrs. as_ref ( ) , container_attrs) ,
383
402
throws ( attrs) ,
384
403
false ,
@@ -516,6 +535,8 @@ impl<'src> FirstPassRecord<'src> {
516
535
OperationId :: IndexingDeleter => ( "delete" , true , false ) ,
517
536
} ;
518
537
538
+ let is_indexing_getter = id == & OperationId :: IndexingGetter ;
539
+
519
540
let mut ret = Vec :: new ( ) ;
520
541
for signature in actual_signatures. iter ( ) {
521
542
// Ignore signatures with invalid return types
@@ -598,6 +619,7 @@ impl<'src> FirstPassRecord<'src> {
598
619
. map ( |( idl_type, orig_arg) | ( orig_arg. name , idl_type) ) ,
599
620
& ret_ty,
600
621
kind. clone ( ) ,
622
+ is_indexing_getter,
601
623
structural,
602
624
catch,
603
625
variadic,
@@ -624,6 +646,7 @@ impl<'src> FirstPassRecord<'src> {
624
646
. map ( |( name, idl_type) | ( & name[ ..] , idl_type. clone ( ) ) ) ,
625
647
& ret_ty,
626
648
kind. clone ( ) ,
649
+ is_indexing_getter,
627
650
structural,
628
651
catch,
629
652
false ,
0 commit comments