@@ -197,18 +197,23 @@ impl ToTokens for ast::Struct {
197
197
impl wasm_bindgen:: __rt:: core:: convert:: From <#name> for
198
198
wasm_bindgen:: JsValue
199
199
{
200
- #[ cfg( all( target_arch = "wasm32" , not( target_os = "emscripten" ) ) ) ]
201
200
fn from( value: #name) -> Self {
202
201
let ptr = wasm_bindgen:: convert:: IntoWasmAbi :: into_abi(
203
202
value,
204
203
unsafe { & mut wasm_bindgen:: convert:: GlobalStack :: new( ) } ,
205
204
) ;
206
205
207
206
#[ link( wasm_import_module = "__wbindgen_placeholder__" ) ]
207
+ #[ cfg( all( target_arch = "wasm32" , not( target_os = "emscripten" ) ) ) ]
208
208
extern "C" {
209
209
fn #new_fn( ptr: u32 ) -> u32 ;
210
210
}
211
211
212
+ #[ cfg( not( all( target_arch = "wasm32" , not( target_os = "emscripten" ) ) ) ) ]
213
+ unsafe fn #new_fn( ptr: u32 ) -> u32 {
214
+ panic!( "cannot convert to JsValue outside of the wasm target" )
215
+ }
216
+
212
217
unsafe {
213
218
<wasm_bindgen:: JsValue as wasm_bindgen:: convert:: FromWasmAbi >
214
219
:: from_abi(
@@ -217,11 +222,6 @@ impl ToTokens for ast::Struct {
217
222
)
218
223
}
219
224
}
220
-
221
- #[ cfg( not( all( target_arch = "wasm32" , not( target_os = "emscripten" ) ) ) ) ]
222
- fn from( _value: #name) -> Self {
223
- panic!( "cannot convert to JsValue outside of the wasm target" )
224
- }
225
225
}
226
226
227
227
#[ cfg( all( target_arch = "wasm32" , not( target_os = "emscripten" ) ) ) ]
@@ -712,24 +712,22 @@ impl ToTokens for ast::ImportType {
712
712
}
713
713
714
714
impl JsCast for #rust_name {
715
- #[ cfg( all( target_arch = "wasm32" , not( target_os = "emscripten" ) ) ) ]
716
715
fn instanceof( val: & JsValue ) -> bool {
717
716
#[ link( wasm_import_module = "__wbindgen_placeholder__" ) ]
717
+ #[ cfg( all( target_arch = "wasm32" , not( target_os = "emscripten" ) ) ) ]
718
718
extern "C" {
719
719
fn #instanceof_shim( val: u32 ) -> u32 ;
720
720
}
721
+ #[ cfg( not( all( target_arch = "wasm32" , not( target_os = "emscripten" ) ) ) ) ]
722
+ unsafe fn #instanceof_shim( val: u32 ) -> u32 {
723
+ panic!( "cannot check instanceof on non-wasm targets" ) ;
724
+ }
721
725
unsafe {
722
726
let idx = val. into_abi( & mut wasm_bindgen:: convert:: GlobalStack :: new( ) ) ;
723
727
#instanceof_shim( idx) != 0
724
728
}
725
729
}
726
730
727
- #[ cfg( not( all( target_arch = "wasm32" , not( target_os = "emscripten" ) ) ) ) ]
728
- fn instanceof( val: & JsValue ) -> bool {
729
- drop( val) ;
730
- panic!( "cannot check instanceof on non-wasm targets" ) ;
731
- }
732
-
733
731
#is_type_of
734
732
735
733
#[ inline]
@@ -998,6 +996,7 @@ impl TryToTokens for ast::ImportFunction {
998
996
let import_name = & self . shim ;
999
997
let attrs = & self . function . rust_attrs ;
1000
998
let arguments = & arguments;
999
+ let abi_arguments = & abi_arguments;
1001
1000
1002
1001
let doc_comment = match & self . doc_comment {
1003
1002
None => "" ,
@@ -1012,14 +1011,20 @@ impl TryToTokens for ast::ImportFunction {
1012
1011
let invocation = quote ! {
1013
1012
#( #attrs) *
1014
1013
#[ allow( bad_style) ]
1015
- #[ cfg( all( target_arch = "wasm32" , not( target_os = "emscripten" ) ) ) ]
1016
1014
#[ doc = #doc_comment]
1017
1015
#[ allow( clippy:: all) ]
1018
1016
#vis fn #rust_name( #me #( #arguments) , * ) #ret {
1019
1017
#[ link( wasm_import_module = "__wbindgen_placeholder__" ) ]
1018
+ #[ cfg( all( target_arch = "wasm32" , not( target_os = "emscripten" ) ) ) ]
1020
1019
extern "C" {
1021
1020
fn #import_name( #( #abi_arguments) , * ) -> #abi_ret;
1022
1021
}
1022
+ #[ cfg( not( all( target_arch = "wasm32" , not( target_os = "emscripten" ) ) ) ) ]
1023
+ unsafe fn #import_name( #( #abi_arguments) , * ) -> #abi_ret {
1024
+ panic!( "cannot call wasm-bindgen imported functions on \
1025
+ non-wasm targets") ;
1026
+ }
1027
+
1023
1028
unsafe {
1024
1029
#exn_data
1025
1030
let #ret_ident = {
@@ -1031,17 +1036,6 @@ impl TryToTokens for ast::ImportFunction {
1031
1036
#convert_ret
1032
1037
}
1033
1038
}
1034
-
1035
- #( #attrs) *
1036
- #[ allow( bad_style, unused_variables) ]
1037
- #[ cfg( not( all( target_arch = "wasm32" , not( target_os = "emscripten" ) ) ) ) ]
1038
- #[ doc = #doc_comment]
1039
- #[ allow( clippy:: all) ]
1040
- #vis fn #rust_name( #me #( #arguments) , * ) #ret {
1041
- panic!( "cannot call wasm-bindgen imported functions on \
1042
- non-wasm targets") ;
1043
- }
1044
-
1045
1039
} ;
1046
1040
1047
1041
if let Some ( class) = class_ty {
@@ -1164,12 +1158,17 @@ impl ToTokens for ast::ImportStatic {
1164
1158
#[ allow( bad_style) ]
1165
1159
#[ allow( clippy:: all) ]
1166
1160
#vis static #name: wasm_bindgen:: JsStatic <#ty> = {
1167
- #[ cfg( all( target_arch = "wasm32" , not( target_os = "emscripten" ) ) ) ]
1168
1161
fn init( ) -> #ty {
1169
1162
#[ link( wasm_import_module = "__wbindgen_placeholder__" ) ]
1163
+ #[ cfg( all( target_arch = "wasm32" , not( target_os = "emscripten" ) ) ) ]
1170
1164
extern "C" {
1171
1165
fn #shim_name( ) -> <#ty as wasm_bindgen:: convert:: FromWasmAbi >:: Abi ;
1172
1166
}
1167
+ #[ cfg( not( all( target_arch = "wasm32" , not( target_os = "emscripten" ) ) ) ) ]
1168
+ unsafe fn #shim_name( ) -> <#ty as wasm_bindgen:: convert:: FromWasmAbi >:: Abi {
1169
+ panic!( "cannot access imported statics on non-wasm targets" )
1170
+ }
1171
+
1173
1172
unsafe {
1174
1173
<#ty as wasm_bindgen:: convert:: FromWasmAbi >:: from_abi(
1175
1174
#shim_name( ) ,
@@ -1178,10 +1177,6 @@ impl ToTokens for ast::ImportStatic {
1178
1177
1179
1178
}
1180
1179
}
1181
- #[ cfg( not( all( target_arch = "wasm32" , not( target_os = "emscripten" ) ) ) ) ]
1182
- fn init( ) -> #ty {
1183
- panic!( "cannot access imported statics on non-wasm targets" )
1184
- }
1185
1180
thread_local!( static _VAL: #ty = init( ) ; ) ;
1186
1181
wasm_bindgen:: JsStatic {
1187
1182
__inner: & _VAL,
0 commit comments