Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
n14little committed May 25, 2020
1 parent b41c589 commit f32e4ad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
39 changes: 18 additions & 21 deletions boa/src/builtins/json/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,20 @@ pub fn stringify(_: &mut Value, args: &[Value], interpreter: &mut Interpreter) -
.as_object()
.map(|obj| {
let object_to_return = Value::new_object(None);
for (key, val) in obj.properties.iter() {
if let Some(value) = &val.value {
let mut this_arg = object.clone();
object_to_return.set_property(
String::from(key),
Property::default().value(
interpreter
.call(
replacer,
&mut this_arg,
&[Value::string(key), Value::from(value)],
)
.expect("failed to get returned value from replacer function"),
),
);
}
for (key, val) in obj.properties.iter().filter(|(_, v)|v.value.is_some()) {
let mut this_arg = object.clone();
object_to_return.set_property(
key.to_owned(),
Property::default().value(
interpreter
.call(
replacer,
&mut this_arg,
&[Value::string(key), Value::from(val.value.as_ref())],
)
.expect("failed to get returned value from replacer function"),
),
);
}
Value::from(object_to_return.to_json().to_string())
})
Expand All @@ -111,18 +109,17 @@ pub fn stringify(_: &mut Value, args: &[Value], interpreter: &mut Interpreter) -
serde_json::Map::with_capacity(replacer_as_object.properties.len() - 1);
let fields = replacer_as_object
.properties
.iter()
.filter_map(|(key, prop)| {
.keys()
.filter_map(|key| {
if key == "length" {
None
} else {
// TODO: this should be the abstract operation `Get`
prop.value.as_ref().map(Value::to_string)
Some(replacer.get_field_slice(&key.to_string()))
}
});
for field in fields {
if let Some(value) = object
.get_property(&field)
.get_property(&field.to_string())
.map(|prop| prop.value.as_ref().map(|v| v.to_json()))
.flatten()
{
Expand Down
4 changes: 2 additions & 2 deletions boa/src/builtins/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ impl ValueData {
Self::Object(ref obj) => {
if obj.borrow().kind == ObjectKind::Array {
let mut arr: Vec<JSONValue> = Vec::new();
obj.borrow().properties.iter().for_each(|(k, _)| {
obj.borrow().properties.keys().for_each(|k| {
if k != "length" {
let value = self.get_field_slice(k);
if value.is_undefined() || value.is_function() {
Expand All @@ -741,7 +741,7 @@ impl ValueData {
JSONValue::Array(arr)
} else {
let mut new_obj = Map::new();
obj.borrow().properties.iter().for_each(|(k, _)| {
obj.borrow().properties.keys().for_each(|k| {
let key = k.clone();
let value = self.get_field_slice(k);
if !value.is_undefined() && !value.is_function() {
Expand Down

0 comments on commit f32e4ad

Please sign in to comment.