summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-09-25 00:07:22 +0200
committerGitHub <noreply@github.com>2023-09-24 22:07:22 +0000
commitb2abae477115dc6ca97a767c6800c7c3f1aa0ebb (patch)
tree30efc8654c21ebeb65cc3e60b14b336506ca42ad
parent98ef7bd8183f7fa534c3bfea8376d4c452b5d8d7 (diff)
refactor: rewrite more ops to op2 (#20666)
-rw-r--r--ext/fs/ops.rs91
-rw-r--r--ext/http/http_next.rs11
-rw-r--r--ext/net/ops.rs12
-rw-r--r--ext/net/ops_unix.rs12
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<P>(
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<P>(
state: Rc<RefCell<OpState>>,
- 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<P>(
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<P>(
state: Rc<RefCell<OpState>>,
- 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<SeekFrom, AnyError> {
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<u64, AnyError> {
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<RefCell<OpState>>,
- rid: ResourceId,
- offset: i64,
- whence: i32,
+ #[smi] rid: ResourceId,
+ #[number] offset: i64,
+ #[smi] whence: i32,
) -> Result<u64, AnyError> {
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<RefCell<OpState>>,
- 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<RefCell<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.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::<UpgradeStream>(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<RefCell<OpState>>,
- rid: ResourceId,
- buf1: JsBuffer,
- buf2: JsBuffer,
+ #[smi] rid: ResourceId,
+ #[buffer] buf1: JsBuffer,
+ #[buffer] buf2: JsBuffer,
) -> Result<usize, AnyError> {
let resource: Rc<UpgradeStream> =
state.borrow().resource_table.get::<UpgradeStream>(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<NP>(
+#[op2(async)]
+#[number]
+pub async fn op_net_send_udp<NP>(
state: Rc<RefCell<OpState>>,
- rid: ResourceId,
- addr: IpAddr,
- zero_copy: JsBuffer,
+ #[smi] rid: ResourceId,
+ #[serde] addr: IpAddr,
+ #[buffer] zero_copy: JsBuffer,
) -> Result<usize, AnyError>
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<NP>(
+#[op2(async)]
+#[number]
+pub async fn op_net_send_unixpacket<NP>(
state: Rc<RefCell<OpState>>,
- rid: ResourceId,
- path: String,
- zero_copy: JsBuffer,
+ #[smi] rid: ResourceId,
+ #[string] path: String,
+ #[buffer] zero_copy: JsBuffer,
) -> Result<usize, AnyError>
where
NP: NetPermissions + 'static,