1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:27:45 +00:00

LibJS: Start implementing object shapes

This patch adds JS::Shape, which implements a transition tree for our
Object class. Object property keys, prototypes and attributes are now
stored in a Shape, and each Object has a Shape.

When adding a property to an Object, we make a transition from the old
Shape to a new Shape. If we've made the same exact transition in the
past (with another Object), we reuse the same transition and both
objects may now share a Shape.

This will become the foundation of inline caching and other engine
optimizations in the future. :^)
This commit is contained in:
Andreas Kling 2020-04-02 19:32:21 +02:00
parent 3906d2b46a
commit 5e6e1fd482
10 changed files with 252 additions and 29 deletions

View file

@ -129,6 +129,8 @@ public:
return m_call_stack.last().this_value;
}
Shape* empty_object_shape() { return m_empty_object_shape; }
Object* string_prototype() { return m_string_prototype; }
Object* object_prototype() { return m_object_prototype; }
Object* array_prototype() { return m_array_prototype; }
@ -158,6 +160,8 @@ private:
Vector<ScopeFrame> m_scope_stack;
Vector<CallFrame> m_call_stack;
Shape* m_empty_object_shape { nullptr };
Object* m_global_object { nullptr };
Object* m_string_prototype { nullptr };
Object* m_object_prototype { nullptr };