summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/broadcast_channel/lib.rs6
-rw-r--r--ext/crypto/lib.rs26
-rw-r--r--ext/fetch/lib.rs10
-rw-r--r--ext/http/lib.rs10
-rw-r--r--ext/net/io.rs19
-rw-r--r--ext/net/ops.rs9
-rw-r--r--ext/net/ops_unix.rs5
-rw-r--r--ext/timers/lib.rs4
-rw-r--r--ext/webgpu/buffer.rs4
-rw-r--r--ext/webgpu/queue.rs7
-rw-r--r--ext/websocket/01_websocket.js14
-rw-r--r--ext/websocket/02_websocketstream.js12
-rw-r--r--ext/websocket/lib.rs26
13 files changed, 58 insertions, 94 deletions
diff --git a/ext/broadcast_channel/lib.rs b/ext/broadcast_channel/lib.rs
index de6c56667..b499d6fbf 100644
--- a/ext/broadcast_channel/lib.rs
+++ b/ext/broadcast_channel/lib.rs
@@ -45,8 +45,8 @@ struct Unstable(bool); // --unstable
pub fn op_broadcast_subscribe<BC: BroadcastChannel + 'static>(
state: &mut OpState,
- _args: (),
- _buf: (),
+ _: (),
+ _: (),
) -> Result<ResourceId, AnyError> {
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>(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
- _buf: (),
+ _: (),
) -> Result<Option<Message>, AnyError> {
let resource = state.borrow().resource_table.get::<BC::Resource>(rid)?;
let bc = state.borrow().borrow::<BC>().clone();
diff --git a/ext/crypto/lib.rs b/ext/crypto/lib.rs
index 157a9f04b..a562eaf01 100644
--- a/ext/crypto/lib.rs
+++ b/ext/crypto/lib.rs
@@ -2,7 +2,6 @@
use deno_core::error::custom_error;
use deno_core::error::not_supported;
-use deno_core::error::null_opbuf;
use deno_core::error::type_error;
use deno_core::error::AnyError;
use deno_core::include_js_files;
@@ -296,9 +295,8 @@ pub struct SignArg {
pub async fn op_crypto_sign_key(
_state: Rc<RefCell<OpState>>,
args: SignArg,
- zero_copy: Option<ZeroCopyBuf>,
+ zero_copy: ZeroCopyBuf,
) -> Result<ZeroCopyBuf, AnyError> {
- let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
let data = &*zero_copy;
let algorithm = args.algorithm;
@@ -451,9 +449,8 @@ pub struct VerifyArg {
pub async fn op_crypto_verify_key(
_state: Rc<RefCell<OpState>>,
args: VerifyArg,
- zero_copy: Option<ZeroCopyBuf>,
+ zero_copy: ZeroCopyBuf,
) -> Result<bool, AnyError> {
- let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
let data = &*zero_copy;
let algorithm = args.algorithm;
@@ -599,7 +596,7 @@ pub struct ExportKeyArg {
pub async fn op_crypto_export_key(
_state: Rc<RefCell<OpState>>,
args: ExportKeyArg,
- _zero_copy: Option<ZeroCopyBuf>,
+ _: (),
) -> Result<ZeroCopyBuf, AnyError> {
let algorithm = args.algorithm;
match algorithm {
@@ -731,9 +728,8 @@ pub struct DeriveKeyArg {
pub async fn op_crypto_derive_bits(
_state: Rc<RefCell<OpState>>,
args: DeriveKeyArg,
- zero_copy: Option<ZeroCopyBuf>,
+ zero_copy: ZeroCopyBuf,
) -> Result<ZeroCopyBuf, AnyError> {
- let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
let salt = &*zero_copy;
let algorithm = args.algorithm;
match algorithm {
@@ -798,9 +794,8 @@ pub struct EncryptArg {
pub async fn op_crypto_encrypt_key(
_state: Rc<RefCell<OpState>>,
args: EncryptArg,
- zero_copy: Option<ZeroCopyBuf>,
+ zero_copy: ZeroCopyBuf,
) -> Result<ZeroCopyBuf, AnyError> {
- let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
let data = &*zero_copy;
let algorithm = args.algorithm;
@@ -1035,9 +1030,8 @@ pub struct ImportKeyResult {
pub async fn op_crypto_import_key(
_state: Rc<RefCell<OpState>>,
args: ImportKeyArg,
- zero_copy: Option<ZeroCopyBuf>,
+ zero_copy: ZeroCopyBuf,
) -> Result<ImportKeyResult, AnyError> {
- let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
let data = &*zero_copy;
let algorithm = args.algorithm;
@@ -1359,9 +1353,8 @@ pub struct DecryptArg {
pub async fn op_crypto_decrypt_key(
_state: Rc<RefCell<OpState>>,
args: DecryptArg,
- zero_copy: Option<ZeroCopyBuf>,
+ zero_copy: ZeroCopyBuf,
) -> Result<ZeroCopyBuf, AnyError> {
- let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
let data = &*zero_copy;
let algorithm = args.algorithm;
@@ -1431,11 +1424,10 @@ pub fn op_crypto_random_uuid(
pub async fn op_crypto_subtle_digest(
_state: Rc<RefCell<OpState>>,
algorithm: CryptoHash,
- data: Option<ZeroCopyBuf>,
+ data: ZeroCopyBuf,
) -> Result<ZeroCopyBuf, AnyError> {
- let input = data.ok_or_else(null_opbuf)?;
let output = tokio::task::spawn_blocking(move || {
- digest::digest(algorithm.into(), &input)
+ digest::digest(algorithm.into(), &data)
.as_ref()
.to_vec()
.into()
diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs
index dfb1ce059..ae81d126c 100644
--- a/ext/fetch/lib.rs
+++ b/ext/fetch/lib.rs
@@ -1,7 +1,6 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use data_url::DataUrl;
-use deno_core::error::null_opbuf;
use deno_core::error::type_error;
use deno_core::error::AnyError;
use deno_core::futures::Future;
@@ -341,10 +340,9 @@ pub async fn op_fetch_send(
pub async fn op_fetch_request_write(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
- data: Option<ZeroCopyBuf>,
+ data: ZeroCopyBuf,
) -> Result<(), AnyError> {
- let data = data.ok_or_else(null_opbuf)?;
- let buf = Vec::from(&*data);
+ let buf = data.to_vec();
let resource = state
.borrow()
@@ -362,10 +360,8 @@ pub async fn op_fetch_request_write(
pub async fn op_fetch_response_read(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
- data: Option<ZeroCopyBuf>,
+ data: ZeroCopyBuf,
) -> Result<usize, AnyError> {
- let data = data.ok_or_else(null_opbuf)?;
-
let resource = state
.borrow()
.resource_table
diff --git a/ext/http/lib.rs b/ext/http/lib.rs
index f1b0c911a..a4e908537 100644
--- a/ext/http/lib.rs
+++ b/ext/http/lib.rs
@@ -1,7 +1,6 @@
// 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::future::poll_fn;
@@ -513,10 +512,8 @@ async fn op_http_response_close(
async fn op_http_request_read(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
- data: Option<ZeroCopyBuf>,
+ mut data: ZeroCopyBuf,
) -> Result<usize, AnyError> {
- let mut data = data.ok_or_else(null_opbuf)?;
-
let resource = state
.borrow()
.resource_table
@@ -565,9 +562,8 @@ async fn op_http_request_read(
async fn op_http_response_write(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
- data: Option<ZeroCopyBuf>,
+ data: ZeroCopyBuf,
) -> Result<(), AnyError> {
- let buf = data.ok_or_else(null_opbuf)?;
let resource = state
.borrow()
.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 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| {
let r = send_data_fut.poll_unpin(cx).map_err(AnyError::from);
diff --git a/ext/net/io.rs b/ext/net/io.rs
index f1403679a..6a93b8cf6 100644
--- a/ext/net/io.rs
+++ b/ext/net/io.rs
@@ -2,7 +2,6 @@
use crate::ops_tls as tls;
use deno_core::error::not_supported;
-use deno_core::error::null_opbuf;
use deno_core::error::AnyError;
use deno_core::op_async;
use deno_core::AsyncMutFuture;
@@ -166,16 +165,15 @@ impl Resource for UnixStreamResource {
async fn op_read_async(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
- buf: Option<ZeroCopyBuf>,
+ mut buf: ZeroCopyBuf,
) -> Result<u32, AnyError> {
- let buf = &mut buf.ok_or_else(null_opbuf)?;
let resource = state.borrow().resource_table.get_any(rid)?;
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>() {
- s.read(buf).await?
+ s.read(&mut buf).await?
} else if let Some(s) = resource.downcast_rc::<UnixStreamResource>() {
- s.read(buf).await?
+ s.read(&mut buf).await?
} else {
return Err(not_supported());
};
@@ -185,16 +183,15 @@ async fn op_read_async(
async fn op_write_async(
state: Rc<RefCell<OpState>>,
rid: ResourceId,
- buf: Option<ZeroCopyBuf>,
+ buf: ZeroCopyBuf,
) -> Result<u32, AnyError> {
- let buf = &buf.ok_or_else(null_opbuf)?;
let resource = state.borrow().resource_table.get_any(rid)?;
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>() {
- s.write(buf).await?
+ s.write(&buf).await?
} else if let Some(s) = resource.downcast_rc::<UnixStreamResource>() {
- s.write(buf).await?
+ s.write(&buf).await?
} else {
return Err(not_supported());
};
diff --git a/ext/net/ops.rs b/ext/net/ops.rs
index 52e513f71..7019a9b1f 100644
--- a/ext/net/ops.rs
+++ b/ext/net/ops.rs
@@ -7,7 +7,6 @@ use crate::NetPermissions;
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::op_async;
@@ -167,9 +166,8 @@ pub(crate) struct ReceiveArgs {
async fn receive_udp(
state: Rc<RefCell<OpState>>,
args: ReceiveArgs,
- zero_copy: Option<ZeroCopyBuf>,
+ zero_copy: ZeroCopyBuf,
) -> Result<OpPacket, AnyError> {
- let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
let mut zero_copy = zero_copy.clone();
let rid = args.rid;
@@ -197,7 +195,7 @@ async fn receive_udp(
async fn op_datagram_receive(
state: Rc<RefCell<OpState>>,
args: ReceiveArgs,
- zero_copy: Option<ZeroCopyBuf>,
+ zero_copy: ZeroCopyBuf,
) -> Result<OpPacket, AnyError> {
match args.transport.as_str() {
"udp" => receive_udp(state, args, zero_copy).await,
@@ -218,12 +216,11 @@ struct SendArgs {
async fn op_datagram_send<NP>(
state: Rc<RefCell<OpState>>,
args: SendArgs,
- zero_copy: Option<ZeroCopyBuf>,
+ zero_copy: ZeroCopyBuf,
) -> Result<usize, AnyError>
where
NP: NetPermissions + 'static,
{
- let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
let zero_copy = zero_copy.clone();
match args {
diff --git a/ext/net/ops_unix.rs b/ext/net/ops_unix.rs
index c39252fbf..20d085a5d 100644
--- a/ext/net/ops_unix.rs
+++ b/ext/net/ops_unix.rs
@@ -8,7 +8,6 @@ use crate::ops::OpPacket;
use crate::ops::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::AsyncRefCell;
use deno_core::CancelHandle;
@@ -114,10 +113,8 @@ pub(crate) async fn accept_unix(
pub(crate) async fn receive_unix_packet(
state: Rc<RefCell<OpState>>,
args: ReceiveArgs,
- buf: Option<ZeroCopyBuf>,
+ mut buf: ZeroCopyBuf,
) -> Result<OpPacket, AnyError> {
- let mut buf = buf.ok_or_else(null_opbuf)?;
-
let rid = args.rid;
let resource = state
diff --git a/ext/timers/lib.rs b/ext/timers/lib.rs
index 384627c57..d95ac71e8 100644
--- a/ext/timers/lib.rs
+++ b/ext/timers/lib.rs
@@ -93,7 +93,7 @@ impl GlobalTimer {
pub fn op_global_timer_stop(
state: &mut OpState,
- _args: (),
+ _: (),
_: (),
) -> Result<(), AnyError> {
let global_timer = state.borrow_mut::<GlobalTimer>();
@@ -127,7 +127,7 @@ pub fn op_global_timer_start(
pub async fn op_global_timer(
state: Rc<RefCell<OpState>>,
- _args: (),
+ _: (),
_: (),
) -> Result<(), AnyError> {
let maybe_timer_fut = {
diff --git a/ext/webgpu/buffer.rs b/ext/webgpu/buffer.rs
index 92afd2ef9..30818194f 100644
--- a/ext/webgpu/buffer.rs
+++ b/ext/webgpu/buffer.rs
@@ -1,6 +1,5 @@
// 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::AnyError;
use deno_core::futures::channel::oneshot;
@@ -171,9 +170,8 @@ pub struct BufferGetMappedRangeArgs {
pub fn op_webgpu_buffer_get_mapped_range(
state: &mut OpState,
args: BufferGetMappedRangeArgs,
- zero_copy: Option<ZeroCopyBuf>,
+ mut zero_copy: ZeroCopyBuf,
) -> Result<WebGpuResult, AnyError> {
- let mut zero_copy = zero_copy.ok_or_else(null_opbuf)?;
let instance = state.borrow::<super::Instance>();
let buffer_resource =
state.resource_table.get::<WebGpuBuffer>(args.buffer_rid)?;
diff --git a/ext/webgpu/queue.rs b/ext/webgpu/queue.rs
index ddb653fca..79698e7b8 100644
--- a/ext/webgpu/queue.rs
+++ b/ext/webgpu/queue.rs
@@ -2,7 +2,6 @@
use std::num::NonZeroU32;
-use deno_core::error::null_opbuf;
use deno_core::error::AnyError;
use deno_core::OpState;
use deno_core::ResourceId;
@@ -77,9 +76,8 @@ pub struct QueueWriteBufferArgs {
pub fn op_webgpu_write_buffer(
state: &mut OpState,
args: QueueWriteBufferArgs,
- zero_copy: Option<ZeroCopyBuf>,
+ zero_copy: ZeroCopyBuf,
) -> Result<WebGpuResult, AnyError> {
- let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
let instance = state.borrow::<super::Instance>();
let buffer_resource = state
.resource_table
@@ -116,9 +114,8 @@ pub struct QueueWriteTextureArgs {
pub fn op_webgpu_write_texture(
state: &mut OpState,
args: QueueWriteTextureArgs,
- zero_copy: Option<ZeroCopyBuf>,
+ zero_copy: ZeroCopyBuf,
) -> Result<WebGpuResult, AnyError> {
- let zero_copy = zero_copy.ok_or_else(null_opbuf)?;
let instance = state.borrow::<super::Instance>();
let texture_resource = state
.resource_table
diff --git a/ext/websocket/01_websocket.js b/ext/websocket/01_websocket.js
index 79e4d923c..54e05c408 100644
--- a/ext/websocket/01_websocket.js
+++ b/ext/websocket/01_websocket.js
@@ -324,10 +324,10 @@
const sendTypedArray = (ta) => {
this[_bufferedAmount] += ta.byteLength;
PromisePrototypeThen(
- core.opAsync("op_ws_send", {
- rid: this[_rid],
+ core.opAsync("op_ws_send", this[_rid], {
kind: "binary",
- }, ta),
+ value: ta,
+ }),
() => {
this[_bufferedAmount] -= ta.byteLength;
},
@@ -348,10 +348,9 @@
const d = core.encode(string);
this[_bufferedAmount] += d.byteLength;
PromisePrototypeThen(
- core.opAsync("op_ws_send", {
- rid: this[_rid],
+ core.opAsync("op_ws_send", this[_rid], {
kind: "text",
- text: string,
+ value: string,
}),
() => {
this[_bufferedAmount] -= d.byteLength;
@@ -456,8 +455,7 @@
break;
}
case "ping": {
- core.opAsync("op_ws_send", {
- rid: this[_rid],
+ core.opAsync("op_ws_send", this[_rid], {
kind: "pong",
});
break;
diff --git a/ext/websocket/02_websocketstream.js b/ext/websocket/02_websocketstream.js
index f7c4d4d0f..82f306333 100644
--- a/ext/websocket/02_websocketstream.js
+++ b/ext/websocket/02_websocketstream.js
@@ -190,15 +190,14 @@
const writable = new WritableStream({
write: async (chunk) => {
if (typeof chunk === "string") {
- await core.opAsync("op_ws_send", {
- rid: this[_rid],
+ await core.opAsync("op_ws_send", this[_rid], {
kind: "text",
- text: chunk,
+ value: chunk,
});
} else if (chunk instanceof Uint8Array) {
- await core.opAsync("op_ws_send", {
- rid: this[_rid],
+ await core.opAsync("op_ws_send", this[_rid], {
kind: "binary",
+ value: chunk,
}, chunk);
} else {
throw new TypeError(
@@ -257,8 +256,7 @@
break;
}
case "ping": {
- await core.opAsync("op_ws_send", {
- rid: this[_rid],
+ await core.opAsync("op_ws_send", this[_rid], {
kind: "pong",
});
break;
diff --git a/ext/websocket/lib.rs b/ext/websocket/lib.rs
index ebb2186d0..32ac4cf03 100644
--- a/ext/websocket/lib.rs
+++ b/ext/websocket/lib.rs
@@ -1,7 +1,6 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use deno_core::error::invalid_hostname;
-use deno_core::error::null_opbuf;
use deno_core::error::AnyError;
use deno_core::futures::stream::SplitSink;
use deno_core::futures::stream::SplitStream;
@@ -309,29 +308,28 @@ where
}
#[derive(Deserialize)]
-#[serde(rename_all = "camelCase")]
-pub struct SendArgs {
- rid: ResourceId,
- kind: String,
- text: Option<String>,
+#[serde(tag = "kind", content = "value", rename_all = "camelCase")]
+pub enum SendValue {
+ Text(String),
+ Binary(ZeroCopyBuf),
+ Pong,
}
pub async fn op_ws_send(
state: Rc<RefCell<OpState>>,
- args: SendArgs,
- buf: Option<ZeroCopyBuf>,
+ rid: ResourceId,
+ value: SendValue,
) -> Result<(), AnyError> {
- let msg = match args.kind.as_str() {
- "text" => Message::Text(args.text.unwrap()),
- "binary" => Message::Binary(buf.ok_or_else(null_opbuf)?.to_vec()),
- "pong" => Message::Pong(vec![]),
- _ => unreachable!(),
+ let msg = match value {
+ SendValue::Text(text) => Message::Text(text),
+ SendValue::Binary(buf) => Message::Binary(buf.to_vec()),
+ SendValue::Pong => Message::Pong(vec![]),
};
let resource = state
.borrow_mut()
.resource_table
- .get::<WsStreamResource>(args.rid)?;
+ .get::<WsStreamResource>(rid)?;
resource.send(msg).await?;
Ok(())
}