fn codegen_v8_sync(
  core: &TokenStream2,
  f: &syn::ItemFn,
  margs: MacroArgs,
) -> TokenStream2 {
  let MacroArgs { is_v8, .. } = margs;
  let scope_arg = |arg: &FnArg| {
    if is_handle_scope(arg) {
      Some(quote! { scope, })
    } else {
      None
    }
  };
  let opstate_arg = |arg: &FnArg| match arg {
    arg if is_rc_refcell_opstate(arg) => Some(quote! { ctx.state.clone(), }),
    arg if is_mut_ref_opstate(arg) => {
      Some(quote! { &mut ctx.state.borrow_mut(), })
    }
    _ => None,
  };
  let special_args = f
    .sig
    .inputs
    .iter()
    .map_while(|a| {
      (if is_v8 { scope_arg(a) } else { None }).or_else(|| opstate_arg(a))
    })
    .collect::<Vec<_>>();
  let rust_i0 = special_args.len();
  let args_head = special_args.into_iter().collect::<TokenStream2>();

  let (arg_decls, args_tail) = codegen_args(core, f, rust_i0, 0);
  let ret = codegen_sync_ret(core, &f.sig.output);
  let type_params = exclude_lifetime_params(&f.sig.generics.params);

  quote! {
    // SAFETY: #core guarantees args.data() is a v8 External pointing to an OpCtx for the isolates lifetime
    let ctx = unsafe {
      &*(#core::v8::Local::<#core::v8::External>::cast(args.data().unwrap_unchecked()).value()
      as *const #core::_ops::OpCtx)
    };

    #arg_decls

    let result = Self::call::<#type_params>(#args_head #args_tail);

    let op_state = &mut ctx.state.borrow();
    op_state.tracker.track_sync(ctx.id);

    #ret
  }
}
/// Generate the body of a v8 func for a sync op
Generate the body of a v8 func for a sync op
Generate the body of a v8 func for a sync op
fn codegen_v8_sync(
  core: &TokenStream2,
  f: &syn::ItemFn,
  margs: MacroArgs,
) -> TokenStream2 {
  let MacroArgs { is_v8, .. } = margs;
  let scope_arg = |arg: &FnArg| {
    if is_handle_scope(arg) {
      Some(quote! { scope, })
    } else {
      None
    }
  };
  let opstate_arg = |arg: &FnArg| match arg {
    arg if is_rc_refcell_opstate(arg) => Some(quote! { ctx.state.clone(), }),
    arg if is_mut_ref_opstate(arg) => {
      Some(quote! { &mut ctx.state.borrow_mut(), })
    }
    _ => None,
  };
  let special_args = f
    .sig
    .inputs
    .iter()
    .map_while(|a| {
      (if is_v8 { scope_arg(a) } else { None }).or_else(|| opstate_arg(a))
    })
    .collect::<Vec<_>>();
  let rust_i0 = special_args.len();
  let args_head = special_args.into_iter().collect::<TokenStream2>();
  let (arg_decls, args_tail) = codegen_args(core, f, rust_i0, 0);
  let ret = codegen_sync_ret(core, &f.sig.output);
  let type_params = exclude_lifetime_params(&f.sig.generics.params);
  quote! {
    // SAFETY: #core guarantees args.data() is a v8 External pointing to an OpCtx for the isolates lifetime
    let ctx = unsafe {
      &*(#core::v8::Local::<#core::v8::External>::cast(args.data().unwrap_unchecked()).value()
      as *const #core::_ops::OpCtx)
    };
    #arg_decls
    let result = Self::call::<#type_params>(#args_head #args_tail);
    let op_state = &mut ctx.state.borrow();
    op_state.tracker.track_sync(ctx.id);
    #ret
  }
}
fn codegen_v8_sync ( core : & TokenStream2 , f : & syn :: ItemFn , margs : MacroArgs , ) -> TokenStream2 { let MacroArgs { is_v8 , .. } = margs ; let scope_arg = | arg : & FnArg | { if is_handle_scope ( arg ) { Some ( quote ! { scope } ) } else { None } } ; let opstate_arg = | arg : & FnArg | match arg { arg if is_rc_refcell_opstate ( arg ) => Some ( quote ! { ctx state clone ( ) } ) , arg if is_mut_ref_opstate ( arg ) => { Some ( quote ! { mut ctx state borrow_mut ( ) } ) } _ => None , } ; let special_args = f . sig . inputs . iter ( ) . map_while ( | a | { ( if is_v8 { scope_arg ( a ) } else { None } ) . or_else ( | | opstate_arg ( a ) ) } ) . collect :: < Vec < _ > > ( ) ; let rust_i0 = special_args . len ( ) ; let args_head = special_args . into_iter ( ) . collect :: < TokenStream2 > ( ) ; let ( arg_decls , args_tail ) = codegen_args ( core , f , rust_i0 , 0 ) ; let ret = codegen_sync_ret ( core , & f . sig . output ) ; let type_params = exclude_lifetime_params ( & f . sig . generics . params ) ; quote ! { // SAFETY: #core guarantees args.data() is a v8 External pointing to an OpCtx for the isolates lifetime let ctx unsafe { ( core v8 Local core v8 External cast ( args data ( ) unwrap_unchecked ( ) ) value ( ) as const core ops OpCtx ) } arg_decls let result Self call type_params ( args_head args_tail ) let op_state mut ctx state borrow ( ) op_state tracker track_sync ( ctx id ) ret } }
Generate the body of a v8 func for a sync op
Generate the body of a v8 func for a sync op
core
&TokenStream2
f
&syn::ItemFn
margs
MacroArgs
core
&TokenStream2
f
&syn::ItemFn
margs
MacroArgs