summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock10
-rw-r--r--core/Cargo.toml1
-rw-r--r--core/bindings.rs2
-rw-r--r--core/lib.rs1
-rw-r--r--core/ops.rs3
-rw-r--r--core/runtime.rs2
-rw-r--r--serde_v8/src/lib.rs2
-rw-r--r--serde_v8/src/serializable.rs22
8 files changed, 27 insertions, 16 deletions
diff --git a/Cargo.lock b/Cargo.lock
index fc1d4ca84..1af9d8e75 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -565,7 +565,6 @@ version = "0.83.0"
dependencies = [
"anyhow",
"bencher",
- "erased-serde",
"futures",
"indexmap",
"lazy_static",
@@ -898,15 +897,6 @@ dependencies = [
]
[[package]]
-name = "erased-serde"
-version = "0.3.13"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0465971a8cc1fa2455c8465aaa377131e1f1cf4983280f474a13e68793aa770c"
-dependencies = [
- "serde",
-]
-
-[[package]]
name = "errno"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/core/Cargo.toml b/core/Cargo.toml
index 1e23f788e..a06e1e43f 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -14,7 +14,6 @@ path = "lib.rs"
[dependencies]
anyhow = "1.0.38"
-erased-serde = "0.3.13"
futures = "0.3.12"
indexmap = "1.6.1"
lazy_static = "1.4.0"
diff --git a/core/bindings.rs b/core/bindings.rs
index 3484d3cbd..f086e1f9c 100644
--- a/core/bindings.rs
+++ b/core/bindings.rs
@@ -438,7 +438,7 @@ fn send<'s>(
match op {
Op::Sync(resp) => match resp {
OpResponse::Value(v) => {
- rv.set(to_v8(scope, v).unwrap());
+ rv.set(v.to_v8(scope).unwrap());
}
OpResponse::Buffer(buf) => {
rv.set(boxed_slice_to_uint8array(scope, buf).into());
diff --git a/core/lib.rs b/core/lib.rs
index 3ee08689e..f51411083 100644
--- a/core/lib.rs
+++ b/core/lib.rs
@@ -65,7 +65,6 @@ pub use crate::ops::OpResponse;
pub use crate::ops::OpState;
pub use crate::ops::OpTable;
pub use crate::ops::PromiseId;
-pub use crate::ops::Serializable;
pub use crate::ops_bin::bin_op_async;
pub use crate::ops_bin::bin_op_sync;
pub use crate::ops_bin::ValueOrVector;
diff --git a/core/ops.rs b/core/ops.rs
index 5bd0928b6..1a2a2ebc7 100644
--- a/core/ops.rs
+++ b/core/ops.rs
@@ -22,7 +22,6 @@ use std::ops::DerefMut;
use std::pin::Pin;
use std::rc::Rc;
-pub use erased_serde::Serialize as Serializable;
pub type PromiseId = u64;
pub type OpAsyncFuture = Pin<Box<dyn Future<Output = OpResponse>>>;
pub type OpFn =
@@ -60,7 +59,7 @@ impl<'a, 'b, 'c> OpPayload<'a, 'b, 'c> {
}
pub enum OpResponse {
- Value(Box<dyn Serializable>),
+ Value(Box<dyn serde_v8::Serializable>),
Buffer(Box<[u8]>),
}
diff --git a/core/runtime.rs b/core/runtime.rs
index a64a71449..f358cf05e 100644
--- a/core/runtime.rs
+++ b/core/runtime.rs
@@ -1419,7 +1419,7 @@ impl JsRuntime {
let (promise_id, resp) = overflown_response;
args.push(v8::Integer::new(scope, promise_id as i32).into());
args.push(match resp {
- OpResponse::Value(value) => serde_v8::to_v8(scope, value).unwrap(),
+ OpResponse::Value(value) => value.to_v8(scope).unwrap(),
OpResponse::Buffer(buf) => {
bindings::boxed_slice_to_uint8array(scope, buf).into()
}
diff --git a/serde_v8/src/lib.rs b/serde_v8/src/lib.rs
index 9413791bb..bd4b00b32 100644
--- a/serde_v8/src/lib.rs
+++ b/serde_v8/src/lib.rs
@@ -5,6 +5,7 @@ mod keys;
mod magic;
mod payload;
mod ser;
+mod serializable;
pub mod utils;
pub use de::{from_v8, from_v8_cached, Deserializer};
@@ -12,3 +13,4 @@ pub use error::{Error, Result};
pub use keys::KeyCache;
pub use magic::Value;
pub use ser::{to_v8, Serializer};
+pub use serializable::Serializable;
diff --git a/serde_v8/src/serializable.rs b/serde_v8/src/serializable.rs
new file mode 100644
index 000000000..2e781340b
--- /dev/null
+++ b/serde_v8/src/serializable.rs
@@ -0,0 +1,22 @@
+use rusty_v8 as v8;
+
+/// Serializable exists to allow boxing values as "objects" to be serialized later,
+/// this is particularly useful for async op-responses. This trait is a more efficient
+/// replacement for erased-serde that makes less allocations, since it's specific to serde_v8
+/// (and thus doesn't have to have generic outputs, etc...)
+pub trait Serializable {
+ fn to_v8<'a>(
+ &self,
+ scope: &mut v8::HandleScope<'a>,
+ ) -> Result<v8::Local<'a, v8::Value>, crate::Error>;
+}
+
+/// Allows all implementors of `serde::Serialize` to implement Serializable
+impl<T: serde::Serialize> Serializable for T {
+ fn to_v8<'a>(
+ &self,
+ scope: &mut v8::HandleScope<'a>,
+ ) -> Result<v8::Local<'a, v8::Value>, crate::Error> {
+ crate::to_v8(scope, self)
+ }
+}