diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-06-22 23:37:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-22 23:37:56 +0200 |
commit | dda0f1c343bfb3196ce6a7c7e8c2acccfd5c2e5b (patch) | |
tree | 10fc273a620949ccf63826363499f8f39056896d /core/ops_builtin.rs | |
parent | b319fa7f4965af3d3d576ea528248a31c96a4053 (diff) |
refactor(serde_v8): split ZeroCopyBuf into JsBuffer and ToJsBuffer (#19566)
`ZeroCopyBuf` was convenient to use, but sometimes it did hide details
that some copies were necessary in certain cases. Also it made it way to easy
for the caller to pass around and convert into different values. This commit
splits `ZeroCopyBuf` into `JsBuffer` (an array buffer coming from V8) and
`ToJsBuffer` (a Rust buffer that will be converted into a V8 array buffer).
As a result some magical conversions were removed (they were never used)
limiting the API surface and preparing for changes in #19534.
Diffstat (limited to 'core/ops_builtin.rs')
-rw-r--r-- | core/ops_builtin.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/core/ops_builtin.rs b/core/ops_builtin.rs index 70f478acd..2334c6918 100644 --- a/core/ops_builtin.rs +++ b/core/ops_builtin.rs @@ -6,11 +6,12 @@ use crate::io::BufView; use crate::ops_builtin_v8; use crate::ops_metrics::OpMetrics; use crate::resources::ResourceId; +use crate::JsBuffer; use crate::OpState; use crate::Resource; -use crate::ZeroCopyBuf; use anyhow::Error; use deno_ops::op; +use serde_v8::ToJsBuffer; use std::cell::RefCell; use std::io::stderr; use std::io::stdout; @@ -218,7 +219,7 @@ pub fn op_wasm_streaming_set_url( async fn op_read( state: Rc<RefCell<OpState>>, rid: ResourceId, - buf: ZeroCopyBuf, + buf: JsBuffer, ) -> Result<u32, Error> { let resource = state.borrow().resource_table.get_any(rid)?; let view = BufMutView::from(buf); @@ -229,7 +230,7 @@ async fn op_read( async fn op_read_all( state: Rc<RefCell<OpState>>, rid: ResourceId, -) -> Result<ZeroCopyBuf, Error> { +) -> Result<ToJsBuffer, Error> { let resource = state.borrow().resource_table.get_any(rid)?; // The number of bytes we attempt to grow the buffer by each time it fills @@ -291,14 +292,14 @@ async fn op_read_all( vec.truncate(nread); } - Ok(ZeroCopyBuf::from(vec)) + Ok(ToJsBuffer::from(vec)) } #[op] async fn op_write( state: Rc<RefCell<OpState>>, rid: ResourceId, - buf: ZeroCopyBuf, + buf: JsBuffer, ) -> Result<u32, Error> { let resource = state.borrow().resource_table.get_any(rid)?; let view = BufView::from(buf); @@ -331,7 +332,7 @@ fn op_write_sync( async fn op_write_all( state: Rc<RefCell<OpState>>, rid: ResourceId, - buf: ZeroCopyBuf, + buf: JsBuffer, ) -> Result<(), Error> { let resource = state.borrow().resource_table.get_any(rid)?; let view = BufView::from(buf); |