1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 08:35:09 +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:
Andreas Kling 2020-04-06 16:53:02 +02:00
parent 65dd9d5ad3
commit 90ba0145f6
6 changed files with 69 additions and 50 deletions

View file

@ -64,11 +64,9 @@ Value ObjectConstructor::get_own_property_names(Interpreter& interpreter)
if (interpreter.exception())
return {};
auto* result = interpreter.heap().allocate<Array>();
if (object->is_array()) {
auto* array = static_cast<const Array*>(object);
for (i32 i = 0; i < array->length(); ++i)
result->push(js_string(interpreter, String::number(i)));
}
for (size_t i = 0; i < object->elements().size(); ++i)
result->push(js_string(interpreter, String::number(i)));
for (auto& it : object->shape().property_table())
result->push(js_string(interpreter, it.key));
return result;