mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
feat(ops): optional OpState (#13954)
This commit is contained in:
parent
672f66dde1
commit
bd481bf095
20 changed files with 63 additions and 100 deletions
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
|
@ -244,7 +244,7 @@ jobs:
|
||||||
~/.cargo/registry/index
|
~/.cargo/registry/index
|
||||||
~/.cargo/registry/cache
|
~/.cargo/registry/cache
|
||||||
~/.cargo/git/db
|
~/.cargo/git/db
|
||||||
key: 8-cargo-home-${{ matrix.os }}-${{ hashFiles('Cargo.lock') }}
|
key: 9-cargo-home-${{ matrix.os }}-${{ hashFiles('Cargo.lock') }}
|
||||||
|
|
||||||
# In main branch, always creates fresh cache
|
# In main branch, always creates fresh cache
|
||||||
- name: Cache build output (main)
|
- name: Cache build output (main)
|
||||||
|
@ -260,7 +260,7 @@ jobs:
|
||||||
!./target/*/*.zip
|
!./target/*/*.zip
|
||||||
!./target/*/*.tar.gz
|
!./target/*/*.tar.gz
|
||||||
key: |
|
key: |
|
||||||
8-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-${{ github.sha }}
|
9-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-${{ github.sha }}
|
||||||
|
|
||||||
# Restore cache from the latest 'main' branch build.
|
# Restore cache from the latest 'main' branch build.
|
||||||
- name: Cache build output (PR)
|
- name: Cache build output (PR)
|
||||||
|
@ -276,7 +276,7 @@ jobs:
|
||||||
!./target/*/*.tar.gz
|
!./target/*/*.tar.gz
|
||||||
key: never_saved
|
key: never_saved
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
8-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-
|
9-cargo-target-${{ matrix.os }}-${{ matrix.profile }}-
|
||||||
|
|
||||||
# Don't save cache after building PRs or branches other than 'main'.
|
# Don't save cache after building PRs or branches other than 'main'.
|
||||||
- name: Skip save cache (PR)
|
- name: Skip save cache (PR)
|
||||||
|
|
|
@ -22,12 +22,12 @@ fn setup() -> Vec<Extension> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_nop(_: &mut OpState) -> Result<(), AnyError> {
|
fn op_nop() -> Result<(), AnyError> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_pi_json(_: &mut OpState) -> Result<i64, AnyError> {
|
fn op_pi_json() -> Result<i64, AnyError> {
|
||||||
Ok(314159)
|
Ok(314159)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -202,12 +202,12 @@ fn create_compiler_snapshot(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_cwd(_state: &mut OpState, _args: Value) -> Result<Value, AnyError> {
|
fn op_cwd(_args: Value) -> Result<Value, AnyError> {
|
||||||
Ok(json!("cache:///"))
|
Ok(json!("cache:///"))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_exists(_state: &mut OpState, _args: Value) -> Result<Value, AnyError> {
|
fn op_exists(_args: Value) -> Result<Value, AnyError> {
|
||||||
Ok(json!(false))
|
Ok(json!(false))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,18 +67,12 @@ fn op_apply_source_map(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_format_diagnostic(
|
fn op_format_diagnostic(args: Value) -> Result<Value, AnyError> {
|
||||||
_state: &mut OpState,
|
|
||||||
args: Value,
|
|
||||||
) -> Result<Value, AnyError> {
|
|
||||||
let diagnostic: Diagnostics = serde_json::from_value(args)?;
|
let diagnostic: Diagnostics = serde_json::from_value(args)?;
|
||||||
Ok(json!(diagnostic.to_string()))
|
Ok(json!(diagnostic.to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_format_file_name(
|
fn op_format_file_name(file_name: String) -> Result<String, AnyError> {
|
||||||
_state: &mut OpState,
|
|
||||||
file_name: String,
|
|
||||||
) -> Result<String, AnyError> {
|
|
||||||
Ok(format_file_name(&file_name))
|
Ok(format_file_name(&file_name))
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,7 @@ use deno_core::RuntimeOptions;
|
||||||
use deno_core::*;
|
use deno_core::*;
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_sum(
|
fn op_sum(nums: Vec<f64>) -> Result<f64, deno_core::error::AnyError> {
|
||||||
_state: &mut OpState,
|
|
||||||
nums: Vec<f64>,
|
|
||||||
) -> Result<f64, deno_core::error::AnyError> {
|
|
||||||
// Sum inputs
|
// Sum inputs
|
||||||
let sum = nums.iter().fold(0.0, |a, v| a + v);
|
let sum = nums.iter().fold(0.0, |a, v| a + v);
|
||||||
// return as a Result<f64, AnyError>
|
// return as a Result<f64, AnyError>
|
||||||
|
|
|
@ -54,7 +54,7 @@ pub fn op_resources(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
pub fn op_void_sync(_state: &mut OpState) -> Result<(), Error> {
|
pub fn op_void_sync() -> Result<(), Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,11 +101,7 @@ pub fn op_metrics(
|
||||||
|
|
||||||
/// Builtin utility to print to stdout/stderr
|
/// Builtin utility to print to stdout/stderr
|
||||||
#[op]
|
#[op]
|
||||||
pub fn op_print(
|
pub fn op_print(msg: String, is_err: bool) -> Result<(), Error> {
|
||||||
_state: &mut OpState,
|
|
||||||
msg: String,
|
|
||||||
is_err: bool,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
if is_err {
|
if is_err {
|
||||||
stderr().write_all(msg.as_bytes())?;
|
stderr().write_all(msg.as_bytes())?;
|
||||||
stderr().flush().unwrap();
|
stderr().flush().unwrap();
|
||||||
|
|
|
@ -2088,7 +2088,7 @@ pub mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_error_builder() {
|
fn test_error_builder() {
|
||||||
#[op]
|
#[op]
|
||||||
fn op_err(_: &mut OpState) -> Result<(), Error> {
|
fn op_err() -> Result<(), Error> {
|
||||||
Err(custom_error("DOMExceptionOperationError", "abc"))
|
Err(custom_error("DOMExceptionOperationError", "abc"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2533,9 +2533,7 @@ assertEquals(1, notify_return_value);
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_set_macrotask_callback_set_next_tick_callback() {
|
async fn test_set_macrotask_callback_set_next_tick_callback() {
|
||||||
#[op]
|
#[op]
|
||||||
async fn op_async_sleep(
|
async fn op_async_sleep() -> Result<(), Error> {
|
||||||
_op_state: Rc<RefCell<OpState>>,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
// Future must be Poll::Pending on first call
|
// Future must be Poll::Pending on first call
|
||||||
tokio::time::sleep(std::time::Duration::from_millis(1)).await;
|
tokio::time::sleep(std::time::Duration::from_millis(1)).await;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -2610,13 +2608,13 @@ assertEquals(1, notify_return_value);
|
||||||
static NEXT_TICK: AtomicUsize = AtomicUsize::new(0);
|
static NEXT_TICK: AtomicUsize = AtomicUsize::new(0);
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_macrotask(_: &mut OpState) -> Result<(), AnyError> {
|
fn op_macrotask() -> Result<(), AnyError> {
|
||||||
MACROTASK.fetch_add(1, Ordering::Relaxed);
|
MACROTASK.fetch_add(1, Ordering::Relaxed);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_next_tick(_: &mut OpState) -> Result<(), AnyError> {
|
fn op_next_tick() -> Result<(), AnyError> {
|
||||||
NEXT_TICK.fetch_add(1, Ordering::Relaxed);
|
NEXT_TICK.fetch_add(1, Ordering::Relaxed);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -2747,13 +2745,13 @@ assertEquals(1, notify_return_value);
|
||||||
static UNCAUGHT_EXCEPTION: AtomicUsize = AtomicUsize::new(0);
|
static UNCAUGHT_EXCEPTION: AtomicUsize = AtomicUsize::new(0);
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_promise_reject(_: &mut OpState) -> Result<(), AnyError> {
|
fn op_promise_reject() -> Result<(), AnyError> {
|
||||||
PROMISE_REJECT.fetch_add(1, Ordering::Relaxed);
|
PROMISE_REJECT.fetch_add(1, Ordering::Relaxed);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_uncaught_exception(_: &mut OpState) -> Result<(), AnyError> {
|
fn op_uncaught_exception() -> Result<(), AnyError> {
|
||||||
UNCAUGHT_EXCEPTION.fetch_add(1, Ordering::Relaxed);
|
UNCAUGHT_EXCEPTION.fetch_add(1, Ordering::Relaxed);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
use crate::shared::*;
|
use crate::shared::*;
|
||||||
use aes::BlockEncrypt;
|
use aes::BlockEncrypt;
|
||||||
use aes::NewBlockCipher;
|
use aes::NewBlockCipher;
|
||||||
|
@ -25,7 +22,6 @@ use deno_core::error::custom_error;
|
||||||
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::op;
|
||||||
use deno_core::OpState;
|
|
||||||
use deno_core::ZeroCopyBuf;
|
use deno_core::ZeroCopyBuf;
|
||||||
use rsa::pkcs1::FromRsaPrivateKey;
|
use rsa::pkcs1::FromRsaPrivateKey;
|
||||||
use rsa::PaddingScheme;
|
use rsa::PaddingScheme;
|
||||||
|
@ -79,7 +75,6 @@ pub enum DecryptAlgorithm {
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
pub async fn op_crypto_decrypt(
|
pub async fn op_crypto_decrypt(
|
||||||
_state: Rc<RefCell<OpState>>,
|
|
||||||
opts: DecryptOptions,
|
opts: DecryptOptions,
|
||||||
data: ZeroCopyBuf,
|
data: ZeroCopyBuf,
|
||||||
) -> Result<ZeroCopyBuf, AnyError> {
|
) -> Result<ZeroCopyBuf, AnyError> {
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
use crate::shared::*;
|
use crate::shared::*;
|
||||||
|
|
||||||
use aes::cipher::NewCipher;
|
use aes::cipher::NewCipher;
|
||||||
|
@ -27,7 +24,6 @@ use ctr::flavors::Ctr64BE;
|
||||||
use ctr::flavors::CtrFlavor;
|
use ctr::flavors::CtrFlavor;
|
||||||
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::OpState;
|
|
||||||
use deno_core::ZeroCopyBuf;
|
use deno_core::ZeroCopyBuf;
|
||||||
use rand::rngs::OsRng;
|
use rand::rngs::OsRng;
|
||||||
use rsa::pkcs1::FromRsaPublicKey;
|
use rsa::pkcs1::FromRsaPublicKey;
|
||||||
|
@ -83,7 +79,6 @@ pub enum EncryptAlgorithm {
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
pub async fn op_crypto_encrypt(
|
pub async fn op_crypto_encrypt(
|
||||||
_state: Rc<RefCell<OpState>>,
|
|
||||||
opts: EncryptOptions,
|
opts: EncryptOptions,
|
||||||
data: ZeroCopyBuf,
|
data: ZeroCopyBuf,
|
||||||
) -> Result<ZeroCopyBuf, AnyError> {
|
) -> Result<ZeroCopyBuf, AnyError> {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use deno_core::error::custom_error;
|
use deno_core::error::custom_error;
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::op;
|
use deno_core::op;
|
||||||
use deno_core::OpState;
|
|
||||||
use deno_core::ZeroCopyBuf;
|
use deno_core::ZeroCopyBuf;
|
||||||
use rsa::pkcs1::UIntBytes;
|
use rsa::pkcs1::UIntBytes;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
@ -87,7 +86,6 @@ pub enum ExportKeyResult {
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
pub fn op_crypto_export_key(
|
pub fn op_crypto_export_key(
|
||||||
_state: &mut OpState,
|
|
||||||
opts: ExportKeyOptions,
|
opts: ExportKeyOptions,
|
||||||
key_data: RawKeyData,
|
key_data: RawKeyData,
|
||||||
) -> Result<ExportKeyResult, AnyError> {
|
) -> Result<ExportKeyResult, AnyError> {
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
use crate::shared::*;
|
use crate::shared::*;
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::op;
|
use deno_core::op;
|
||||||
use deno_core::OpState;
|
|
||||||
use deno_core::ZeroCopyBuf;
|
use deno_core::ZeroCopyBuf;
|
||||||
use elliptic_curve::rand_core::OsRng;
|
use elliptic_curve::rand_core::OsRng;
|
||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
|
@ -44,7 +40,6 @@ pub enum GenerateKeyOptions {
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
pub async fn op_crypto_generate_key(
|
pub async fn op_crypto_generate_key(
|
||||||
_state: Rc<RefCell<OpState>>,
|
|
||||||
opts: GenerateKeyOptions,
|
opts: GenerateKeyOptions,
|
||||||
) -> Result<ZeroCopyBuf, AnyError> {
|
) -> Result<ZeroCopyBuf, AnyError> {
|
||||||
let fun = || match opts {
|
let fun = || match opts {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::op;
|
use deno_core::op;
|
||||||
use deno_core::OpState;
|
|
||||||
use deno_core::ZeroCopyBuf;
|
use deno_core::ZeroCopyBuf;
|
||||||
use elliptic_curve::pkcs8::der::Decodable as Pkcs8Decodable;
|
use elliptic_curve::pkcs8::der::Decodable as Pkcs8Decodable;
|
||||||
use elliptic_curve::pkcs8::PrivateKeyInfo;
|
use elliptic_curve::pkcs8::PrivateKeyInfo;
|
||||||
|
@ -90,7 +89,6 @@ pub enum ImportKeyResult {
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
pub fn op_crypto_import_key(
|
pub fn op_crypto_import_key(
|
||||||
_state: &mut OpState,
|
|
||||||
opts: ImportKeyOptions,
|
opts: ImportKeyOptions,
|
||||||
key_data: KeyData,
|
key_data: KeyData,
|
||||||
) -> Result<ImportKeyResult, AnyError> {
|
) -> Result<ImportKeyResult, AnyError> {
|
||||||
|
|
|
@ -17,9 +17,7 @@ use deno_core::ZeroCopyBuf;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use shared::operation_error;
|
use shared::operation_error;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
use std::rc::Rc;
|
|
||||||
|
|
||||||
use p256::elliptic_curve::sec1::FromEncodedPoint;
|
use p256::elliptic_curve::sec1::FromEncodedPoint;
|
||||||
use p256::pkcs8::FromPrivateKey;
|
use p256::pkcs8::FromPrivateKey;
|
||||||
|
@ -169,7 +167,6 @@ pub struct SignArg {
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
pub async fn op_crypto_sign_key(
|
pub async fn op_crypto_sign_key(
|
||||||
_state: Rc<RefCell<OpState>>,
|
|
||||||
args: SignArg,
|
args: SignArg,
|
||||||
zero_copy: ZeroCopyBuf,
|
zero_copy: ZeroCopyBuf,
|
||||||
) -> Result<ZeroCopyBuf, AnyError> {
|
) -> Result<ZeroCopyBuf, AnyError> {
|
||||||
|
@ -324,7 +321,6 @@ pub struct VerifyArg {
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
pub async fn op_crypto_verify_key(
|
pub async fn op_crypto_verify_key(
|
||||||
_state: Rc<RefCell<OpState>>,
|
|
||||||
args: VerifyArg,
|
args: VerifyArg,
|
||||||
zero_copy: ZeroCopyBuf,
|
zero_copy: ZeroCopyBuf,
|
||||||
) -> Result<bool, AnyError> {
|
) -> Result<bool, AnyError> {
|
||||||
|
@ -485,7 +481,6 @@ pub struct DeriveKeyArg {
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
pub async fn op_crypto_derive_bits(
|
pub async fn op_crypto_derive_bits(
|
||||||
_state: Rc<RefCell<OpState>>,
|
|
||||||
args: DeriveKeyArg,
|
args: DeriveKeyArg,
|
||||||
zero_copy: Option<ZeroCopyBuf>,
|
zero_copy: Option<ZeroCopyBuf>,
|
||||||
) -> Result<ZeroCopyBuf, AnyError> {
|
) -> Result<ZeroCopyBuf, AnyError> {
|
||||||
|
@ -807,7 +802,6 @@ pub fn op_crypto_random_uuid(state: &mut OpState) -> Result<String, AnyError> {
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
pub async fn op_crypto_subtle_digest(
|
pub async fn op_crypto_subtle_digest(
|
||||||
_state: Rc<RefCell<OpState>>,
|
|
||||||
algorithm: CryptoHash,
|
algorithm: CryptoHash,
|
||||||
data: ZeroCopyBuf,
|
data: ZeroCopyBuf,
|
||||||
) -> Result<ZeroCopyBuf, AnyError> {
|
) -> Result<ZeroCopyBuf, AnyError> {
|
||||||
|
@ -831,7 +825,6 @@ pub struct WrapUnwrapKeyArg {
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
pub fn op_crypto_wrap_key(
|
pub fn op_crypto_wrap_key(
|
||||||
_state: &mut OpState,
|
|
||||||
args: WrapUnwrapKeyArg,
|
args: WrapUnwrapKeyArg,
|
||||||
data: ZeroCopyBuf,
|
data: ZeroCopyBuf,
|
||||||
) -> Result<ZeroCopyBuf, AnyError> {
|
) -> Result<ZeroCopyBuf, AnyError> {
|
||||||
|
@ -861,7 +854,6 @@ pub fn op_crypto_wrap_key(
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
pub fn op_crypto_unwrap_key(
|
pub fn op_crypto_unwrap_key(
|
||||||
_state: &mut OpState,
|
|
||||||
args: WrapUnwrapKeyArg,
|
args: WrapUnwrapKeyArg,
|
||||||
data: ZeroCopyBuf,
|
data: ZeroCopyBuf,
|
||||||
) -> Result<ZeroCopyBuf, AnyError> {
|
) -> Result<ZeroCopyBuf, AnyError> {
|
||||||
|
|
|
@ -648,17 +648,13 @@ fn ffi_call(args: FfiCallArgs, symbol: &Symbol) -> Result<Value, AnyError> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_ffi_call_ptr(
|
fn op_ffi_call_ptr(args: FfiCallPtrArgs) -> Result<Value, AnyError> {
|
||||||
_state: &mut deno_core::OpState,
|
|
||||||
args: FfiCallPtrArgs,
|
|
||||||
) -> Result<Value, AnyError> {
|
|
||||||
let symbol = args.get_symbol();
|
let symbol = args.get_symbol();
|
||||||
ffi_call(args.into(), &symbol)
|
ffi_call(args.into(), &symbol)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
async fn op_ffi_call_ptr_nonblocking(
|
async fn op_ffi_call_ptr_nonblocking(
|
||||||
_state: Rc<RefCell<deno_core::OpState>>,
|
|
||||||
args: FfiCallPtrArgs,
|
args: FfiCallPtrArgs,
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<Value, AnyError> {
|
||||||
let symbol = args.get_symbol();
|
let symbol = args.get_symbol();
|
||||||
|
|
|
@ -797,10 +797,7 @@ async fn op_http_read(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_http_websocket_accept_header(
|
fn op_http_websocket_accept_header(key: String) -> Result<String, AnyError> {
|
||||||
_: &mut OpState,
|
|
||||||
key: String,
|
|
||||||
) -> Result<String, AnyError> {
|
|
||||||
let digest = ring::digest::digest(
|
let digest = ring::digest::digest(
|
||||||
&ring::digest::SHA1_FOR_LEGACY_USE_ONLY,
|
&ring::digest::SHA1_FOR_LEGACY_USE_ONLY,
|
||||||
format!("{}258EAFA5-E914-47DA-95CA-C5AB0DC85B11", key).as_bytes(),
|
format!("{}258EAFA5-E914-47DA-95CA-C5AB0DC85B11", key).as_bytes(),
|
||||||
|
|
|
@ -58,7 +58,6 @@ type UrlParts = String;
|
||||||
/// optional part to "set" after parsing. Return `UrlParts`.
|
/// optional part to "set" after parsing. Return `UrlParts`.
|
||||||
#[op]
|
#[op]
|
||||||
pub fn op_url_parse(
|
pub fn op_url_parse(
|
||||||
_state: &mut deno_core::OpState,
|
|
||||||
href: String,
|
href: String,
|
||||||
base_href: Option<String>,
|
base_href: Option<String>,
|
||||||
) -> Result<UrlParts, AnyError> {
|
) -> Result<UrlParts, AnyError> {
|
||||||
|
@ -92,7 +91,6 @@ pub enum UrlSetter {
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
pub fn op_url_reparse(
|
pub fn op_url_reparse(
|
||||||
_state: &mut deno_core::OpState,
|
|
||||||
href: String,
|
href: String,
|
||||||
setter_opts: (UrlSetter, String),
|
setter_opts: (UrlSetter, String),
|
||||||
) -> Result<UrlParts, AnyError> {
|
) -> Result<UrlParts, AnyError> {
|
||||||
|
@ -162,7 +160,6 @@ fn url_result(
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
pub fn op_url_parse_search_params(
|
pub fn op_url_parse_search_params(
|
||||||
_state: &mut deno_core::OpState,
|
|
||||||
args: Option<String>,
|
args: Option<String>,
|
||||||
zero_copy: Option<ZeroCopyBuf>,
|
zero_copy: Option<ZeroCopyBuf>,
|
||||||
) -> Result<Vec<(String, String)>, AnyError> {
|
) -> Result<Vec<(String, String)>, AnyError> {
|
||||||
|
@ -182,7 +179,6 @@ pub fn op_url_parse_search_params(
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
pub fn op_url_stringify_search_params(
|
pub fn op_url_stringify_search_params(
|
||||||
_state: &mut deno_core::OpState,
|
|
||||||
args: Vec<(String, String)>,
|
args: Vec<(String, String)>,
|
||||||
) -> Result<String, AnyError> {
|
) -> Result<String, AnyError> {
|
||||||
let search = form_urlencoded::Serializer::new(String::new())
|
let search = form_urlencoded::Serializer::new(String::new())
|
||||||
|
|
|
@ -9,7 +9,6 @@ use urlpattern::quirks::UrlPattern;
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
pub fn op_urlpattern_parse(
|
pub fn op_urlpattern_parse(
|
||||||
_state: &mut deno_core::OpState,
|
|
||||||
input: StringOrInit,
|
input: StringOrInit,
|
||||||
base_url: Option<String>,
|
base_url: Option<String>,
|
||||||
) -> Result<UrlPattern, AnyError> {
|
) -> Result<UrlPattern, AnyError> {
|
||||||
|
@ -27,7 +26,6 @@ pub fn op_urlpattern_parse(
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
pub fn op_urlpattern_process_match_input(
|
pub fn op_urlpattern_process_match_input(
|
||||||
_state: &mut deno_core::OpState,
|
|
||||||
input: StringOrInit,
|
input: StringOrInit,
|
||||||
base_url: Option<String>,
|
base_url: Option<String>,
|
||||||
) -> Result<Option<(MatchInput, quirks::Inputs)>, AnyError> {
|
) -> Result<Option<(MatchInput, quirks::Inputs)>, AnyError> {
|
||||||
|
|
|
@ -121,20 +121,14 @@ pub fn init<P: TimersPermission + 'static>(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_base64_decode(
|
fn op_base64_decode(input: String) -> Result<ZeroCopyBuf, AnyError> {
|
||||||
_: &mut OpState,
|
|
||||||
input: String,
|
|
||||||
) -> Result<ZeroCopyBuf, AnyError> {
|
|
||||||
let mut input = input.into_bytes();
|
let mut input = input.into_bytes();
|
||||||
input.retain(|c| !c.is_ascii_whitespace());
|
input.retain(|c| !c.is_ascii_whitespace());
|
||||||
Ok(b64_decode(&input)?.into())
|
Ok(b64_decode(&input)?.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_base64_atob(
|
fn op_base64_atob(s: ByteString) -> Result<ByteString, AnyError> {
|
||||||
_: &mut OpState,
|
|
||||||
s: ByteString,
|
|
||||||
) -> Result<ByteString, AnyError> {
|
|
||||||
let mut s = s.0;
|
let mut s = s.0;
|
||||||
s.retain(|c| !c.is_ascii_whitespace());
|
s.retain(|c| !c.is_ascii_whitespace());
|
||||||
|
|
||||||
|
@ -184,15 +178,12 @@ fn b64_decode(input: &[u8]) -> Result<Vec<u8>, AnyError> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_base64_encode(
|
fn op_base64_encode(s: ZeroCopyBuf) -> Result<String, AnyError> {
|
||||||
_: &mut OpState,
|
|
||||||
s: ZeroCopyBuf,
|
|
||||||
) -> Result<String, AnyError> {
|
|
||||||
Ok(b64_encode(&s))
|
Ok(b64_encode(&s))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_base64_btoa(_: &mut OpState, s: ByteString) -> Result<String, AnyError> {
|
fn op_base64_btoa(s: ByteString) -> Result<String, AnyError> {
|
||||||
Ok(b64_encode(&s))
|
Ok(b64_encode(&s))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,10 +202,7 @@ struct DecoderOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_encoding_normalize_label(
|
fn op_encoding_normalize_label(label: String) -> Result<String, AnyError> {
|
||||||
_state: &mut OpState,
|
|
||||||
label: String,
|
|
||||||
) -> Result<String, AnyError> {
|
|
||||||
let encoding = Encoding::for_label_no_replacement(label.as_bytes())
|
let encoding = Encoding::for_label_no_replacement(label.as_bytes())
|
||||||
.ok_or_else(|| {
|
.ok_or_else(|| {
|
||||||
range_error(format!(
|
range_error(format!(
|
||||||
|
@ -331,7 +319,6 @@ struct EncodeIntoResult {
|
||||||
|
|
||||||
#[op]
|
#[op]
|
||||||
fn op_encoding_encode_into(
|
fn op_encoding_encode_into(
|
||||||
_state: &mut OpState,
|
|
||||||
input: String,
|
input: String,
|
||||||
mut buffer: ZeroCopyBuf,
|
mut buffer: ZeroCopyBuf,
|
||||||
) -> Result<EncodeIntoResult, AnyError> {
|
) -> Result<EncodeIntoResult, AnyError> {
|
||||||
|
|
39
ops/lib.rs
39
ops/lib.rs
|
@ -5,6 +5,7 @@ use proc_macro2::TokenStream as TokenStream2;
|
||||||
use proc_macro_crate::crate_name;
|
use proc_macro_crate::crate_name;
|
||||||
use proc_macro_crate::FoundCrate;
|
use proc_macro_crate::FoundCrate;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
|
use quote::ToTokens;
|
||||||
use syn::Ident;
|
use syn::Ident;
|
||||||
|
|
||||||
// Identifer to the `deno_core` crate.
|
// Identifer to the `deno_core` crate.
|
||||||
|
@ -94,7 +95,15 @@ pub fn op(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
|
|
||||||
/// Generate the body of a v8 func for an async op
|
/// Generate the body of a v8 func for an async op
|
||||||
fn codegen_v8_async(core: &TokenStream2, f: &syn::ItemFn) -> TokenStream2 {
|
fn codegen_v8_async(core: &TokenStream2, f: &syn::ItemFn) -> TokenStream2 {
|
||||||
let (arg_decls, args_tail) = codegen_args(core, f, 1, 2);
|
let arg0 = f.sig.inputs.first();
|
||||||
|
let uses_opstate = arg0.map(is_rc_refcell_opstate).unwrap_or_default();
|
||||||
|
let args_head = if uses_opstate {
|
||||||
|
quote! { state, }
|
||||||
|
} else {
|
||||||
|
quote! {}
|
||||||
|
};
|
||||||
|
let rust_i0 = if uses_opstate { 1 } else { 0 };
|
||||||
|
let (arg_decls, args_tail) = codegen_args(core, f, rust_i0, 2);
|
||||||
let type_params = &f.sig.generics.params;
|
let type_params = &f.sig.generics.params;
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
|
@ -139,7 +148,7 @@ fn codegen_v8_async(core: &TokenStream2, f: &syn::ItemFn) -> TokenStream2 {
|
||||||
};
|
};
|
||||||
|
|
||||||
#core::_ops::queue_async_op(scope, async move {
|
#core::_ops::queue_async_op(scope, async move {
|
||||||
let result = Self::call::<#type_params>(state, #args_tail).await;
|
let result = Self::call::<#type_params>(#args_head #args_tail).await;
|
||||||
(promise_id, op_id, #core::_ops::to_op_result(get_class, result))
|
(promise_id, op_id, #core::_ops::to_op_result(get_class, result))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -147,7 +156,15 @@ fn codegen_v8_async(core: &TokenStream2, f: &syn::ItemFn) -> TokenStream2 {
|
||||||
|
|
||||||
/// Generate the body of a v8 func for a sync op
|
/// Generate the body of a v8 func for a sync op
|
||||||
fn codegen_v8_sync(core: &TokenStream2, f: &syn::ItemFn) -> TokenStream2 {
|
fn codegen_v8_sync(core: &TokenStream2, f: &syn::ItemFn) -> TokenStream2 {
|
||||||
let (arg_decls, args_tail) = codegen_args(core, f, 1, 1);
|
let arg0 = f.sig.inputs.first();
|
||||||
|
let uses_opstate = arg0.map(is_mut_ref_opstate).unwrap_or_default();
|
||||||
|
let args_head = if uses_opstate {
|
||||||
|
quote! { op_state, }
|
||||||
|
} else {
|
||||||
|
quote! {}
|
||||||
|
};
|
||||||
|
let rust_i0 = if uses_opstate { 1 } else { 0 };
|
||||||
|
let (arg_decls, args_tail) = codegen_args(core, f, rust_i0, 1);
|
||||||
let ret = codegen_sync_ret(core, &f.sig.output);
|
let ret = codegen_sync_ret(core, &f.sig.output);
|
||||||
let type_params = &f.sig.generics.params;
|
let type_params = &f.sig.generics.params;
|
||||||
|
|
||||||
|
@ -168,7 +185,7 @@ fn codegen_v8_sync(core: &TokenStream2, f: &syn::ItemFn) -> TokenStream2 {
|
||||||
let state = unsafe { &*(state_refcell_raw as *const std::cell::RefCell<#core::OpState>) };
|
let state = unsafe { &*(state_refcell_raw as *const std::cell::RefCell<#core::OpState>) };
|
||||||
|
|
||||||
let op_state = &mut state.borrow_mut();
|
let op_state = &mut state.borrow_mut();
|
||||||
let result = Self::call::<#type_params>(op_state, #args_tail);
|
let result = Self::call::<#type_params>(#args_head #args_tail);
|
||||||
|
|
||||||
op_state.tracker.track_sync(op_id);
|
op_state.tracker.track_sync(op_id);
|
||||||
|
|
||||||
|
@ -284,3 +301,17 @@ fn is_unit_result(ty: &syn::Type) -> bool {
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_mut_ref_opstate(arg: &syn::FnArg) -> bool {
|
||||||
|
tokens(arg).ends_with(": & mut OpState")
|
||||||
|
|| tokens(arg).ends_with(": & mut deno_core :: OpState")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_rc_refcell_opstate(arg: &syn::FnArg) -> bool {
|
||||||
|
tokens(arg).ends_with(": Rc < RefCell < OpState > >")
|
||||||
|
|| tokens(arg).ends_with(": Rc < RefCell < deno_core :: OpState > >")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn tokens(x: impl ToTokens) -> String {
|
||||||
|
x.to_token_stream().to_string()
|
||||||
|
}
|
||||||
|
|
|
@ -225,18 +225,18 @@ pub fn op_signal_unbind(
|
||||||
|
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
#[op]
|
#[op]
|
||||||
pub fn op_signal_bind(_state: &mut OpState) -> Result<(), AnyError> {
|
pub fn op_signal_bind() -> Result<(), AnyError> {
|
||||||
Err(generic_error("not implemented"))
|
Err(generic_error("not implemented"))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
#[op]
|
#[op]
|
||||||
fn op_signal_unbind(_state: &mut OpState) -> Result<(), AnyError> {
|
fn op_signal_unbind() -> Result<(), AnyError> {
|
||||||
Err(generic_error("not implemented"))
|
Err(generic_error("not implemented"))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
#[op]
|
#[op]
|
||||||
async fn op_signal_poll(_state: Rc<RefCell<OpState>>) -> Result<(), AnyError> {
|
async fn op_signal_poll() -> Result<(), AnyError> {
|
||||||
Err(generic_error("not implemented"))
|
Err(generic_error("not implemented"))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue