mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 11:47:45 +00:00
LibJS: Visit WeakMap's values as long as their keys were not collected
While the WeakMap only holds a weak reference to its keys, their accompanying values should be kept alive as long as they're accessible.
This commit is contained in:
parent
073a1dec16
commit
b92871f7ef
2 changed files with 8 additions and 0 deletions
|
@ -29,4 +29,11 @@ void WeakMap::remove_swept_cells(Badge<Heap>, Span<Cell*> cells)
|
||||||
m_values.remove(cell);
|
m_values.remove(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WeakMap::visit_edges(Visitor& visitor)
|
||||||
|
{
|
||||||
|
Base::visit_edges(visitor);
|
||||||
|
for (auto& entry : m_values)
|
||||||
|
visitor.visit(entry.value);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void did_become_zombie() override { deregister(); }
|
virtual void did_become_zombie() override { deregister(); }
|
||||||
|
void visit_edges(Visitor&) override;
|
||||||
|
|
||||||
HashMap<Cell*, Value> m_values; // This stores Cell pointers instead of Object pointers to aide with sweeping
|
HashMap<Cell*, Value> m_values; // This stores Cell pointers instead of Object pointers to aide with sweeping
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue