2022-03-14 13:44:15 -04:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
|
|
|
use proc_macro::TokenStream;
|
|
|
|
use proc_macro2::Span;
|
|
|
|
use proc_macro2::TokenStream as TokenStream2;
|
|
|
|
use proc_macro_crate::crate_name;
|
|
|
|
use proc_macro_crate::FoundCrate;
|
|
|
|
use quote::quote;
|
2022-03-15 19:33:46 -04:00
|
|
|
use quote::ToTokens;
|
2022-06-07 05:25:10 -04:00
|
|
|
use syn::punctuated::Punctuated;
|
|
|
|
use syn::token::Comma;
|
2022-05-12 13:06:42 -04:00
|
|
|
use syn::FnArg;
|
2022-06-07 05:25:10 -04:00
|
|
|
use syn::GenericParam;
|
2022-03-14 13:44:15 -04:00
|
|
|
use syn::Ident;
|
|
|
|
|
2022-06-02 08:28:19 -04:00
|
|
|
// Identifier to the `deno_core` crate.
|
2022-03-14 13:44:15 -04:00
|
|
|
//
|
|
|
|
// If macro called in deno_core, `crate` is used.
|
|
|
|
// If macro called outside deno_core, `deno_core` OR the renamed
|
|
|
|
// version from Cargo.toml is used.
|
|
|
|
fn core_import() -> TokenStream2 {
|
|
|
|
let found_crate =
|
|
|
|
crate_name("deno_core").expect("deno_core not present in `Cargo.toml`");
|
|
|
|
|
|
|
|
match found_crate {
|
|
|
|
FoundCrate::Itself => {
|
|
|
|
// TODO(@littledivy): This won't work for `deno_core` examples
|
|
|
|
// since `crate` does not refer to `deno_core`.
|
|
|
|
// examples must re-export deno_core to make this work
|
|
|
|
// until Span inspection APIs are stabalized.
|
|
|
|
//
|
|
|
|
// https://github.com/rust-lang/rust/issues/54725
|
|
|
|
quote!(crate)
|
|
|
|
}
|
|
|
|
FoundCrate::Name(name) => {
|
|
|
|
let ident = Ident::new(&name, Span::call_site());
|
|
|
|
quote!(#ident)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-12 13:06:42 -04:00
|
|
|
#[derive(Copy, Clone, Debug, Default)]
|
2022-04-01 18:09:21 -04:00
|
|
|
struct MacroArgs {
|
|
|
|
is_unstable: bool,
|
2022-05-12 13:06:42 -04:00
|
|
|
is_v8: bool,
|
2022-04-01 18:09:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl syn::parse::Parse for MacroArgs {
|
|
|
|
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
|
|
|
|
let vars =
|
|
|
|
syn::punctuated::Punctuated::<Ident, syn::Token![,]>::parse_terminated(
|
|
|
|
input,
|
|
|
|
)?;
|
|
|
|
let vars: Vec<_> = vars.iter().map(Ident::to_string).collect();
|
|
|
|
let vars: Vec<_> = vars.iter().map(String::as_str).collect();
|
2022-05-12 13:06:42 -04:00
|
|
|
for var in vars.iter() {
|
|
|
|
if !["unstable", "v8"].contains(var) {
|
|
|
|
return Err(syn::Error::new(
|
|
|
|
input.span(),
|
|
|
|
"Ops expect #[op] or #[op(unstable)]",
|
|
|
|
));
|
|
|
|
}
|
2022-04-01 18:09:21 -04:00
|
|
|
}
|
2022-05-12 13:06:42 -04:00
|
|
|
Ok(Self {
|
|
|
|
is_unstable: vars.contains(&"unstable"),
|
|
|
|
is_v8: vars.contains(&"v8"),
|
|
|
|
})
|
2022-04-01 18:09:21 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-14 13:44:15 -04:00
|
|
|
#[proc_macro_attribute]
|
2022-04-01 18:09:21 -04:00
|
|
|
pub fn op(attr: TokenStream, item: TokenStream) -> TokenStream {
|
2022-05-12 13:06:42 -04:00
|
|
|
let margs = syn::parse_macro_input!(attr as MacroArgs);
|
|
|
|
let MacroArgs { is_unstable, is_v8 } = margs;
|
2022-03-14 13:44:15 -04:00
|
|
|
let func = syn::parse::<syn::ItemFn>(item).expect("expected a function");
|
|
|
|
let name = &func.sig.ident;
|
|
|
|
let generics = &func.sig.generics;
|
2022-06-07 05:25:10 -04:00
|
|
|
let type_params = exclude_lifetime_params(&func.sig.generics.params);
|
2022-03-14 13:44:15 -04:00
|
|
|
let where_clause = &func.sig.generics.where_clause;
|
|
|
|
|
|
|
|
// Preserve the original func as op_foo::call()
|
|
|
|
let original_func = {
|
|
|
|
let mut func = func.clone();
|
|
|
|
func.sig.ident = quote::format_ident!("call");
|
|
|
|
func
|
|
|
|
};
|
|
|
|
|
|
|
|
let core = core_import();
|
|
|
|
|
2022-06-07 22:28:26 -04:00
|
|
|
let asyncness = func.sig.asyncness.is_some();
|
|
|
|
let is_async = asyncness || is_future(&func.sig.output);
|
2022-03-22 11:39:58 -04:00
|
|
|
let v8_body = if is_async {
|
2022-06-07 22:28:26 -04:00
|
|
|
codegen_v8_async(&core, &func, margs, asyncness)
|
2022-03-14 13:44:15 -04:00
|
|
|
} else {
|
2022-05-12 13:06:42 -04:00
|
|
|
codegen_v8_sync(&core, &func, margs)
|
2022-03-14 13:44:15 -04:00
|
|
|
};
|
|
|
|
|
2022-03-19 17:13:53 -04:00
|
|
|
let docline = format!("Use `{name}::decl()` to get an op-declaration");
|
2022-03-14 13:44:15 -04:00
|
|
|
// Generate wrapper
|
|
|
|
quote! {
|
|
|
|
#[allow(non_camel_case_types)]
|
2022-03-19 17:13:53 -04:00
|
|
|
#[doc="Auto-generated by `deno_ops`, i.e: `#[op]`"]
|
|
|
|
#[doc=""]
|
|
|
|
#[doc=#docline]
|
|
|
|
#[doc="you can include in a `deno_core::Extension`."]
|
2022-03-14 13:44:15 -04:00
|
|
|
pub struct #name;
|
|
|
|
|
2022-03-19 17:13:53 -04:00
|
|
|
#[doc(hidden)]
|
2022-03-14 13:44:15 -04:00
|
|
|
impl #name {
|
|
|
|
pub fn name() -> &'static str {
|
|
|
|
stringify!(#name)
|
|
|
|
}
|
|
|
|
|
2022-03-15 18:43:17 -04:00
|
|
|
pub fn v8_fn_ptr #generics () -> #core::v8::FunctionCallback #where_clause {
|
2022-03-14 13:44:15 -04:00
|
|
|
use #core::v8::MapFnTo;
|
|
|
|
Self::v8_func::<#type_params>.map_fn_to()
|
|
|
|
}
|
|
|
|
|
2022-03-15 18:43:17 -04:00
|
|
|
pub fn decl #generics () -> #core::OpDecl #where_clause {
|
|
|
|
#core::OpDecl {
|
|
|
|
name: Self::name(),
|
|
|
|
v8_fn_ptr: Self::v8_fn_ptr::<#type_params>(),
|
2022-03-22 11:39:58 -04:00
|
|
|
enabled: true,
|
|
|
|
is_async: #is_async,
|
2022-04-01 18:09:21 -04:00
|
|
|
is_unstable: #is_unstable,
|
2022-05-12 13:06:42 -04:00
|
|
|
is_v8: #is_v8,
|
2022-03-15 18:43:17 -04:00
|
|
|
}
|
2022-03-14 13:44:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2022-04-23 12:49:06 -04:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2022-03-14 13:44:15 -04:00
|
|
|
#original_func
|
|
|
|
|
|
|
|
pub fn v8_func #generics (
|
|
|
|
scope: &mut #core::v8::HandleScope,
|
|
|
|
args: #core::v8::FunctionCallbackArguments,
|
|
|
|
mut rv: #core::v8::ReturnValue,
|
|
|
|
) #where_clause {
|
|
|
|
#v8_body
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.into()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Generate the body of a v8 func for an async op
|
2022-05-12 13:06:42 -04:00
|
|
|
fn codegen_v8_async(
|
|
|
|
core: &TokenStream2,
|
|
|
|
f: &syn::ItemFn,
|
|
|
|
_margs: MacroArgs,
|
2022-06-07 22:28:26 -04:00
|
|
|
asyncness: bool,
|
2022-05-12 13:06:42 -04:00
|
|
|
) -> TokenStream2 {
|
2022-03-15 19:33:46 -04:00
|
|
|
let arg0 = f.sig.inputs.first();
|
|
|
|
let uses_opstate = arg0.map(is_rc_refcell_opstate).unwrap_or_default();
|
|
|
|
let args_head = if uses_opstate {
|
|
|
|
quote! { state, }
|
|
|
|
} else {
|
|
|
|
quote! {}
|
|
|
|
};
|
|
|
|
let rust_i0 = if uses_opstate { 1 } else { 0 };
|
2022-04-08 04:32:48 -04:00
|
|
|
let (arg_decls, args_tail) = codegen_args(core, f, rust_i0, 1);
|
2022-06-07 05:25:10 -04:00
|
|
|
let type_params = exclude_lifetime_params(&f.sig.generics.params);
|
2022-03-14 13:44:15 -04:00
|
|
|
|
2022-06-07 22:28:26 -04:00
|
|
|
let (pre_result, result_fut) = match asyncness {
|
|
|
|
true => (
|
|
|
|
quote! {},
|
|
|
|
quote! { Self::call::<#type_params>(#args_head #args_tail) },
|
|
|
|
),
|
|
|
|
false => (
|
|
|
|
quote! { let result_fut = Self::call::<#type_params>(#args_head #args_tail); },
|
|
|
|
quote! { result_fut },
|
|
|
|
),
|
|
|
|
};
|
2022-05-12 13:13:25 -04:00
|
|
|
let result_wrapper = match is_result(&f.sig.output) {
|
|
|
|
true => quote! {},
|
|
|
|
false => quote! { let result = Ok(result); },
|
|
|
|
};
|
|
|
|
|
2022-03-14 13:44:15 -04:00
|
|
|
quote! {
|
|
|
|
use #core::futures::FutureExt;
|
2022-04-08 04:32:48 -04:00
|
|
|
// 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)
|
|
|
|
};
|
|
|
|
let op_id = ctx.id;
|
2022-03-14 13:44:15 -04:00
|
|
|
|
2022-04-08 04:32:48 -04:00
|
|
|
let promise_id = args.get(0);
|
2022-03-14 13:44:15 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-14 18:38:53 -04:00
|
|
|
#arg_decls
|
2022-03-14 13:44:15 -04:00
|
|
|
|
2022-04-08 04:32:48 -04:00
|
|
|
let state = ctx.state.clone();
|
|
|
|
|
2022-03-14 13:44:15 -04:00
|
|
|
// Track async call & get copy of get_error_class_fn
|
|
|
|
let get_class = {
|
|
|
|
let state = state.borrow();
|
|
|
|
state.tracker.track_async(op_id);
|
|
|
|
state.get_error_class_fn
|
|
|
|
};
|
|
|
|
|
2022-06-07 22:28:26 -04:00
|
|
|
#pre_result
|
2022-03-14 13:44:15 -04:00
|
|
|
#core::_ops::queue_async_op(scope, async move {
|
2022-06-07 22:28:26 -04:00
|
|
|
let result = #result_fut.await;
|
2022-05-12 13:13:25 -04:00
|
|
|
#result_wrapper
|
2022-03-14 13:44:15 -04:00
|
|
|
(promise_id, op_id, #core::_ops::to_op_result(get_class, result))
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Generate the body of a v8 func for a sync op
|
2022-05-12 13:06:42 -04:00
|
|
|
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
|
2022-05-04 20:44:34 -04:00
|
|
|
}
|
2022-05-12 13:06:42 -04:00
|
|
|
};
|
|
|
|
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(), })
|
2022-05-04 20:44:34 -04:00
|
|
|
}
|
2022-05-12 13:06:42 -04:00
|
|
|
_ => None,
|
2022-03-15 19:33:46 -04:00
|
|
|
};
|
2022-05-12 13:06:42 -04:00
|
|
|
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>();
|
2022-05-12 06:36:09 -04:00
|
|
|
|
2022-04-08 04:32:48 -04:00
|
|
|
let (arg_decls, args_tail) = codegen_args(core, f, rust_i0, 0);
|
2022-03-14 13:44:15 -04:00
|
|
|
let ret = codegen_sync_ret(core, &f.sig.output);
|
2022-06-07 05:25:10 -04:00
|
|
|
let type_params = exclude_lifetime_params(&f.sig.generics.params);
|
2022-03-14 13:44:15 -04:00
|
|
|
|
|
|
|
quote! {
|
2022-04-08 04:32:48 -04:00
|
|
|
// 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)
|
|
|
|
};
|
2022-03-14 13:44:15 -04:00
|
|
|
|
2022-03-14 18:38:53 -04:00
|
|
|
#arg_decls
|
2022-03-14 13:44:15 -04:00
|
|
|
|
2022-05-12 13:06:42 -04:00
|
|
|
let result = Self::call::<#type_params>(#args_head #args_tail);
|
2022-03-14 13:44:15 -04:00
|
|
|
|
2022-05-04 20:44:34 -04:00
|
|
|
let op_state = &mut ctx.state.borrow();
|
2022-04-08 04:32:48 -04:00
|
|
|
op_state.tracker.track_sync(ctx.id);
|
2022-03-14 13:44:15 -04:00
|
|
|
|
|
|
|
#ret
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-14 18:38:53 -04:00
|
|
|
fn codegen_args(
|
|
|
|
core: &TokenStream2,
|
|
|
|
f: &syn::ItemFn,
|
|
|
|
rust_i0: usize, // Index of first generic arg in rust
|
|
|
|
v8_i0: usize, // Index of first generic arg in v8/js
|
|
|
|
) -> (TokenStream2, TokenStream2) {
|
|
|
|
let inputs = &f.sig.inputs.iter().skip(rust_i0).enumerate();
|
|
|
|
let ident_seq: TokenStream2 = inputs
|
|
|
|
.clone()
|
|
|
|
.map(|(i, _)| format!("arg_{i}"))
|
|
|
|
.collect::<Vec<_>>()
|
|
|
|
.join(", ")
|
|
|
|
.parse()
|
|
|
|
.unwrap();
|
|
|
|
let decls: TokenStream2 = inputs
|
|
|
|
.clone()
|
|
|
|
.map(|(i, arg)| {
|
|
|
|
codegen_arg(core, arg, format!("arg_{i}").as_ref(), v8_i0 + i)
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
(decls, ident_seq)
|
|
|
|
}
|
|
|
|
|
2022-03-14 13:44:15 -04:00
|
|
|
fn codegen_arg(
|
|
|
|
core: &TokenStream2,
|
|
|
|
arg: &syn::FnArg,
|
|
|
|
name: &str,
|
2022-03-14 18:38:53 -04:00
|
|
|
idx: usize,
|
2022-03-14 13:44:15 -04:00
|
|
|
) -> TokenStream2 {
|
|
|
|
let ident = quote::format_ident!("{name}");
|
|
|
|
let pat = match arg {
|
|
|
|
syn::FnArg::Typed(pat) => &pat.pat,
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
// Fast path if arg should be skipped
|
|
|
|
if matches!(**pat, syn::Pat::Wild(_)) {
|
|
|
|
return quote! { let #ident = (); };
|
|
|
|
}
|
|
|
|
// Otherwise deserialize it via serde_v8
|
|
|
|
quote! {
|
2022-03-14 18:38:53 -04:00
|
|
|
let #ident = args.get(#idx as i32);
|
2022-03-14 13:44:15 -04:00
|
|
|
let #ident = match #core::serde_v8::from_v8(scope, #ident) {
|
|
|
|
Ok(v) => v,
|
|
|
|
Err(err) => {
|
2022-03-18 11:23:31 -04:00
|
|
|
let msg = format!("Error parsing args at position {}: {}", #idx, #core::anyhow::Error::from(err));
|
2022-03-14 13:44:15 -04:00
|
|
|
return #core::_ops::throw_type_error(scope, msg);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn codegen_sync_ret(
|
|
|
|
core: &TokenStream2,
|
|
|
|
output: &syn::ReturnType,
|
|
|
|
) -> TokenStream2 {
|
2022-05-12 15:51:57 -04:00
|
|
|
if is_void(output) {
|
|
|
|
return quote! {};
|
|
|
|
}
|
2022-03-14 13:44:15 -04:00
|
|
|
|
|
|
|
// Optimize Result<(), Err> to skip serde_v8 when Ok(...)
|
2022-05-12 15:51:57 -04:00
|
|
|
let ok_block = if is_unit_result(output) {
|
2022-03-14 13:44:15 -04:00
|
|
|
quote! {}
|
|
|
|
} else {
|
|
|
|
quote! {
|
2022-05-12 15:51:57 -04:00
|
|
|
match #core::serde_v8::to_v8(scope, result) {
|
2022-03-19 10:59:44 -04:00
|
|
|
Ok(ret) => rv.set(ret),
|
|
|
|
Err(err) => #core::_ops::throw_type_error(
|
|
|
|
scope,
|
|
|
|
format!("Error serializing return: {}", #core::anyhow::Error::from(err)),
|
|
|
|
),
|
|
|
|
};
|
2022-03-14 13:44:15 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-05-12 15:51:57 -04:00
|
|
|
if !is_result(output) {
|
|
|
|
return ok_block;
|
|
|
|
}
|
2022-05-12 13:13:25 -04:00
|
|
|
|
2022-03-14 13:44:15 -04:00
|
|
|
quote! {
|
|
|
|
match result {
|
2022-05-12 15:51:57 -04:00
|
|
|
Ok(result) => {
|
2022-03-14 13:44:15 -04:00
|
|
|
#ok_block
|
|
|
|
},
|
|
|
|
Err(err) => {
|
|
|
|
let err = #core::OpError::new(op_state.get_error_class_fn, err);
|
|
|
|
rv.set(#core::serde_v8::to_v8(scope, err).unwrap());
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-12 15:51:57 -04:00
|
|
|
fn is_void(ty: impl ToTokens) -> bool {
|
|
|
|
tokens(ty).is_empty()
|
|
|
|
}
|
|
|
|
|
2022-05-12 13:13:25 -04:00
|
|
|
fn is_result(ty: impl ToTokens) -> bool {
|
|
|
|
let tokens = tokens(ty);
|
|
|
|
if tokens.trim_start_matches("-> ").starts_with("Result <") {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Detect `io::Result<...>`, `anyhow::Result<...>`, etc...
|
|
|
|
// i.e: Result aliases/shorthands which are unfortunately "opaque" at macro-time
|
|
|
|
match tokens.find(":: Result <") {
|
|
|
|
Some(idx) => !tokens.split_at(idx).0.contains('<'),
|
|
|
|
None => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-14 13:44:15 -04:00
|
|
|
/// Detects if a type is of the form Result<(), Err>
|
2022-05-12 14:22:42 -04:00
|
|
|
fn is_unit_result(ty: impl ToTokens) -> bool {
|
|
|
|
is_result(&ty) && tokens(&ty).contains("Result < ()")
|
2022-03-14 13:44:15 -04:00
|
|
|
}
|
2022-03-15 19:33:46 -04:00
|
|
|
|
|
|
|
fn is_mut_ref_opstate(arg: &syn::FnArg) -> bool {
|
|
|
|
tokens(arg).ends_with(": & mut OpState")
|
|
|
|
|| tokens(arg).ends_with(": & mut deno_core :: OpState")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_rc_refcell_opstate(arg: &syn::FnArg) -> bool {
|
|
|
|
tokens(arg).ends_with(": Rc < RefCell < OpState > >")
|
|
|
|
|| tokens(arg).ends_with(": Rc < RefCell < deno_core :: OpState > >")
|
|
|
|
}
|
|
|
|
|
2022-05-12 06:36:09 -04:00
|
|
|
fn is_handle_scope(arg: &syn::FnArg) -> bool {
|
|
|
|
tokens(arg).ends_with(": & mut v8 :: HandleScope")
|
2022-06-07 05:25:10 -04:00
|
|
|
|| tokens(arg).ends_with(": & mut v8 :: HandleScope < 'a >")
|
2022-05-12 06:36:09 -04:00
|
|
|
|| tokens(arg).ends_with(": & mut deno_core :: v8 :: HandleScope")
|
2022-06-07 05:25:10 -04:00
|
|
|
|| tokens(arg).ends_with(": & mut deno_core :: v8 :: HandleScope < 'a >")
|
2022-05-12 06:36:09 -04:00
|
|
|
}
|
|
|
|
|
2022-06-07 22:28:26 -04:00
|
|
|
fn is_future(ty: impl ToTokens) -> bool {
|
|
|
|
tokens(&ty).contains("impl Future < Output =")
|
|
|
|
}
|
|
|
|
|
2022-03-15 19:33:46 -04:00
|
|
|
fn tokens(x: impl ToTokens) -> String {
|
|
|
|
x.to_token_stream().to_string()
|
|
|
|
}
|
2022-06-07 05:25:10 -04:00
|
|
|
|
|
|
|
fn exclude_lifetime_params(
|
|
|
|
generic_params: &Punctuated<GenericParam, Comma>,
|
|
|
|
) -> Punctuated<GenericParam, Comma> {
|
|
|
|
generic_params
|
|
|
|
.iter()
|
|
|
|
.filter(|t| !tokens(t).starts_with('\''))
|
|
|
|
.cloned()
|
|
|
|
.collect::<Punctuated<GenericParam, Comma>>()
|
|
|
|
}
|