From 1ad097c4bf7fb6ba0c64c050224b39dba4ad8574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 23 Sep 2023 14:04:47 +0200 Subject: [PATCH] refactor: rewrite ops using i64/usize to op2 (#20647) --- cli/ops/bench.rs | 5 ++-- ext/cache/lib.rs | 6 ++--- ext/fetch/lib.rs | 17 +++++++------- ext/node/ops/zlib/brotli.rs | 46 ++++++++++++++++++++----------------- 4 files changed, 39 insertions(+), 35 deletions(-) diff --git a/cli/ops/bench.rs b/cli/ops/bench.rs index 7a1572a838..e23ed4e16f 100644 --- a/cli/ops/bench.rs +++ b/cli/ops/bench.rs @@ -6,7 +6,6 @@ use std::time; use deno_core::error::generic_error; use deno_core::error::AnyError; -use deno_core::op; use deno_core::op2; use deno_core::serde_v8; use deno_core::v8; @@ -156,8 +155,8 @@ fn op_dispatch_bench_event(state: &mut OpState, #[serde] event: BenchEvent) { sender.send(event).ok(); } -// TODO(bartlomieju): op2 forces to use bigint, but JS doesn't expect a bigint -#[op] +#[op2(fast)] +#[number] fn op_bench_now(state: &mut OpState) -> Result { let ns = state.borrow::().elapsed().as_nanos(); let ns_u64 = u64::try_from(ns)?; diff --git a/ext/cache/lib.rs b/ext/cache/lib.rs index 553dd1ee68..59be8cfdc1 100644 --- a/ext/cache/lib.rs +++ b/ext/cache/lib.rs @@ -7,7 +7,6 @@ use std::sync::Arc; use async_trait::async_trait; use deno_core::error::AnyError; -use deno_core::op; use deno_core::op2; use deno_core::serde::Deserialize; use deno_core::serde::Serialize; @@ -118,10 +117,11 @@ pub trait Cache: Clone + 'static { -> Result; } -#[op] +#[op2(async)] +#[number] pub async fn op_cache_storage_open( state: Rc>, - cache_name: String, + #[string] cache_name: String, ) -> Result where CA: Cache, diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index dd3526ff88..589e6ebd8e 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -20,7 +20,6 @@ use deno_core::futures::Future; use deno_core::futures::FutureExt; use deno_core::futures::Stream; use deno_core::futures::StreamExt; -use deno_core::op; use deno_core::op2; use deno_core::BufView; use deno_core::WriteOutcome; @@ -215,16 +214,18 @@ pub fn get_or_create_client_from_state( } } -#[op] +#[op2] +#[serde] +#[allow(clippy::too_many_arguments)] pub fn op_fetch( state: &mut OpState, - method: ByteString, - url: String, - headers: Vec<(ByteString, ByteString)>, - client_rid: Option, + #[serde] method: ByteString, + #[string] url: String, + #[serde] headers: Vec<(ByteString, ByteString)>, + #[smi] client_rid: Option, has_body: bool, - body_length: Option, - data: Option, + #[number] body_length: Option, + #[buffer] data: Option, ) -> Result where FP: FetchPermissions + 'static, diff --git a/ext/node/ops/zlib/brotli.rs b/ext/node/ops/zlib/brotli.rs index a5c0f0f922..c1a48ac58b 100644 --- a/ext/node/ops/zlib/brotli.rs +++ b/ext/node/ops/zlib/brotli.rs @@ -7,7 +7,6 @@ use brotli::ffi::decompressor::*; use brotli::Decompressor; use deno_core::error::type_error; use deno_core::error::AnyError; -use deno_core::op; use deno_core::op2; use deno_core::JsBuffer; use deno_core::OpState; @@ -23,13 +22,14 @@ fn encoder_mode(mode: u32) -> Result { unsafe { Ok(std::mem::transmute::(mode)) } } -#[op] +#[op2(fast)] +#[number] pub fn op_brotli_compress( - buffer: &[u8], - out: &mut [u8], - quality: i32, - lgwin: i32, - mode: u32, + #[buffer] buffer: &[u8], + #[buffer] out: &mut [u8], + #[smi] quality: i32, + #[smi] lgwin: i32, + #[smi] mode: u32, ) -> Result { let in_buffer = buffer.as_ptr(); let in_size = buffer.len(); @@ -151,12 +151,13 @@ fn encoder_param(param: u8) -> BrotliEncoderParameter { unsafe { std::mem::transmute(param as u32) } } -#[op] +#[op2(fast)] +#[number] pub fn op_brotli_compress_stream( state: &mut OpState, - rid: u32, - input: &[u8], - output: &mut [u8], + #[smi] rid: u32, + #[buffer] input: &[u8], + #[buffer] output: &mut [u8], ) -> Result { let ctx = state.resource_table.get::(rid)?; @@ -186,11 +187,12 @@ pub fn op_brotli_compress_stream( } } -#[op] +#[op2(fast)] +#[number] pub fn op_brotli_compress_stream_end( state: &mut OpState, - rid: u32, - output: &mut [u8], + #[smi] rid: u32, + #[buffer] output: &mut [u8], ) -> Result { let ctx = state.resource_table.take::(rid)?; @@ -263,12 +265,13 @@ pub fn op_create_brotli_decompress(state: &mut OpState) -> u32 { state.resource_table.add(BrotliDecompressCtx { inst }) } -#[op] +#[op2(fast)] +#[number] pub fn op_brotli_decompress_stream( state: &mut OpState, - rid: u32, - input: &[u8], - output: &mut [u8], + #[smi] rid: u32, + #[buffer] input: &[u8], + #[buffer] output: &mut [u8], ) -> Result { let ctx = state.resource_table.get::(rid)?; @@ -299,11 +302,12 @@ pub fn op_brotli_decompress_stream( } } -#[op] +#[op2(fast)] +#[number] pub fn op_brotli_decompress_stream_end( state: &mut OpState, - rid: u32, - output: &mut [u8], + #[smi] rid: u32, + #[buffer] output: &mut [u8], ) -> Result { let ctx = state.resource_table.get::(rid)?;