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

feat(ecmascript): Implement JSON.stringify #527

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions nova_vm/src/ecmascript/builtins/primitive_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,28 @@ impl TryFrom<PrimitiveObjectData> for Symbol<'_> {
}
}

impl IntoValue for PrimitiveObjectData {
fn into_value(self) -> Value {
self.into()
}
}

impl From<PrimitiveObjectData> for Value {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: IntoPrimitive as well? And perhaps create IntoValue based on that?

fn from(value: PrimitiveObjectData) -> Self {
match value {
PrimitiveObjectData::Boolean(data) => Value::Boolean(data),
PrimitiveObjectData::String(data) => Value::String(data),
PrimitiveObjectData::SmallString(data) => Value::SmallString(data),
PrimitiveObjectData::Symbol(data) => Value::Symbol(data),
PrimitiveObjectData::Number(data) => Value::Number(data),
PrimitiveObjectData::Integer(data) => Value::Integer(data),
PrimitiveObjectData::Float(data) => Value::SmallF64(data),
PrimitiveObjectData::BigInt(data) => Value::BigInt(data),
PrimitiveObjectData::SmallBigInt(data) => Value::SmallBigInt(data),
}
}
}

#[derive(Debug, Clone, Copy)]
pub struct PrimitiveObjectHeapData {
pub(crate) object_index: Option<OrdinaryObject<'static>>,
Expand Down
Loading
Loading