summaryrefslogtreecommitdiff
path: root/ops/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ops/lib.rs')
-rw-r--r--ops/lib.rs54
1 files changed, 49 insertions, 5 deletions
diff --git a/ops/lib.rs b/ops/lib.rs
index 19667ab45..21812f605 100644
--- a/ops/lib.rs
+++ b/ops/lib.rs
@@ -111,24 +111,68 @@ impl Op {
active,
} = fast_call::generate(&core, &mut optimizer, &item);
+ let docline = format!("Use `{name}::decl()` to get an op-declaration");
+
+ let is_v8 = attrs.is_v8;
+ let is_unstable = attrs.is_unstable;
+
+ if let Some(v8_fn) = attrs.relation {
+ return quote! {
+ #[allow(non_camel_case_types)]
+ #[doc="Auto-generated by `deno_ops`, i.e: `#[op]`"]
+ #[doc=""]
+ #[doc=#docline]
+ #[doc="you can include in a `deno_core::Extension`."]
+ pub struct #name;
+
+ #[doc(hidden)]
+ impl #name {
+ pub fn name() -> &'static str {
+ stringify!(#name)
+ }
+
+ pub fn v8_fn_ptr #generics () -> #core::v8::FunctionCallback #where_clause {
+ use #core::v8::MapFnTo;
+ #v8_fn::v8_func::<#type_params>.map_fn_to()
+ }
+
+ pub fn decl #generics () -> #core::OpDecl #where_clause {
+ #core::OpDecl {
+ name: Self::name(),
+ v8_fn_ptr: Self::v8_fn_ptr::<#type_params>(),
+ enabled: true,
+ fast_fn: #decl,
+ is_async: #is_async,
+ is_unstable: #is_unstable,
+ is_v8: #is_v8,
+ argc: 0,
+ }
+ }
+
+ #[inline]
+ #[allow(clippy::too_many_arguments)]
+ #orig
+ }
+
+ #impl_and_fn
+ };
+ }
+
let has_fallible_fast_call = active && optimizer.returns_result;
let (v8_body, argc) = if is_async {
+ let deferred = attrs.deferred;
codegen_v8_async(
&core,
&item,
attrs,
item.sig.asyncness.is_some(),
- attrs.deferred,
+ deferred,
)
} else {
codegen_v8_sync(&core, &item, attrs, has_fallible_fast_call)
};
- let is_v8 = attrs.is_v8;
- let is_unstable = attrs.is_unstable;
-
- let docline = format!("Use `{name}::decl()` to get an op-declaration");
// Generate wrapper
quote! {
#[allow(non_camel_case_types)]