1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:47:34 +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

@ -39,6 +39,7 @@
#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/PrimitiveString.h>
#include <LibJS/Runtime/Shape.h>
#include <LibJS/Runtime/Value.h>
#include <LibLine/Editor.h>
#include <stdio.h>
@ -113,10 +114,10 @@ static void print_object(const JS::Object& object, HashTable<JS::Object*>& seen_
{
fputs("{ ", stdout);
size_t index = 0;
for (auto& it : object.own_properties()) {
for (auto& it : object.shape().property_table()) {
printf("\"\033[33;1m%s\033[0m\": ", it.key.characters());
print_value(it.value, seen_objects);
if (index != object.own_properties().size() - 1)
print_value(object.get_direct(it.value.offset), seen_objects);
if (index != object.shape().property_table().size() - 1)
fputs(", ", stdout);
++index;
}