mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 00:29:09 -05:00
chore: various op cleanup (#12329)
This commit is contained in:
parent
d67e858506
commit
77a00ce1fb
26 changed files with 131 additions and 185 deletions
|
@ -11,6 +11,7 @@ use deno_core::serde_json::json;
|
||||||
use deno_core::serde_json::Value;
|
use deno_core::serde_json::Value;
|
||||||
use deno_core::OpState;
|
use deno_core::OpState;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use serde::Serialize;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub fn init(rt: &mut deno_core::JsRuntime) {
|
pub fn init(rt: &mut deno_core::JsRuntime) {
|
||||||
|
@ -27,13 +28,19 @@ struct ApplySourceMap {
|
||||||
column_number: i32,
|
column_number: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct AppliedSourceMap {
|
||||||
|
file_name: String,
|
||||||
|
line_number: u32,
|
||||||
|
column_number: u32,
|
||||||
|
}
|
||||||
|
|
||||||
fn op_apply_source_map(
|
fn op_apply_source_map(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
args: Value,
|
args: ApplySourceMap,
|
||||||
_: (),
|
_: (),
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<AppliedSourceMap, AnyError> {
|
||||||
let args: ApplySourceMap = serde_json::from_value(args)?;
|
|
||||||
|
|
||||||
let mut mappings_map: CachedMaps = HashMap::new();
|
let mut mappings_map: CachedMaps = HashMap::new();
|
||||||
let ps = state.borrow::<ProcState>().clone();
|
let ps = state.borrow::<ProcState>().clone();
|
||||||
|
|
||||||
|
@ -46,11 +53,11 @@ fn op_apply_source_map(
|
||||||
ps,
|
ps,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(json!({
|
Ok(AppliedSourceMap {
|
||||||
"fileName": orig_file_name,
|
file_name: orig_file_name,
|
||||||
"lineNumber": orig_line_number as u32,
|
line_number: orig_line_number as u32,
|
||||||
"columnNumber": orig_column_number as u32,
|
column_number: orig_column_number as u32,
|
||||||
}))
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_format_diagnostic(
|
fn op_format_diagnostic(
|
||||||
|
|
|
@ -14,13 +14,12 @@ use deno_core::error::AnyError;
|
||||||
use deno_core::error::Context;
|
use deno_core::error::Context;
|
||||||
use deno_core::parking_lot::Mutex;
|
use deno_core::parking_lot::Mutex;
|
||||||
use deno_core::resolve_url_or_path;
|
use deno_core::resolve_url_or_path;
|
||||||
use deno_core::serde_json;
|
|
||||||
use deno_core::serde_json::json;
|
|
||||||
use deno_core::serde_json::Value;
|
use deno_core::serde_json::Value;
|
||||||
use deno_core::OpState;
|
use deno_core::OpState;
|
||||||
use deno_runtime::permissions::Permissions;
|
use deno_runtime::permissions::Permissions;
|
||||||
use import_map::ImportMap;
|
use import_map::ImportMap;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use serde::Serialize;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -50,13 +49,21 @@ struct EmitArgs {
|
||||||
sources: Option<HashMap<String, Arc<String>>>,
|
sources: Option<HashMap<String, Arc<String>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
struct EmitResult {
|
||||||
|
diagnostics: crate::diagnostics::Diagnostics,
|
||||||
|
files: HashMap<String, String>,
|
||||||
|
ignored_options: Option<crate::config_file::IgnoredCompilerOptions>,
|
||||||
|
stats: crate::module_graph::Stats,
|
||||||
|
}
|
||||||
|
|
||||||
async fn op_emit(
|
async fn op_emit(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
args: Value,
|
args: EmitArgs,
|
||||||
_: (),
|
_: (),
|
||||||
) -> Result<Value, AnyError> {
|
) -> Result<EmitResult, AnyError> {
|
||||||
deno_runtime::ops::check_unstable2(&state, "Deno.emit");
|
deno_runtime::ops::check_unstable2(&state, "Deno.emit");
|
||||||
let args: EmitArgs = serde_json::from_value(args)?;
|
|
||||||
let root_specifier = args.root_specifier;
|
let root_specifier = args.root_specifier;
|
||||||
let ps = state.borrow().borrow::<ProcState>().clone();
|
let ps = state.borrow().borrow::<ProcState>().clone();
|
||||||
let mut runtime_permissions = {
|
let mut runtime_permissions = {
|
||||||
|
@ -127,10 +134,10 @@ async fn op_emit(
|
||||||
})?;
|
})?;
|
||||||
result_info.diagnostics.extend_graph_errors(graph_errors);
|
result_info.diagnostics.extend_graph_errors(graph_errors);
|
||||||
|
|
||||||
Ok(json!({
|
Ok(EmitResult {
|
||||||
"diagnostics": result_info.diagnostics,
|
diagnostics: result_info.diagnostics,
|
||||||
"files": files,
|
files,
|
||||||
"ignoredOptions": result_info.maybe_ignored_options,
|
ignored_options: result_info.maybe_ignored_options,
|
||||||
"stats": result_info.stats,
|
stats: result_info.stats,
|
||||||
}))
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,10 +67,6 @@ pub fn resource_unavailable() -> AnyError {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn null_opbuf() -> AnyError {
|
|
||||||
type_error("expected non-null op buffer arg")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A simple error type that lets the creator specify both the error message and
|
/// A simple error type that lets the creator specify both the error message and
|
||||||
/// the error class name. This type is private; externally it only ever appears
|
/// the error class name. This type is private; externally it only ever appears
|
||||||
/// wrapped in an `AnyError`. To retrieve the error class name from a wrapped
|
/// wrapped in an `AnyError`. To retrieve the error class name from a wrapped
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||||
use deno_core::error::null_opbuf;
|
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::AsyncRefCell;
|
use deno_core::AsyncRefCell;
|
||||||
use deno_core::CancelHandle;
|
use deno_core::CancelHandle;
|
||||||
|
@ -121,7 +120,7 @@ fn create_js_runtime() -> JsRuntime {
|
||||||
|
|
||||||
fn op_listen(
|
fn op_listen(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
_args: (),
|
_: (),
|
||||||
_: (),
|
_: (),
|
||||||
) -> Result<ResourceId, AnyError> {
|
) -> Result<ResourceId, AnyError> {
|
||||||
log::debug!("listen");
|
log::debug!("listen");
|
||||||
|
@ -158,9 +157,8 @@ async fn op_accept(
|
||||||
async fn op_read(
|
async fn op_read(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
rid: ResourceId,
|
rid: ResourceId,
|
||||||
buf: Option<ZeroCopyBuf>,
|
mut buf: ZeroCopyBuf,
|
||||||
) -> Result<usize, AnyError> {
|
) -> Result<usize, AnyError> {
|
||||||
let mut buf = buf.ok_or_else(null_opbuf)?;
|
|
||||||
log::debug!("read rid={}", rid);
|
log::debug!("read rid={}", rid);
|
||||||
|
|
||||||
let stream = state.borrow().resource_table.get::<TcpStream>(rid)?;
|
let stream = state.borrow().resource_table.get::<TcpStream>(rid)?;
|
||||||
|
@ -171,9 +169,8 @@ async fn op_read(
|
||||||
async fn op_write(
|
async fn op_write(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
rid: ResourceId,
|
rid: ResourceId,
|
||||||
buf: Option<ZeroCopyBuf>,
|
buf: ZeroCopyBuf,
|
||||||
) -> Result<usize, AnyError> {
|
) -> Result<usize, AnyError> {
|
||||||
let buf = buf.ok_or_else(null_opbuf)?;
|
|
||||||
log::debug!("write rid={}", rid);
|
log::debug!("write rid={}", rid);
|
||||||
|
|
||||||
let stream = state.borrow().resource_table.get::<TcpStream>(rid)?;
|
let stream = state.borrow().resource_table.get::<TcpStream>(rid)?;
|
||||||
|
|
|
@ -34,7 +34,7 @@ pub(crate) fn init_builtins() -> Extension {
|
||||||
/// and string representation as value.
|
/// and string representation as value.
|
||||||
pub fn op_resources(
|
pub fn op_resources(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
_args: (),
|
_: (),
|
||||||
_: (),
|
_: (),
|
||||||
) -> Result<Vec<(ResourceId, String)>, AnyError> {
|
) -> Result<Vec<(ResourceId, String)>, AnyError> {
|
||||||
let serialized_resources = state
|
let serialized_resources = state
|
||||||
|
|
|
@ -1919,11 +1919,7 @@ pub mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_error_builder() {
|
fn test_error_builder() {
|
||||||
fn op_err(
|
fn op_err(_: &mut OpState, _: (), _: ()) -> Result<(), AnyError> {
|
||||||
_: &mut OpState,
|
|
||||||
_: (),
|
|
||||||
_: Option<ZeroCopyBuf>,
|
|
||||||
) -> Result<(), AnyError> {
|
|
||||||
Err(custom_error("DOMExceptionOperationError", "abc"))
|
Err(custom_error("DOMExceptionOperationError", "abc"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,8 +45,8 @@ struct Unstable(bool); // --unstable
|
||||||
|
|
||||||
pub fn op_broadcast_subscribe<BC: BroadcastChannel + 'static>(
|
pub fn op_broadcast_subscribe<BC: BroadcastChannel + 'static>(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
_args: (),
|
_: (),
|
||||||
_buf: (),
|
_: (),
|
||||||
) -> Result<ResourceId, AnyError> {
|
) -> Result<ResourceId, AnyError> {
|
||||||
let unstable = state.borrow::<Unstable>().0;
|
let unstable = state.borrow::<Unstable>().0;
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ pub async fn op_broadcast_send<BC: BroadcastChannel + 'static>(
|
||||||
pub async fn op_broadcast_recv<BC: BroadcastChannel + 'static>(
|
pub async fn op_broadcast_recv<BC: BroadcastChannel + 'static>(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
rid: ResourceId,
|
rid: ResourceId,
|
||||||
_buf: (),
|
_: (),
|
||||||
) -> Result<Option<Message>, AnyError> {
|
) -> Result<Option<Message>, AnyError> {
|
||||||
let resource = state.borrow().resource_table.get::<BC::Resource>(rid)?;
|
let resource = state.borrow().resource_table.get::<BC::Resource>(rid)?;
|
||||||
let bc = state.borrow().borrow::<BC>().clone();
|
let bc = state.borrow().borrow::<BC>().clone();
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
use deno_core::error::custom_error;
|
use deno_core::error::custom_error;
|
||||||
use deno_core::error::not_supported;
|
use deno_core::error::not_supported;
|
||||||
use deno_core::error::null_opbuf;
|
|
||||||
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::include_js_files;
|
use deno_core::include_js_files;
|
||||||
|
@ -296,9 +295,8 @@ pub struct SignArg {
|
||||||
pub async fn op_crypto_sign_key(
|
pub async fn op_crypto_sign_key(
|
||||||
_state: Rc<RefCell<OpState>>,
|
_state: Rc<RefCell<OpState>>,
|
||||||
args: SignArg,
|
args: SignArg,
|
||||||
zero_copy: Option<ZeroCopyBuf>,
|
zero_copy: ZeroCopyBuf,
|
||||||
) -> Result<ZeroCopyBuf, AnyError> {
|
) -> Result<ZeroCopyBuf, AnyError> {
|
||||||
let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
|
|
||||||
let data = &*zero_copy;
|
let data = &*zero_copy;
|
||||||
let algorithm = args.algorithm;
|
let algorithm = args.algorithm;
|
||||||
|
|
||||||
|
@ -451,9 +449,8 @@ pub struct VerifyArg {
|
||||||
pub async fn op_crypto_verify_key(
|
pub async fn op_crypto_verify_key(
|
||||||
_state: Rc<RefCell<OpState>>,
|
_state: Rc<RefCell<OpState>>,
|
||||||
args: VerifyArg,
|
args: VerifyArg,
|
||||||
zero_copy: Option<ZeroCopyBuf>,
|
zero_copy: ZeroCopyBuf,
|
||||||
) -> Result<bool, AnyError> {
|
) -> Result<bool, AnyError> {
|
||||||
let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
|
|
||||||
let data = &*zero_copy;
|
let data = &*zero_copy;
|
||||||
let algorithm = args.algorithm;
|
let algorithm = args.algorithm;
|
||||||
|
|
||||||
|
@ -599,7 +596,7 @@ pub struct ExportKeyArg {
|
||||||
pub async fn op_crypto_export_key(
|
pub async fn op_crypto_export_key(
|
||||||
_state: Rc<RefCell<OpState>>,
|
_state: Rc<RefCell<OpState>>,
|
||||||
args: ExportKeyArg,
|
args: ExportKeyArg,
|
||||||
_zero_copy: Option<ZeroCopyBuf>,
|
_: (),
|
||||||
) -> Result<ZeroCopyBuf, AnyError> {
|
) -> Result<ZeroCopyBuf, AnyError> {
|
||||||
let algorithm = args.algorithm;
|
let algorithm = args.algorithm;
|
||||||
match algorithm {
|
match algorithm {
|
||||||
|
@ -731,9 +728,8 @@ pub struct DeriveKeyArg {
|
||||||
pub async fn op_crypto_derive_bits(
|
pub async fn op_crypto_derive_bits(
|
||||||
_state: Rc<RefCell<OpState>>,
|
_state: Rc<RefCell<OpState>>,
|
||||||
args: DeriveKeyArg,
|
args: DeriveKeyArg,
|
||||||
zero_copy: Option<ZeroCopyBuf>,
|
zero_copy: ZeroCopyBuf,
|
||||||
) -> Result<ZeroCopyBuf, AnyError> {
|
) -> Result<ZeroCopyBuf, AnyError> {
|
||||||
let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
|
|
||||||
let salt = &*zero_copy;
|
let salt = &*zero_copy;
|
||||||
let algorithm = args.algorithm;
|
let algorithm = args.algorithm;
|
||||||
match algorithm {
|
match algorithm {
|
||||||
|
@ -798,9 +794,8 @@ pub struct EncryptArg {
|
||||||
pub async fn op_crypto_encrypt_key(
|
pub async fn op_crypto_encrypt_key(
|
||||||
_state: Rc<RefCell<OpState>>,
|
_state: Rc<RefCell<OpState>>,
|
||||||
args: EncryptArg,
|
args: EncryptArg,
|
||||||
zero_copy: Option<ZeroCopyBuf>,
|
zero_copy: ZeroCopyBuf,
|
||||||
) -> Result<ZeroCopyBuf, AnyError> {
|
) -> Result<ZeroCopyBuf, AnyError> {
|
||||||
let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
|
|
||||||
let data = &*zero_copy;
|
let data = &*zero_copy;
|
||||||
let algorithm = args.algorithm;
|
let algorithm = args.algorithm;
|
||||||
|
|
||||||
|
@ -1035,9 +1030,8 @@ pub struct ImportKeyResult {
|
||||||
pub async fn op_crypto_import_key(
|
pub async fn op_crypto_import_key(
|
||||||
_state: Rc<RefCell<OpState>>,
|
_state: Rc<RefCell<OpState>>,
|
||||||
args: ImportKeyArg,
|
args: ImportKeyArg,
|
||||||
zero_copy: Option<ZeroCopyBuf>,
|
zero_copy: ZeroCopyBuf,
|
||||||
) -> Result<ImportKeyResult, AnyError> {
|
) -> Result<ImportKeyResult, AnyError> {
|
||||||
let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
|
|
||||||
let data = &*zero_copy;
|
let data = &*zero_copy;
|
||||||
let algorithm = args.algorithm;
|
let algorithm = args.algorithm;
|
||||||
|
|
||||||
|
@ -1359,9 +1353,8 @@ pub struct DecryptArg {
|
||||||
pub async fn op_crypto_decrypt_key(
|
pub async fn op_crypto_decrypt_key(
|
||||||
_state: Rc<RefCell<OpState>>,
|
_state: Rc<RefCell<OpState>>,
|
||||||
args: DecryptArg,
|
args: DecryptArg,
|
||||||
zero_copy: Option<ZeroCopyBuf>,
|
zero_copy: ZeroCopyBuf,
|
||||||
) -> Result<ZeroCopyBuf, AnyError> {
|
) -> Result<ZeroCopyBuf, AnyError> {
|
||||||
let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
|
|
||||||
let data = &*zero_copy;
|
let data = &*zero_copy;
|
||||||
let algorithm = args.algorithm;
|
let algorithm = args.algorithm;
|
||||||
|
|
||||||
|
@ -1431,11 +1424,10 @@ pub fn op_crypto_random_uuid(
|
||||||
pub async fn op_crypto_subtle_digest(
|
pub async fn op_crypto_subtle_digest(
|
||||||
_state: Rc<RefCell<OpState>>,
|
_state: Rc<RefCell<OpState>>,
|
||||||
algorithm: CryptoHash,
|
algorithm: CryptoHash,
|
||||||
data: Option<ZeroCopyBuf>,
|
data: ZeroCopyBuf,
|
||||||
) -> Result<ZeroCopyBuf, AnyError> {
|
) -> Result<ZeroCopyBuf, AnyError> {
|
||||||
let input = data.ok_or_else(null_opbuf)?;
|
|
||||||
let output = tokio::task::spawn_blocking(move || {
|
let output = tokio::task::spawn_blocking(move || {
|
||||||
digest::digest(algorithm.into(), &input)
|
digest::digest(algorithm.into(), &data)
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.to_vec()
|
.to_vec()
|
||||||
.into()
|
.into()
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
use data_url::DataUrl;
|
use data_url::DataUrl;
|
||||||
use deno_core::error::null_opbuf;
|
|
||||||
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::futures::Future;
|
use deno_core::futures::Future;
|
||||||
|
@ -341,10 +340,9 @@ pub async fn op_fetch_send(
|
||||||
pub async fn op_fetch_request_write(
|
pub async fn op_fetch_request_write(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
rid: ResourceId,
|
rid: ResourceId,
|
||||||
data: Option<ZeroCopyBuf>,
|
data: ZeroCopyBuf,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let data = data.ok_or_else(null_opbuf)?;
|
let buf = data.to_vec();
|
||||||
let buf = Vec::from(&*data);
|
|
||||||
|
|
||||||
let resource = state
|
let resource = state
|
||||||
.borrow()
|
.borrow()
|
||||||
|
@ -362,10 +360,8 @@ pub async fn op_fetch_request_write(
|
||||||
pub async fn op_fetch_response_read(
|
pub async fn op_fetch_response_read(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
rid: ResourceId,
|
rid: ResourceId,
|
||||||
data: Option<ZeroCopyBuf>,
|
data: ZeroCopyBuf,
|
||||||
) -> Result<usize, AnyError> {
|
) -> Result<usize, AnyError> {
|
||||||
let data = data.ok_or_else(null_opbuf)?;
|
|
||||||
|
|
||||||
let resource = state
|
let resource = state
|
||||||
.borrow()
|
.borrow()
|
||||||
.resource_table
|
.resource_table
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
use deno_core::error::bad_resource_id;
|
use deno_core::error::bad_resource_id;
|
||||||
use deno_core::error::null_opbuf;
|
|
||||||
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::futures::future::poll_fn;
|
use deno_core::futures::future::poll_fn;
|
||||||
|
@ -513,10 +512,8 @@ async fn op_http_response_close(
|
||||||
async fn op_http_request_read(
|
async fn op_http_request_read(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
rid: ResourceId,
|
rid: ResourceId,
|
||||||
data: Option<ZeroCopyBuf>,
|
mut data: ZeroCopyBuf,
|
||||||
) -> Result<usize, AnyError> {
|
) -> Result<usize, AnyError> {
|
||||||
let mut data = data.ok_or_else(null_opbuf)?;
|
|
||||||
|
|
||||||
let resource = state
|
let resource = state
|
||||||
.borrow()
|
.borrow()
|
||||||
.resource_table
|
.resource_table
|
||||||
|
@ -565,9 +562,8 @@ async fn op_http_request_read(
|
||||||
async fn op_http_response_write(
|
async fn op_http_response_write(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
rid: ResourceId,
|
rid: ResourceId,
|
||||||
data: Option<ZeroCopyBuf>,
|
data: ZeroCopyBuf,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let buf = data.ok_or_else(null_opbuf)?;
|
|
||||||
let resource = state
|
let resource = state
|
||||||
.borrow()
|
.borrow()
|
||||||
.resource_table
|
.resource_table
|
||||||
|
@ -580,7 +576,7 @@ async fn op_http_response_write(
|
||||||
|
|
||||||
let mut body = RcRef::map(&resource, |r| &r.body).borrow_mut().await;
|
let mut body = RcRef::map(&resource, |r| &r.body).borrow_mut().await;
|
||||||
|
|
||||||
let mut send_data_fut = body.send_data(Vec::from(&*buf).into()).boxed_local();
|
let mut send_data_fut = body.send_data(data.to_vec().into()).boxed_local();
|
||||||
|
|
||||||
poll_fn(|cx| {
|
poll_fn(|cx| {
|
||||||
let r = send_data_fut.poll_unpin(cx).map_err(AnyError::from);
|
let r = send_data_fut.poll_unpin(cx).map_err(AnyError::from);
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
use crate::ops_tls as tls;
|
use crate::ops_tls as tls;
|
||||||
use deno_core::error::not_supported;
|
use deno_core::error::not_supported;
|
||||||
use deno_core::error::null_opbuf;
|
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::op_async;
|
use deno_core::op_async;
|
||||||
use deno_core::AsyncMutFuture;
|
use deno_core::AsyncMutFuture;
|
||||||
|
@ -166,16 +165,15 @@ impl Resource for UnixStreamResource {
|
||||||
async fn op_read_async(
|
async fn op_read_async(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
rid: ResourceId,
|
rid: ResourceId,
|
||||||
buf: Option<ZeroCopyBuf>,
|
mut buf: ZeroCopyBuf,
|
||||||
) -> Result<u32, AnyError> {
|
) -> Result<u32, AnyError> {
|
||||||
let buf = &mut buf.ok_or_else(null_opbuf)?;
|
|
||||||
let resource = state.borrow().resource_table.get_any(rid)?;
|
let resource = state.borrow().resource_table.get_any(rid)?;
|
||||||
let nread = if let Some(s) = resource.downcast_rc::<TcpStreamResource>() {
|
let nread = if let Some(s) = resource.downcast_rc::<TcpStreamResource>() {
|
||||||
s.read(buf).await?
|
s.read(&mut buf).await?
|
||||||
} else if let Some(s) = resource.downcast_rc::<TlsStreamResource>() {
|
} else if let Some(s) = resource.downcast_rc::<TlsStreamResource>() {
|
||||||
s.read(buf).await?
|
s.read(&mut buf).await?
|
||||||
} else if let Some(s) = resource.downcast_rc::<UnixStreamResource>() {
|
} else if let Some(s) = resource.downcast_rc::<UnixStreamResource>() {
|
||||||
s.read(buf).await?
|
s.read(&mut buf).await?
|
||||||
} else {
|
} else {
|
||||||
return Err(not_supported());
|
return Err(not_supported());
|
||||||
};
|
};
|
||||||
|
@ -185,16 +183,15 @@ async fn op_read_async(
|
||||||
async fn op_write_async(
|
async fn op_write_async(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
rid: ResourceId,
|
rid: ResourceId,
|
||||||
buf: Option<ZeroCopyBuf>,
|
buf: ZeroCopyBuf,
|
||||||
) -> Result<u32, AnyError> {
|
) -> Result<u32, AnyError> {
|
||||||
let buf = &buf.ok_or_else(null_opbuf)?;
|
|
||||||
let resource = state.borrow().resource_table.get_any(rid)?;
|
let resource = state.borrow().resource_table.get_any(rid)?;
|
||||||
let nwritten = if let Some(s) = resource.downcast_rc::<TcpStreamResource>() {
|
let nwritten = if let Some(s) = resource.downcast_rc::<TcpStreamResource>() {
|
||||||
s.write(buf).await?
|
s.write(&buf).await?
|
||||||
} else if let Some(s) = resource.downcast_rc::<TlsStreamResource>() {
|
} else if let Some(s) = resource.downcast_rc::<TlsStreamResource>() {
|
||||||
s.write(buf).await?
|
s.write(&buf).await?
|
||||||
} else if let Some(s) = resource.downcast_rc::<UnixStreamResource>() {
|
} else if let Some(s) = resource.downcast_rc::<UnixStreamResource>() {
|
||||||
s.write(buf).await?
|
s.write(&buf).await?
|
||||||
} else {
|
} else {
|
||||||
return Err(not_supported());
|
return Err(not_supported());
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,6 @@ use crate::NetPermissions;
|
||||||
use deno_core::error::bad_resource;
|
use deno_core::error::bad_resource;
|
||||||
use deno_core::error::custom_error;
|
use deno_core::error::custom_error;
|
||||||
use deno_core::error::generic_error;
|
use deno_core::error::generic_error;
|
||||||
use deno_core::error::null_opbuf;
|
|
||||||
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_async;
|
use deno_core::op_async;
|
||||||
|
@ -167,9 +166,8 @@ pub(crate) struct ReceiveArgs {
|
||||||
async fn receive_udp(
|
async fn receive_udp(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
args: ReceiveArgs,
|
args: ReceiveArgs,
|
||||||
zero_copy: Option<ZeroCopyBuf>,
|
zero_copy: ZeroCopyBuf,
|
||||||
) -> Result<OpPacket, AnyError> {
|
) -> Result<OpPacket, AnyError> {
|
||||||
let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
|
|
||||||
let mut zero_copy = zero_copy.clone();
|
let mut zero_copy = zero_copy.clone();
|
||||||
|
|
||||||
let rid = args.rid;
|
let rid = args.rid;
|
||||||
|
@ -197,7 +195,7 @@ async fn receive_udp(
|
||||||
async fn op_datagram_receive(
|
async fn op_datagram_receive(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
args: ReceiveArgs,
|
args: ReceiveArgs,
|
||||||
zero_copy: Option<ZeroCopyBuf>,
|
zero_copy: ZeroCopyBuf,
|
||||||
) -> Result<OpPacket, AnyError> {
|
) -> Result<OpPacket, AnyError> {
|
||||||
match args.transport.as_str() {
|
match args.transport.as_str() {
|
||||||
"udp" => receive_udp(state, args, zero_copy).await,
|
"udp" => receive_udp(state, args, zero_copy).await,
|
||||||
|
@ -218,12 +216,11 @@ struct SendArgs {
|
||||||
async fn op_datagram_send<NP>(
|
async fn op_datagram_send<NP>(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
args: SendArgs,
|
args: SendArgs,
|
||||||
zero_copy: Option<ZeroCopyBuf>,
|
zero_copy: ZeroCopyBuf,
|
||||||
) -> Result<usize, AnyError>
|
) -> Result<usize, AnyError>
|
||||||
where
|
where
|
||||||
NP: NetPermissions + 'static,
|
NP: NetPermissions + 'static,
|
||||||
{
|
{
|
||||||
let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
|
|
||||||
let zero_copy = zero_copy.clone();
|
let zero_copy = zero_copy.clone();
|
||||||
|
|
||||||
match args {
|
match args {
|
||||||
|
|
|
@ -8,7 +8,6 @@ use crate::ops::OpPacket;
|
||||||
use crate::ops::ReceiveArgs;
|
use crate::ops::ReceiveArgs;
|
||||||
use deno_core::error::bad_resource;
|
use deno_core::error::bad_resource;
|
||||||
use deno_core::error::custom_error;
|
use deno_core::error::custom_error;
|
||||||
use deno_core::error::null_opbuf;
|
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::AsyncRefCell;
|
use deno_core::AsyncRefCell;
|
||||||
use deno_core::CancelHandle;
|
use deno_core::CancelHandle;
|
||||||
|
@ -114,10 +113,8 @@ pub(crate) async fn accept_unix(
|
||||||
pub(crate) async fn receive_unix_packet(
|
pub(crate) async fn receive_unix_packet(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
args: ReceiveArgs,
|
args: ReceiveArgs,
|
||||||
buf: Option<ZeroCopyBuf>,
|
mut buf: ZeroCopyBuf,
|
||||||
) -> Result<OpPacket, AnyError> {
|
) -> Result<OpPacket, AnyError> {
|
||||||
let mut buf = buf.ok_or_else(null_opbuf)?;
|
|
||||||
|
|
||||||
let rid = args.rid;
|
let rid = args.rid;
|
||||||
|
|
||||||
let resource = state
|
let resource = state
|
||||||
|
|
|
@ -93,7 +93,7 @@ impl GlobalTimer {
|
||||||
|
|
||||||
pub fn op_global_timer_stop(
|
pub fn op_global_timer_stop(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
_args: (),
|
_: (),
|
||||||
_: (),
|
_: (),
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let global_timer = state.borrow_mut::<GlobalTimer>();
|
let global_timer = state.borrow_mut::<GlobalTimer>();
|
||||||
|
@ -127,7 +127,7 @@ pub fn op_global_timer_start(
|
||||||
|
|
||||||
pub async fn op_global_timer(
|
pub async fn op_global_timer(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
_args: (),
|
_: (),
|
||||||
_: (),
|
_: (),
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let maybe_timer_fut = {
|
let maybe_timer_fut = {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
use deno_core::error::null_opbuf;
|
|
||||||
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::futures::channel::oneshot;
|
use deno_core::futures::channel::oneshot;
|
||||||
|
@ -171,9 +170,8 @@ pub struct BufferGetMappedRangeArgs {
|
||||||
pub fn op_webgpu_buffer_get_mapped_range(
|
pub fn op_webgpu_buffer_get_mapped_range(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
args: BufferGetMappedRangeArgs,
|
args: BufferGetMappedRangeArgs,
|
||||||
zero_copy: Option<ZeroCopyBuf>,
|
mut zero_copy: ZeroCopyBuf,
|
||||||
) -> Result<WebGpuResult, AnyError> {
|
) -> Result<WebGpuResult, AnyError> {
|
||||||
let mut zero_copy = zero_copy.ok_or_else(null_opbuf)?;
|
|
||||||
let instance = state.borrow::<super::Instance>();
|
let instance = state.borrow::<super::Instance>();
|
||||||
let buffer_resource =
|
let buffer_resource =
|
||||||
state.resource_table.get::<WebGpuBuffer>(args.buffer_rid)?;
|
state.resource_table.get::<WebGpuBuffer>(args.buffer_rid)?;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
use std::num::NonZeroU32;
|
use std::num::NonZeroU32;
|
||||||
|
|
||||||
use deno_core::error::null_opbuf;
|
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::OpState;
|
use deno_core::OpState;
|
||||||
use deno_core::ResourceId;
|
use deno_core::ResourceId;
|
||||||
|
@ -77,9 +76,8 @@ pub struct QueueWriteBufferArgs {
|
||||||
pub fn op_webgpu_write_buffer(
|
pub fn op_webgpu_write_buffer(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
args: QueueWriteBufferArgs,
|
args: QueueWriteBufferArgs,
|
||||||
zero_copy: Option<ZeroCopyBuf>,
|
zero_copy: ZeroCopyBuf,
|
||||||
) -> Result<WebGpuResult, AnyError> {
|
) -> Result<WebGpuResult, AnyError> {
|
||||||
let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
|
|
||||||
let instance = state.borrow::<super::Instance>();
|
let instance = state.borrow::<super::Instance>();
|
||||||
let buffer_resource = state
|
let buffer_resource = state
|
||||||
.resource_table
|
.resource_table
|
||||||
|
@ -116,9 +114,8 @@ pub struct QueueWriteTextureArgs {
|
||||||
pub fn op_webgpu_write_texture(
|
pub fn op_webgpu_write_texture(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
args: QueueWriteTextureArgs,
|
args: QueueWriteTextureArgs,
|
||||||
zero_copy: Option<ZeroCopyBuf>,
|
zero_copy: ZeroCopyBuf,
|
||||||
) -> Result<WebGpuResult, AnyError> {
|
) -> Result<WebGpuResult, AnyError> {
|
||||||
let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
|
|
||||||
let instance = state.borrow::<super::Instance>();
|
let instance = state.borrow::<super::Instance>();
|
||||||
let texture_resource = state
|
let texture_resource = state
|
||||||
.resource_table
|
.resource_table
|
||||||
|
|
|
@ -324,10 +324,10 @@
|
||||||
const sendTypedArray = (ta) => {
|
const sendTypedArray = (ta) => {
|
||||||
this[_bufferedAmount] += ta.byteLength;
|
this[_bufferedAmount] += ta.byteLength;
|
||||||
PromisePrototypeThen(
|
PromisePrototypeThen(
|
||||||
core.opAsync("op_ws_send", {
|
core.opAsync("op_ws_send", this[_rid], {
|
||||||
rid: this[_rid],
|
|
||||||
kind: "binary",
|
kind: "binary",
|
||||||
}, ta),
|
value: ta,
|
||||||
|
}),
|
||||||
() => {
|
() => {
|
||||||
this[_bufferedAmount] -= ta.byteLength;
|
this[_bufferedAmount] -= ta.byteLength;
|
||||||
},
|
},
|
||||||
|
@ -348,10 +348,9 @@
|
||||||
const d = core.encode(string);
|
const d = core.encode(string);
|
||||||
this[_bufferedAmount] += d.byteLength;
|
this[_bufferedAmount] += d.byteLength;
|
||||||
PromisePrototypeThen(
|
PromisePrototypeThen(
|
||||||
core.opAsync("op_ws_send", {
|
core.opAsync("op_ws_send", this[_rid], {
|
||||||
rid: this[_rid],
|
|
||||||
kind: "text",
|
kind: "text",
|
||||||
text: string,
|
value: string,
|
||||||
}),
|
}),
|
||||||
() => {
|
() => {
|
||||||
this[_bufferedAmount] -= d.byteLength;
|
this[_bufferedAmount] -= d.byteLength;
|
||||||
|
@ -456,8 +455,7 @@
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "ping": {
|
case "ping": {
|
||||||
core.opAsync("op_ws_send", {
|
core.opAsync("op_ws_send", this[_rid], {
|
||||||
rid: this[_rid],
|
|
||||||
kind: "pong",
|
kind: "pong",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -190,15 +190,14 @@
|
||||||
const writable = new WritableStream({
|
const writable = new WritableStream({
|
||||||
write: async (chunk) => {
|
write: async (chunk) => {
|
||||||
if (typeof chunk === "string") {
|
if (typeof chunk === "string") {
|
||||||
await core.opAsync("op_ws_send", {
|
await core.opAsync("op_ws_send", this[_rid], {
|
||||||
rid: this[_rid],
|
|
||||||
kind: "text",
|
kind: "text",
|
||||||
text: chunk,
|
value: chunk,
|
||||||
});
|
});
|
||||||
} else if (chunk instanceof Uint8Array) {
|
} else if (chunk instanceof Uint8Array) {
|
||||||
await core.opAsync("op_ws_send", {
|
await core.opAsync("op_ws_send", this[_rid], {
|
||||||
rid: this[_rid],
|
|
||||||
kind: "binary",
|
kind: "binary",
|
||||||
|
value: chunk,
|
||||||
}, chunk);
|
}, chunk);
|
||||||
} else {
|
} else {
|
||||||
throw new TypeError(
|
throw new TypeError(
|
||||||
|
@ -257,8 +256,7 @@
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "ping": {
|
case "ping": {
|
||||||
await core.opAsync("op_ws_send", {
|
await core.opAsync("op_ws_send", this[_rid], {
|
||||||
rid: this[_rid],
|
|
||||||
kind: "pong",
|
kind: "pong",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
use deno_core::error::invalid_hostname;
|
use deno_core::error::invalid_hostname;
|
||||||
use deno_core::error::null_opbuf;
|
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::futures::stream::SplitSink;
|
use deno_core::futures::stream::SplitSink;
|
||||||
use deno_core::futures::stream::SplitStream;
|
use deno_core::futures::stream::SplitStream;
|
||||||
|
@ -309,29 +308,28 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(tag = "kind", content = "value", rename_all = "camelCase")]
|
||||||
pub struct SendArgs {
|
pub enum SendValue {
|
||||||
rid: ResourceId,
|
Text(String),
|
||||||
kind: String,
|
Binary(ZeroCopyBuf),
|
||||||
text: Option<String>,
|
Pong,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn op_ws_send(
|
pub async fn op_ws_send(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
args: SendArgs,
|
rid: ResourceId,
|
||||||
buf: Option<ZeroCopyBuf>,
|
value: SendValue,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
let msg = match args.kind.as_str() {
|
let msg = match value {
|
||||||
"text" => Message::Text(args.text.unwrap()),
|
SendValue::Text(text) => Message::Text(text),
|
||||||
"binary" => Message::Binary(buf.ok_or_else(null_opbuf)?.to_vec()),
|
SendValue::Binary(buf) => Message::Binary(buf.to_vec()),
|
||||||
"pong" => Message::Pong(vec![]),
|
SendValue::Pong => Message::Pong(vec![]),
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let resource = state
|
let resource = state
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.resource_table
|
.resource_table
|
||||||
.get::<WsStreamResource>(args.rid)?;
|
.get::<WsStreamResource>(rid)?;
|
||||||
resource.send(msg).await?;
|
resource.send(msg).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function setEnv(key, value) {
|
function setEnv(key, value) {
|
||||||
core.opSync("op_set_env", { key, value });
|
core.opSync("op_set_env", key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getEnv(key) {
|
function getEnv(key) {
|
||||||
|
|
|
@ -27,7 +27,7 @@ struct MetricsReturn {
|
||||||
|
|
||||||
fn op_metrics(
|
fn op_metrics(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
_args: (),
|
_: (),
|
||||||
_: (),
|
_: (),
|
||||||
) -> Result<MetricsReturn, AnyError> {
|
) -> Result<MetricsReturn, AnyError> {
|
||||||
let m = state.borrow::<RuntimeMetrics>();
|
let m = state.borrow::<RuntimeMetrics>();
|
||||||
|
|
|
@ -1769,7 +1769,7 @@ async fn op_utime_async(
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_cwd(state: &mut OpState, _args: (), _: ()) -> Result<String, AnyError> {
|
fn op_cwd(state: &mut OpState, _: (), _: ()) -> Result<String, AnyError> {
|
||||||
let path = current_dir()?;
|
let path = current_dir()?;
|
||||||
state
|
state
|
||||||
.borrow_mut::<Permissions>()
|
.borrow_mut::<Permissions>()
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
use deno_core::error::not_supported;
|
use deno_core::error::not_supported;
|
||||||
use deno_core::error::null_opbuf;
|
|
||||||
use deno_core::error::resource_unavailable;
|
use deno_core::error::resource_unavailable;
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::op_async;
|
use deno_core::op_async;
|
||||||
|
@ -387,9 +386,8 @@ impl Resource for StdFileResource {
|
||||||
fn op_read_sync(
|
fn op_read_sync(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
rid: ResourceId,
|
rid: ResourceId,
|
||||||
buf: Option<ZeroCopyBuf>,
|
mut buf: ZeroCopyBuf,
|
||||||
) -> Result<u32, AnyError> {
|
) -> Result<u32, AnyError> {
|
||||||
let mut buf = buf.ok_or_else(null_opbuf)?;
|
|
||||||
StdFileResource::with(state, rid, move |r| match r {
|
StdFileResource::with(state, rid, move |r| match r {
|
||||||
Ok(std_file) => std_file
|
Ok(std_file) => std_file
|
||||||
.read(&mut buf)
|
.read(&mut buf)
|
||||||
|
@ -402,22 +400,21 @@ fn op_read_sync(
|
||||||
async fn op_read_async(
|
async fn op_read_async(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
rid: ResourceId,
|
rid: ResourceId,
|
||||||
buf: Option<ZeroCopyBuf>,
|
mut buf: ZeroCopyBuf,
|
||||||
) -> Result<u32, AnyError> {
|
) -> Result<u32, AnyError> {
|
||||||
let buf = &mut buf.ok_or_else(null_opbuf)?;
|
|
||||||
let resource = state.borrow().resource_table.get_any(rid)?;
|
let resource = state.borrow().resource_table.get_any(rid)?;
|
||||||
let nread = if let Some(s) = resource.downcast_rc::<ChildStdoutResource>() {
|
let nread = if let Some(s) = resource.downcast_rc::<ChildStdoutResource>() {
|
||||||
s.read(buf).await?
|
s.read(&mut buf).await?
|
||||||
} else if let Some(s) = resource.downcast_rc::<ChildStderrResource>() {
|
} else if let Some(s) = resource.downcast_rc::<ChildStderrResource>() {
|
||||||
s.read(buf).await?
|
s.read(&mut buf).await?
|
||||||
} else if let Some(s) = resource.downcast_rc::<TcpStreamResource>() {
|
} else if let Some(s) = resource.downcast_rc::<TcpStreamResource>() {
|
||||||
s.read(buf).await?
|
s.read(&mut buf).await?
|
||||||
} else if let Some(s) = resource.downcast_rc::<TlsStreamResource>() {
|
} else if let Some(s) = resource.downcast_rc::<TlsStreamResource>() {
|
||||||
s.read(buf).await?
|
s.read(&mut buf).await?
|
||||||
} else if let Some(s) = resource.downcast_rc::<UnixStreamResource>() {
|
} else if let Some(s) = resource.downcast_rc::<UnixStreamResource>() {
|
||||||
s.read(buf).await?
|
s.read(&mut buf).await?
|
||||||
} else if let Some(s) = resource.downcast_rc::<StdFileResource>() {
|
} else if let Some(s) = resource.downcast_rc::<StdFileResource>() {
|
||||||
s.read(buf).await?
|
s.read(&mut buf).await?
|
||||||
} else {
|
} else {
|
||||||
return Err(not_supported());
|
return Err(not_supported());
|
||||||
};
|
};
|
||||||
|
@ -427,9 +424,8 @@ async fn op_read_async(
|
||||||
fn op_write_sync(
|
fn op_write_sync(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
rid: ResourceId,
|
rid: ResourceId,
|
||||||
buf: Option<ZeroCopyBuf>,
|
buf: ZeroCopyBuf,
|
||||||
) -> Result<u32, AnyError> {
|
) -> Result<u32, AnyError> {
|
||||||
let buf = buf.ok_or_else(null_opbuf)?;
|
|
||||||
StdFileResource::with(state, rid, move |r| match r {
|
StdFileResource::with(state, rid, move |r| match r {
|
||||||
Ok(std_file) => std_file
|
Ok(std_file) => std_file
|
||||||
.write(&buf)
|
.write(&buf)
|
||||||
|
@ -442,20 +438,19 @@ fn op_write_sync(
|
||||||
async fn op_write_async(
|
async fn op_write_async(
|
||||||
state: Rc<RefCell<OpState>>,
|
state: Rc<RefCell<OpState>>,
|
||||||
rid: ResourceId,
|
rid: ResourceId,
|
||||||
buf: Option<ZeroCopyBuf>,
|
buf: ZeroCopyBuf,
|
||||||
) -> Result<u32, AnyError> {
|
) -> Result<u32, AnyError> {
|
||||||
let buf = &buf.ok_or_else(null_opbuf)?;
|
|
||||||
let resource = state.borrow().resource_table.get_any(rid)?;
|
let resource = state.borrow().resource_table.get_any(rid)?;
|
||||||
let nwritten = if let Some(s) = resource.downcast_rc::<ChildStdinResource>() {
|
let nwritten = if let Some(s) = resource.downcast_rc::<ChildStdinResource>() {
|
||||||
s.write(buf).await?
|
s.write(&buf).await?
|
||||||
} else if let Some(s) = resource.downcast_rc::<TcpStreamResource>() {
|
} else if let Some(s) = resource.downcast_rc::<TcpStreamResource>() {
|
||||||
s.write(buf).await?
|
s.write(&buf).await?
|
||||||
} else if let Some(s) = resource.downcast_rc::<TlsStreamResource>() {
|
} else if let Some(s) = resource.downcast_rc::<TlsStreamResource>() {
|
||||||
s.write(buf).await?
|
s.write(&buf).await?
|
||||||
} else if let Some(s) = resource.downcast_rc::<UnixStreamResource>() {
|
} else if let Some(s) = resource.downcast_rc::<UnixStreamResource>() {
|
||||||
s.write(buf).await?
|
s.write(&buf).await?
|
||||||
} else if let Some(s) = resource.downcast_rc::<StdFileResource>() {
|
} else if let Some(s) = resource.downcast_rc::<StdFileResource>() {
|
||||||
s.write(buf).await?
|
s.write(&buf).await?
|
||||||
} else {
|
} else {
|
||||||
return Err(not_supported());
|
return Err(not_supported());
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,6 @@ use deno_core::op_sync;
|
||||||
use deno_core::url::Url;
|
use deno_core::url::Url;
|
||||||
use deno_core::Extension;
|
use deno_core::Extension;
|
||||||
use deno_core::OpState;
|
use deno_core::OpState;
|
||||||
use serde::Deserialize;
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
@ -29,11 +28,7 @@ pub fn init() -> Extension {
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_exec_path(
|
fn op_exec_path(state: &mut OpState, _: (), _: ()) -> Result<String, AnyError> {
|
||||||
state: &mut OpState,
|
|
||||||
_args: (),
|
|
||||||
_: (),
|
|
||||||
) -> Result<String, AnyError> {
|
|
||||||
let current_exe = env::current_exe().unwrap();
|
let current_exe = env::current_exe().unwrap();
|
||||||
state
|
state
|
||||||
.borrow_mut::<Permissions>()
|
.borrow_mut::<Permissions>()
|
||||||
|
@ -47,31 +42,24 @@ fn op_exec_path(
|
||||||
into_string(path.into_os_string())
|
into_string(path.into_os_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
pub struct SetEnv {
|
|
||||||
key: String,
|
|
||||||
value: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn op_set_env(
|
fn op_set_env(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
args: SetEnv,
|
key: String,
|
||||||
_: (),
|
value: String,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
state.borrow_mut::<Permissions>().env.check(&args.key)?;
|
state.borrow_mut::<Permissions>().env.check(&key)?;
|
||||||
let invalid_key =
|
let invalid_key = key.is_empty() || key.contains(&['=', '\0'] as &[char]);
|
||||||
args.key.is_empty() || args.key.contains(&['=', '\0'] as &[char]);
|
let invalid_value = value.contains('\0');
|
||||||
let invalid_value = args.value.contains('\0');
|
|
||||||
if invalid_key || invalid_value {
|
if invalid_key || invalid_value {
|
||||||
return Err(type_error("Key or value contains invalid characters."));
|
return Err(type_error("Key or value contains invalid characters."));
|
||||||
}
|
}
|
||||||
env::set_var(args.key, args.value);
|
env::set_var(key, value);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_env(
|
fn op_env(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
_args: (),
|
_: (),
|
||||||
_: (),
|
_: (),
|
||||||
) -> Result<HashMap<String, String>, AnyError> {
|
) -> Result<HashMap<String, String>, AnyError> {
|
||||||
state.borrow_mut::<Permissions>().env.check_all()?;
|
state.borrow_mut::<Permissions>().env.check_all()?;
|
||||||
|
@ -113,7 +101,7 @@ fn op_exit(_state: &mut OpState, code: i32, _: ()) -> Result<(), AnyError> {
|
||||||
|
|
||||||
fn op_loadavg(
|
fn op_loadavg(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
_args: (),
|
_: (),
|
||||||
_: (),
|
_: (),
|
||||||
) -> Result<(f64, f64, f64), AnyError> {
|
) -> Result<(f64, f64, f64), AnyError> {
|
||||||
super::check_unstable(state, "Deno.loadavg");
|
super::check_unstable(state, "Deno.loadavg");
|
||||||
|
@ -124,11 +112,7 @@ fn op_loadavg(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn op_hostname(
|
fn op_hostname(state: &mut OpState, _: (), _: ()) -> Result<String, AnyError> {
|
||||||
state: &mut OpState,
|
|
||||||
_args: (),
|
|
||||||
_: (),
|
|
||||||
) -> Result<String, AnyError> {
|
|
||||||
super::check_unstable(state, "Deno.hostname");
|
super::check_unstable(state, "Deno.hostname");
|
||||||
state.borrow_mut::<Permissions>().env.check_all()?;
|
state.borrow_mut::<Permissions>().env.check_all()?;
|
||||||
let hostname = sys_info::hostname().unwrap_or_else(|_| "".to_string());
|
let hostname = sys_info::hostname().unwrap_or_else(|_| "".to_string());
|
||||||
|
@ -137,7 +121,7 @@ fn op_hostname(
|
||||||
|
|
||||||
fn op_os_release(
|
fn op_os_release(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
_args: (),
|
_: (),
|
||||||
_: (),
|
_: (),
|
||||||
) -> Result<String, AnyError> {
|
) -> Result<String, AnyError> {
|
||||||
super::check_unstable(state, "Deno.osRelease");
|
super::check_unstable(state, "Deno.osRelease");
|
||||||
|
@ -161,7 +145,7 @@ struct MemInfo {
|
||||||
|
|
||||||
fn op_system_memory_info(
|
fn op_system_memory_info(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
_args: (),
|
_: (),
|
||||||
_: (),
|
_: (),
|
||||||
) -> Result<Option<MemInfo>, AnyError> {
|
) -> Result<Option<MemInfo>, AnyError> {
|
||||||
super::check_unstable(state, "Deno.systemMemoryInfo");
|
super::check_unstable(state, "Deno.systemMemoryInfo");
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub fn init(main_module: ModuleSpecifier) -> Extension {
|
||||||
|
|
||||||
fn op_main_module(
|
fn op_main_module(
|
||||||
state: &mut OpState,
|
state: &mut OpState,
|
||||||
_args: (),
|
_: (),
|
||||||
_: (),
|
_: (),
|
||||||
) -> Result<String, AnyError> {
|
) -> Result<String, AnyError> {
|
||||||
let main = state.borrow::<ModuleSpecifier>().to_string();
|
let main = state.borrow::<ModuleSpecifier>().to_string();
|
||||||
|
|
|
@ -224,7 +224,7 @@ pub fn op_signal_unbind(
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
pub fn op_signal_bind(
|
pub fn op_signal_bind(
|
||||||
_state: &mut OpState,
|
_state: &mut OpState,
|
||||||
_args: (),
|
_: (),
|
||||||
_: (),
|
_: (),
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
Err(generic_error("not implemented"))
|
Err(generic_error("not implemented"))
|
||||||
|
@ -233,7 +233,7 @@ pub fn op_signal_bind(
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
fn op_signal_unbind(
|
fn op_signal_unbind(
|
||||||
_state: &mut OpState,
|
_state: &mut OpState,
|
||||||
_args: (),
|
_: (),
|
||||||
_: (),
|
_: (),
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
Err(generic_error("not implemented"))
|
Err(generic_error("not implemented"))
|
||||||
|
@ -242,7 +242,7 @@ fn op_signal_unbind(
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
async fn op_signal_poll(
|
async fn op_signal_poll(
|
||||||
_state: Rc<RefCell<OpState>>,
|
_state: Rc<RefCell<OpState>>,
|
||||||
_args: (),
|
_: (),
|
||||||
_: (),
|
_: (),
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
Err(generic_error("not implemented"))
|
Err(generic_error("not implemented"))
|
||||||
|
|
Loading…
Reference in a new issue