@@ -224,6 +224,13 @@ impl ToTokens for ast::Struct {
224
224
let unwrap_fn = Ident :: new ( & shared:: unwrap_function ( & name_str) , Span :: call_site ( ) ) ;
225
225
let wasm_bindgen = & self . wasm_bindgen ;
226
226
( quote ! {
227
+ #[ automatically_derived]
228
+ impl #wasm_bindgen:: __rt:: marker:: SupportsConstructor for #name { }
229
+ #[ automatically_derived]
230
+ impl #wasm_bindgen:: __rt:: marker:: SupportsInstanceProperty for #name { }
231
+ #[ automatically_derived]
232
+ impl #wasm_bindgen:: __rt:: marker:: SupportsStaticProperty for #name { }
233
+
227
234
#[ automatically_derived]
228
235
impl #wasm_bindgen:: describe:: WasmDescribe for #name {
229
236
fn describe( ) {
@@ -782,12 +789,41 @@ impl TryToTokens for ast::Export {
782
789
let nargs = self . function . arguments . len ( ) as u32 ;
783
790
let attrs = & self . function . rust_attrs ;
784
791
785
- let start_check = if self . start {
786
- quote ! { const _ASSERT: fn ( ) = || -> #projection:: Abi { loop { } } ; }
787
- } else {
788
- quote ! { }
792
+ let mut checks = Vec :: new ( ) ;
793
+ if self . start {
794
+ checks. push ( quote ! { const _ASSERT: fn ( ) = || -> #projection:: Abi { loop { } } ; } ) ;
789
795
} ;
790
796
797
+ if let Some ( class) = self . rust_class . as_ref ( ) {
798
+ // little helper function to make sure the check points to the
799
+ // location of the function causing the assert to fail
800
+ let mut add_check = |token_stream| {
801
+ checks. push ( respan ( token_stream, & self . rust_name ) ) ;
802
+ } ;
803
+
804
+ match & self . method_kind {
805
+ ast:: MethodKind :: Constructor => {
806
+ add_check ( quote ! {
807
+ let _: #wasm_bindgen:: __rt:: marker:: CheckSupportsConstructor <#class>;
808
+ } ) ;
809
+ }
810
+ ast:: MethodKind :: Operation ( operation) => match operation. kind {
811
+ ast:: OperationKind :: Getter ( _) | ast:: OperationKind :: Setter ( _) => {
812
+ if operation. is_static {
813
+ add_check ( quote ! {
814
+ let _: #wasm_bindgen:: __rt:: marker:: CheckSupportsStaticProperty <#class>;
815
+ } ) ;
816
+ } else {
817
+ add_check ( quote ! {
818
+ let _: #wasm_bindgen:: __rt:: marker:: CheckSupportsInstanceProperty <#class>;
819
+ } ) ;
820
+ }
821
+ }
822
+ _ => { }
823
+ } ,
824
+ }
825
+ }
826
+
791
827
( quote ! {
792
828
#[ automatically_derived]
793
829
const _: ( ) = {
@@ -798,7 +834,9 @@ impl TryToTokens for ast::Export {
798
834
export_name = #export_name,
799
835
) ]
800
836
pub unsafe extern "C" fn #generated_name( #( #args) , * ) -> #wasm_bindgen:: convert:: WasmRet <#projection:: Abi > {
801
- #start_check
837
+ const _: ( ) = {
838
+ #( #checks) *
839
+ } ;
802
840
803
841
let #ret = #call;
804
842
#convert_ret
0 commit comments