mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:18:11 +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:
parent
3906d2b46a
commit
5e6e1fd482
10 changed files with 252 additions and 29 deletions
|
@ -35,6 +35,7 @@
|
|||
#include <LibJS/Runtime/NativeFunction.h>
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
#include <LibJS/Runtime/ObjectPrototype.h>
|
||||
#include <LibJS/Runtime/Shape.h>
|
||||
#include <LibJS/Runtime/StringPrototype.h>
|
||||
#include <LibJS/Runtime/Value.h>
|
||||
|
||||
|
@ -43,6 +44,8 @@ namespace JS {
|
|||
Interpreter::Interpreter()
|
||||
: m_heap(*this)
|
||||
{
|
||||
m_empty_object_shape = heap().allocate<Shape>();
|
||||
|
||||
m_object_prototype = heap().allocate<ObjectPrototype>();
|
||||
m_string_prototype = heap().allocate<StringPrototype>();
|
||||
m_array_prototype = heap().allocate<ArrayPrototype>();
|
||||
|
@ -160,6 +163,8 @@ Optional<Value> Interpreter::get_variable(const FlyString& name)
|
|||
|
||||
void Interpreter::gather_roots(Badge<Heap>, HashTable<Cell*>& roots)
|
||||
{
|
||||
roots.set(m_empty_object_shape);
|
||||
|
||||
roots.set(m_global_object);
|
||||
roots.set(m_string_prototype);
|
||||
roots.set(m_object_prototype);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue