summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron O'Mullan <aaron.omullan@gmail.com>2021-10-20 23:17:12 +0200
committerGitHub <noreply@github.com>2021-10-20 23:17:12 +0200
commitf250faaf05827a8f45bdb7a1f4c191ee3657baea (patch)
treeee94eb7ba327903743aa0c23a5e3d9cdba1dde35
parent9bece95f2884570f440006aeaf68d663599999d2 (diff)
feat(serde_v8): allow all values to deserialize to unit type (#12504)
-rw-r--r--core/ops_json.rs18
-rw-r--r--serde_v8/src/de.rs6
-rw-r--r--serde_v8/src/error.rs1
3 files changed, 3 insertions, 22 deletions
diff --git a/core/ops_json.rs b/core/ops_json.rs
index dca9a9a77..a2eff40ef 100644
--- a/core/ops_json.rs
+++ b/core/ops_json.rs
@@ -16,28 +16,14 @@ use std::rc::Rc;
///
/// It's mainly intended for embedders who want to disable ops, see ./examples/disable_ops.rs
pub fn void_op_sync() -> Box<OpFn> {
- // TODO(@AaronO): use this simpler implementation after changing serde_v8 to allow all values
- // to deserialize to the unit type instead of failing with `ExpectedNull`
- // op_sync(|_, _: (), _: ()| Ok(()))
- Box::new(move |state, _| -> Op {
- let op_result = serialize_op_result(Ok(()), state);
- Op::Sync(op_result)
- })
+ op_sync(|_, _: (), _: ()| Ok(()))
}
/// A helper function that returns an async NOP OpFn
///
/// It's mainly intended for embedders who want to disable ops, see ./examples/disable_ops.rs
pub fn void_op_async() -> Box<OpFn> {
- // TODO(@AaronO): use this simpler implementation after changing serde_v8 to allow all values
- // to deserialize to the unit type instead of failing with `ExpectedNull`
- // op_async(|_, _: (), _: ()| futures::future::ok(()))
- Box::new(move |state, payload| -> Op {
- let op_id = payload.op_id;
- let pid = payload.promise_id;
- let op_result = serialize_op_result(Ok(()), state);
- Op::Async(OpCall::ready((pid, op_id, op_result)))
- })
+ op_async(|_, _: (), _: ()| futures::future::ok(()))
}
/// Creates an op that passes data synchronously using JSON.
diff --git a/serde_v8/src/de.rs b/serde_v8/src/de.rs
index d4338a37f..b865547ec 100644
--- a/serde_v8/src/de.rs
+++ b/serde_v8/src/de.rs
@@ -218,11 +218,7 @@ impl<'de, 'a, 'b, 's, 'x> de::Deserializer<'de>
where
V: Visitor<'de>,
{
- if self.input.is_null_or_undefined() {
- visitor.visit_unit()
- } else {
- Err(Error::ExpectedNull)
- }
+ visitor.visit_unit()
}
fn deserialize_unit_struct<V>(
diff --git a/serde_v8/src/error.rs b/serde_v8/src/error.rs
index 39625da13..099d8493d 100644
--- a/serde_v8/src/error.rs
+++ b/serde_v8/src/error.rs
@@ -12,7 +12,6 @@ pub enum Error {
ExpectedBoolean,
ExpectedInteger,
ExpectedString,
- ExpectedNull,
ExpectedArray,
ExpectedMap,
ExpectedEnum,