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/result_void.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/result_void.out')
| -rw-r--r-- | ops/op2/test_cases/sync/result_void.out | 79 |
1 files changed, 51 insertions, 28 deletions
diff --git a/ops/op2/test_cases/sync/result_void.out b/ops/op2/test_cases/sync/result_void.out index afc10582b..74aa84a8d 100644 --- a/ops/op2/test_cases/sync/result_void.out +++ b/ops/op2/test_cases/sync/result_void.out @@ -1,5 +1,28 @@ #[allow(non_camel_case_types)] -pub struct op_void_with_result {} +pub struct op_void_with_result { + _unconstructable: ::std::marker::PhantomData<()>, +} +impl deno_core::_ops::Op for op_void_with_result { + const NAME: &'static str = stringify!(op_void_with_result); + const DECL: deno_core::_ops::OpDecl = deno_core::_ops::OpDecl { + name: stringify!(op_void_with_result), + 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, Type::CallbackOptions], + 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 op_void_with_result { pub const fn name() -> &'static str { stringify!(op_void_with_result) @@ -7,7 +30,7 @@ impl op_void_with_result { pub const fn decl() -> deno_core::_ops::OpDecl { deno_core::_ops::OpDecl { name: stringify!(op_void_with_result), - v8_fn_ptr: Self::slow_function as _, + v8_fn_ptr: Self::v8_fn_ptr as _, enabled: true, fast_fn: Some({ use deno_core::v8::fast_api::Type; @@ -15,7 +38,7 @@ impl op_void_with_result { deno_core::v8::fast_api::FastFunction::new( &[Type::V8Value, Type::CallbackOptions], CType::Void, - Self::fast_function as *const ::std::ffi::c_void, + Self::v8_fn_ptr_fast as *const ::std::ffi::c_void, ) }), is_async: false, @@ -24,7 +47,31 @@ impl op_void_with_result { arg_count: 0usize as u8, } } - pub extern "C" fn slow_function(info: *const deno_core::v8::FunctionCallbackInfo) { + fn v8_fn_ptr_fast( + _: deno_core::v8::Local<deno_core::v8::Object>, + fast_api_callback_options: *mut deno_core::v8::fast_api::FastApiCallbackOptions, + ) -> () { + let fast_api_callback_options = unsafe { &mut *fast_api_callback_options }; + let opctx = unsafe { + &*(deno_core::v8::Local::< + v8::External, + >::cast(unsafe { fast_api_callback_options.data.data }) + .value() as *const deno_core::_ops::OpCtx) + }; + let result = Self::call(); + let result = match result { + Ok(result) => result, + Err(err) => { + unsafe { + opctx.unsafely_set_last_error_for_ops_only(err); + } + fast_api_callback_options.fallback = true; + return ::std::default::Default::default(); + } + }; + result + } + extern "C" fn v8_fn_ptr(info: *const deno_core::v8::FunctionCallbackInfo) { let args = deno_core::v8::FunctionCallbackArguments::from_function_callback_info(unsafe { &*info }); @@ -65,30 +112,6 @@ impl op_void_with_result { } }; } - fn fast_function( - _: deno_core::v8::Local<deno_core::v8::Object>, - fast_api_callback_options: *mut deno_core::v8::fast_api::FastApiCallbackOptions, - ) -> () { - let fast_api_callback_options = unsafe { &mut *fast_api_callback_options }; - let opctx = unsafe { - &*(deno_core::v8::Local::< - v8::External, - >::cast(unsafe { fast_api_callback_options.data.data }) - .value() as *const deno_core::_ops::OpCtx) - }; - let result = Self::call(); - let result = match result { - Ok(result) => result, - Err(err) => { - unsafe { - opctx.unsafely_set_last_error_for_ops_only(err); - } - fast_api_callback_options.fallback = true; - return ::std::default::Default::default(); - } - }; - result - } #[inline(always)] pub fn call() -> Result<(), AnyError> {} } |
