mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 16:45:03 +00:00
LibJS: Add a number-indexed property storage to all Objects
Objects can have both named and indexed properties. Previously we kept all property names as strings. This patch separates named and indexed properties and splits them between Object::m_storage and m_elements. This allows us to do much faster array-style access using numeric indices. It also makes the Array class much less special, since all Objects now have number-indexed storage. :^)
This commit is contained in:
@@ -117,11 +117,22 @@ static void print_array(const JS::Array& array, HashTable<JS::Object*>& seen_obj
|
||||
static void print_object(const JS::Object& object, HashTable<JS::Object*>& seen_objects)
|
||||
{
|
||||
fputs("{ ", stdout);
|
||||
|
||||
for (size_t i = 0; i < object.elements().size(); ++i) {
|
||||
printf("\"\033[33;1m%zu\033[0m\": ", i);
|
||||
print_value(object.elements()[i], seen_objects);
|
||||
if (i != object.elements().size() - 1)
|
||||
fputs(", ", stdout);
|
||||
}
|
||||
|
||||
if (!object.elements().is_empty() && object.shape().property_count())
|
||||
fputs(", ", stdout);
|
||||
|
||||
size_t index = 0;
|
||||
for (auto& it : object.shape().property_table()) {
|
||||
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_table().size() - 1)
|
||||
if (index != object.shape().property_count() - 1)
|
||||
fputs(", ", stdout);
|
||||
++index;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user