mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 20:37:34 +00:00
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:
parent
1f4e3dd073
commit
1b391d78ae
5 changed files with 16 additions and 13 deletions
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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&) {}
|
||||
|
|
|
@ -45,7 +45,6 @@ LexicalEnvironment::~LexicalEnvironment()
|
|||
void LexicalEnvironment::visit_children(Visitor& visitor)
|
||||
{
|
||||
Cell::visit_children(visitor);
|
||||
if (m_parent)
|
||||
visitor.visit(m_parent);
|
||||
for (auto& it : m_variables)
|
||||
visitor.visit(it.value.value);
|
||||
|
|
|
@ -81,9 +81,7 @@ 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);
|
||||
for (auto& it : m_forward_transitions)
|
||||
visitor.visit(it.value);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue