diff options
author | Andreas Kling <kling@serenityos.org> | 2020-04-06 16:53:02 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-06 18:09:26 +0200 |
commit | 90ba0145f6baec96bee41d2d0aa63253a42f4101 (patch) | |
tree | a42337a2f11df06901f6b151591e7b086980484e /Libraries/LibJS/Runtime/ObjectConstructor.cpp | |
parent | 65dd9d5ad3024d843c47073175546a509e12b336 (diff) | |
download | serenity-90ba0145f6baec96bee41d2d0aa63253a42f4101.zip |
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. :^)
Diffstat (limited to 'Libraries/LibJS/Runtime/ObjectConstructor.cpp')
-rw-r--r-- | Libraries/LibJS/Runtime/ObjectConstructor.cpp | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/Libraries/LibJS/Runtime/ObjectConstructor.cpp b/Libraries/LibJS/Runtime/ObjectConstructor.cpp index 41376b5cbc..f56ae2f161 100644 --- a/Libraries/LibJS/Runtime/ObjectConstructor.cpp +++ b/Libraries/LibJS/Runtime/ObjectConstructor.cpp @@ -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; |