mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:58:11 +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:
parent
58f6f50de4
commit
95abcc3722
9 changed files with 41 additions and 9 deletions
|
@ -142,7 +142,7 @@ static void print_object(const JS::Object& object, HashTable<JS::Object*>& seen_
|
|||
fputs(", ", stdout);
|
||||
|
||||
size_t index = 0;
|
||||
for (auto& it : object.shape().property_table()) {
|
||||
for (auto& it : object.shape().property_table_ordered()) {
|
||||
printf("\"\033[33;1m%s\033[0m\": ", it.key.characters());
|
||||
print_value(object.get_direct(it.value.offset), seen_objects);
|
||||
if (index != object.shape().property_count() - 1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue