Skip to content

Commit

Permalink
Merge b955a0f into 8036a49
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat authored Aug 2, 2020
2 parents 8036a49 + b955a0f commit 262d32d
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 151 deletions.
15 changes: 10 additions & 5 deletions boa/src/builtins/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use crate::builtins::{
function::make_builtin_fn,
property::Property,
property::{Property, PropertyKey},
value::{ResultValue, Value},
};
use crate::{exec::Interpreter, BoaProfiler};
Expand Down Expand Up @@ -54,7 +54,7 @@ impl Json {
Some(reviver) if reviver.is_function() => {
let mut holder = Value::new_object(None);
holder.set_field("", j);
Self::walk(reviver, ctx, &mut holder, Value::from(""))
Self::walk(reviver, ctx, &mut holder, &"".into())
}
_ => Ok(j),
}
Expand All @@ -69,13 +69,18 @@ impl Json {
/// for possible transformation.
///
/// [polyfill]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
fn walk(reviver: &Value, ctx: &mut Interpreter, holder: &mut Value, key: Value) -> ResultValue {
fn walk(
reviver: &Value,
ctx: &mut Interpreter,
holder: &mut Value,
key: &PropertyKey,
) -> ResultValue {
let mut value = holder.get_field(key.clone());

let obj = value.as_object().as_deref().cloned();
if let Some(obj) = obj {
for key in obj.properties().keys() {
let v = Self::walk(reviver, ctx, &mut value, Value::from(key.as_str()));
let v = Self::walk(reviver, ctx, &mut value, &key.as_str().into());
match v {
Ok(v) if !v.is_undefined() => {
value.set_field(key.as_str(), v);
Expand All @@ -87,7 +92,7 @@ impl Json {
}
}
}
ctx.call(reviver, holder, &[key, value])
ctx.call(reviver, holder, &[key.into(), value])
}

/// `JSON.stringify( value[, replacer[, space]] )`
Expand Down
Loading

0 comments on commit 262d32d

Please sign in to comment.