1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

refactor: rewrite ops using i64/usize to op2 (#20647)

This commit is contained in:
Bartek Iwańczuk 2023-09-23 14:04:47 +02:00 committed by GitHub
parent 75a724890d
commit 1ad097c4bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 35 deletions

View file

@ -6,7 +6,6 @@ use std::time;
use deno_core::error::generic_error; use deno_core::error::generic_error;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::op;
use deno_core::op2; use deno_core::op2;
use deno_core::serde_v8; use deno_core::serde_v8;
use deno_core::v8; use deno_core::v8;
@ -156,8 +155,8 @@ fn op_dispatch_bench_event(state: &mut OpState, #[serde] event: BenchEvent) {
sender.send(event).ok(); sender.send(event).ok();
} }
// TODO(bartlomieju): op2 forces to use bigint, but JS doesn't expect a bigint #[op2(fast)]
#[op] #[number]
fn op_bench_now(state: &mut OpState) -> Result<u64, AnyError> { fn op_bench_now(state: &mut OpState) -> Result<u64, AnyError> {
let ns = state.borrow::<time::Instant>().elapsed().as_nanos(); let ns = state.borrow::<time::Instant>().elapsed().as_nanos();
let ns_u64 = u64::try_from(ns)?; let ns_u64 = u64::try_from(ns)?;

6
ext/cache/lib.rs vendored
View file

@ -7,7 +7,6 @@ use std::sync::Arc;
use async_trait::async_trait; use async_trait::async_trait;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::op;
use deno_core::op2; use deno_core::op2;
use deno_core::serde::Deserialize; use deno_core::serde::Deserialize;
use deno_core::serde::Serialize; use deno_core::serde::Serialize;
@ -118,10 +117,11 @@ pub trait Cache: Clone + 'static {
-> Result<bool, AnyError>; -> Result<bool, AnyError>;
} }
#[op] #[op2(async)]
#[number]
pub async fn op_cache_storage_open<CA>( pub async fn op_cache_storage_open<CA>(
state: Rc<RefCell<OpState>>, state: Rc<RefCell<OpState>>,
cache_name: String, #[string] cache_name: String,
) -> Result<i64, AnyError> ) -> Result<i64, AnyError>
where where
CA: Cache, CA: Cache,

View file

@ -20,7 +20,6 @@ use deno_core::futures::Future;
use deno_core::futures::FutureExt; use deno_core::futures::FutureExt;
use deno_core::futures::Stream; use deno_core::futures::Stream;
use deno_core::futures::StreamExt; use deno_core::futures::StreamExt;
use deno_core::op;
use deno_core::op2; use deno_core::op2;
use deno_core::BufView; use deno_core::BufView;
use deno_core::WriteOutcome; 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<FP>( pub fn op_fetch<FP>(
state: &mut OpState, state: &mut OpState,
method: ByteString, #[serde] method: ByteString,
url: String, #[string] url: String,
headers: Vec<(ByteString, ByteString)>, #[serde] headers: Vec<(ByteString, ByteString)>,
client_rid: Option<u32>, #[smi] client_rid: Option<u32>,
has_body: bool, has_body: bool,
body_length: Option<u64>, #[number] body_length: Option<u64>,
data: Option<JsBuffer>, #[buffer] data: Option<JsBuffer>,
) -> Result<FetchReturn, AnyError> ) -> Result<FetchReturn, AnyError>
where where
FP: FetchPermissions + 'static, FP: FetchPermissions + 'static,

View file

@ -7,7 +7,6 @@ use brotli::ffi::decompressor::*;
use brotli::Decompressor; use brotli::Decompressor;
use deno_core::error::type_error; use deno_core::error::type_error;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::op;
use deno_core::op2; use deno_core::op2;
use deno_core::JsBuffer; use deno_core::JsBuffer;
use deno_core::OpState; use deno_core::OpState;
@ -23,13 +22,14 @@ fn encoder_mode(mode: u32) -> Result<BrotliEncoderMode, AnyError> {
unsafe { Ok(std::mem::transmute::<u32, BrotliEncoderMode>(mode)) } unsafe { Ok(std::mem::transmute::<u32, BrotliEncoderMode>(mode)) }
} }
#[op] #[op2(fast)]
#[number]
pub fn op_brotli_compress( pub fn op_brotli_compress(
buffer: &[u8], #[buffer] buffer: &[u8],
out: &mut [u8], #[buffer] out: &mut [u8],
quality: i32, #[smi] quality: i32,
lgwin: i32, #[smi] lgwin: i32,
mode: u32, #[smi] mode: u32,
) -> Result<usize, AnyError> { ) -> Result<usize, AnyError> {
let in_buffer = buffer.as_ptr(); let in_buffer = buffer.as_ptr();
let in_size = buffer.len(); let in_size = buffer.len();
@ -151,12 +151,13 @@ fn encoder_param(param: u8) -> BrotliEncoderParameter {
unsafe { std::mem::transmute(param as u32) } unsafe { std::mem::transmute(param as u32) }
} }
#[op] #[op2(fast)]
#[number]
pub fn op_brotli_compress_stream( pub fn op_brotli_compress_stream(
state: &mut OpState, state: &mut OpState,
rid: u32, #[smi] rid: u32,
input: &[u8], #[buffer] input: &[u8],
output: &mut [u8], #[buffer] output: &mut [u8],
) -> Result<usize, AnyError> { ) -> Result<usize, AnyError> {
let ctx = state.resource_table.get::<BrotliCompressCtx>(rid)?; let ctx = state.resource_table.get::<BrotliCompressCtx>(rid)?;
@ -186,11 +187,12 @@ pub fn op_brotli_compress_stream(
} }
} }
#[op] #[op2(fast)]
#[number]
pub fn op_brotli_compress_stream_end( pub fn op_brotli_compress_stream_end(
state: &mut OpState, state: &mut OpState,
rid: u32, #[smi] rid: u32,
output: &mut [u8], #[buffer] output: &mut [u8],
) -> Result<usize, AnyError> { ) -> Result<usize, AnyError> {
let ctx = state.resource_table.take::<BrotliCompressCtx>(rid)?; let ctx = state.resource_table.take::<BrotliCompressCtx>(rid)?;
@ -263,12 +265,13 @@ pub fn op_create_brotli_decompress(state: &mut OpState) -> u32 {
state.resource_table.add(BrotliDecompressCtx { inst }) state.resource_table.add(BrotliDecompressCtx { inst })
} }
#[op] #[op2(fast)]
#[number]
pub fn op_brotli_decompress_stream( pub fn op_brotli_decompress_stream(
state: &mut OpState, state: &mut OpState,
rid: u32, #[smi] rid: u32,
input: &[u8], #[buffer] input: &[u8],
output: &mut [u8], #[buffer] output: &mut [u8],
) -> Result<usize, AnyError> { ) -> Result<usize, AnyError> {
let ctx = state.resource_table.get::<BrotliDecompressCtx>(rid)?; let ctx = state.resource_table.get::<BrotliDecompressCtx>(rid)?;
@ -299,11 +302,12 @@ pub fn op_brotli_decompress_stream(
} }
} }
#[op] #[op2(fast)]
#[number]
pub fn op_brotli_decompress_stream_end( pub fn op_brotli_decompress_stream_end(
state: &mut OpState, state: &mut OpState,
rid: u32, #[smi] rid: u32,
output: &mut [u8], #[buffer] output: &mut [u8],
) -> Result<usize, AnyError> { ) -> Result<usize, AnyError> {
let ctx = state.resource_table.get::<BrotliDecompressCtx>(rid)?; let ctx = state.resource_table.get::<BrotliDecompressCtx>(rid)?;