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_v8.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_v8.rs')
-rw-r--r-- | core/ops_builtin_v8.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/core/ops_builtin_v8.rs b/core/ops_builtin_v8.rs index 9fd906291..034a3810d 100644 --- a/core/ops_builtin_v8.rs +++ b/core/ops_builtin_v8.rs @@ -9,9 +9,10 @@ use crate::resolve_url; use crate::runtime::script_origin; use crate::serde_v8::from_v8; use crate::source_map::apply_source_map; +use crate::JsBuffer; use crate::JsRealm; use crate::JsRuntime; -use crate::ZeroCopyBuf; +use crate::ToJsBuffer; use anyhow::Error; use deno_ops::op; use serde::Deserialize; @@ -375,7 +376,7 @@ fn op_serialize( value: serde_v8::Value, options: Option<SerializeDeserializeOptions>, error_callback: Option<serde_v8::Value>, -) -> Result<ZeroCopyBuf, Error> { +) -> Result<ToJsBuffer, Error> { let options = options.unwrap_or_default(); let error_callback = match error_callback { Some(cb) => Some( @@ -448,7 +449,7 @@ fn op_serialize( if scope.has_caught() || scope.has_terminated() { scope.rethrow(); // Dummy value, this result will be discarded because an error was thrown. - Ok(ZeroCopyBuf::empty()) + Ok(ToJsBuffer::empty()) } else if let Some(true) = ret { let vector = value_serializer.release(); Ok(vector.into()) @@ -460,7 +461,7 @@ fn op_serialize( #[op(v8)] fn op_deserialize<'a>( scope: &mut v8::HandleScope<'a>, - zero_copy: ZeroCopyBuf, + zero_copy: JsBuffer, options: Option<SerializeDeserializeOptions>, ) -> Result<serde_v8::Value<'a>, Error> { let options = options.unwrap_or_default(); |