@@ -2,13 +2,12 @@ use crate::ast;
2
2
use crate :: encode;
3
3
use crate :: encode:: EncodeChunk ;
4
4
use crate :: Diagnostic ;
5
- use once_cell:: sync:: Lazy ;
6
5
use proc_macro2:: { Ident , Span , TokenStream } ;
7
6
use quote:: format_ident;
8
7
use quote:: quote_spanned;
9
8
use quote:: { quote, ToTokens } ;
9
+ use std:: cell:: RefCell ;
10
10
use std:: collections:: { HashMap , HashSet } ;
11
- use std:: sync:: Mutex ;
12
11
use syn:: parse_quote;
13
12
use syn:: spanned:: Spanned ;
14
13
use wasm_bindgen_shared as shared;
@@ -224,7 +223,6 @@ impl ToTokens for ast::Struct {
224
223
let free_fn = Ident :: new ( & shared:: free_function ( & name_str) , Span :: call_site ( ) ) ;
225
224
let unwrap_fn = Ident :: new ( & shared:: unwrap_function ( & name_str) , Span :: call_site ( ) ) ;
226
225
let wasm_bindgen = & self . wasm_bindgen ;
227
- let maybe_no_coverage = coverage ( ) ;
228
226
( quote ! {
229
227
#[ automatically_derived]
230
228
impl #wasm_bindgen:: describe:: WasmDescribe for #name {
@@ -296,11 +294,11 @@ impl ToTokens for ast::Struct {
296
294
#[ cfg( all( target_arch = "wasm32" , any( target_os = "unknown" , target_os = "none" ) ) ) ]
297
295
#[ automatically_derived]
298
296
const _: ( ) = {
297
+ #wasm_bindgen:: __wbindgen_coverage! {
299
298
#[ no_mangle]
300
299
#[ doc( hidden) ]
301
300
// `allow_delayed` is whether it's ok to not actually free the `ptr` immediately
302
301
// if it's still borrowed.
303
- #maybe_no_coverage
304
302
pub unsafe extern "C" fn #free_fn( ptr: u32 , allow_delayed: u32 ) {
305
303
use #wasm_bindgen:: __rt:: alloc:: rc:: Rc ;
306
304
@@ -315,6 +313,7 @@ impl ToTokens for ast::Struct {
315
313
let _ = <#name as #wasm_bindgen:: convert:: FromWasmAbi >:: from_abi( ptr) ;
316
314
}
317
315
}
316
+ }
318
317
} ;
319
318
320
319
#[ automatically_derived]
@@ -476,7 +475,6 @@ impl ToTokens for ast::StructField {
476
475
quote ! { assert_copy:: <#ty>( ) }
477
476
} ;
478
477
let maybe_assert_copy = respan ( maybe_assert_copy, ty) ;
479
- let maybe_no_coverage = coverage ( ) ;
480
478
481
479
// Split this out so that it isn't affected by `quote_spanned!`.
482
480
//
@@ -495,9 +493,9 @@ impl ToTokens for ast::StructField {
495
493
( quote ! {
496
494
#[ automatically_derived]
497
495
const _: ( ) = {
496
+ #wasm_bindgen:: __wbindgen_coverage! {
498
497
#[ cfg_attr( all( target_arch = "wasm32" , any( target_os = "unknown" , target_os = "none" ) ) , no_mangle) ]
499
498
#[ doc( hidden) ]
500
- #maybe_no_coverage
501
499
pub unsafe extern "C" fn #getter( js: u32 )
502
500
-> #wasm_bindgen:: convert:: WasmRet <<#ty as #wasm_bindgen:: convert:: IntoWasmAbi >:: Abi >
503
501
{
@@ -512,6 +510,7 @@ impl ToTokens for ast::StructField {
512
510
let val = #val;
513
511
<#ty as IntoWasmAbi >:: into_abi( val) . into( )
514
512
}
513
+ }
515
514
} ;
516
515
} )
517
516
. to_tokens ( tokens) ;
@@ -537,9 +536,9 @@ impl ToTokens for ast::StructField {
537
536
#[ cfg( all( target_arch = "wasm32" , any( target_os = "unknown" , target_os = "none" ) ) ) ]
538
537
#[ automatically_derived]
539
538
const _: ( ) = {
539
+ #wasm_bindgen:: __wbindgen_coverage! {
540
540
#[ no_mangle]
541
541
#[ doc( hidden) ]
542
- #maybe_no_coverage
543
542
pub unsafe extern "C" fn #setter(
544
543
js: u32 ,
545
544
#( #args, ) *
@@ -553,6 +552,7 @@ impl ToTokens for ast::StructField {
553
552
let val = <#ty as FromWasmAbi >:: from_abi( val) ;
554
553
( * js) . borrow_mut( ) . #rust_name = val;
555
554
}
555
+ }
556
556
} ;
557
557
} )
558
558
. to_tokens ( tokens) ;
@@ -788,23 +788,22 @@ impl TryToTokens for ast::Export {
788
788
quote ! { }
789
789
} ;
790
790
791
- let maybe_no_coverage = coverage ( ) ;
792
-
793
791
( quote ! {
794
792
#[ automatically_derived]
795
793
const _: ( ) = {
794
+ #wasm_bindgen:: __wbindgen_coverage! {
796
795
#( #attrs) *
797
796
#[ cfg_attr(
798
797
all( target_arch = "wasm32" , any( target_os = "unknown" , target_os = "none" ) ) ,
799
798
export_name = #export_name,
800
799
) ]
801
- #maybe_no_coverage
802
800
pub unsafe extern "C" fn #generated_name( #( #args) , * ) -> #wasm_bindgen:: convert:: WasmRet <#projection:: Abi > {
803
801
#start_check
804
802
805
803
let #ret = #call;
806
804
#convert_ret
807
805
}
806
+ }
808
807
} ;
809
808
} )
810
809
. to_tokens ( into) ;
@@ -1159,8 +1158,6 @@ impl ToTokens for ast::StringEnum {
1159
1158
let hole = variant_count + 1 ;
1160
1159
let attrs = & self . rust_attrs ;
1161
1160
1162
- let maybe_no_coverage = coverage ( ) ;
1163
-
1164
1161
let invalid_to_str_msg = format ! (
1165
1162
"Converting an invalid string enum ({}) back to a string is currently not supported" ,
1166
1163
enum_name
@@ -1247,7 +1244,6 @@ impl ToTokens for ast::StringEnum {
1247
1244
1248
1245
#[ automatically_derived]
1249
1246
impl #wasm_bindgen:: describe:: WasmDescribe for #enum_name {
1250
- #maybe_no_coverage
1251
1247
fn describe( ) {
1252
1248
use #wasm_bindgen:: describe:: * ;
1253
1249
inform( STRING_ENUM ) ;
@@ -1546,7 +1542,6 @@ impl ToTokens for ast::Enum {
1546
1542
} else {
1547
1543
quote ! { u32 }
1548
1544
} ;
1549
- let maybe_no_coverage = coverage ( ) ;
1550
1545
let cast_clauses = self . variants . iter ( ) . map ( |variant| {
1551
1546
let variant_name = & variant. name ;
1552
1547
quote ! {
@@ -1594,7 +1589,6 @@ impl ToTokens for ast::Enum {
1594
1589
1595
1590
#[ automatically_derived]
1596
1591
impl #wasm_bindgen:: describe:: WasmDescribe for #enum_name {
1597
- #maybe_no_coverage
1598
1592
fn describe( ) {
1599
1593
use #wasm_bindgen:: describe:: * ;
1600
1594
inform( ENUM ) ;
@@ -1778,20 +1772,9 @@ fn thread_local_import(
1778
1772
__inner: & _VAL,
1779
1773
}
1780
1774
} ;
1781
- #[ cfg( all( not( feature = "std" ) , not( feature = "atomics" ) ) ) ]
1782
- let inner = quote ! {
1783
- static _VAL: #wasm_bindgen:: __rt:: LazyCell <#actual_ty> = #wasm_bindgen:: __rt:: LazyCell :: new( init) ;
1784
- #wasm_bindgen:: JsThreadLocal {
1785
- __inner: & _VAL,
1786
- }
1787
- } ;
1788
- #[ cfg( all( not( feature = "std" ) , feature = "atomics" ) ) ]
1775
+ #[ cfg( not( feature = "std" ) ) ]
1789
1776
let inner = quote ! {
1790
- #[ thread_local]
1791
- static _VAL: #wasm_bindgen:: __rt:: LazyCell <#actual_ty> = #wasm_bindgen:: __rt:: LazyCell :: new( init) ;
1792
- #wasm_bindgen:: JsThreadLocal {
1793
- __inner: || unsafe { #wasm_bindgen:: __rt:: LazyCell :: force( & _VAL) as * const #actual_ty } ,
1794
- }
1777
+ #wasm_bindgen:: __wbindgen_thread_local!( #wasm_bindgen, #actual_ty)
1795
1778
} ;
1796
1779
1797
1780
quote ! {
@@ -1847,20 +1830,16 @@ impl<T: ToTokens> ToTokens for Descriptor<'_, T> {
1847
1830
// It's up to the descriptors themselves to ensure they have unique
1848
1831
// names for unique items imported, currently done via `ShortHash` and
1849
1832
// hashing appropriate data into the symbol name.
1850
- static DESCRIPTORS_EMITTED : Lazy < Mutex < HashSet < String > > > = Lazy :: new ( Default :: default) ;
1833
+ thread_local ! {
1834
+ static DESCRIPTORS_EMITTED : RefCell <HashSet <String >> = RefCell :: default ( ) ;
1835
+ }
1851
1836
1852
1837
let ident = self . ident ;
1853
1838
1854
- if !DESCRIPTORS_EMITTED
1855
- . lock ( )
1856
- . unwrap ( )
1857
- . insert ( ident. to_string ( ) )
1858
- {
1839
+ if !DESCRIPTORS_EMITTED . with ( |list| list. borrow_mut ( ) . insert ( ident. to_string ( ) ) ) {
1859
1840
return ;
1860
1841
}
1861
1842
1862
- let maybe_no_coverage = coverage ( ) ;
1863
-
1864
1843
let name = Ident :: new ( & format ! ( "__wbindgen_describe_{}" , ident) , ident. span ( ) ) ;
1865
1844
let inner = & self . inner ;
1866
1845
let attrs = & self . attrs ;
@@ -1869,16 +1848,17 @@ impl<T: ToTokens> ToTokens for Descriptor<'_, T> {
1869
1848
#[ cfg( all( target_arch = "wasm32" , any( target_os = "unknown" , target_os = "none" ) ) ) ]
1870
1849
#[ automatically_derived]
1871
1850
const _: ( ) = {
1851
+ #wasm_bindgen:: __wbindgen_coverage! {
1872
1852
#( #attrs) *
1873
1853
#[ no_mangle]
1874
1854
#[ doc( hidden) ]
1875
- #maybe_no_coverage
1876
1855
pub extern "C" fn #name( ) {
1877
1856
use #wasm_bindgen:: describe:: * ;
1878
1857
// See definition of `link_mem_intrinsics` for what this is doing
1879
1858
#wasm_bindgen:: __rt:: link_mem_intrinsics( ) ;
1880
1859
#inner
1881
1860
}
1861
+ }
1882
1862
} ;
1883
1863
} )
1884
1864
. to_tokens ( tokens) ;
@@ -1963,10 +1943,3 @@ fn respan(input: TokenStream, span: &dyn ToTokens) -> TokenStream {
1963
1943
}
1964
1944
new_tokens. into_iter ( ) . collect ( )
1965
1945
}
1966
-
1967
- fn coverage ( ) -> Option < TokenStream > {
1968
- #[ cfg( all( not( feature = "xxx_resolver_1" ) , feature = "coverage" ) ) ]
1969
- return Some ( quote ! { #[ coverage( off) ] } ) ;
1970
- #[ cfg( any( feature = "xxx_resolver_1" , not( feature = "coverage" ) ) ) ]
1971
- None
1972
- }
0 commit comments