LibWeb: Do not dereference empty Optional in ReadableStream::visit_edges

There are quite a few steps between a ReadableStream being created and
its controller being set. If GC occurs between those points, we will
have an empty Optional in ReadableStream::visit_edges. Seen on YouTube.
This commit is contained in:
Timothy Flynn 2023-04-14 08:43:47 -04:00 committed by Linus Groh
parent 9be5dcfd89
commit 781287c1e3
Notes: sideshowbarker 2024-07-17 03:14:39 +09:00

View File

@ -108,7 +108,8 @@ JS::ThrowCompletionOr<void> ReadableStream::initialize(JS::Realm& realm)
void ReadableStream::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
m_controller->visit([&](auto& controller) { visitor.visit(controller); });
if (m_controller.has_value())
m_controller->visit([&](auto& controller) { visitor.visit(controller); });
visitor.visit(m_stored_error);
visitor.visit(m_reader);
}