summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Runtime/Shape.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-06-08 12:15:58 +0200
committerAndreas Kling <kling@serenityos.org>2020-06-08 12:15:58 +0200
commitff8bb962b620874668b797a1ee1c25de3f5c1074 (patch)
tree7267c17fdfa4fd6b1bb51daafe980cfc96937e96 /Libraries/LibJS/Runtime/Shape.cpp
parent10aebabf0bd21c2b0599525a708c95dca502fa7a (diff)
downloadserenity-ff8bb962b620874668b797a1ee1c25de3f5c1074.zip
LibJS: Always keep a reference to the global object in Shape
We need to move towards supporting multiple global objects, which will be a large refactoring. To keep it manageable, let's do it in steps, starting with giving Object a way to find the GlobalObject it lives inside by asking its Shape for it.
Diffstat (limited to 'Libraries/LibJS/Runtime/Shape.cpp')
-rw-r--r--Libraries/LibJS/Runtime/Shape.cpp25
1 files changed, 15 insertions, 10 deletions
diff --git a/Libraries/LibJS/Runtime/Shape.cpp b/Libraries/LibJS/Runtime/Shape.cpp
index 549ec600e7..cf6821e04d 100644
--- a/Libraries/LibJS/Runtime/Shape.cpp
+++ b/Libraries/LibJS/Runtime/Shape.cpp
@@ -25,13 +25,14 @@
*/
#include <LibJS/Interpreter.h>
+#include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Shape.h>
namespace JS {
Shape* Shape::create_unique_clone() const
{
- auto* new_shape = heap().allocate<Shape>();
+ auto* new_shape = heap().allocate<Shape>(m_global_object);
new_shape->m_unique = true;
new_shape->m_prototype = m_prototype;
ensure_property_table();
@@ -45,7 +46,7 @@ Shape* Shape::create_put_transition(const FlyString& property_name, PropertyAttr
TransitionKey key { property_name, attributes };
if (auto* existing_shape = m_forward_transitions.get(key).value_or(nullptr))
return existing_shape;
- auto* new_shape = heap().allocate<Shape>(this, property_name, attributes, TransitionType::Put);
+ auto* new_shape = heap().allocate<Shape>(*this, property_name, attributes, TransitionType::Put);
m_forward_transitions.set(key, new_shape);
return new_shape;
}
@@ -55,31 +56,34 @@ Shape* Shape::create_configure_transition(const FlyString& property_name, Proper
TransitionKey key { property_name, attributes };
if (auto* existing_shape = m_forward_transitions.get(key).value_or(nullptr))
return existing_shape;
- auto* new_shape = heap().allocate<Shape>(this, property_name, attributes, TransitionType::Configure);
+ auto* new_shape = heap().allocate<Shape>(*this, property_name, attributes, TransitionType::Configure);
m_forward_transitions.set(key, new_shape);
return new_shape;
}
Shape* Shape::create_prototype_transition(Object* new_prototype)
{
- return heap().allocate<Shape>(this, new_prototype);
+ return heap().allocate<Shape>(*this, new_prototype);
}
-Shape::Shape()
+Shape::Shape(GlobalObject& global_object)
+ : m_global_object(global_object)
{
}
-Shape::Shape(Shape* previous_shape, const FlyString& property_name, PropertyAttributes attributes, TransitionType transition_type)
- : m_previous(previous_shape)
+Shape::Shape(Shape& previous_shape, const FlyString& property_name, PropertyAttributes attributes, TransitionType transition_type)
+ : m_global_object(previous_shape.m_global_object)
+ , m_previous(&previous_shape)
, m_property_name(property_name)
, m_attributes(attributes)
- , m_prototype(previous_shape->m_prototype)
+ , m_prototype(previous_shape.m_prototype)
, m_transition_type(transition_type)
{
}
-Shape::Shape(Shape* previous_shape, Object* new_prototype)
- : m_previous(previous_shape)
+Shape::Shape(Shape& previous_shape, Object* new_prototype)
+ : m_global_object(previous_shape.m_global_object)
+ , m_previous(&previous_shape)
, m_prototype(new_prototype)
, m_transition_type(TransitionType::Prototype)
{
@@ -92,6 +96,7 @@ Shape::~Shape()
void Shape::visit_children(Cell::Visitor& visitor)
{
Cell::visit_children(visitor);
+ visitor.visit(&m_global_object);
visitor.visit(m_prototype);
visitor.visit(m_previous);
for (auto& it : m_forward_transitions)