diff options
| author | Matt Mastracci <matthew@mastracci.com> | 2023-06-29 10:23:14 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-29 10:23:14 -0600 |
| commit | fbb69329343c9985c26181e6297e6556c46d381d (patch) | |
| tree | ee428c94727bdfdf9040a4944bd66981b4cd07fb /ops/op2/test_cases/sync/generics.out | |
| parent | 98df69fd4cbe3687e2ff3519fbd6bff4e5f3101f (diff) | |
refactor(ops): op2 support for generics (#19636)
Implementation of generics for `#[op2]`, along with some refactoring to
improve the ergonomics of ops with generics parameters:
- The ops have generics on the struct rather than the associated
methods, which allows us to trait-ify ops (impossible when they are on
the methods)
- The decl() method can become a trait-associated const field which
unlocks future optimizations
Callers of ops need to switch from:
`op_net_connect_tcp::call::<TestPermission>(conn_state, ip_addr)` to
`op_net_connect_tcp::<TestPermission>::call(conn_state, ip_addr)`.
Diffstat (limited to 'ops/op2/test_cases/sync/generics.out')
| -rw-r--r-- | ops/op2/test_cases/sync/generics.out | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/ops/op2/test_cases/sync/generics.out b/ops/op2/test_cases/sync/generics.out new file mode 100644 index 000000000..26e3af9b7 --- /dev/null +++ b/ops/op2/test_cases/sync/generics.out @@ -0,0 +1,59 @@ +#[allow(non_camel_case_types)] +pub struct op_generics<T> { + _unconstructable: ::std::marker::PhantomData<(T)>, +} +impl<T: Trait> deno_core::_ops::Op for op_generics<T> { + const NAME: &'static str = stringify!(op_generics); + const DECL: deno_core::_ops::OpDecl = deno_core::_ops::OpDecl { + name: stringify!(op_generics), + v8_fn_ptr: Self::v8_fn_ptr as _, + enabled: true, + fast_fn: Some({ + use deno_core::v8::fast_api::Type; + use deno_core::v8::fast_api::CType; + deno_core::v8::fast_api::FastFunction::new( + &[Type::V8Value], + CType::Void, + Self::v8_fn_ptr_fast as *const ::std::ffi::c_void, + ) + }), + is_async: false, + is_unstable: false, + is_v8: false, + arg_count: 0usize as u8, + }; +} +impl<T: Trait> op_generics<T> { + pub const fn name() -> &'static str { + stringify!(op_generics) + } + pub const fn decl() -> deno_core::_ops::OpDecl { + deno_core::_ops::OpDecl { + name: stringify!(op_generics), + v8_fn_ptr: Self::v8_fn_ptr as _, + enabled: true, + fast_fn: Some({ + use deno_core::v8::fast_api::Type; + use deno_core::v8::fast_api::CType; + deno_core::v8::fast_api::FastFunction::new( + &[Type::V8Value], + CType::Void, + Self::v8_fn_ptr_fast as *const ::std::ffi::c_void, + ) + }), + is_async: false, + is_unstable: false, + is_v8: false, + arg_count: 0usize as u8, + } + } + fn v8_fn_ptr_fast(_: deno_core::v8::Local<deno_core::v8::Object>) -> () { + let result = Self::call(); + result + } + extern "C" fn v8_fn_ptr(info: *const deno_core::v8::FunctionCallbackInfo) { + let result = Self::call(); + } + #[inline(always)] + pub fn call() {} +} |
