1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 20:17:41 +00:00

LibJS: Move the empty object shape from Interpreter to GlobalObject

The big remaining hurdle before a GlobalObject-agnostic Interpreter is
the fact that Interpreter owns and vends the GlobalObject :^)
This commit is contained in:
Andreas Kling 2020-04-18 13:56:13 +02:00
parent 75f6454de7
commit 3072f9fd82
5 changed files with 13 additions and 7 deletions

View file

@ -40,7 +40,6 @@ namespace JS {
Interpreter::Interpreter() Interpreter::Interpreter()
: m_heap(*this) : m_heap(*this)
{ {
m_empty_object_shape = heap().allocate<Shape>();
} }
Interpreter::~Interpreter() Interpreter::~Interpreter()
@ -161,7 +160,6 @@ Optional<Value> Interpreter::get_variable(const FlyString& name)
void Interpreter::gather_roots(Badge<Heap>, HashTable<Cell*>& roots) void Interpreter::gather_roots(Badge<Heap>, HashTable<Cell*>& roots)
{ {
roots.set(m_empty_object_shape);
roots.set(m_global_object); roots.set(m_global_object);
roots.set(m_exception); roots.set(m_exception);

View file

@ -139,8 +139,6 @@ public:
return m_call_stack.last().this_value; return m_call_stack.last().this_value;
} }
Shape* empty_object_shape() { return m_empty_object_shape; }
Exception* exception() Exception* exception()
{ {
return m_exception; return m_exception;
@ -171,7 +169,6 @@ private:
Vector<ScopeFrame> m_scope_stack; Vector<ScopeFrame> m_scope_stack;
Vector<CallFrame> m_call_stack; Vector<CallFrame> m_call_stack;
Shape* m_empty_object_shape { nullptr };
Object* m_global_object { nullptr }; Object* m_global_object { nullptr };
Exception* m_exception { nullptr }; Exception* m_exception { nullptr };

View file

@ -72,6 +72,7 @@ GlobalObject::GlobalObject()
void GlobalObject::initialize() void GlobalObject::initialize()
{ {
// These are done first since other prototypes depend on their presence. // These are done first since other prototypes depend on their presence.
m_empty_object_shape = heap().allocate<Shape>();
m_object_prototype = heap().allocate<ObjectPrototype>(); m_object_prototype = heap().allocate<ObjectPrototype>();
m_function_prototype = heap().allocate<FunctionPrototype>(); m_function_prototype = heap().allocate<FunctionPrototype>();
@ -119,6 +120,8 @@ void GlobalObject::visit_children(Visitor& visitor)
{ {
Object::visit_children(visitor); Object::visit_children(visitor);
visitor.visit(m_empty_object_shape);
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
visitor.visit(m_##snake_name##_constructor); visitor.visit(m_##snake_name##_constructor);
JS_ENUMERATE_ERROR_SUBCLASSES JS_ENUMERATE_ERROR_SUBCLASSES

View file

@ -37,6 +37,8 @@ public:
virtual ~GlobalObject() override; virtual ~GlobalObject() override;
Shape* empty_object_shape() { return m_empty_object_shape; }
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
ConstructorName* snake_name##_constructor() { return m_##snake_name##_constructor; } \ ConstructorName* snake_name##_constructor() { return m_##snake_name##_constructor; } \
Object* snake_name##_prototype() { return m_##snake_name##_prototype; } Object* snake_name##_prototype() { return m_##snake_name##_prototype; }
@ -55,6 +57,8 @@ private:
template<typename ConstructorType> template<typename ConstructorType>
void add_constructor(const FlyString& property_name, ConstructorType*&, Object& prototype); void add_constructor(const FlyString& property_name, ConstructorType*&, Object& prototype);
Shape* m_empty_object_shape { nullptr };
#define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \ #define __JS_ENUMERATE(ClassName, snake_name, PrototypeName, ConstructorName) \
ConstructorName* m_##snake_name##_constructor { nullptr }; \ ConstructorName* m_##snake_name##_constructor { nullptr }; \
Object* m_##snake_name##_prototype { nullptr }; Object* m_##snake_name##_prototype { nullptr };

View file

@ -45,8 +45,12 @@ Object* Object::create_empty(Interpreter&, GlobalObject& global_object)
Object::Object(Object* prototype) Object::Object(Object* prototype)
{ {
m_shape = interpreter().empty_object_shape(); if (prototype) {
set_prototype(prototype); m_shape = interpreter().global_object().empty_object_shape();
set_prototype(prototype);
} else {
m_shape = interpreter().heap().allocate<Shape>();
}
} }
Object::~Object() Object::~Object()