0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

refactor: rewrite more ops to op2 (#20666)

This commit is contained in:
Bartek Iwańczuk 2023-09-25 00:07:22 +02:00 committed by GitHub
parent 98ef7bd818
commit b2abae4771
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 63 deletions

View file

@ -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

View file

@ -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)?;

View file

@ -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,

View file

@ -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,