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:
parent
75a724890d
commit
1ad097c4bf
4 changed files with 39 additions and 35 deletions
|
@ -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<u64, AnyError> {
|
||||
let ns = state.borrow::<time::Instant>().elapsed().as_nanos();
|
||||
let ns_u64 = u64::try_from(ns)?;
|
||||
|
|
6
ext/cache/lib.rs
vendored
6
ext/cache/lib.rs
vendored
|
@ -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<bool, AnyError>;
|
||||
}
|
||||
|
||||
#[op]
|
||||
#[op2(async)]
|
||||
#[number]
|
||||
pub async fn op_cache_storage_open<CA>(
|
||||
state: Rc<RefCell<OpState>>,
|
||||
cache_name: String,
|
||||
#[string] cache_name: String,
|
||||
) -> Result<i64, AnyError>
|
||||
where
|
||||
CA: Cache,
|
||||
|
|
|
@ -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<FP>(
|
||||
state: &mut OpState,
|
||||
method: ByteString,
|
||||
url: String,
|
||||
headers: Vec<(ByteString, ByteString)>,
|
||||
client_rid: Option<u32>,
|
||||
#[serde] method: ByteString,
|
||||
#[string] url: String,
|
||||
#[serde] headers: Vec<(ByteString, ByteString)>,
|
||||
#[smi] client_rid: Option<u32>,
|
||||
has_body: bool,
|
||||
body_length: Option<u64>,
|
||||
data: Option<JsBuffer>,
|
||||
#[number] body_length: Option<u64>,
|
||||
#[buffer] data: Option<JsBuffer>,
|
||||
) -> Result<FetchReturn, AnyError>
|
||||
where
|
||||
FP: FetchPermissions + 'static,
|
||||
|
|
|
@ -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<BrotliEncoderMode, AnyError> {
|
|||
unsafe { Ok(std::mem::transmute::<u32, BrotliEncoderMode>(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<usize, AnyError> {
|
||||
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<usize, AnyError> {
|
||||
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(
|
||||
state: &mut OpState,
|
||||
rid: u32,
|
||||
output: &mut [u8],
|
||||
#[smi] rid: u32,
|
||||
#[buffer] output: &mut [u8],
|
||||
) -> Result<usize, AnyError> {
|
||||
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 })
|
||||
}
|
||||
|
||||
#[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<usize, AnyError> {
|
||||
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(
|
||||
state: &mut OpState,
|
||||
rid: u32,
|
||||
output: &mut [u8],
|
||||
#[smi] rid: u32,
|
||||
#[buffer] output: &mut [u8],
|
||||
) -> Result<usize, AnyError> {
|
||||
let ctx = state.resource_table.get::<BrotliDecompressCtx>(rid)?;
|
||||
|
||||
|
|
Loading…
Reference in a new issue