Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: introduce serde_v8 #9722

Merged
merged 24 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
clippy
  • Loading branch information
AaronO committed Mar 19, 2021
commit a2f620683ce7bda4a1562fc59383718947b762ec
1 change: 0 additions & 1 deletion serde_v8/examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use rusty_v8 as v8;
use serde_v8;

use serde::Deserialize;

Expand Down
5 changes: 2 additions & 3 deletions serde_v8/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ impl<'de, 'a, 'b, 's, 'x> de::Deserializer<'de>
// Regular struct
let obj = v8::Local::<v8::Object>::try_from(self.input).unwrap();
let map = ObjectAccess {
fields: fields,
obj: obj,
fields,
obj,
pos: 0,
scope: self.scope,
_cache: None,
Expand Down Expand Up @@ -387,7 +387,6 @@ fn v8_struct_key<'s>(
v8::NewStringType::Internalized,
)
.unwrap()
.into()

// TODO: consider external strings later
// right now non-deduped external strings (without KeyCache)
Expand Down
1 change: 0 additions & 1 deletion serde_v8/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std;
use std::fmt::{self, Display};

use serde::{de, ser};
Expand Down
5 changes: 2 additions & 3 deletions serde_v8/src/magic.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use rusty_v8 as v8;
use serde;

use std::fmt;
use std::marker::PhantomData;

pub const FIELD: &'static str = "$__v8_magic_value";
pub const NAME: &'static str = "$__v8_magic_Value";
pub const FIELD: &str = "$__v8_magic_value";
pub const NAME: &str = "$__v8_magic_Value";

pub struct Value<'s> {
pub v8_value: v8::Local<'s, v8::Value>,
Expand Down
6 changes: 1 addition & 5 deletions serde_v8/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ type JsResult<'s> = Result<JsValue<'s>>;

type ScopePtr<'a, 'b> = Rc<RefCell<v8::EscapableHandleScope<'a, 'b>>>;

pub fn to_v8<'a, 'b, T>(
scope: &mut v8::HandleScope<'a>,
input: T,
) -> JsResult<'a>
pub fn to_v8<'a, T>(scope: &mut v8::HandleScope<'a>, input: T) -> JsResult<'a>
where
T: Serialize,
{
Expand Down Expand Up @@ -604,5 +601,4 @@ fn v8_struct_key<'s>(
v8::NewStringType::Internalized,
)
.unwrap()
.into()
}
3 changes: 1 addition & 2 deletions serde_v8/tests/de.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use rusty_v8 as v8;
use serde_v8;

use serde::Deserialize;

Expand Down Expand Up @@ -52,7 +51,7 @@ fn de_basic() {

let v: v8::Local<v8::Value> = v8::Number::new(scope, 12345.0).into();
let x: f64 = serde_v8::from_v8(scope, v).unwrap();
assert_eq!(x, 12345.0);
assert!((x - 12345.0).abs() < f64::EPSILON);
}

v8_shutdown();
Expand Down
1 change: 0 additions & 1 deletion serde_v8/tests/magic.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use rusty_v8 as v8;
use serde_v8;

use serde::{Deserialize, Serialize};

Expand Down