Skip to content

Commit

Permalink
use IndexSet
Browse files Browse the repository at this point in the history
  • Loading branch information
changhc committed Mar 1, 2025
1 parent b90fb3e commit 3f448c1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions core/engine/src/value/conversions/serde_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ use crate::{
js_string,
object::JsObject,
property::{PropertyDescriptor, PropertyKey},
Context, JsResult, JsVariant, NativeObject,
Context, JsResult, JsVariant,
};
use indexmap::IndexSet;
use serde_json::{Map, Value};

impl JsValue {
Expand Down Expand Up @@ -113,14 +114,14 @@ impl JsValue {
///
/// Panics if the `JsValue` is `Undefined`.
pub fn to_json(&self, context: &mut Context) -> JsResult<Value> {
let mut stack = vec![];
let mut stack = IndexSet::new();
self.to_json_inner(context, &mut stack)
}

fn to_json_inner(
&self,
context: &mut Context,
stack: &mut Vec<JsObject<dyn NativeObject>>,
stack: &mut IndexSet<JsObject>,
) -> JsResult<Value> {
match self.variant() {
JsVariant::Null => Ok(Value::Null),
Expand All @@ -138,7 +139,7 @@ impl JsValue {
.with_message("cyclic object value")
.into());
}
stack.push(obj.clone());
stack.insert(obj.clone());
let mut value_by_prop_key = |property_key, context: &mut Context| {
obj.borrow()
.properties()
Expand Down

0 comments on commit 3f448c1

Please sign in to comment.