summaryrefslogtreecommitdiff
path: root/ops/fast_call.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ops/fast_call.rs')
-rw-r--r--ops/fast_call.rs41
1 files changed, 30 insertions, 11 deletions
diff --git a/ops/fast_call.rs b/ops/fast_call.rs
index 8f6348ec4..07bf87026 100644
--- a/ops/fast_call.rs
+++ b/ops/fast_call.rs
@@ -141,10 +141,19 @@ pub(crate) fn generate(
if optimizer.has_fast_callback_option
|| optimizer.needs_opstate()
|| optimizer.is_async
+ || optimizer.needs_fast_callback_option
{
- fast_fn_inputs.push(parse_quote! {
+ let decl = parse_quote! {
fast_api_callback_options: *mut #core::v8::fast_api::FastApiCallbackOptions
- });
+ };
+
+ if optimizer.has_fast_callback_option {
+ // Replace last parameter.
+ assert!(fast_fn_inputs.pop().is_some());
+ fast_fn_inputs.push(decl);
+ } else {
+ fast_fn_inputs.push(decl);
+ }
input_variants.push(q!({ CallbackOptions }));
}
@@ -162,14 +171,10 @@ pub(crate) fn generate(
let mut output_transforms = q!({});
- if optimizer.needs_opstate() || optimizer.is_async {
- // Grab the op_state identifier, the first one. ¯\_(ツ)_/¯
- let op_state = match idents.first() {
- Some(ident) if optimizer.has_opstate_in_parameters() => ident.clone(),
- // fn op_foo() -> Result<...>
- _ => Ident::new("op_state", Span::call_site()),
- };
-
+ if optimizer.needs_opstate()
+ || optimizer.is_async
+ || optimizer.has_fast_callback_option
+ {
// Dark arts 🪄 ✨
//
// - V8 calling convention guarantees that the callback options pointer is non-null.
@@ -179,13 +184,27 @@ pub(crate) fn generate(
let prelude = q!({
let __opts: &mut v8::fast_api::FastApiCallbackOptions =
unsafe { &mut *fast_api_callback_options };
+ });
+
+ pre_transforms.push_tokens(&prelude);
+ }
+
+ if optimizer.needs_opstate() || optimizer.is_async {
+ // Grab the op_state identifier, the first one. ¯\_(ツ)_/¯
+ let op_state = match idents.first() {
+ Some(ident) if optimizer.has_opstate_in_parameters() => ident.clone(),
+ // fn op_foo() -> Result<...>
+ _ => Ident::new("op_state", Span::call_site()),
+ };
+
+ let ctx = q!({
let __ctx = unsafe {
&*(v8::Local::<v8::External>::cast(unsafe { __opts.data.data }).value()
as *const _ops::OpCtx)
};
});
- pre_transforms.push_tokens(&prelude);
+ pre_transforms.push_tokens(&ctx);
pre_transforms.push_tokens(&match optimizer.is_async {
false => q!(
Vars {