mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 09:27:34 +00:00
LibJS: Allow Shape without a global object
It would be nice to be able to cache some shapes globally in the VM, but then they can't be tied to a specific global object. So let's just get rid of the requirement that shapes are tied to a global object.
This commit is contained in:
parent
d66087ac2f
commit
97a05ac9ac
3 changed files with 14 additions and 6 deletions
|
@ -88,7 +88,7 @@ public:
|
||||||
Shape& shape() { return *m_shape; }
|
Shape& shape() { return *m_shape; }
|
||||||
const Shape& shape() const { return *m_shape; }
|
const Shape& shape() const { return *m_shape; }
|
||||||
|
|
||||||
GlobalObject& global_object() const { return shape().global_object(); }
|
GlobalObject& global_object() const { return *shape().global_object(); }
|
||||||
|
|
||||||
virtual Value get(const PropertyName&, Value receiver = {}) const;
|
virtual Value get(const PropertyName&, Value receiver = {}) const;
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,8 @@ namespace JS {
|
||||||
|
|
||||||
Shape* Shape::create_unique_clone() const
|
Shape* Shape::create_unique_clone() const
|
||||||
{
|
{
|
||||||
auto* new_shape = heap().allocate_without_global_object<Shape>(m_global_object);
|
ASSERT(m_global_object);
|
||||||
|
auto* new_shape = heap().allocate_without_global_object<Shape>(*m_global_object);
|
||||||
new_shape->m_unique = true;
|
new_shape->m_unique = true;
|
||||||
new_shape->m_prototype = m_prototype;
|
new_shape->m_prototype = m_prototype;
|
||||||
ensure_property_table();
|
ensure_property_table();
|
||||||
|
@ -67,8 +68,12 @@ Shape* Shape::create_prototype_transition(Object* new_prototype)
|
||||||
return heap().allocate_without_global_object<Shape>(*this, new_prototype);
|
return heap().allocate_without_global_object<Shape>(*this, new_prototype);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Shape::Shape(ShapeWithoutGlobalObjectTag)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Shape::Shape(GlobalObject& global_object)
|
Shape::Shape(GlobalObject& global_object)
|
||||||
: m_global_object(global_object)
|
: m_global_object(&global_object)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +104,7 @@ Shape::~Shape()
|
||||||
void Shape::visit_children(Cell::Visitor& visitor)
|
void Shape::visit_children(Cell::Visitor& visitor)
|
||||||
{
|
{
|
||||||
Cell::visit_children(visitor);
|
Cell::visit_children(visitor);
|
||||||
visitor.visit(&m_global_object);
|
visitor.visit(m_global_object);
|
||||||
visitor.visit(m_prototype);
|
visitor.visit(m_prototype);
|
||||||
visitor.visit(m_previous);
|
visitor.visit(m_previous);
|
||||||
m_property_name.visit_children(visitor);
|
m_property_name.visit_children(visitor);
|
||||||
|
|
|
@ -62,6 +62,9 @@ public:
|
||||||
Prototype,
|
Prototype,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class ShapeWithoutGlobalObjectTag { Tag };
|
||||||
|
|
||||||
|
explicit Shape(ShapeWithoutGlobalObjectTag);
|
||||||
explicit Shape(GlobalObject&);
|
explicit Shape(GlobalObject&);
|
||||||
Shape(Shape& previous_shape, const StringOrSymbol& property_name, PropertyAttributes attributes, TransitionType);
|
Shape(Shape& previous_shape, const StringOrSymbol& property_name, PropertyAttributes attributes, TransitionType);
|
||||||
Shape(Shape& previous_shape, Object* new_prototype);
|
Shape(Shape& previous_shape, Object* new_prototype);
|
||||||
|
@ -75,7 +78,7 @@ public:
|
||||||
bool is_unique() const { return m_unique; }
|
bool is_unique() const { return m_unique; }
|
||||||
Shape* create_unique_clone() const;
|
Shape* create_unique_clone() const;
|
||||||
|
|
||||||
GlobalObject& global_object() const { return m_global_object; }
|
GlobalObject* global_object() const { return m_global_object; }
|
||||||
|
|
||||||
Object* prototype() { return m_prototype; }
|
Object* prototype() { return m_prototype; }
|
||||||
const Object* prototype() const { return m_prototype; }
|
const Object* prototype() const { return m_prototype; }
|
||||||
|
@ -107,7 +110,7 @@ private:
|
||||||
TransitionType m_transition_type : 6 { TransitionType::Invalid };
|
TransitionType m_transition_type : 6 { TransitionType::Invalid };
|
||||||
bool m_unique : 1 { false };
|
bool m_unique : 1 { false };
|
||||||
|
|
||||||
GlobalObject& m_global_object;
|
GlobalObject* m_global_object { nullptr };
|
||||||
|
|
||||||
mutable OwnPtr<HashMap<StringOrSymbol, PropertyMetadata>> m_property_table;
|
mutable OwnPtr<HashMap<StringOrSymbol, PropertyMetadata>> m_property_table;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue