@@ -185,13 +185,15 @@ fn codegen_v8_async(core: &TokenStream2, f: &syn::ItemFn) -> TokenStream2 {
185
185
/// Generate the body of a v8 func for a sync op
186
186
fn codegen_v8_sync ( core : & TokenStream2 , f : & syn:: ItemFn ) -> TokenStream2 {
187
187
let arg0 = f. sig . inputs . first ( ) ;
188
- let uses_opstate = arg0. map ( is_mut_ref_opstate) . unwrap_or_default ( ) ;
189
- let args_head = if uses_opstate {
190
- quote ! { op_state, }
191
- } else {
192
- quote ! { }
188
+ let ( rust_i0, args_head) = match arg0 {
189
+ Some ( arg0) if is_rc_refcell_opstate ( arg0) => {
190
+ ( 1 , quote ! { ctx. state. clone( ) , } )
191
+ }
192
+ Some ( arg0) if is_mut_ref_opstate ( arg0) => {
193
+ ( 1 , quote ! { & mut ctx. state. borrow_mut( ) , } )
194
+ }
195
+ _ => ( 0 , quote ! { } ) ,
193
196
} ;
194
- let rust_i0 = if uses_opstate { 1 } else { 0 } ;
195
197
let ( arg_decls, args_tail) = codegen_args ( core, f, rust_i0, 0 ) ;
196
198
let ret = codegen_sync_ret ( core, & f. sig . output ) ;
197
199
let type_params = & f. sig . generics . params ;
@@ -205,9 +207,9 @@ fn codegen_v8_sync(core: &TokenStream2, f: &syn::ItemFn) -> TokenStream2 {
205
207
206
208
#arg_decls
207
209
208
- let op_state = & mut ctx. state. borrow_mut( ) ;
209
210
let result = Self :: call:: <#type_params>( #args_head #args_tail) ;
210
211
212
+ let op_state = & mut ctx. state. borrow( ) ;
211
213
op_state. tracker. track_sync( ctx. id) ;
212
214
213
215
#ret
0 commit comments