@@ -578,14 +578,24 @@ impl ToTokens for ast::ImportType {
578
578
let const_name = format ! ( "__wbg_generated_const_{}" , rust_name) ;
579
579
let const_name = Ident :: new ( & const_name, Span :: call_site ( ) ) ;
580
580
let instanceof_shim = Ident :: new ( & self . instanceof_shim , Span :: call_site ( ) ) ;
581
+
582
+ let internal_obj = match self . extends . first ( ) {
583
+ Some ( target) => {
584
+ quote ! { #target }
585
+ }
586
+ None => {
587
+ quote ! { wasm_bindgen:: JsValue }
588
+ }
589
+ } ;
590
+
581
591
( quote ! {
582
592
#[ allow( bad_style) ]
583
593
#( #attrs) *
584
594
#[ doc = #doc_comment]
585
595
#[ repr( transparent) ]
586
596
#[ allow( clippy:: all) ]
587
597
#vis struct #rust_name {
588
- obj: wasm_bindgen :: JsValue ,
598
+ obj: #internal_obj
589
599
}
590
600
591
601
#[ allow( bad_style) ]
@@ -604,6 +614,15 @@ impl ToTokens for ast::ImportType {
604
614
}
605
615
}
606
616
617
+ impl core:: ops:: Deref for #rust_name {
618
+ type Target = #internal_obj;
619
+
620
+ #[ inline]
621
+ fn deref( & self ) -> & #internal_obj {
622
+ & self . obj
623
+ }
624
+ }
625
+
607
626
impl IntoWasmAbi for #rust_name {
608
627
type Abi = <JsValue as IntoWasmAbi >:: Abi ;
609
628
@@ -629,7 +648,7 @@ impl ToTokens for ast::ImportType {
629
648
#[ inline]
630
649
unsafe fn from_abi( js: Self :: Abi , extra: & mut Stack ) -> Self {
631
650
#rust_name {
632
- obj: JsValue :: from_abi( js, extra) ,
651
+ obj: JsValue :: from_abi( js, extra) . into ( ) ,
633
652
}
634
653
}
635
654
}
@@ -656,7 +675,7 @@ impl ToTokens for ast::ImportType {
656
675
unsafe fn ref_from_abi( js: Self :: Abi , extra: & mut Stack ) -> Self :: Anchor {
657
676
let tmp = <JsValue as RefFromWasmAbi >:: ref_from_abi( js, extra) ;
658
677
core:: mem:: ManuallyDrop :: new( #rust_name {
659
- obj: core:: mem:: ManuallyDrop :: into_inner( tmp) ,
678
+ obj: core:: mem:: ManuallyDrop :: into_inner( tmp) . into ( ) ,
660
679
} )
661
680
}
662
681
}
@@ -665,20 +684,20 @@ impl ToTokens for ast::ImportType {
665
684
impl From <JsValue > for #rust_name {
666
685
#[ inline]
667
686
fn from( obj: JsValue ) -> #rust_name {
668
- #rust_name { obj }
687
+ #rust_name { obj: obj . into ( ) }
669
688
}
670
689
}
671
690
672
691
impl AsRef <JsValue > for #rust_name {
673
692
#[ inline]
674
- fn as_ref( & self ) -> & JsValue { & self . obj }
693
+ fn as_ref( & self ) -> & JsValue { self . obj. as_ref ( ) }
675
694
}
676
695
677
696
678
697
impl From <#rust_name> for JsValue {
679
698
#[ inline]
680
699
fn from( obj: #rust_name) -> JsValue {
681
- obj. obj
700
+ obj. obj. into ( )
682
701
}
683
702
}
684
703
@@ -703,7 +722,7 @@ impl ToTokens for ast::ImportType {
703
722
704
723
#[ inline]
705
724
fn unchecked_from_js( val: JsValue ) -> Self {
706
- #rust_name { obj: val }
725
+ #rust_name { obj: val. into ( ) }
707
726
}
708
727
709
728
#[ inline]
@@ -719,22 +738,6 @@ impl ToTokens for ast::ImportType {
719
738
} )
720
739
. to_tokens ( tokens) ;
721
740
722
- let deref_target = match self . extends . first ( ) {
723
- Some ( target) => quote ! { #target } ,
724
- None => quote ! { JsValue } ,
725
- } ;
726
- ( quote ! {
727
- #[ allow( clippy:: all) ]
728
- impl core:: ops:: Deref for #rust_name {
729
- type Target = #deref_target;
730
-
731
- #[ inline]
732
- fn deref( & self ) -> & #deref_target {
733
- self . as_ref( )
734
- }
735
- }
736
- } )
737
- . to_tokens ( tokens) ;
738
741
for superclass in self . extends . iter ( ) {
739
742
( quote ! {
740
743
#[ allow( clippy:: all) ]
0 commit comments