summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Runtime/Object.h
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-04-06 16:53:02 +0200
committerAndreas Kling <kling@serenityos.org>2020-04-06 18:09:26 +0200
commit90ba0145f6baec96bee41d2d0aa63253a42f4101 (patch)
treea42337a2f11df06901f6b151591e7b086980484e /Libraries/LibJS/Runtime/Object.h
parent65dd9d5ad3024d843c47073175546a509e12b336 (diff)
downloadserenity-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/Object.h')
-rw-r--r--Libraries/LibJS/Runtime/Object.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/Libraries/LibJS/Runtime/Object.h b/Libraries/LibJS/Runtime/Object.h
index f47b35ac72..529fdb92cc 100644
--- a/Libraries/LibJS/Runtime/Object.h
+++ b/Libraries/LibJS/Runtime/Object.h
@@ -43,7 +43,10 @@ public:
Shape& shape() { return *m_shape; }
const Shape& shape() const { return *m_shape; }
+ Optional<Value> get_by_index(i32 property_index) const;
Optional<Value> get(const FlyString& property_name) const;
+
+ void put_by_index(i32 property_index, Value);
void put(const FlyString& property_name, Value);
virtual Optional<Value> get_own_property(const Object& this_object, const FlyString& property_name) const;
@@ -81,11 +84,15 @@ public:
Value get_direct(size_t index) const { return m_storage[index]; }
+ const Vector<Value>& elements() const { return m_elements; }
+ Vector<Value>& elements() { return m_elements; }
+
private:
void set_shape(Shape&);
Shape* m_shape { nullptr };
Vector<Value> m_storage;
+ Vector<Value> m_elements;
};
}