1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:58:11 +00:00

LibWeb: Make BrowsingContext GC-allocated

(And BrowsingContextGroup had to come along for the ride as well.)
This solves a number of nasty reference cycles between browsing
contexts, history items, and their documents.
This commit is contained in:
Andreas Kling 2022-10-17 11:06:50 +02:00
parent 2898701459
commit 83c5ff57d8
15 changed files with 225 additions and 44 deletions

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/MainThreadVM.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/BrowsingContextGroup.h>
@ -27,21 +28,28 @@ BrowsingContextGroup::~BrowsingContextGroup()
user_agent_browsing_context_group_set().remove(this);
}
void BrowsingContextGroup::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
for (auto& context : m_browsing_context_set)
visitor.visit(context);
}
// https://html.spec.whatwg.org/multipage/browsers.html#creating-a-new-browsing-context-group
NonnullRefPtr<BrowsingContextGroup> BrowsingContextGroup::create_a_new_browsing_context_group(Web::Page& page)
JS::NonnullGCPtr<BrowsingContextGroup> BrowsingContextGroup::create_a_new_browsing_context_group(Web::Page& page)
{
// 1. Let group be a new browsing context group.
// 2. Append group to the user agent's browsing context group set.
auto group = adopt_ref(*new BrowsingContextGroup(page));
auto group = Bindings::main_thread_vm().heap().allocate_without_realm<BrowsingContextGroup>(page);
// 3. Let browsingContext be the result of creating a new browsing context with null, null, and group.
auto browsing_context = BrowsingContext::create_a_new_browsing_context(page, nullptr, nullptr, group);
auto browsing_context = BrowsingContext::create_a_new_browsing_context(page, nullptr, nullptr, *group);
// 4. Append browsingContext to group.
group->append(move(browsing_context));
// 5. Return group.
return group;
return *group;
}
// https://html.spec.whatwg.org/multipage/browsers.html#bcg-append
@ -50,7 +58,7 @@ void BrowsingContextGroup::append(BrowsingContext& browsing_context)
VERIFY(browsing_context.is_top_level());
// 1. Append browsingContext to group's browsing context set.
m_browsing_context_set.set(browsing_context);
m_browsing_context_set.set(&browsing_context);
// 2. Set browsingContext's group to group.
browsing_context.set_group(this);