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.
This commit is contained in:
Andreas Kling 2020-04-16 16:07:50 +02:00
parent 1f4e3dd073
commit 1b391d78ae
Notes: sideshowbarker 2024-07-19 07:33:06 +09:00
5 changed files with 16 additions and 13 deletions

View file

@ -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()

View file

@ -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

View file

@ -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&) {}

View file

@ -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);
}

View file

@ -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);
}