From 88d0f01948b68f4a4d87e02a5138e94ac0a6eaea Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Mon, 14 Mar 2022 23:38:53 +0100 Subject: feat(ops): custom arity (#13949) Also cleanup & drop ignored wildcard op-args --- core/examples/hello_world.rs | 1 - core/examples/http_bench_json_ops.rs | 3 +-- core/examples/schedule_task.rs | 2 +- core/modules.rs | 2 +- core/ops_builtin.rs | 17 +++-------------- core/runtime.rs | 22 +++++----------------- 6 files changed, 11 insertions(+), 36 deletions(-) (limited to 'core') diff --git a/core/examples/hello_world.rs b/core/examples/hello_world.rs index bfca5447c..d5d7af94d 100644 --- a/core/examples/hello_world.rs +++ b/core/examples/hello_world.rs @@ -17,7 +17,6 @@ use deno_core::*; fn op_sum( _state: &mut OpState, nums: Vec, - _: (), ) -> Result { // Sum inputs let sum = nums.iter().fold(0.0, |a, v| a + v); diff --git a/core/examples/http_bench_json_ops.rs b/core/examples/http_bench_json_ops.rs index 3f608eeae..2068c3b85 100644 --- a/core/examples/http_bench_json_ops.rs +++ b/core/examples/http_bench_json_ops.rs @@ -135,7 +135,7 @@ fn create_js_runtime() -> JsRuntime { } #[op] -fn op_listen(state: &mut OpState, _: (), _: ()) -> Result { +fn op_listen(state: &mut OpState) -> Result { log::debug!("listen"); let addr = "127.0.0.1:4544".parse::().unwrap(); let std_listener = std::net::TcpListener::bind(&addr)?; @@ -149,7 +149,6 @@ fn op_listen(state: &mut OpState, _: (), _: ()) -> Result { async fn op_accept( state: Rc>, rid: ResourceId, - _: (), ) -> Result { log::debug!("accept rid={}", rid); diff --git a/core/examples/schedule_task.rs b/core/examples/schedule_task.rs index 3ada86417..7812dcb49 100644 --- a/core/examples/schedule_task.rs +++ b/core/examples/schedule_task.rs @@ -62,7 +62,7 @@ fn main() { } #[op] -fn op_schedule_task(state: &mut OpState, i: u8, _: ()) -> Result<(), Error> { +fn op_schedule_task(state: &mut OpState, i: u8) -> Result<(), Error> { let tx = state.borrow_mut::>(); tx.unbounded_send(Box::new(move || println!("Hello, world! x{}", i))) .expect("unbounded_send failed"); diff --git a/core/modules.rs b/core/modules.rs index 7c5274193..481091e0f 100644 --- a/core/modules.rs +++ b/core/modules.rs @@ -1406,7 +1406,7 @@ import "/a.js"; static DISPATCH_COUNT: AtomicUsize = AtomicUsize::new(0); #[op] - fn op_test(_: &mut OpState, control: u8, _: ()) -> Result { + fn op_test(_: &mut OpState, control: u8) -> Result { DISPATCH_COUNT.fetch_add(1, Ordering::Relaxed); assert_eq!(control, 42); Ok(43) diff --git a/core/ops_builtin.rs b/core/ops_builtin.rs index 14d8c6e39..a742a77b1 100644 --- a/core/ops_builtin.rs +++ b/core/ops_builtin.rs @@ -40,7 +40,7 @@ pub(crate) fn init_builtins() -> Extension { } #[op] -pub fn void_op_sync(_: &mut OpState, _: (), _: ()) -> Result<(), Error> { +pub fn void_op_sync(_: &mut OpState) -> Result<(), Error> { Ok(()) } @@ -57,8 +57,6 @@ pub async fn void_op_async( #[op] pub fn op_resources( state: &mut OpState, - _: (), - _: (), ) -> Result, Error> { let serialized_resources = state .resource_table @@ -69,16 +67,12 @@ pub fn op_resources( } #[op] -pub fn op_void_sync(_state: &mut OpState, _: (), _: ()) -> Result<(), Error> { +pub fn op_void_sync(_state: &mut OpState) -> Result<(), Error> { Ok(()) } #[op] -pub async fn op_void_async( - _state: Rc>, - _: (), - _: (), -) -> Result<(), Error> { +pub async fn op_void_async(_state: Rc>) -> Result<(), Error> { Ok(()) } @@ -87,7 +81,6 @@ pub async fn op_void_async( pub fn op_close( state: &mut OpState, rid: Option, - _: (), ) -> Result<(), Error> { // TODO(@AaronO): drop Option after improving type-strictness balance in // serde_v8 @@ -102,7 +95,6 @@ pub fn op_close( pub fn op_try_close( state: &mut OpState, rid: Option, - _: (), ) -> Result<(), Error> { // TODO(@AaronO): drop Option after improving type-strictness balance in // serde_v8. @@ -114,8 +106,6 @@ pub fn op_try_close( #[op] pub fn op_metrics( state: &mut OpState, - _: (), - _: (), ) -> Result<(OpMetrics, Vec), Error> { let aggregate = state.tracker.aggregate(); let per_op = state.tracker.per_op(); @@ -229,7 +219,6 @@ async fn op_write( async fn op_shutdown( state: Rc>, rid: ResourceId, - _: (), ) -> Result<(), Error> { let resource = state.borrow().resource_table.get_any(rid)?; resource.shutdown().await diff --git a/core/runtime.rs b/core/runtime.rs index a4fa0c51f..019065526 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -2062,7 +2062,7 @@ pub mod tests { #[test] fn test_error_builder() { #[op] - fn op_err(_: &mut OpState, _: (), _: ()) -> Result<(), Error> { + fn op_err(_: &mut OpState) -> Result<(), Error> { Err(custom_error("DOMExceptionOperationError", "abc")) } @@ -2468,8 +2468,6 @@ assertEquals(1, notify_return_value); #[op] async fn op_async_borrow( op_state: Rc>, - _: (), - _: (), ) -> Result<(), Error> { let n = { let op_state = op_state.borrow(); @@ -2511,8 +2509,6 @@ assertEquals(1, notify_return_value); #[op] async fn op_async_sleep( _op_state: Rc>, - _: (), - _: (), ) -> Result<(), Error> { // Future must be Poll::Pending on first call tokio::time::sleep(std::time::Duration::from_millis(1)).await; @@ -2588,13 +2584,13 @@ assertEquals(1, notify_return_value); static NEXT_TICK: AtomicUsize = AtomicUsize::new(0); #[op] - fn op_macrotask(_: &mut OpState, _: (), _: ()) -> Result<(), AnyError> { + fn op_macrotask(_: &mut OpState) -> Result<(), AnyError> { MACROTASK.fetch_add(1, Ordering::Relaxed); Ok(()) } #[op] - fn op_next_tick(_: &mut OpState, _: (), _: ()) -> Result<(), AnyError> { + fn op_next_tick(_: &mut OpState) -> Result<(), AnyError> { NEXT_TICK.fetch_add(1, Ordering::Relaxed); Ok(()) } @@ -2725,21 +2721,13 @@ assertEquals(1, notify_return_value); static UNCAUGHT_EXCEPTION: AtomicUsize = AtomicUsize::new(0); #[op] - fn op_promise_reject( - _: &mut OpState, - _: (), - _: (), - ) -> Result<(), AnyError> { + fn op_promise_reject(_: &mut OpState) -> Result<(), AnyError> { PROMISE_REJECT.fetch_add(1, Ordering::Relaxed); Ok(()) } #[op] - fn op_uncaught_exception( - _: &mut OpState, - _: (), - _: (), - ) -> Result<(), AnyError> { + fn op_uncaught_exception(_: &mut OpState) -> Result<(), AnyError> { UNCAUGHT_EXCEPTION.fetch_add(1, Ordering::Relaxed); Ok(()) } -- cgit v1.2.3