1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -05:00

refactor(ops): remove variadic buffers (#9944)

This commit is contained in:
Aaron O'Mullan 2021-04-02 15:47:57 +02:00 committed by GitHub
parent adf5761090
commit 058579da56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 332 additions and 385 deletions

1
Cargo.lock generated
View file

@ -576,7 +576,6 @@ dependencies = [
"serde",
"serde_json",
"serde_v8",
"smallvec",
"tokio",
"url",
]

View file

@ -30,7 +30,7 @@ struct ApplySourceMap {
fn op_apply_source_map(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let args: ApplySourceMap = serde_json::from_value(args)?;
@ -56,7 +56,7 @@ fn op_apply_source_map(
fn op_format_diagnostic(
_state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let diagnostic: Diagnostics = serde_json::from_value(args)?;
Ok(json!(diagnostic.to_string()))

View file

@ -7,7 +7,6 @@ use deno_core::error::AnyError;
use deno_core::json_op_async;
use deno_core::json_op_sync;
use deno_core::serde_json::Value;
use deno_core::BufVec;
use deno_core::JsRuntime;
use deno_core::OpState;
use deno_core::ZeroCopyBuf;
@ -18,7 +17,7 @@ use std::rc::Rc;
pub fn reg_json_async<F, R>(rt: &mut JsRuntime, name: &'static str, op_fn: F)
where
F: Fn(Rc<RefCell<OpState>>, Value, BufVec) -> R + 'static,
F: Fn(Rc<RefCell<OpState>>, Value, Option<ZeroCopyBuf>) -> R + 'static,
R: Future<Output = Result<Value, AnyError>> + 'static,
{
rt.register_op(name, metrics_op(name, json_op_async(op_fn)));
@ -26,7 +25,7 @@ where
pub fn reg_json_sync<F>(rt: &mut JsRuntime, name: &'static str, op_fn: F)
where
F: Fn(&mut OpState, Value, &mut [ZeroCopyBuf]) -> Result<Value, AnyError>
F: Fn(&mut OpState, Value, Option<ZeroCopyBuf>) -> Result<Value, AnyError>
+ 'static,
{
rt.register_op(name, metrics_op(name, json_op_sync(op_fn)));

View file

@ -17,8 +17,8 @@ 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::BufVec;
use deno_core::OpState;
use deno_core::ZeroCopyBuf;
use deno_runtime::permissions::Permissions;
use serde::Deserialize;
use std::cell::RefCell;
@ -54,7 +54,7 @@ struct EmitArgs {
async fn op_emit(
state: Rc<RefCell<OpState>>,
args: Value,
_data: BufVec,
_data: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
deno_runtime::ops::check_unstable2(&state, "Deno.emit");
let args: EmitArgs = serde_json::from_value(args)?;

View file

@ -25,7 +25,6 @@ rusty_v8 = "0.21.0"
serde = { version = "1.0.123", features = ["derive"] }
serde_json = { version = "1.0.62", features = ["preserve_order"] }
serde_v8 = { version = "0.1.0", path = "../serde_v8" }
smallvec = "1.6.1"
url = { version = "2.2.0", features = ["serde"] }
[[example]]

View file

@ -59,6 +59,10 @@ 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
/// 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

View file

@ -35,7 +35,7 @@ fn main() {
}
// Write the contents of every buffer to stdout
for buf in zero_copy {
if let Some(buf) = zero_copy {
out.write_all(&buf).unwrap();
}

View file

@ -1,8 +1,8 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use deno_core::error::bad_resource_id;
use deno_core::error::null_opbuf;
use deno_core::error::AnyError;
use deno_core::AsyncRefCell;
use deno_core::BufVec;
use deno_core::CancelHandle;
use deno_core::CancelTryFuture;
use deno_core::JsRuntime;
@ -122,7 +122,7 @@ fn create_js_runtime() -> JsRuntime {
fn op_listen(
state: &mut OpState,
_rid: ResourceId,
_bufs: &mut [ZeroCopyBuf],
_bufs: Option<ZeroCopyBuf>,
) -> Result<u32, AnyError> {
log::debug!("listen");
let addr = "127.0.0.1:4544".parse::<SocketAddr>().unwrap();
@ -136,7 +136,7 @@ fn op_listen(
fn op_close(
state: &mut OpState,
rid: ResourceId,
_bufs: &mut [ZeroCopyBuf],
_bufs: Option<ZeroCopyBuf>,
) -> Result<u32, AnyError> {
log::debug!("close rid={}", rid);
state
@ -149,7 +149,7 @@ fn op_close(
async fn op_accept(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
_bufs: BufVec,
_bufs: Option<ZeroCopyBuf>,
) -> Result<u32, AnyError> {
log::debug!("accept rid={}", rid);
@ -166,9 +166,9 @@ async fn op_accept(
async fn op_read(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
mut bufs: BufVec,
buf: Option<ZeroCopyBuf>,
) -> Result<u32, AnyError> {
assert_eq!(bufs.len(), 1, "Invalid number of arguments");
let mut buf = buf.ok_or_else(null_opbuf)?;
log::debug!("read rid={}", rid);
let stream = state
@ -176,16 +176,16 @@ async fn op_read(
.resource_table
.get::<TcpStream>(rid)
.ok_or_else(bad_resource_id)?;
let nread = stream.read(&mut bufs[0]).await?;
let nread = stream.read(&mut buf).await?;
Ok(nread as u32)
}
async fn op_write(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
bufs: BufVec,
buf: Option<ZeroCopyBuf>,
) -> Result<u32, AnyError> {
assert_eq!(bufs.len(), 1, "Invalid number of arguments");
let buf = buf.ok_or_else(null_opbuf)?;
log::debug!("write rid={}", rid);
let stream = state
@ -193,7 +193,7 @@ async fn op_write(
.resource_table
.get::<TcpStream>(rid)
.ok_or_else(bad_resource_id)?;
let nwritten = stream.write(&bufs[0]).await?;
let nwritten = stream.write(&buf).await?;
Ok(nwritten as u32)
}

View file

@ -1,8 +1,8 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use deno_core::error::bad_resource_id;
use deno_core::error::null_opbuf;
use deno_core::error::AnyError;
use deno_core::AsyncRefCell;
use deno_core::BufVec;
use deno_core::CancelHandle;
use deno_core::CancelTryFuture;
use deno_core::JsRuntime;
@ -122,7 +122,7 @@ fn create_js_runtime() -> JsRuntime {
fn op_listen(
state: &mut OpState,
_args: (),
_bufs: &mut [ZeroCopyBuf],
_bufs: Option<ZeroCopyBuf>,
) -> Result<ResourceId, AnyError> {
log::debug!("listen");
let addr = "127.0.0.1:4544".parse::<SocketAddr>().unwrap();
@ -136,7 +136,7 @@ fn op_listen(
fn op_close(
state: &mut OpState,
rid: ResourceId,
_buf: &mut [ZeroCopyBuf],
_buf: Option<ZeroCopyBuf>,
) -> Result<(), AnyError> {
log::debug!("close rid={}", rid);
state
@ -149,7 +149,7 @@ fn op_close(
async fn op_accept(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
_bufs: BufVec,
_buf: Option<ZeroCopyBuf>,
) -> Result<ResourceId, AnyError> {
log::debug!("accept rid={}", rid);
@ -166,9 +166,9 @@ async fn op_accept(
async fn op_read(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
mut bufs: BufVec,
buf: Option<ZeroCopyBuf>,
) -> Result<usize, AnyError> {
assert_eq!(bufs.len(), 1, "Invalid number of arguments");
let mut buf = buf.ok_or_else(null_opbuf)?;
log::debug!("read rid={}", rid);
let stream = state
@ -176,16 +176,16 @@ async fn op_read(
.resource_table
.get::<TcpStream>(rid)
.ok_or_else(bad_resource_id)?;
let nread = stream.read(&mut bufs[0]).await?;
let nread = stream.read(&mut buf).await?;
Ok(nread)
}
async fn op_write(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
bufs: BufVec,
buf: Option<ZeroCopyBuf>,
) -> Result<usize, AnyError> {
assert_eq!(bufs.len(), 1, "Invalid number of arguments");
let buf = buf.ok_or_else(null_opbuf)?;
log::debug!("write rid={}", rid);
let stream = state
@ -193,7 +193,7 @@ async fn op_write(
.resource_table
.get::<TcpStream>(rid)
.ok_or_else(bad_resource_id)?;
let nwritten = stream.write(&bufs[0]).await?;
let nwritten = stream.write(&buf).await?;
Ok(nwritten)
}

View file

@ -79,7 +79,6 @@ pub use crate::runtime::JsErrorCreateFn;
pub use crate::runtime::JsRuntime;
pub use crate::runtime::RuntimeOptions;
pub use crate::runtime::Snapshot;
pub use crate::zero_copy_buf::BufVec;
pub use crate::zero_copy_buf::ZeroCopyBuf;
pub fn v8_version() -> &'static str {

View file

@ -191,7 +191,7 @@ impl Default for OpTable {
pub fn op_resources(
state: &mut OpState,
_args: Value,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let serialized_resources: HashMap<u32, String> = state
.resource_table
@ -207,7 +207,7 @@ pub fn op_resources(
pub fn op_close(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let rid = args
.get("rid")

View file

@ -1,10 +1,8 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use crate::error::type_error;
use crate::error::AnyError;
use crate::futures::future::FutureExt;
use crate::serialize_op_result;
use crate::BufVec;
use crate::Op;
use crate::OpFn;
use crate::OpPayload;
@ -66,26 +64,13 @@ impl ValueOrVector for u32 {
/// A more complete example is available in the examples directory.
pub fn bin_op_sync<F, R>(op_fn: F) -> Box<OpFn>
where
F: Fn(&mut OpState, u32, &mut [ZeroCopyBuf]) -> Result<R, AnyError> + 'static,
F:
Fn(&mut OpState, u32, Option<ZeroCopyBuf>) -> Result<R, AnyError> + 'static,
R: ValueOrVector,
{
Box::new(move |state, payload, buf| -> Op {
let min_arg: u32 = payload.deserialize().unwrap();
// For sig compat map Option<ZeroCopyBuf> to BufVec
let mut bufs: BufVec = match buf {
Some(b) => vec![b],
None => vec![],
}
.into();
// Bin op buffer arg assert
if bufs.is_empty() {
return Op::Sync(serialize_bin_result::<u32>(
Err(type_error("bin-ops require a non-null buffer arg")),
state,
));
}
let result = op_fn(&mut state.borrow_mut(), min_arg, &mut bufs);
let result = op_fn(&mut state.borrow_mut(), min_arg, buf);
Op::Sync(serialize_bin_result(result, state))
})
}
@ -138,7 +123,7 @@ where
/// A more complete example is available in the examples directory.
pub fn bin_op_async<F, R, RV>(op_fn: F) -> Box<OpFn>
where
F: Fn(Rc<RefCell<OpState>>, u32, BufVec) -> R + 'static,
F: Fn(Rc<RefCell<OpState>>, u32, Option<ZeroCopyBuf>) -> R + 'static,
R: Future<Output = Result<RV, AnyError>> + 'static,
RV: ValueOrVector,
{
@ -148,21 +133,7 @@ where
b: Option<ZeroCopyBuf>|
-> Op {
let min_arg: u32 = p.deserialize().unwrap();
// For sig compat map Option<ZeroCopyBuf> to BufVec
let bufs: BufVec = match b {
Some(b) => vec![b],
None => vec![],
}
.into();
// Bin op buffer arg assert
if bufs.is_empty() {
return Op::Sync(serialize_bin_result::<u32>(
Err(type_error("bin-ops require a non-null buffer arg")),
state,
));
}
let fut = op_fn(state.clone(), min_arg, bufs)
let fut = op_fn(state.clone(), min_arg, b)
.map(move |result| serialize_bin_result(result, state));
let temp = Box::pin(fut);
Op::Async(temp)

View file

@ -2,7 +2,6 @@
use crate::error::AnyError;
use crate::serialize_op_result;
use crate::BufVec;
use crate::Op;
use crate::OpFn;
use crate::OpPayload;
@ -39,21 +38,14 @@ use std::rc::Rc;
/// A more complete example is available in the examples directory.
pub fn json_op_sync<F, V, R>(op_fn: F) -> Box<OpFn>
where
F: Fn(&mut OpState, V, &mut [ZeroCopyBuf]) -> Result<R, AnyError> + 'static,
F: Fn(&mut OpState, V, Option<ZeroCopyBuf>) -> Result<R, AnyError> + 'static,
V: DeserializeOwned,
R: Serialize + 'static,
{
Box::new(move |state, payload, buf: Option<ZeroCopyBuf>| -> Op {
// For sig compat map Option<ZeroCopyBuf> to BufVec
let mut bufs: BufVec = match buf {
Some(b) => vec![b],
None => vec![],
}
.into();
Box::new(move |state, payload, buf| -> Op {
let result = payload
.deserialize()
.and_then(|args| op_fn(&mut state.borrow_mut(), args, &mut bufs));
.and_then(|args| op_fn(&mut state.borrow_mut(), args, buf));
Op::Sync(serialize_op_result(result, state))
})
}
@ -84,26 +76,20 @@ where
/// A more complete example is available in the examples directory.
pub fn json_op_async<F, V, R, RV>(op_fn: F) -> Box<OpFn>
where
F: Fn(Rc<RefCell<OpState>>, V, BufVec) -> R + 'static,
F: Fn(Rc<RefCell<OpState>>, V, Option<ZeroCopyBuf>) -> R + 'static,
V: DeserializeOwned,
R: Future<Output = Result<RV, AnyError>> + 'static,
RV: Serialize + 'static,
{
let try_dispatch_op = move |state: Rc<RefCell<OpState>>,
p: OpPayload,
b: Option<ZeroCopyBuf>|
buf: Option<ZeroCopyBuf>|
-> Result<Op, AnyError> {
// For sig compat map Option<ZeroCopyBuf> to BufVec
let bufs: BufVec = match b {
Some(b) => vec![b],
None => vec![],
}
.into();
// Parse args
let args = p.deserialize()?;
use crate::futures::FutureExt;
let fut = op_fn(state.clone(), args, bufs)
let fut = op_fn(state.clone(), args, buf)
.map(move |result| serialize_op_result(result, state));
Ok(Op::Async(Box::pin(fut)))
};

View file

@ -15,7 +15,7 @@ pub use crate::ZeroCopyBuf;
pub type InitFn = fn(&mut dyn Interface);
pub type DispatchOpFn = fn(&mut dyn Interface, &mut [ZeroCopyBuf]) -> Op;
pub type DispatchOpFn = fn(&mut dyn Interface, Option<ZeroCopyBuf>) -> Op;
pub trait Interface {
fn register_op(&mut self, name: &str, dispatcher: DispatchOpFn) -> OpId;

View file

@ -2,12 +2,9 @@
use crate::bindings;
use rusty_v8 as v8;
use smallvec::SmallVec;
use std::ops::Deref;
use std::ops::DerefMut;
pub type BufVec = SmallVec<[ZeroCopyBuf; 2]>;
/// A ZeroCopyBuf encapsulates a slice that's been borrowed from a JavaScript
/// ArrayBuffer object. JavaScript objects can normally be garbage collected,
/// but the existence of a ZeroCopyBuf inhibits this until it is dropped. It

View file

@ -2,6 +2,7 @@
#![deny(warnings)]
use deno_core::error::null_opbuf;
use deno_core::error::AnyError;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
@ -29,15 +30,15 @@ pub fn init(isolate: &mut JsRuntime) {
pub fn op_crypto_get_random_values(
state: &mut OpState,
_args: Value,
zero_copy: &mut [ZeroCopyBuf],
zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
assert_eq!(zero_copy.len(), 1);
let mut zero_copy = zero_copy.ok_or_else(null_opbuf)?;
let maybe_seeded_rng = state.try_borrow_mut::<StdRng>();
if let Some(seeded_rng) = maybe_seeded_rng {
seeded_rng.fill(&mut *zero_copy[0]);
seeded_rng.fill(&mut *zero_copy);
} else {
let mut rng = thread_rng();
rng.fill(&mut *zero_copy[0]);
rng.fill(&mut *zero_copy);
}
Ok(json!({}))

View file

@ -4,6 +4,7 @@
use deno_core::error::bad_resource_id;
use deno_core::error::generic_error;
use deno_core::error::null_opbuf;
use deno_core::error::type_error;
use deno_core::error::AnyError;
use deno_core::futures::Future;
@ -13,7 +14,6 @@ use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_core::url::Url;
use deno_core::AsyncRefCell;
use deno_core::BufVec;
use deno_core::CancelFuture;
use deno_core::CancelHandle;
use deno_core::CancelTryFuture;
@ -124,7 +124,7 @@ pub struct FetchArgs {
pub fn op_fetch<FP>(
state: &mut OpState,
args: FetchArgs,
data: &mut [ZeroCopyBuf],
data: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError>
where
FP: FetchPermissions + 'static,
@ -165,8 +165,8 @@ where
let mut request = client.request(method, url);
let maybe_request_body_rid = if args.has_body {
match data.len() {
0 => {
match data {
None => {
// If no body is passed, we return a writer for streaming the body.
let (tx, rx) = mpsc::channel::<std::io::Result<Vec<u8>>>(1);
request = request.body(Body::wrap_stream(ReceiverStream::new(rx)));
@ -179,12 +179,11 @@ where
Some(request_body_rid)
}
1 => {
Some(data) => {
// If a body is passed, we use it, and don't return a body for streaming.
request = request.body(Vec::from(&*data[0]));
request = request.body(Vec::from(&*data));
None
}
_ => panic!("Invalid number of arguments"),
}
} else {
None
@ -217,7 +216,7 @@ pub struct FetchSendArgs {
pub async fn op_fetch_send(
state: Rc<RefCell<OpState>>,
args: FetchSendArgs,
_data: BufVec,
_data: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let request = state
.borrow_mut()
@ -285,14 +284,11 @@ pub struct FetchRequestWriteArgs {
pub async fn op_fetch_request_write(
state: Rc<RefCell<OpState>>,
args: FetchRequestWriteArgs,
data: BufVec,
data: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let rid = args.rid;
let buf = match data.len() {
1 => Vec::from(&*data[0]),
_ => panic!("Invalid number of arguments"),
};
let data = data.ok_or_else(null_opbuf)?;
let buf = Vec::from(&*data);
let resource = state
.borrow()
@ -315,13 +311,10 @@ pub struct FetchResponseReadArgs {
pub async fn op_fetch_response_read(
state: Rc<RefCell<OpState>>,
args: FetchResponseReadArgs,
data: BufVec,
data: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let rid = args.rid;
if data.len() != 1 {
panic!("Invalid number of arguments");
}
let data = data.ok_or_else(null_opbuf)?;
let resource = state
.borrow()
@ -330,7 +323,7 @@ pub async fn op_fetch_response_read(
.ok_or_else(bad_resource_id)?;
let mut reader = RcRef::map(&resource, |r| &r.reader).borrow_mut().await;
let cancel = RcRef::map(resource, |r| &r.cancel);
let mut buf = data[0].clone();
let mut buf = data.clone();
let read = reader.read(&mut buf).try_or_cancel(cancel).await?;
Ok(json!({ "read": read }))
}
@ -397,7 +390,7 @@ pub struct CreateHttpClientOptions {
pub fn op_create_http_client<FP>(
state: &mut OpState,
args: CreateHttpClientOptions,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError>
where
FP: FetchPermissions + 'static,

View file

@ -39,7 +39,7 @@ pub struct UrlParseArgs {
pub fn op_url_parse(
_state: &mut deno_core::OpState,
args: UrlParseArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let base_url = args
.base_href
@ -120,7 +120,7 @@ pub fn op_url_parse(
pub fn op_url_parse_search_params(
_state: &mut deno_core::OpState,
args: String,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let search_params: Vec<_> = form_urlencoded::parse(args.as_bytes())
.into_iter()
@ -131,7 +131,7 @@ pub fn op_url_parse_search_params(
pub fn op_url_stringify_search_params(
_state: &mut deno_core::OpState,
args: Vec<(String, String)>,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let search = form_urlencoded::Serializer::new(String::new())
.extend_pairs(args)

View file

@ -82,7 +82,7 @@ pub struct CreateBindGroupLayoutArgs {
pub fn op_webgpu_create_bind_group_layout(
state: &mut OpState,
args: CreateBindGroupLayoutArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let device_resource = state
@ -224,7 +224,7 @@ pub struct CreatePipelineLayoutArgs {
pub fn op_webgpu_create_pipeline_layout(
state: &mut OpState,
args: CreatePipelineLayoutArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let device_resource = state
@ -287,7 +287,7 @@ pub struct CreateBindGroupArgs {
pub fn op_webgpu_create_bind_group(
state: &mut OpState,
args: CreateBindGroupArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let device_resource = state

View file

@ -1,14 +1,15 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use deno_core::error::bad_resource_id;
use deno_core::error::null_opbuf;
use deno_core::error::AnyError;
use deno_core::futures::channel::oneshot;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_core::OpState;
use deno_core::Resource;
use deno_core::ResourceId;
use deno_core::ZeroCopyBuf;
use deno_core::{BufVec, Resource};
use serde::Deserialize;
use std::borrow::Cow;
use std::cell::RefCell;
@ -45,7 +46,7 @@ pub struct CreateBufferArgs {
pub fn op_webgpu_create_buffer(
state: &mut OpState,
args: CreateBufferArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let device_resource = state
@ -88,7 +89,7 @@ pub struct BufferGetMapAsyncArgs {
pub async fn op_webgpu_buffer_get_map_async(
state: Rc<RefCell<OpState>>,
args: BufferGetMapAsyncArgs,
_bufs: BufVec,
_bufs: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let (sender, receiver) = oneshot::channel::<Result<(), AnyError>>();
@ -177,8 +178,9 @@ pub struct BufferGetMappedRangeArgs {
pub fn op_webgpu_buffer_get_mapped_range(
state: &mut OpState,
args: BufferGetMappedRangeArgs,
zero_copy: &mut [ZeroCopyBuf],
zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let mut zero_copy = zero_copy.ok_or_else(null_opbuf)?;
let instance = state.borrow::<super::Instance>();
let buffer_resource = state
.resource_table
@ -196,7 +198,7 @@ pub fn op_webgpu_buffer_get_mapped_range(
let slice = unsafe {
std::slice::from_raw_parts_mut(slice_pointer, args.size as usize)
};
zero_copy[0].copy_from_slice(slice);
zero_copy.copy_from_slice(slice);
let rid = state
.resource_table
@ -217,7 +219,7 @@ pub struct BufferUnmapArgs {
pub fn op_webgpu_buffer_unmap(
state: &mut OpState,
args: BufferUnmapArgs,
zero_copy: &mut [ZeroCopyBuf],
zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let mapped_resource = state
.resource_table
@ -233,7 +235,7 @@ pub fn op_webgpu_buffer_unmap(
let slice_pointer = mapped_resource.0;
let size = mapped_resource.1;
if let Some(buffer) = zero_copy.get(0) {
if let Some(buffer) = zero_copy {
let slice = unsafe { std::slice::from_raw_parts_mut(slice_pointer, size) };
slice.copy_from_slice(&buffer);
}

View file

@ -1,6 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use deno_core::error::bad_resource_id;
use deno_core::error::null_opbuf;
use deno_core::error::AnyError;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
@ -44,7 +45,7 @@ pub struct CreateRenderBundleEncoderArgs {
pub fn op_webgpu_create_render_bundle_encoder(
state: &mut OpState,
args: CreateRenderBundleEncoderArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let device_resource = state
.resource_table
@ -100,7 +101,7 @@ pub struct RenderBundleEncoderFinishArgs {
pub fn op_webgpu_render_bundle_encoder_finish(
state: &mut OpState,
args: RenderBundleEncoderFinishArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let render_bundle_encoder_resource = state
.resource_table
@ -143,8 +144,10 @@ pub struct RenderBundleEncoderSetBindGroupArgs {
pub fn op_webgpu_render_bundle_encoder_set_bind_group(
state: &mut OpState,
args: RenderBundleEncoderSetBindGroupArgs,
zero_copy: &mut [ZeroCopyBuf],
zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
let bind_group_resource = state
.resource_table
.get::<super::binding::WebGpuBindGroup>(args.bind_group)
@ -170,7 +173,7 @@ pub fn op_webgpu_render_bundle_encoder_set_bind_group(
);
},
None => {
let (prefix, data, suffix) = unsafe { zero_copy[0].align_to::<u32>() };
let (prefix, data, suffix) = unsafe { zero_copy.align_to::<u32>() };
assert!(prefix.is_empty());
assert!(suffix.is_empty());
unsafe {
@ -198,7 +201,7 @@ pub struct RenderBundleEncoderPushDebugGroupArgs {
pub fn op_webgpu_render_bundle_encoder_push_debug_group(
state: &mut OpState,
args: RenderBundleEncoderPushDebugGroupArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let render_bundle_encoder_resource = state
.resource_table
@ -225,7 +228,7 @@ pub struct RenderBundleEncoderPopDebugGroupArgs {
pub fn op_webgpu_render_bundle_encoder_pop_debug_group(
state: &mut OpState,
args: RenderBundleEncoderPopDebugGroupArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let render_bundle_encoder_resource = state
.resource_table
@ -251,7 +254,7 @@ pub struct RenderBundleEncoderInsertDebugMarkerArgs {
pub fn op_webgpu_render_bundle_encoder_insert_debug_marker(
state: &mut OpState,
args: RenderBundleEncoderInsertDebugMarkerArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let render_bundle_encoder_resource = state
.resource_table
@ -279,7 +282,7 @@ pub struct RenderBundleEncoderSetPipelineArgs {
pub fn op_webgpu_render_bundle_encoder_set_pipeline(
state: &mut OpState,
args: RenderBundleEncoderSetPipelineArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let render_pipeline_resource = state
.resource_table
@ -311,7 +314,7 @@ pub struct RenderBundleEncoderSetIndexBufferArgs {
pub fn op_webgpu_render_bundle_encoder_set_index_buffer(
state: &mut OpState,
args: RenderBundleEncoderSetIndexBufferArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let buffer_resource = state
.resource_table
@ -348,7 +351,7 @@ pub struct RenderBundleEncoderSetVertexBufferArgs {
pub fn op_webgpu_render_bundle_encoder_set_vertex_buffer(
state: &mut OpState,
args: RenderBundleEncoderSetVertexBufferArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let buffer_resource = state
.resource_table
@ -383,7 +386,7 @@ pub struct RenderBundleEncoderDrawArgs {
pub fn op_webgpu_render_bundle_encoder_draw(
state: &mut OpState,
args: RenderBundleEncoderDrawArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let render_bundle_encoder_resource = state
.resource_table
@ -415,7 +418,7 @@ pub struct RenderBundleEncoderDrawIndexedArgs {
pub fn op_webgpu_render_bundle_encoder_draw_indexed(
state: &mut OpState,
args: RenderBundleEncoderDrawIndexedArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let render_bundle_encoder_resource = state
.resource_table
@ -445,7 +448,7 @@ pub struct RenderBundleEncoderDrawIndirectArgs {
pub fn op_webgpu_render_bundle_encoder_draw_indirect(
state: &mut OpState,
args: RenderBundleEncoderDrawIndirectArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let buffer_resource = state
.resource_table

View file

@ -50,7 +50,7 @@ pub struct CreateCommandEncoderArgs {
pub fn op_webgpu_create_command_encoder(
state: &mut OpState,
args: CreateCommandEncoderArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let device_resource = state
@ -116,7 +116,7 @@ pub struct CommandEncoderBeginRenderPassArgs {
pub fn op_webgpu_command_encoder_begin_render_pass(
state: &mut OpState,
args: CommandEncoderBeginRenderPassArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let command_encoder_resource = state
.resource_table
@ -251,7 +251,7 @@ pub struct CommandEncoderBeginComputePassArgs {
pub fn op_webgpu_command_encoder_begin_compute_pass(
state: &mut OpState,
args: CommandEncoderBeginComputePassArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let command_encoder_resource = state
.resource_table
@ -292,7 +292,7 @@ pub struct CommandEncoderCopyBufferToBufferArgs {
pub fn op_webgpu_command_encoder_copy_buffer_to_buffer(
state: &mut OpState,
args: CommandEncoderCopyBufferToBufferArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let command_encoder_resource = state
@ -361,7 +361,7 @@ pub struct CommandEncoderCopyBufferToTextureArgs {
pub fn op_webgpu_command_encoder_copy_buffer_to_texture(
state: &mut OpState,
args: CommandEncoderCopyBufferToTextureArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let command_encoder_resource = state
@ -424,7 +424,7 @@ pub struct CommandEncoderCopyTextureToBufferArgs {
pub fn op_webgpu_command_encoder_copy_texture_to_buffer(
state: &mut OpState,
args: CommandEncoderCopyTextureToBufferArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let command_encoder_resource = state
@ -486,7 +486,7 @@ pub struct CommandEncoderCopyTextureToTextureArgs {
pub fn op_webgpu_command_encoder_copy_texture_to_texture(
state: &mut OpState,
args: CommandEncoderCopyTextureToTextureArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let command_encoder_resource = state
@ -550,7 +550,7 @@ pub struct CommandEncoderPushDebugGroupArgs {
pub fn op_webgpu_command_encoder_push_debug_group(
state: &mut OpState,
args: CommandEncoderPushDebugGroupArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let command_encoder_resource = state
@ -575,7 +575,7 @@ pub struct CommandEncoderPopDebugGroupArgs {
pub fn op_webgpu_command_encoder_pop_debug_group(
state: &mut OpState,
args: CommandEncoderPopDebugGroupArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let command_encoder_resource = state
@ -599,7 +599,7 @@ pub struct CommandEncoderInsertDebugMarkerArgs {
pub fn op_webgpu_command_encoder_insert_debug_marker(
state: &mut OpState,
args: CommandEncoderInsertDebugMarkerArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let command_encoder_resource = state
@ -627,7 +627,7 @@ pub struct CommandEncoderWriteTimestampArgs {
pub fn op_webgpu_command_encoder_write_timestamp(
state: &mut OpState,
args: CommandEncoderWriteTimestampArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let command_encoder_resource = state
@ -665,7 +665,7 @@ pub struct CommandEncoderResolveQuerySetArgs {
pub fn op_webgpu_command_encoder_resolve_query_set(
state: &mut OpState,
args: CommandEncoderResolveQuerySetArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let command_encoder_resource = state
@ -706,7 +706,7 @@ pub struct CommandEncoderFinishArgs {
pub fn op_webgpu_command_encoder_finish(
state: &mut OpState,
args: CommandEncoderFinishArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let command_encoder_resource = state
.resource_table

View file

@ -1,6 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use deno_core::error::bad_resource_id;
use deno_core::error::null_opbuf;
use deno_core::error::AnyError;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
@ -32,7 +33,7 @@ pub struct ComputePassSetPipelineArgs {
pub fn op_webgpu_compute_pass_set_pipeline(
state: &mut OpState,
args: ComputePassSetPipelineArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let compute_pipeline_resource = state
.resource_table
@ -63,7 +64,7 @@ pub struct ComputePassDispatchArgs {
pub fn op_webgpu_compute_pass_dispatch(
state: &mut OpState,
args: ComputePassDispatchArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let compute_pass_resource = state
.resource_table
@ -91,7 +92,7 @@ pub struct ComputePassDispatchIndirectArgs {
pub fn op_webgpu_compute_pass_dispatch_indirect(
state: &mut OpState,
args: ComputePassDispatchIndirectArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let buffer_resource = state
.resource_table
@ -122,7 +123,7 @@ pub struct ComputePassBeginPipelineStatisticsQueryArgs {
pub fn op_webgpu_compute_pass_begin_pipeline_statistics_query(
state: &mut OpState,
args: ComputePassBeginPipelineStatisticsQueryArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let compute_pass_resource = state
.resource_table
@ -153,7 +154,7 @@ pub struct ComputePassEndPipelineStatisticsQueryArgs {
pub fn op_webgpu_compute_pass_end_pipeline_statistics_query(
state: &mut OpState,
args: ComputePassEndPipelineStatisticsQueryArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let compute_pass_resource = state
.resource_table
@ -180,7 +181,7 @@ pub struct ComputePassWriteTimestampArgs {
pub fn op_webgpu_compute_pass_write_timestamp(
state: &mut OpState,
args: ComputePassWriteTimestampArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let compute_pass_resource = state
.resource_table
@ -212,7 +213,7 @@ pub struct ComputePassEndPassArgs {
pub fn op_webgpu_compute_pass_end_pass(
state: &mut OpState,
args: ComputePassEndPassArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let command_encoder_resource = state
.resource_table
@ -252,7 +253,7 @@ pub struct ComputePassSetBindGroupArgs {
pub fn op_webgpu_compute_pass_set_bind_group(
state: &mut OpState,
args: ComputePassSetBindGroupArgs,
zero_copy: &mut [ZeroCopyBuf],
zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let bind_group_resource = state
.resource_table
@ -271,7 +272,8 @@ pub fn op_webgpu_compute_pass_set_bind_group(
match args.dynamic_offsets_data {
Some(data) => data.as_ptr(),
None => {
let (prefix, data, suffix) = zero_copy[0].align_to::<u32>();
let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
let (prefix, data, suffix) = zero_copy.align_to::<u32>();
assert!(prefix.is_empty());
assert!(suffix.is_empty());
data[args.dynamic_offsets_data_start..].as_ptr()
@ -294,7 +296,7 @@ pub struct ComputePassPushDebugGroupArgs {
pub fn op_webgpu_compute_pass_push_debug_group(
state: &mut OpState,
args: ComputePassPushDebugGroupArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let compute_pass_resource = state
.resource_table
@ -322,7 +324,7 @@ pub struct ComputePassPopDebugGroupArgs {
pub fn op_webgpu_compute_pass_pop_debug_group(
state: &mut OpState,
args: ComputePassPopDebugGroupArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let compute_pass_resource = state
.resource_table
@ -346,7 +348,7 @@ pub struct ComputePassInsertDebugMarkerArgs {
pub fn op_webgpu_compute_pass_insert_debug_marker(
state: &mut OpState,
args: ComputePassInsertDebugMarkerArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let compute_pass_resource = state
.resource_table

View file

@ -7,9 +7,9 @@ use deno_core::error::{bad_resource_id, not_supported};
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_core::OpState;
use deno_core::Resource;
use deno_core::ResourceId;
use deno_core::ZeroCopyBuf;
use deno_core::{BufVec, Resource};
use serde::Deserialize;
use std::borrow::Cow;
use std::cell::RefCell;
@ -194,7 +194,7 @@ pub struct RequestAdapterArgs {
pub async fn op_webgpu_request_adapter(
state: Rc<RefCell<OpState>>,
args: RequestAdapterArgs,
_bufs: BufVec,
_bufs: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let mut state = state.borrow_mut();
check_unstable(&state, "navigator.gpu.requestAdapter");
@ -299,7 +299,7 @@ pub struct RequestDeviceArgs {
pub async fn op_webgpu_request_device(
state: Rc<RefCell<OpState>>,
args: RequestDeviceArgs,
_bufs: BufVec,
_bufs: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let mut state = state.borrow_mut();
let adapter_resource = state
@ -472,7 +472,7 @@ pub struct CreateQuerySetArgs {
pub fn op_webgpu_create_query_set(
state: &mut OpState,
args: CreateQuerySetArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let device_resource = state
.resource_table

View file

@ -162,7 +162,7 @@ pub struct CreateComputePipelineArgs {
pub fn op_webgpu_create_compute_pipeline(
state: &mut OpState,
args: CreateComputePipelineArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let device_resource = state
@ -229,7 +229,7 @@ pub struct ComputePipelineGetBindGroupLayoutArgs {
pub fn op_webgpu_compute_pipeline_get_bind_group_layout(
state: &mut OpState,
args: ComputePipelineGetBindGroupLayoutArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let compute_pipeline_resource = state
@ -366,7 +366,7 @@ pub struct CreateRenderPipelineArgs {
pub fn op_webgpu_create_render_pipeline(
state: &mut OpState,
args: CreateRenderPipelineArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let device_resource = state
@ -617,7 +617,7 @@ pub struct RenderPipelineGetBindGroupLayoutArgs {
pub fn op_webgpu_render_pipeline_get_bind_group_layout(
state: &mut OpState,
args: RenderPipelineGetBindGroupLayoutArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let render_pipeline_resource = state

View file

@ -1,6 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use deno_core::error::bad_resource_id;
use deno_core::error::null_opbuf;
use deno_core::error::AnyError;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
@ -23,7 +24,7 @@ pub struct QueueSubmitArgs {
pub fn op_webgpu_queue_submit(
state: &mut OpState,
args: QueueSubmitArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let queue_resource = state
@ -69,8 +70,9 @@ pub struct QueueWriteBufferArgs {
pub fn op_webgpu_write_buffer(
state: &mut OpState,
args: QueueWriteBufferArgs,
zero_copy: &mut [ZeroCopyBuf],
zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
let instance = state.borrow::<super::Instance>();
let buffer_resource = state
.resource_table
@ -84,8 +86,8 @@ pub fn op_webgpu_write_buffer(
let queue = queue_resource.0;
let data = match args.size {
Some(size) => &zero_copy[0][args.data_offset..(args.data_offset + size)],
None => &zero_copy[0][args.data_offset..],
Some(size) => &zero_copy[args.data_offset..(args.data_offset + size)],
None => &zero_copy[args.data_offset..],
};
let maybe_err = gfx_select!(queue => instance.queue_write_buffer(
queue,
@ -110,8 +112,9 @@ pub struct QueueWriteTextureArgs {
pub fn op_webgpu_write_texture(
state: &mut OpState,
args: QueueWriteTextureArgs,
zero_copy: &mut [ZeroCopyBuf],
zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
let instance = state.borrow::<super::Instance>();
let texture_resource = state
.resource_table
@ -144,7 +147,7 @@ pub fn op_webgpu_write_texture(
let maybe_err = gfx_select!(queue => instance.queue_write_texture(
queue,
&destination,
&*zero_copy[0],
&*zero_copy,
&data_layout,
&wgpu_types::Extent3d {
width: args.size.width.unwrap_or(1),

View file

@ -1,6 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use deno_core::error::bad_resource_id;
use deno_core::error::null_opbuf;
use deno_core::error::AnyError;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
@ -37,7 +38,7 @@ pub struct RenderPassSetViewportArgs {
pub fn op_webgpu_render_pass_set_viewport(
state: &mut OpState,
args: RenderPassSetViewportArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let render_pass_resource = state
.resource_table
@ -70,7 +71,7 @@ pub struct RenderPassSetScissorRectArgs {
pub fn op_webgpu_render_pass_set_scissor_rect(
state: &mut OpState,
args: RenderPassSetScissorRectArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let render_pass_resource = state
.resource_table
@ -107,7 +108,7 @@ pub struct RenderPassSetBlendColorArgs {
pub fn op_webgpu_render_pass_set_blend_color(
state: &mut OpState,
args: RenderPassSetBlendColorArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let render_pass_resource = state
.resource_table
@ -137,7 +138,7 @@ pub struct RenderPassSetStencilReferenceArgs {
pub fn op_webgpu_render_pass_set_stencil_reference(
state: &mut OpState,
args: RenderPassSetStencilReferenceArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let render_pass_resource = state
.resource_table
@ -163,7 +164,7 @@ pub struct RenderPassBeginPipelineStatisticsQueryArgs {
pub fn op_webgpu_render_pass_begin_pipeline_statistics_query(
state: &mut OpState,
args: RenderPassBeginPipelineStatisticsQueryArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let render_pass_resource = state
.resource_table
@ -194,7 +195,7 @@ pub struct RenderPassEndPipelineStatisticsQueryArgs {
pub fn op_webgpu_render_pass_end_pipeline_statistics_query(
state: &mut OpState,
args: RenderPassEndPipelineStatisticsQueryArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let render_pass_resource = state
.resource_table
@ -221,7 +222,7 @@ pub struct RenderPassWriteTimestampArgs {
pub fn op_webgpu_render_pass_write_timestamp(
state: &mut OpState,
args: RenderPassWriteTimestampArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let render_pass_resource = state
.resource_table
@ -253,7 +254,7 @@ pub struct RenderPassExecuteBundlesArgs {
pub fn op_webgpu_render_pass_execute_bundles(
state: &mut OpState,
args: RenderPassExecuteBundlesArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let mut render_bundle_ids = vec![];
@ -291,7 +292,7 @@ pub struct RenderPassEndPassArgs {
pub fn op_webgpu_render_pass_end_pass(
state: &mut OpState,
args: RenderPassEndPassArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let command_encoder_resource = state
.resource_table
@ -326,8 +327,9 @@ pub struct RenderPassSetBindGroupArgs {
pub fn op_webgpu_render_pass_set_bind_group(
state: &mut OpState,
args: RenderPassSetBindGroupArgs,
zero_copy: &mut [ZeroCopyBuf],
zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
let bind_group_resource = state
.resource_table
.get::<super::binding::WebGpuBindGroup>(args.bind_group)
@ -353,7 +355,7 @@ pub fn op_webgpu_render_pass_set_bind_group(
);
},
None => {
let (prefix, data, suffix) = unsafe { zero_copy[0].align_to::<u32>() };
let (prefix, data, suffix) = unsafe { zero_copy.align_to::<u32>() };
assert!(prefix.is_empty());
assert!(suffix.is_empty());
unsafe {
@ -381,7 +383,7 @@ pub struct RenderPassPushDebugGroupArgs {
pub fn op_webgpu_render_pass_push_debug_group(
state: &mut OpState,
args: RenderPassPushDebugGroupArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let render_pass_resource = state
.resource_table
@ -409,7 +411,7 @@ pub struct RenderPassPopDebugGroupArgs {
pub fn op_webgpu_render_pass_pop_debug_group(
state: &mut OpState,
args: RenderPassPopDebugGroupArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let render_pass_resource = state
.resource_table
@ -433,7 +435,7 @@ pub struct RenderPassInsertDebugMarkerArgs {
pub fn op_webgpu_render_pass_insert_debug_marker(
state: &mut OpState,
args: RenderPassInsertDebugMarkerArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let render_pass_resource = state
.resource_table
@ -462,7 +464,7 @@ pub struct RenderPassSetPipelineArgs {
pub fn op_webgpu_render_pass_set_pipeline(
state: &mut OpState,
args: RenderPassSetPipelineArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let render_pipeline_resource = state
.resource_table
@ -494,7 +496,7 @@ pub struct RenderPassSetIndexBufferArgs {
pub fn op_webgpu_render_pass_set_index_buffer(
state: &mut OpState,
args: RenderPassSetIndexBufferArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let buffer_resource = state
.resource_table
@ -528,7 +530,7 @@ pub struct RenderPassSetVertexBufferArgs {
pub fn op_webgpu_render_pass_set_vertex_buffer(
state: &mut OpState,
args: RenderPassSetVertexBufferArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let buffer_resource = state
.resource_table
@ -563,7 +565,7 @@ pub struct RenderPassDrawArgs {
pub fn op_webgpu_render_pass_draw(
state: &mut OpState,
args: RenderPassDrawArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let render_pass_resource = state
.resource_table
@ -595,7 +597,7 @@ pub struct RenderPassDrawIndexedArgs {
pub fn op_webgpu_render_pass_draw_indexed(
state: &mut OpState,
args: RenderPassDrawIndexedArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let render_pass_resource = state
.resource_table
@ -625,7 +627,7 @@ pub struct RenderPassDrawIndirectArgs {
pub fn op_webgpu_render_pass_draw_indirect(
state: &mut OpState,
args: RenderPassDrawIndirectArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let buffer_resource = state
.resource_table
@ -656,7 +658,7 @@ pub struct RenderPassDrawIndexedIndirectArgs {
pub fn op_webgpu_render_pass_draw_indexed_indirect(
state: &mut OpState,
args: RenderPassDrawIndexedIndirectArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let buffer_resource = state
.resource_table

View file

@ -82,7 +82,7 @@ pub struct CreateSamplerArgs {
pub fn op_webgpu_create_sampler(
state: &mut OpState,
args: CreateSamplerArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let device_resource = state

View file

@ -1,6 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use deno_core::error::bad_resource_id;
use deno_core::error::null_opbuf;
use deno_core::error::AnyError;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
@ -31,7 +32,7 @@ pub struct CreateShaderModuleArgs {
pub fn op_webgpu_create_shader_module(
state: &mut OpState,
args: CreateShaderModuleArgs,
zero_copy: &mut [ZeroCopyBuf],
zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let device_resource = state
@ -45,10 +46,15 @@ pub fn op_webgpu_create_shader_module(
wgpu_core::pipeline::ShaderModuleSource::Wgsl(Cow::from(code))
}
None => wgpu_core::pipeline::ShaderModuleSource::SpirV(Cow::from(unsafe {
let (prefix, data, suffix) = zero_copy[0].align_to::<u32>();
assert!(prefix.is_empty());
assert!(suffix.is_empty());
data
match &zero_copy {
Some(zero_copy) => {
let (prefix, data, suffix) = zero_copy.align_to::<u32>();
assert!(prefix.is_empty());
assert!(suffix.is_empty());
data
}
None => return Err(null_opbuf()),
}
})),
};

View file

@ -147,7 +147,7 @@ pub struct CreateTextureArgs {
pub fn op_webgpu_create_texture(
state: &mut OpState,
args: CreateTextureArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let device_resource = state
@ -209,7 +209,7 @@ pub struct CreateTextureViewArgs {
pub fn op_webgpu_create_texture_view(
state: &mut OpState,
args: CreateTextureViewArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let instance = state.borrow::<super::Instance>();
let texture_resource = state

View file

@ -1,6 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use deno_core::error::bad_resource_id;
use deno_core::error::null_opbuf;
use deno_core::error::type_error;
use deno_core::error::AnyError;
use deno_core::futures::stream::SplitSink;
@ -11,7 +12,6 @@ use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_core::url;
use deno_core::AsyncRefCell;
use deno_core::BufVec;
use deno_core::CancelFuture;
use deno_core::CancelHandle;
use deno_core::JsRuntime;
@ -94,7 +94,7 @@ pub struct CheckPermissionArgs {
pub fn op_ws_check_permission<WP>(
state: &mut OpState,
args: CheckPermissionArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError>
where
WP: WebSocketPermissions + 'static,
@ -116,7 +116,7 @@ pub struct CreateArgs {
pub async fn op_ws_create<WP>(
state: Rc<RefCell<OpState>>,
args: CreateArgs,
_bufs: BufVec,
_bufs: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError>
where
WP: WebSocketPermissions + 'static,
@ -223,11 +223,11 @@ pub struct SendArgs {
pub async fn op_ws_send(
state: Rc<RefCell<OpState>>,
args: SendArgs,
bufs: BufVec,
buf: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let msg = match args.kind.as_str() {
"text" => Message::Text(args.text.unwrap()),
"binary" => Message::Binary(bufs[0].to_vec()),
"binary" => Message::Binary(buf.ok_or_else(null_opbuf)?.to_vec()),
"pong" => Message::Pong(vec![]),
_ => unreachable!(),
};
@ -254,7 +254,7 @@ pub struct CloseArgs {
pub async fn op_ws_close(
state: Rc<RefCell<OpState>>,
args: CloseArgs,
_bufs: BufVec,
_bufs: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let rid = args.rid;
let msg = Message::Close(args.code.map(|c| CloseFrame {
@ -284,7 +284,7 @@ pub struct NextEventArgs {
pub async fn op_ws_next_event(
state: Rc<RefCell<OpState>>,
args: NextEventArgs,
_bufs: BufVec,
_bufs: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let resource = state
.borrow_mut()

View file

@ -10,7 +10,6 @@ use deno_core::error::AnyError;
use deno_core::serde_json;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_core::BufVec;
use deno_core::OpState;
use deno_core::RcRef;
use deno_core::ResourceId;
@ -183,7 +182,7 @@ fn open_helper(
fn op_open_sync(
state: &mut OpState,
args: OpenArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let (path, open_options) = open_helper(state, args)?;
let std_file = open_options.open(path)?;
@ -196,7 +195,7 @@ fn op_open_sync(
async fn op_open_async(
state: Rc<RefCell<OpState>>,
args: OpenArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let (path, open_options) = open_helper(&mut state.borrow_mut(), args)?;
let tokio_file = tokio::fs::OpenOptions::from(open_options)
@ -235,7 +234,7 @@ fn seek_helper(args: SeekArgs) -> Result<(u32, SeekFrom), AnyError> {
fn op_seek_sync(
state: &mut OpState,
args: SeekArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let (rid, seek_from) = seek_helper(args)?;
let pos = StdFileResource::with(state, rid, |r| match r {
@ -250,7 +249,7 @@ fn op_seek_sync(
async fn op_seek_async(
state: Rc<RefCell<OpState>>,
args: SeekArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let (rid, seek_from) = seek_helper(args)?;
@ -281,7 +280,7 @@ pub struct FdatasyncArgs {
fn op_fdatasync_sync(
state: &mut OpState,
args: FdatasyncArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let rid = args.rid;
StdFileResource::with(state, rid, |r| match r {
@ -294,7 +293,7 @@ fn op_fdatasync_sync(
async fn op_fdatasync_async(
state: Rc<RefCell<OpState>>,
args: FdatasyncArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let rid = args.rid;
@ -325,7 +324,7 @@ pub struct FsyncArgs {
fn op_fsync_sync(
state: &mut OpState,
args: FsyncArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let rid = args.rid;
StdFileResource::with(state, rid, |r| match r {
@ -338,7 +337,7 @@ fn op_fsync_sync(
async fn op_fsync_async(
state: Rc<RefCell<OpState>>,
args: FsyncArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let rid = args.rid;
@ -369,7 +368,7 @@ pub struct FstatArgs {
fn op_fstat_sync(
state: &mut OpState,
args: FstatArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
super::check_unstable(state, "Deno.fstat");
let metadata = StdFileResource::with(state, args.rid, |r| match r {
@ -382,7 +381,7 @@ fn op_fstat_sync(
async fn op_fstat_async(
state: Rc<RefCell<OpState>>,
args: FstatArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
super::check_unstable2(&state, "Deno.fstat");
@ -415,7 +414,7 @@ pub struct UmaskArgs {
fn op_umask(
state: &mut OpState,
args: UmaskArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
super::check_unstable(state, "Deno.umask");
// TODO implement umask for Windows
@ -452,7 +451,7 @@ pub struct ChdirArgs {
fn op_chdir(
state: &mut OpState,
args: ChdirArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let d = PathBuf::from(&args.directory);
state.borrow::<Permissions>().read.check(&d)?;
@ -471,7 +470,7 @@ pub struct MkdirArgs {
fn op_mkdir_sync(
state: &mut OpState,
args: MkdirArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let path = Path::new(&args.path).to_path_buf();
let mode = args.mode.unwrap_or(0o777) & 0o777;
@ -491,7 +490,7 @@ fn op_mkdir_sync(
async fn op_mkdir_async(
state: Rc<RefCell<OpState>>,
args: MkdirArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let path = Path::new(&args.path).to_path_buf();
let mode = args.mode.unwrap_or(0o777) & 0o777;
@ -527,7 +526,7 @@ pub struct ChmodArgs {
fn op_chmod_sync(
state: &mut OpState,
args: ChmodArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let path = Path::new(&args.path).to_path_buf();
let mode = args.mode & 0o777;
@ -553,7 +552,7 @@ fn op_chmod_sync(
async fn op_chmod_async(
state: Rc<RefCell<OpState>>,
args: ChmodArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let path = Path::new(&args.path).to_path_buf();
let mode = args.mode & 0o777;
@ -595,7 +594,7 @@ pub struct ChownArgs {
fn op_chown_sync(
state: &mut OpState,
args: ChownArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let path = Path::new(&args.path).to_path_buf();
state.borrow::<Permissions>().write.check(&path)?;
@ -623,7 +622,7 @@ fn op_chown_sync(
async fn op_chown_async(
state: Rc<RefCell<OpState>>,
args: ChownArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let path = Path::new(&args.path).to_path_buf();
@ -665,7 +664,7 @@ pub struct RemoveArgs {
fn op_remove_sync(
state: &mut OpState,
args: RemoveArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let path = PathBuf::from(&args.path);
let recursive = args.recursive;
@ -707,7 +706,7 @@ fn op_remove_sync(
async fn op_remove_async(
state: Rc<RefCell<OpState>>,
args: RemoveArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let path = PathBuf::from(&args.path);
let recursive = args.recursive;
@ -763,7 +762,7 @@ pub struct CopyFileArgs {
fn op_copy_file_sync(
state: &mut OpState,
args: CopyFileArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let from = PathBuf::from(&args.from);
let to = PathBuf::from(&args.to);
@ -788,7 +787,7 @@ fn op_copy_file_sync(
async fn op_copy_file_async(
state: Rc<RefCell<OpState>>,
args: CopyFileArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let from = PathBuf::from(&args.from);
let to = PathBuf::from(&args.to);
@ -885,7 +884,7 @@ pub struct StatArgs {
fn op_stat_sync(
state: &mut OpState,
args: StatArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let path = PathBuf::from(&args.path);
let lstat = args.lstat;
@ -902,7 +901,7 @@ fn op_stat_sync(
async fn op_stat_async(
state: Rc<RefCell<OpState>>,
args: StatArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let path = PathBuf::from(&args.path);
let lstat = args.lstat;
@ -934,7 +933,7 @@ pub struct RealpathArgs {
fn op_realpath_sync(
state: &mut OpState,
args: RealpathArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let path = PathBuf::from(&args.path);
@ -955,7 +954,7 @@ fn op_realpath_sync(
async fn op_realpath_async(
state: Rc<RefCell<OpState>>,
args: RealpathArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let path = PathBuf::from(&args.path);
@ -989,7 +988,7 @@ pub struct ReadDirArgs {
fn op_read_dir_sync(
state: &mut OpState,
args: ReadDirArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let path = PathBuf::from(&args.path);
@ -1019,7 +1018,7 @@ fn op_read_dir_sync(
async fn op_read_dir_async(
state: Rc<RefCell<OpState>>,
args: ReadDirArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let path = PathBuf::from(&args.path);
{
@ -1061,7 +1060,7 @@ pub struct RenameArgs {
fn op_rename_sync(
state: &mut OpState,
args: RenameArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let oldpath = PathBuf::from(&args.oldpath);
let newpath = PathBuf::from(&args.newpath);
@ -1078,7 +1077,7 @@ fn op_rename_sync(
async fn op_rename_async(
state: Rc<RefCell<OpState>>,
args: RenameArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let oldpath = PathBuf::from(&args.oldpath);
let newpath = PathBuf::from(&args.newpath);
@ -1112,7 +1111,7 @@ pub struct LinkArgs {
fn op_link_sync(
state: &mut OpState,
args: LinkArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let oldpath = PathBuf::from(&args.oldpath);
let newpath = PathBuf::from(&args.newpath);
@ -1131,7 +1130,7 @@ fn op_link_sync(
async fn op_link_async(
state: Rc<RefCell<OpState>>,
args: LinkArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let oldpath = PathBuf::from(&args.oldpath);
let newpath = PathBuf::from(&args.newpath);
@ -1173,7 +1172,7 @@ pub struct SymlinkOptions {
fn op_symlink_sync(
state: &mut OpState,
args: SymlinkArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let oldpath = PathBuf::from(&args.oldpath);
let newpath = PathBuf::from(&args.newpath);
@ -1222,7 +1221,7 @@ fn op_symlink_sync(
async fn op_symlink_async(
state: Rc<RefCell<OpState>>,
args: SymlinkArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let oldpath = PathBuf::from(&args.oldpath);
let newpath = PathBuf::from(&args.newpath);
@ -1280,7 +1279,7 @@ pub struct ReadLinkArgs {
fn op_read_link_sync(
state: &mut OpState,
args: ReadLinkArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let path = PathBuf::from(&args.path);
@ -1295,7 +1294,7 @@ fn op_read_link_sync(
async fn op_read_link_async(
state: Rc<RefCell<OpState>>,
args: ReadLinkArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let path = PathBuf::from(&args.path);
{
@ -1322,7 +1321,7 @@ pub struct FtruncateArgs {
fn op_ftruncate_sync(
state: &mut OpState,
args: FtruncateArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
super::check_unstable(state, "Deno.ftruncate");
let rid = args.rid;
@ -1337,7 +1336,7 @@ fn op_ftruncate_sync(
async fn op_ftruncate_async(
state: Rc<RefCell<OpState>>,
args: FtruncateArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
super::check_unstable2(&state, "Deno.ftruncate");
let rid = args.rid;
@ -1371,7 +1370,7 @@ pub struct TruncateArgs {
fn op_truncate_sync(
state: &mut OpState,
args: TruncateArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let path = PathBuf::from(&args.path);
let len = args.len;
@ -1387,7 +1386,7 @@ fn op_truncate_sync(
async fn op_truncate_async(
state: Rc<RefCell<OpState>>,
args: TruncateArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let path = PathBuf::from(&args.path);
let len = args.len;
@ -1461,7 +1460,7 @@ pub struct MakeTempArgs {
fn op_make_temp_dir_sync(
state: &mut OpState,
args: MakeTempArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let dir = args.dir.map(|s| PathBuf::from(&s));
let prefix = args.prefix.map(String::from);
@ -1490,7 +1489,7 @@ fn op_make_temp_dir_sync(
async fn op_make_temp_dir_async(
state: Rc<RefCell<OpState>>,
args: MakeTempArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let dir = args.dir.map(|s| PathBuf::from(&s));
let prefix = args.prefix.map(String::from);
@ -1524,7 +1523,7 @@ async fn op_make_temp_dir_async(
fn op_make_temp_file_sync(
state: &mut OpState,
args: MakeTempArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let dir = args.dir.map(|s| PathBuf::from(&s));
let prefix = args.prefix.map(String::from);
@ -1553,7 +1552,7 @@ fn op_make_temp_file_sync(
async fn op_make_temp_file_async(
state: Rc<RefCell<OpState>>,
args: MakeTempArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let dir = args.dir.map(|s| PathBuf::from(&s));
let prefix = args.prefix.map(String::from);
@ -1595,7 +1594,7 @@ pub struct FutimeArgs {
fn op_futime_sync(
state: &mut OpState,
args: FutimeArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
super::check_unstable(state, "Deno.futimeSync");
let rid = args.rid;
@ -1618,7 +1617,7 @@ fn op_futime_sync(
async fn op_futime_async(
state: Rc<RefCell<OpState>>,
args: FutimeArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
super::check_unstable2(&state, "Deno.futime");
let rid = args.rid;
@ -1667,7 +1666,7 @@ pub struct UtimeArgs {
fn op_utime_sync(
state: &mut OpState,
args: UtimeArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
super::check_unstable(state, "Deno.utime");
@ -1683,7 +1682,7 @@ fn op_utime_sync(
async fn op_utime_async(
state: Rc<RefCell<OpState>>,
args: UtimeArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
super::check_unstable(&state.borrow(), "Deno.utime");
@ -1704,7 +1703,7 @@ async fn op_utime_async(
fn op_cwd(
state: &mut OpState,
_args: Value,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let path = current_dir()?;
state

View file

@ -6,7 +6,6 @@ use deno_core::error::AnyError;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_core::AsyncRefCell;
use deno_core::BufVec;
use deno_core::CancelFuture;
use deno_core::CancelHandle;
use deno_core::OpState;
@ -93,7 +92,7 @@ pub struct OpenArgs {
fn op_fs_events_open(
state: &mut OpState,
args: OpenArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let (sender, receiver) = mpsc::channel::<Result<FsEvent, AnyError>>(16);
let sender = std::sync::Mutex::new(sender);
@ -134,7 +133,7 @@ pub struct PollArgs {
async fn op_fs_events_poll(
state: Rc<RefCell<OpState>>,
args: PollArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let resource = state
.borrow()

View file

@ -1,5 +1,6 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use deno_core::error::null_opbuf;
use deno_core::error::resource_unavailable;
use deno_core::error::AnyError;
use deno_core::error::{bad_resource_id, not_supported};
@ -7,7 +8,6 @@ use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_core::AsyncMutFuture;
use deno_core::AsyncRefCell;
use deno_core::BufVec;
use deno_core::CancelHandle;
use deno_core::CancelTryFuture;
use deno_core::JsRuntime;
@ -523,11 +523,12 @@ impl Resource for StdFileResource {
fn op_read_sync(
state: &mut OpState,
rid: ResourceId,
bufs: &mut [ZeroCopyBuf],
buf: Option<ZeroCopyBuf>,
) -> Result<u32, AnyError> {
let mut buf = buf.ok_or_else(null_opbuf)?;
StdFileResource::with(state, rid, move |r| match r {
Ok(std_file) => std_file
.read(&mut bufs[0])
.read(&mut buf)
.map(|n: usize| n as u32)
.map_err(AnyError::from),
Err(_) => Err(not_supported()),
@ -537,9 +538,9 @@ fn op_read_sync(
async fn op_read_async(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
mut bufs: BufVec,
buf: Option<ZeroCopyBuf>,
) -> Result<u32, AnyError> {
let buf = &mut bufs[0];
let buf = &mut buf.ok_or_else(null_opbuf)?;
let resource = state
.borrow()
.resource_table
@ -568,11 +569,12 @@ async fn op_read_async(
fn op_write_sync(
state: &mut OpState,
rid: ResourceId,
bufs: &mut [ZeroCopyBuf],
buf: Option<ZeroCopyBuf>,
) -> Result<u32, AnyError> {
let buf = buf.ok_or_else(null_opbuf)?;
StdFileResource::with(state, rid, move |r| match r {
Ok(std_file) => std_file
.write(&bufs[0])
.write(&buf)
.map(|nwritten: usize| nwritten as u32)
.map_err(AnyError::from),
Err(_) => Err(not_supported()),
@ -582,9 +584,9 @@ fn op_write_sync(
async fn op_write_async(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
bufs: BufVec,
buf: Option<ZeroCopyBuf>,
) -> Result<u32, AnyError> {
let buf = &bufs[0];
let buf = &buf.ok_or_else(null_opbuf)?;
let resource = state
.borrow()
.resource_table
@ -616,7 +618,7 @@ struct ShutdownArgs {
async fn op_shutdown(
state: Rc<RefCell<OpState>>,
args: ShutdownArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let resource = state
.borrow()

View file

@ -31,7 +31,6 @@ use deno_core::json_op_async;
use deno_core::json_op_sync;
use deno_core::serde::de::DeserializeOwned;
use deno_core::serde::Serialize;
use deno_core::BufVec;
use deno_core::JsRuntime;
use deno_core::OpState;
use deno_core::ValueOrVector;
@ -45,7 +44,7 @@ pub fn reg_json_async<F, V, R, RV>(
name: &'static str,
op_fn: F,
) where
F: Fn(Rc<RefCell<OpState>>, V, BufVec) -> R + 'static,
F: Fn(Rc<RefCell<OpState>>, V, Option<ZeroCopyBuf>) -> R + 'static,
V: DeserializeOwned,
R: Future<Output = Result<RV, AnyError>> + 'static,
RV: Serialize + 'static,
@ -55,7 +54,7 @@ pub fn reg_json_async<F, V, R, RV>(
pub fn reg_json_sync<F, V, R>(rt: &mut JsRuntime, name: &'static str, op_fn: F)
where
F: Fn(&mut OpState, V, &mut [ZeroCopyBuf]) -> Result<R, AnyError> + 'static,
F: Fn(&mut OpState, V, Option<ZeroCopyBuf>) -> Result<R, AnyError> + 'static,
V: DeserializeOwned,
R: Serialize + 'static,
{
@ -64,7 +63,7 @@ where
pub fn reg_bin_async<F, R, RV>(rt: &mut JsRuntime, name: &'static str, op_fn: F)
where
F: Fn(Rc<RefCell<OpState>>, u32, BufVec) -> R + 'static,
F: Fn(Rc<RefCell<OpState>>, u32, Option<ZeroCopyBuf>) -> R + 'static,
R: Future<Output = Result<RV, AnyError>> + 'static,
RV: ValueOrVector,
{
@ -73,7 +72,8 @@ where
pub fn reg_bin_sync<F, R>(rt: &mut JsRuntime, name: &'static str, op_fn: F)
where
F: Fn(&mut OpState, u32, &mut [ZeroCopyBuf]) -> Result<R, AnyError> + 'static,
F:
Fn(&mut OpState, u32, Option<ZeroCopyBuf>) -> Result<R, AnyError> + 'static,
R: ValueOrVector,
{
rt.register_op(name, metrics_op(name, bin_op_sync(op_fn)));

View file

@ -6,13 +6,13 @@ use crate::resolve_addr::resolve_addr_sync;
use deno_core::error::bad_resource;
use deno_core::error::custom_error;
use deno_core::error::generic_error;
use deno_core::error::null_opbuf;
use deno_core::error::type_error;
use deno_core::error::AnyError;
use deno_core::serde_json;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_core::AsyncRefCell;
use deno_core::BufVec;
use deno_core::CancelHandle;
use deno_core::CancelTryFuture;
use deno_core::OpState;
@ -63,7 +63,7 @@ pub(crate) struct AcceptArgs {
async fn accept_tcp(
state: Rc<RefCell<OpState>>,
args: AcceptArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let rid = args.rid;
@ -110,13 +110,13 @@ async fn accept_tcp(
async fn op_accept(
state: Rc<RefCell<OpState>>,
args: Value,
bufs: BufVec,
_buf: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let args: AcceptArgs = serde_json::from_value(args)?;
match args.transport.as_str() {
"tcp" => accept_tcp(state, args, bufs).await,
"tcp" => accept_tcp(state, args, _buf).await,
#[cfg(unix)]
"unix" => net_unix::accept_unix(state, args, bufs).await,
"unix" => net_unix::accept_unix(state, args, _buf).await,
_ => Err(generic_error(format!(
"Unsupported transport protocol {}",
args.transport
@ -133,10 +133,10 @@ pub(crate) struct ReceiveArgs {
async fn receive_udp(
state: Rc<RefCell<OpState>>,
args: ReceiveArgs,
zero_copy: BufVec,
zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
assert_eq!(zero_copy.len(), 1, "Invalid number of arguments");
let mut zero_copy = zero_copy[0].clone();
let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
let mut zero_copy = zero_copy.clone();
let rid = args.rid;
@ -164,10 +164,8 @@ async fn receive_udp(
async fn op_datagram_receive(
state: Rc<RefCell<OpState>>,
args: Value,
zero_copy: BufVec,
zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
assert_eq!(zero_copy.len(), 1, "Invalid number of arguments");
let args: ReceiveArgs = serde_json::from_value(args)?;
match args.transport.as_str() {
"udp" => receive_udp(state, args, zero_copy).await,
@ -191,10 +189,10 @@ struct SendArgs {
async fn op_datagram_send(
state: Rc<RefCell<OpState>>,
args: Value,
zero_copy: BufVec,
zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
assert_eq!(zero_copy.len(), 1, "Invalid number of arguments");
let zero_copy = zero_copy[0].clone();
let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
let zero_copy = zero_copy.clone();
match serde_json::from_value(args)? {
SendArgs {
@ -260,7 +258,7 @@ struct ConnectArgs {
async fn op_connect(
state: Rc<RefCell<OpState>>,
args: Value,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
match serde_json::from_value(args)? {
ConnectArgs {
@ -424,7 +422,7 @@ fn listen_udp(
fn op_listen(
state: &mut OpState,
args: Value,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let permissions = state.borrow::<Permissions>();
match serde_json::from_value(args)? {
@ -550,7 +548,7 @@ pub struct NameServer {
async fn op_dns_resolve(
state: Rc<RefCell<OpState>>,
args: ResolveAddrArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let ResolveAddrArgs {
query,

View file

@ -5,16 +5,17 @@ use crate::ops::net::AcceptArgs;
use crate::ops::net::ReceiveArgs;
use deno_core::error::bad_resource;
use deno_core::error::custom_error;
use deno_core::error::null_opbuf;
use deno_core::error::AnyError;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_core::AsyncRefCell;
use deno_core::BufVec;
use deno_core::CancelHandle;
use deno_core::CancelTryFuture;
use deno_core::OpState;
use deno_core::RcRef;
use deno_core::Resource;
use deno_core::ZeroCopyBuf;
use serde::Deserialize;
use std::borrow::Cow;
use std::cell::RefCell;
@ -63,7 +64,7 @@ pub struct UnixListenArgs {
pub(crate) async fn accept_unix(
state: Rc<RefCell<OpState>>,
args: AcceptArgs,
_bufs: BufVec,
_bufs: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let rid = args.rid;
@ -100,12 +101,11 @@ pub(crate) async fn accept_unix(
pub(crate) async fn receive_unix_packet(
state: Rc<RefCell<OpState>>,
args: ReceiveArgs,
bufs: BufVec,
buf: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
assert_eq!(bufs.len(), 1, "Invalid number of arguments");
let mut buf = buf.ok_or_else(null_opbuf)?;
let rid = args.rid;
let mut buf = bufs.into_iter().next().unwrap();
let resource = state
.borrow()

View file

@ -28,7 +28,7 @@ pub fn init(rt: &mut deno_core::JsRuntime) {
fn op_exec_path(
state: &mut OpState,
_args: Value,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let current_exe = env::current_exe().unwrap();
state
@ -51,7 +51,7 @@ pub struct SetEnv {
fn op_set_env(
state: &mut OpState,
args: SetEnv,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
state.borrow::<Permissions>().env.check()?;
let invalid_key =
@ -67,7 +67,7 @@ fn op_set_env(
fn op_env(
state: &mut OpState,
_args: Value,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
state.borrow::<Permissions>().env.check()?;
let v = env::vars().collect::<HashMap<String, String>>();
@ -82,7 +82,7 @@ pub struct GetEnv {
fn op_get_env(
state: &mut OpState,
args: GetEnv,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
state.borrow::<Permissions>().env.check()?;
if args.key.is_empty() || args.key.contains(&['=', '\0'] as &[char]) {
@ -103,7 +103,7 @@ pub struct DeleteEnv {
fn op_delete_env(
state: &mut OpState,
args: DeleteEnv,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
state.borrow::<Permissions>().env.check()?;
if args.key.is_empty() || args.key.contains(&['=', '\0'] as &[char]) {
@ -121,7 +121,7 @@ pub struct Exit {
fn op_exit(
_state: &mut OpState,
args: Exit,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
std::process::exit(args.code)
}
@ -129,7 +129,7 @@ fn op_exit(
fn op_loadavg(
state: &mut OpState,
_args: Value,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
super::check_unstable(state, "Deno.loadavg");
state.borrow::<Permissions>().env.check()?;
@ -142,7 +142,7 @@ fn op_loadavg(
fn op_hostname(
state: &mut OpState,
_args: Value,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
super::check_unstable(state, "Deno.hostname");
state.borrow::<Permissions>().env.check()?;
@ -153,7 +153,7 @@ fn op_hostname(
fn op_os_release(
state: &mut OpState,
_args: Value,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
super::check_unstable(state, "Deno.osRelease");
state.borrow::<Permissions>().env.check()?;
@ -164,7 +164,7 @@ fn op_os_release(
fn op_system_memory_info(
state: &mut OpState,
_args: Value,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
super::check_unstable(state, "Deno.systemMemoryInfo");
state.borrow::<Permissions>().env.check()?;
@ -185,7 +185,7 @@ fn op_system_memory_info(
fn op_system_cpu_info(
state: &mut OpState,
_args: Value,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
super::check_unstable(state, "Deno.systemCpuInfo");
state.borrow::<Permissions>().env.check()?;

View file

@ -28,7 +28,7 @@ pub struct PermissionArgs {
pub fn op_query_permission(
state: &mut OpState,
args: PermissionArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let permissions = state.borrow::<Permissions>();
let path = args.path.as_deref();
@ -59,7 +59,7 @@ pub fn op_query_permission(
pub fn op_revoke_permission(
state: &mut OpState,
args: PermissionArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let permissions = state.borrow_mut::<Permissions>();
let path = args.path.as_deref();
@ -90,7 +90,7 @@ pub fn op_revoke_permission(
pub fn op_request_permission(
state: &mut OpState,
args: PermissionArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let permissions = state.borrow_mut::<Permissions>();
let path = args.path.as_deref();

View file

@ -6,7 +6,6 @@ use deno_core::futures::prelude::*;
use deno_core::plugin_api;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_core::BufVec;
use deno_core::JsRuntime;
use deno_core::Op;
use deno_core::OpAsyncFuture;
@ -38,7 +37,7 @@ pub struct OpenPluginArgs {
pub fn op_open_plugin(
state: &mut OpState,
args: OpenPluginArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let filename = PathBuf::from(&args.filename);
@ -111,16 +110,9 @@ impl<'a> plugin_api::Interface for PluginInterface<'a> {
) -> OpId {
let plugin_lib = self.plugin_lib.clone();
let plugin_op_fn: Box<OpFn> = Box::new(move |state_rc, _payload, buf| {
// For sig compat map Option<ZeroCopyBuf> to BufVec
let mut bufs: BufVec = match buf {
Some(b) => vec![b],
None => vec![],
}
.into();
let mut state = state_rc.borrow_mut();
let mut interface = PluginInterface::new(&mut state, &plugin_lib);
let op = dispatch_op_fn(&mut interface, &mut bufs);
let op = dispatch_op_fn(&mut interface, buf);
match op {
sync_op @ Op::Sync(..) => sync_op,
Op::Async(fut) => Op::Async(PluginOpAsyncFuture::new(&plugin_lib, fut)),

View file

@ -12,7 +12,6 @@ use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_core::AsyncMutFuture;
use deno_core::AsyncRefCell;
use deno_core::BufVec;
use deno_core::OpState;
use deno_core::RcRef;
use deno_core::Resource;
@ -85,7 +84,7 @@ impl ChildResource {
fn op_run(
state: &mut OpState,
run_args: RunArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
state.borrow::<Permissions>().run.check()?;
@ -185,7 +184,7 @@ pub struct RunStatusArgs {
async fn op_run_status(
state: Rc<RefCell<OpState>>,
args: RunStatusArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let rid = args.rid;
@ -280,7 +279,7 @@ struct KillArgs {
fn op_kill(
state: &mut OpState,
args: KillArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
super::check_unstable(state, "Deno.kill");
state.borrow::<Permissions>().run.check()?;

View file

@ -24,7 +24,7 @@ pub fn init(rt: &mut deno_core::JsRuntime, main_module: ModuleSpecifier) {
fn op_main_module(
state: &mut OpState,
_args: Value,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let main = state.borrow::<ModuleSpecifier>().to_string();
let main_url = deno_core::resolve_url_or_path(&main)?;
@ -42,7 +42,7 @@ fn op_main_module(
fn op_metrics(
state: &mut OpState,
_args: Value,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let m = state.borrow::<RuntimeMetrics>();
let combined = m.combined_metrics();

View file

@ -1,7 +1,6 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use deno_core::error::AnyError;
use deno_core::serde_json::Value;
use deno_core::BufVec;
use deno_core::OpState;
use deno_core::ZeroCopyBuf;
use std::cell::RefCell;
@ -70,7 +69,7 @@ pub struct SignalArgs {
fn op_signal_bind(
state: &mut OpState,
args: BindSignalArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
super::check_unstable(state, "Deno.signal");
let resource = SignalStreamResource {
@ -89,7 +88,7 @@ fn op_signal_bind(
async fn op_signal_poll(
state: Rc<RefCell<OpState>>,
args: SignalArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
super::check_unstable2(&state, "Deno.signal");
let rid = args.rid;
@ -112,7 +111,7 @@ async fn op_signal_poll(
pub fn op_signal_unbind(
state: &mut OpState,
args: SignalArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
super::check_unstable(state, "Deno.signal");
let rid = args.rid;
@ -127,7 +126,7 @@ pub fn op_signal_unbind(
pub fn op_signal_bind(
_state: &mut OpState,
_args: Value,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
unimplemented!();
}
@ -136,7 +135,7 @@ pub fn op_signal_bind(
fn op_signal_unbind(
_state: &mut OpState,
_args: Value,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
unimplemented!();
}
@ -145,7 +144,7 @@ fn op_signal_unbind(
async fn op_signal_poll(
_state: Rc<RefCell<OpState>>,
_args: Value,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
unimplemented!();
}

View file

@ -9,7 +9,7 @@
//! calls it) for an entire Isolate. This is what is implemented here.
use crate::permissions::Permissions;
use deno_core::error::type_error;
use deno_core::error::null_opbuf;
use deno_core::error::AnyError;
use deno_core::futures;
use deno_core::futures::channel::oneshot;
@ -17,7 +17,6 @@ use deno_core::futures::FutureExt;
use deno_core::futures::TryFutureExt;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_core::BufVec;
use deno_core::OpState;
use deno_core::ZeroCopyBuf;
use serde::Deserialize;
@ -85,7 +84,7 @@ pub fn init(rt: &mut deno_core::JsRuntime) {
fn op_global_timer_stop(
state: &mut OpState,
_args: Value,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let global_timer = state.borrow_mut::<GlobalTimer>();
global_timer.cancel();
@ -108,7 +107,7 @@ pub struct GlobalTimerArgs {
fn op_global_timer_start(
state: &mut OpState,
args: GlobalTimerArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let val = args.timeout;
@ -121,7 +120,7 @@ fn op_global_timer_start(
async fn op_global_timer(
state: Rc<RefCell<OpState>>,
_args: Value,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let maybe_timer_fut = {
let mut s = state.borrow_mut();
@ -141,13 +140,9 @@ async fn op_global_timer(
fn op_now(
op_state: &mut OpState,
_argument: u32,
zero_copy: &mut [ZeroCopyBuf],
zero_copy: Option<ZeroCopyBuf>,
) -> Result<u32, AnyError> {
match zero_copy.len() {
0 => return Err(type_error("no buffer specified")),
1 => {}
_ => return Err(type_error("Invalid number of arguments")),
}
let mut zero_copy = zero_copy.ok_or_else(null_opbuf)?;
let start_time = op_state.borrow::<StartTime>();
let seconds = start_time.elapsed().as_secs();
@ -163,7 +158,7 @@ fn op_now(
let result = (seconds * 1_000) as f64 + (subsec_nanos / 1_000_000.0);
(&mut zero_copy[0]).copy_from_slice(&result.to_be_bytes());
(&mut zero_copy).copy_from_slice(&result.to_be_bytes());
Ok(0)
}
@ -177,7 +172,7 @@ pub struct SleepArgs {
fn op_sleep_sync(
state: &mut OpState,
args: SleepArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
super::check_unstable(state, "Deno.sleepSync");
sleep(Duration::from_millis(args.millis));

View file

@ -14,7 +14,6 @@ use deno_core::error::AnyError;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_core::AsyncRefCell;
use deno_core::BufVec;
use deno_core::CancelHandle;
use deno_core::CancelTryFuture;
use deno_core::OpState;
@ -97,7 +96,7 @@ struct StartTlsArgs {
async fn op_start_tls(
state: Rc<RefCell<OpState>>,
args: StartTlsArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let rid = args.rid;
@ -167,7 +166,7 @@ async fn op_start_tls(
async fn op_connect_tls(
state: Rc<RefCell<OpState>>,
args: ConnectTlsArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
{
let s = state.borrow();
@ -307,7 +306,7 @@ pub struct ListenTlsArgs {
fn op_listen_tls(
state: &mut OpState,
args: ListenTlsArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
assert_eq!(args.transport, "tcp");
@ -357,7 +356,7 @@ pub struct AcceptTlsArgs {
async fn op_accept_tls(
state: Rc<RefCell<OpState>>,
args: AcceptTlsArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let rid = args.rid;

View file

@ -67,7 +67,7 @@ pub struct SetRawArgs {
fn op_set_raw(
state: &mut OpState,
args: SetRawArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
super::check_unstable(state, "Deno.setRaw");
@ -222,7 +222,7 @@ pub struct IsattyArgs {
fn op_isatty(
state: &mut OpState,
args: IsattyArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let rid = args.rid;
@ -263,7 +263,7 @@ struct ConsoleSize {
fn op_console_size(
state: &mut OpState,
args: ConsoleSizeArgs,
_zero_copy: &mut [ZeroCopyBuf],
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<ConsoleSize, AnyError> {
super::check_unstable(state, "Deno.consoleSize");

View file

@ -2,6 +2,7 @@
use crate::web_worker::WebWorkerHandle;
use crate::web_worker::WorkerEvent;
use deno_core::error::null_opbuf;
use deno_core::futures::channel::mpsc;
use deno_core::serde_json::{json, Value};
@ -15,9 +16,9 @@ pub fn init(
super::reg_json_sync(
rt,
"op_worker_post_message",
move |_state, _args: Value, bufs| {
assert_eq!(bufs.len(), 1, "Invalid number of arguments");
let msg_buf: Box<[u8]> = (*bufs[0]).into();
move |_state, _args: Value, buf| {
let buf = buf.ok_or_else(null_opbuf)?;
let msg_buf: Box<[u8]> = (*buf).into();
sender_
.clone()
.try_send(WorkerEvent::Message(msg_buf))

View file

@ -14,6 +14,7 @@ use crate::web_worker::WebWorkerHandle;
use crate::web_worker::WorkerEvent;
use deno_core::error::custom_error;
use deno_core::error::generic_error;
use deno_core::error::null_opbuf;
use deno_core::error::AnyError;
use deno_core::error::JsError;
use deno_core::futures::channel::mpsc;
@ -23,7 +24,6 @@ use deno_core::serde::Deserialize;
use deno_core::serde::Deserializer;
use deno_core::serde_json::json;
use deno_core::serde_json::Value;
use deno_core::BufVec;
use deno_core::ModuleSpecifier;
use deno_core::OpState;
use deno_core::ZeroCopyBuf;
@ -369,7 +369,7 @@ pub struct CreateWorkerArgs {
fn op_create_worker(
state: &mut OpState,
args: CreateWorkerArgs,
_data: &mut [ZeroCopyBuf],
_data: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let specifier = args.specifier.clone();
let maybe_source_code = if args.has_source_code {
@ -457,7 +457,7 @@ pub struct WorkerArgs {
fn op_host_terminate_worker(
state: &mut OpState,
args: WorkerArgs,
_data: &mut [ZeroCopyBuf],
_data: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let id = args.id as u32;
let worker_thread = state
@ -533,7 +533,7 @@ fn try_remove_and_close(state: Rc<RefCell<OpState>>, id: u32) {
async fn op_host_get_message(
state: Rc<RefCell<OpState>>,
args: WorkerArgs,
_zero_copy: BufVec,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
let id = args.id as u32;
@ -567,11 +567,11 @@ async fn op_host_get_message(
fn op_host_post_message(
state: &mut OpState,
args: WorkerArgs,
data: &mut [ZeroCopyBuf],
data: Option<ZeroCopyBuf>,
) -> Result<Value, AnyError> {
assert_eq!(data.len(), 1, "Invalid number of arguments");
let data = data.ok_or_else(null_opbuf)?;
let id = args.id as u32;
let msg = Vec::from(&*data[0]).into_boxed_slice();
let msg = Vec::from(&*data).into_boxed_slice();
debug!("post message to worker {}", id);
let worker_thread = state

View file

@ -14,15 +14,14 @@ pub fn deno_plugin_init(interface: &mut dyn Interface) {
fn op_test_sync(
_interface: &mut dyn Interface,
zero_copy: &mut [ZeroCopyBuf],
zero_copy: Option<ZeroCopyBuf>,
) -> Op {
if !zero_copy.is_empty() {
if zero_copy.is_some() {
println!("Hello from plugin.");
}
let zero_copy = zero_copy.to_vec();
for (idx, buf) in zero_copy.iter().enumerate() {
if let Some(buf) = zero_copy {
let buf_str = std::str::from_utf8(&buf[..]).unwrap();
println!("zero_copy[{}]: {}", idx, buf_str);
println!("zero_copy: {}", buf_str);
}
let result = b"test";
let result_box: Box<[u8]> = Box::new(*result);
@ -31,16 +30,15 @@ fn op_test_sync(
fn op_test_async(
_interface: &mut dyn Interface,
zero_copy: &mut [ZeroCopyBuf],
zero_copy: Option<ZeroCopyBuf>,
) -> Op {
if !zero_copy.is_empty() {
if zero_copy.is_some() {
println!("Hello from plugin.");
}
let zero_copy = zero_copy.to_vec();
let fut = async move {
for (idx, buf) in zero_copy.iter().enumerate() {
if let Some(buf) = zero_copy {
let buf_str = std::str::from_utf8(&buf[..]).unwrap();
println!("zero_copy[{}]: {}", idx, buf_str);
println!("zero_copy: {}", buf_str);
}
let (tx, rx) = futures::channel::oneshot::channel::<Result<(), ()>>();
std::thread::spawn(move || {