summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-04-16 16:07:50 +0200
committerAndreas Kling <kling@serenityos.org>2020-04-16 16:10:38 +0200
commit1b391d78ae2829b0c52bca011460046ecf6af230 (patch)
tree1aecde7d83cccabc3c94862c9b3a9ff5fb10e6b2 /Libraries
parent1f4e3dd073610bd5eb8981e7948e51b7094885a1 (diff)
downloadserenity-1b391d78ae2829b0c52bca011460046ecf6af230.zip
LibJS: Allow cells to mark null pointers
This simplifies the cell visiting functions by letting them not worry about the pointers they pass to the visitor being null.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibJS/Heap/Heap.cpp7
-rw-r--r--Libraries/LibJS/Runtime/Cell.cpp8
-rw-r--r--Libraries/LibJS/Runtime/Cell.h5
-rw-r--r--Libraries/LibJS/Runtime/LexicalEnvironment.cpp3
-rw-r--r--Libraries/LibJS/Runtime/Shape.cpp6
5 files changed, 16 insertions, 13 deletions
diff --git a/Libraries/LibJS/Heap/Heap.cpp b/Libraries/LibJS/Heap/Heap.cpp
index ca98e33b91..b565182a3a 100644
--- a/Libraries/LibJS/Heap/Heap.cpp
+++ b/Libraries/LibJS/Heap/Heap.cpp
@@ -188,7 +188,7 @@ class MarkingVisitor final : public Cell::Visitor {
public:
MarkingVisitor() {}
- virtual void visit(Cell* cell)
+ virtual void visit_impl(Cell* cell)
{
if (cell->is_marked())
return;
@@ -206,11 +206,8 @@ void Heap::mark_live_cells(const HashTable<Cell*>& roots)
dbg() << "mark_live_cells:";
#endif
MarkingVisitor visitor;
- for (auto* root : roots) {
- if (!root)
- continue;
+ for (auto* root : roots)
visitor.visit(root);
- }
}
void Heap::sweep_dead_cells()
diff --git a/Libraries/LibJS/Runtime/Cell.cpp b/Libraries/LibJS/Runtime/Cell.cpp
index 222dd85502..c80b59e824 100644
--- a/Libraries/LibJS/Runtime/Cell.cpp
+++ b/Libraries/LibJS/Runtime/Cell.cpp
@@ -34,10 +34,16 @@
namespace JS {
+void Cell::Visitor::visit(Cell* cell)
+{
+ if (cell)
+ visit_impl(cell);
+}
+
void Cell::Visitor::visit(Value value)
{
if (value.is_cell())
- visit(value.as_cell());
+ visit_impl(value.as_cell());
}
Heap& Cell::heap() const
diff --git a/Libraries/LibJS/Runtime/Cell.h b/Libraries/LibJS/Runtime/Cell.h
index f9ae449ab3..9989618ed4 100644
--- a/Libraries/LibJS/Runtime/Cell.h
+++ b/Libraries/LibJS/Runtime/Cell.h
@@ -49,8 +49,11 @@ public:
class Visitor {
public:
- virtual void visit(Cell*) = 0;
+ void visit(Cell*);
void visit(Value);
+
+ protected:
+ virtual void visit_impl(Cell*) = 0;
};
virtual void visit_children(Visitor&) {}
diff --git a/Libraries/LibJS/Runtime/LexicalEnvironment.cpp b/Libraries/LibJS/Runtime/LexicalEnvironment.cpp
index ddf244bb68..518126e0d5 100644
--- a/Libraries/LibJS/Runtime/LexicalEnvironment.cpp
+++ b/Libraries/LibJS/Runtime/LexicalEnvironment.cpp
@@ -45,8 +45,7 @@ LexicalEnvironment::~LexicalEnvironment()
void LexicalEnvironment::visit_children(Visitor& visitor)
{
Cell::visit_children(visitor);
- if (m_parent)
- visitor.visit(m_parent);
+ visitor.visit(m_parent);
for (auto& it : m_variables)
visitor.visit(it.value.value);
}
diff --git a/Libraries/LibJS/Runtime/Shape.cpp b/Libraries/LibJS/Runtime/Shape.cpp
index 28e10c5cc9..cbc7649c81 100644
--- a/Libraries/LibJS/Runtime/Shape.cpp
+++ b/Libraries/LibJS/Runtime/Shape.cpp
@@ -81,10 +81,8 @@ Shape::~Shape()
void Shape::visit_children(Cell::Visitor& visitor)
{
Cell::visit_children(visitor);
- if (m_prototype)
- visitor.visit(m_prototype);
- if (m_previous)
- visitor.visit(m_previous);
+ visitor.visit(m_prototype);
+ visitor.visit(m_previous);
for (auto& it : m_forward_transitions)
visitor.visit(it.value);
}