From b2abae477115dc6ca97a767c6800c7c3f1aa0ebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 25 Sep 2023 00:07:22 +0200 Subject: refactor: rewrite more ops to op2 (#20666) --- ext/fs/ops.rs | 91 ++++++++++++++++++++++++++------------------------- ext/http/http_next.rs | 11 +++---- ext/net/ops.rs | 12 +++---- ext/net/ops_unix.rs | 12 +++---- 4 files changed, 63 insertions(+), 63 deletions(-) diff --git a/ext/fs/ops.rs b/ext/fs/ops.rs index 289c3de72..bc09a4a25 100644 --- a/ext/fs/ops.rs +++ b/ext/fs/ops.rs @@ -11,7 +11,6 @@ use std::rc::Rc; use deno_core::error::custom_error; use deno_core::error::type_error; use deno_core::error::AnyError; -use deno_core::op; use deno_core::op2; use deno_core::CancelFuture; use deno_core::CancelHandle; @@ -767,11 +766,11 @@ where Ok(target_string) } -#[op] +#[op2(fast)] pub fn op_fs_truncate_sync

( state: &mut OpState, - path: &str, - len: u64, + #[string] path: &str, + #[number] len: u64, ) -> Result<(), AnyError> where P: FsPermissions + 'static, @@ -789,11 +788,11 @@ where Ok(()) } -#[op] +#[op2(async)] pub async fn op_fs_truncate_async

( state: Rc>, - path: String, - len: u64, + #[string] path: String, + #[number] len: u64, ) -> Result<(), AnyError> where P: FsPermissions + 'static, @@ -815,14 +814,14 @@ where Ok(()) } -#[op] +#[op2(fast)] pub fn op_fs_utime_sync

( state: &mut OpState, - path: &str, - atime_secs: i64, - atime_nanos: u32, - mtime_secs: i64, - mtime_nanos: u32, + #[string] path: &str, + #[number] atime_secs: i64, + #[smi] atime_nanos: u32, + #[number] mtime_secs: i64, + #[smi] mtime_nanos: u32, ) -> Result<(), AnyError> where P: FsPermissions + 'static, @@ -838,14 +837,14 @@ where Ok(()) } -#[op] +#[op2(async)] pub async fn op_fs_utime_async

( state: Rc>, - path: String, - atime_secs: i64, - atime_nanos: u32, - mtime_secs: i64, - mtime_nanos: u32, + #[string] path: String, + #[number] atime_secs: i64, + #[smi] atime_nanos: u32, + #[number] mtime_secs: i64, + #[smi] mtime_nanos: u32, ) -> Result<(), AnyError> where P: FsPermissions + 'static, @@ -1313,12 +1312,13 @@ fn to_seek_from(offset: i64, whence: i32) -> Result { Ok(seek_from) } -#[op] +#[op2(fast)] +#[number] pub fn op_fs_seek_sync( state: &mut OpState, - rid: ResourceId, - offset: i64, - whence: i32, + #[smi] rid: ResourceId, + #[number] offset: i64, + #[smi] whence: i32, ) -> Result { let pos = to_seek_from(offset, whence)?; let file = FileResource::get_file(state, rid)?; @@ -1326,12 +1326,13 @@ pub fn op_fs_seek_sync( Ok(cursor) } -#[op] +#[op2(async)] +#[number] pub async fn op_fs_seek_async( state: Rc>, - rid: ResourceId, - offset: i64, - whence: i32, + #[smi] rid: ResourceId, + #[number] offset: i64, + #[smi] whence: i32, ) -> Result { let pos = to_seek_from(offset, whence)?; let file = FileResource::get_file(&state.borrow(), rid)?; @@ -1449,50 +1450,50 @@ pub async fn op_fs_funlock_async( Ok(()) } -#[op] +#[op2(fast)] pub fn op_fs_ftruncate_sync( state: &mut OpState, - rid: ResourceId, - len: u64, + #[smi] rid: ResourceId, + #[number] len: u64, ) -> Result<(), AnyError> { let file = FileResource::get_file(state, rid)?; file.truncate_sync(len)?; Ok(()) } -#[op] +#[op2(async)] pub async fn op_fs_ftruncate_async( state: Rc>, - rid: ResourceId, - len: u64, + #[smi] rid: ResourceId, + #[number] len: u64, ) -> Result<(), AnyError> { let file = FileResource::get_file(&state.borrow(), rid)?; file.truncate_async(len).await?; Ok(()) } -#[op] +#[op2(fast)] pub fn op_fs_futime_sync( state: &mut OpState, - rid: ResourceId, - atime_secs: i64, - atime_nanos: u32, - mtime_secs: i64, - mtime_nanos: u32, + #[smi] rid: ResourceId, + #[number] atime_secs: i64, + #[smi] atime_nanos: u32, + #[number] mtime_secs: i64, + #[smi] mtime_nanos: u32, ) -> Result<(), AnyError> { let file = FileResource::get_file(state, rid)?; file.utime_sync(atime_secs, atime_nanos, mtime_secs, mtime_nanos)?; Ok(()) } -#[op] +#[op2(async)] pub async fn op_fs_futime_async( state: Rc>, - rid: ResourceId, - atime_secs: i64, - atime_nanos: u32, - mtime_secs: i64, - mtime_nanos: u32, + #[smi] rid: ResourceId, + #[number] atime_secs: i64, + #[smi] atime_nanos: u32, + #[number] mtime_secs: i64, + #[smi] mtime_nanos: u32, ) -> Result<(), AnyError> { let file = FileResource::get_file(&state.borrow(), rid)?; file diff --git a/ext/http/http_next.rs b/ext/http/http_next.rs index 08d3f54b1..21e138f86 100644 --- a/ext/http/http_next.rs +++ b/ext/http/http_next.rs @@ -23,7 +23,6 @@ use crate::LocalExecutor; use cache_control::CacheControl; use deno_core::error::AnyError; use deno_core::futures::TryFutureExt; -use deno_core::op; use deno_core::op2; use deno_core::serde_v8::from_v8; use deno_core::unsync::spawn; @@ -1264,13 +1263,13 @@ pub fn op_can_write_vectored( state.resource_table.get::(rid).is_ok() } -// TODO(bartlomieju): op2 doesn't want to handle `usize` in the return type -#[op] +#[op2(async)] +#[number] pub async fn op_raw_write_vectored( state: Rc>, - rid: ResourceId, - buf1: JsBuffer, - buf2: JsBuffer, + #[smi] rid: ResourceId, + #[buffer] buf1: JsBuffer, + #[buffer] buf2: JsBuffer, ) -> Result { let resource: Rc = state.borrow().resource_table.get::(rid)?; diff --git a/ext/net/ops.rs b/ext/net/ops.rs index 942afc55f..5deaeb61e 100644 --- a/ext/net/ops.rs +++ b/ext/net/ops.rs @@ -8,7 +8,6 @@ use deno_core::error::bad_resource; use deno_core::error::custom_error; use deno_core::error::generic_error; use deno_core::error::AnyError; -use deno_core::op; use deno_core::op2; use deno_core::CancelFuture; @@ -128,12 +127,13 @@ pub async fn op_net_recv_udp( Ok((nread, IpAddr::from(remote_addr))) } -#[op] -async fn op_net_send_udp( +#[op2(async)] +#[number] +pub async fn op_net_send_udp( state: Rc>, - rid: ResourceId, - addr: IpAddr, - zero_copy: JsBuffer, + #[smi] rid: ResourceId, + #[serde] addr: IpAddr, + #[buffer] zero_copy: JsBuffer, ) -> Result where NP: NetPermissions + 'static, diff --git a/ext/net/ops_unix.rs b/ext/net/ops_unix.rs index 1d20f2911..beb41bb4a 100644 --- a/ext/net/ops_unix.rs +++ b/ext/net/ops_unix.rs @@ -5,7 +5,6 @@ use crate::NetPermissions; use deno_core::error::bad_resource; use deno_core::error::custom_error; use deno_core::error::AnyError; -use deno_core::op; use deno_core::op2; use deno_core::AsyncRefCell; use deno_core::CancelHandle; @@ -159,12 +158,13 @@ pub async fn op_net_recv_unixpacket( Ok((nread, path)) } -#[op] -async fn op_net_send_unixpacket( +#[op2(async)] +#[number] +pub async fn op_net_send_unixpacket( state: Rc>, - rid: ResourceId, - path: String, - zero_copy: JsBuffer, + #[smi] rid: ResourceId, + #[string] path: String, + #[buffer] zero_copy: JsBuffer, ) -> Result where NP: NetPermissions + 'static, -- cgit v1.2.3