diff options
Diffstat (limited to 'ops/lib.rs')
| -rw-r--r-- | ops/lib.rs | 118 |
1 files changed, 55 insertions, 63 deletions
diff --git a/ops/lib.rs b/ops/lib.rs index 21812f605..f7c69ec8a 100644 --- a/ops/lib.rs +++ b/ops/lib.rs @@ -145,7 +145,6 @@ impl Op { is_async: #is_async, is_unstable: #is_unstable, is_v8: #is_v8, - argc: 0, } } @@ -160,7 +159,7 @@ impl Op { let has_fallible_fast_call = active && optimizer.returns_result; - let (v8_body, argc) = if is_async { + let v8_body = if is_async { let deferred = attrs.deferred; codegen_v8_async( &core, @@ -202,7 +201,6 @@ impl Op { is_async: #is_async, is_unstable: #is_unstable, is_v8: #is_v8, - argc: #argc, } } @@ -239,7 +237,7 @@ fn codegen_v8_async( margs: Attributes, asyncness: bool, deferred: bool, -) -> (TokenStream2, usize) { +) -> TokenStream2 { let Attributes { is_v8, .. } = margs; let special_args = f .sig @@ -253,7 +251,7 @@ fn codegen_v8_async( let rust_i0 = special_args.len(); let args_head = special_args.into_iter().collect::<TokenStream2>(); - let (arg_decls, args_tail, argc) = codegen_args(core, f, rust_i0, 1, true); + let (arg_decls, args_tail, _) = codegen_args(core, f, rust_i0, 1, true); let type_params = exclude_lifetime_params(&f.sig.generics.params); let (pre_result, mut result_fut) = match asyncness { @@ -284,48 +282,45 @@ fn codegen_v8_async( false => quote! { let result = Ok(result); }, }; - ( - quote! { - use #core::futures::FutureExt; - // 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()).value() - as *const #core::_ops::OpCtx) - }; - let op_id = ctx.id; - let realm_idx = ctx.realm_idx; - - let promise_id = args.get(0); - let promise_id = #core::v8::Local::<#core::v8::Integer>::try_from(promise_id) - .map(|l| l.value() as #core::PromiseId) - .map_err(#core::anyhow::Error::from); - // Fail if promise id invalid (not an int) - let promise_id: #core::PromiseId = match promise_id { - Ok(promise_id) => promise_id, - Err(err) => { - #core::_ops::throw_type_error(scope, format!("invalid promise id: {}", err)); - return; - } - }; + quote! { + use #core::futures::FutureExt; + // 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()).value() + as *const #core::_ops::OpCtx) + }; + let op_id = ctx.id; + let realm_idx = ctx.realm_idx; + + let promise_id = args.get(0); + let promise_id = #core::v8::Local::<#core::v8::Integer>::try_from(promise_id) + .map(|l| l.value() as #core::PromiseId) + .map_err(#core::anyhow::Error::from); + // Fail if promise id invalid (not an int) + let promise_id: #core::PromiseId = match promise_id { + Ok(promise_id) => promise_id, + Err(err) => { + #core::_ops::throw_type_error(scope, format!("invalid promise id: {}", err)); + return; + } + }; - #arg_decls + #arg_decls - // Track async call & get copy of get_error_class_fn - let get_class = { - let state = ::std::cell::RefCell::borrow(&ctx.state); - state.tracker.track_async(op_id); - state.get_error_class_fn - }; + // Track async call & get copy of get_error_class_fn + let get_class = { + let state = ::std::cell::RefCell::borrow(&ctx.state); + state.tracker.track_async(op_id); + state.get_error_class_fn + }; - #pre_result - #core::_ops::queue_async_op(ctx, scope, #deferred, async move { - let result = #result_fut - #result_wrapper - (realm_idx, promise_id, op_id, #core::_ops::to_op_result(get_class, result)) - }); - }, - argc, - ) + #pre_result + #core::_ops::queue_async_op(ctx, scope, #deferred, async move { + let result = #result_fut + #result_wrapper + (realm_idx, promise_id, op_id, #core::_ops::to_op_result(get_class, result)) + }); + } } fn scope_arg(arg: &FnArg) -> Option<TokenStream2> { @@ -362,7 +357,7 @@ fn codegen_v8_sync( f: &syn::ItemFn, margs: Attributes, has_fallible_fast_call: bool, -) -> (TokenStream2, usize) { +) -> TokenStream2 { let Attributes { is_v8, .. } = margs; let special_args = f .sig @@ -374,7 +369,7 @@ fn codegen_v8_sync( .collect::<Vec<_>>(); let rust_i0 = special_args.len(); let args_head = special_args.into_iter().collect::<TokenStream2>(); - let (arg_decls, args_tail, argc) = codegen_args(core, f, rust_i0, 0, false); + let (arg_decls, args_tail, _) = codegen_args(core, f, rust_i0, 0, false); let ret = codegen_sync_ret(core, &f.sig.output); let type_params = exclude_lifetime_params(&f.sig.generics.params); @@ -393,27 +388,24 @@ fn codegen_v8_sync( quote! {} }; - ( - 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()).value() - as *const #core::_ops::OpCtx) - }; + 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()).value() + as *const #core::_ops::OpCtx) + }; - #fast_error_handler - #arg_decls + #fast_error_handler + #arg_decls - let result = Self::call::<#type_params>(#args_head #args_tail); + let result = Self::call::<#type_params>(#args_head #args_tail); - // use RefCell::borrow instead of state.borrow to avoid clash with std::borrow::Borrow - let op_state = ::std::cell::RefCell::borrow(&*ctx.state); - op_state.tracker.track_sync(ctx.id); + // use RefCell::borrow instead of state.borrow to avoid clash with std::borrow::Borrow + let op_state = ::std::cell::RefCell::borrow(&*ctx.state); + op_state.tracker.track_sync(ctx.id); - #ret - }, - argc, - ) + #ret + } } /// (full declarations, idents, v8 argument count) |
