diff --git a/boa/src/value/mod.rs b/boa/src/value/mod.rs index b243173e8e..f10fbaedc0 100644 --- a/boa/src/value/mod.rs +++ b/boa/src/value/mod.rs @@ -238,15 +238,15 @@ impl Value { Self::Boolean(b) => Ok(JSONValue::Bool(b)), Self::Object(ref obj) => { if obj.borrow().is_array() { - let mut arr: Vec = Vec::new(); - for k in obj.borrow().keys() { - if k != "length" { - let value = self.get_field(k.to_string()); - if value.is_undefined() || value.is_function() || value.is_symbol() { - arr.push(JSONValue::Null); - } else { - arr.push(self.get_field(k.to_string()).to_json(interpreter)?); - } + let mut keys: Vec = obj.borrow().index_property_keys().cloned().collect(); + keys.sort(); + let mut arr: Vec = Vec::with_capacity(keys.len()); + for key in keys { + let value = self.get_field(key); + if value.is_undefined() || value.is_function() || value.is_symbol() { + arr.push(JSONValue::Null); + } else { + arr.push(value.to_json(interpreter)?); } } Ok(JSONValue::Array(arr))