mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-27 03:37:53 +00:00
LibJS: Implement correct object property ordering
This commit introduces a way to get an object's own properties in the
correct order. The "correct order" for JS object properties is first all
array-like index properties (numeric keys) sorted by insertion order,
followed by all string properties sorted by insertion order.
Objects also now print correctly in the repl! Before this commit:
courage ~/js-tests $ js
> ({ foo: 1, bar: 2, baz: 3 })
{ bar: 2, foo: 1, baz: 3 }
After:
courage ~/js-tests $ js
> ({ foo: 1, bar: 2, baz: 3 })
{ foo: 1, bar: 2, baz: 3 }
This commit is contained in:
@@ -1046,8 +1046,8 @@ Value ObjectExpression::execute(Interpreter& interpreter) const
|
||||
} else if (key_result.is_object()) {
|
||||
auto& obj_to_spread = key_result.as_object();
|
||||
|
||||
for (auto& it : obj_to_spread.shape().property_table()) {
|
||||
if (obj_to_spread.has_own_property(it.key) && it.value.attributes & Attribute::Enumerable)
|
||||
for (auto& it : obj_to_spread.shape().property_table_ordered()) {
|
||||
if (it.value.attributes & Attribute::Enumerable)
|
||||
object->put(it.key, obj_to_spread.get(it.key));
|
||||
}
|
||||
} else if (key_result.is_string()) {
|
||||
|
||||
Reference in New Issue
Block a user