mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-19 10:20:22 +00:00
Add a clang plugin check that flags GC::Cell subclasses (and their base classes within the Cell hierarchy) that have destructors with non-trivial bodies. Such logic should use Cell::finalize() instead. Add GC_ALLOW_CELL_DESTRUCTOR annotation macro for opting out in exceptional cases (currently only JS::Object). This prevents us from accidentally adding code in destructors that runs after something we're pointing to may have been destroyed. (This could become a problem when the garbage collector sweeps objects in an unfortunate order.) This new check uncovered a handful of bugs which are then also fixed in this commit. :^)
49 lines
1.3 KiB
C++
49 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/NonnullRefPtr.h>
|
|
#include <AK/WeakPtr.h>
|
|
#include <LibJS/Heap/Cell.h>
|
|
#include <LibWeb/Forward.h>
|
|
|
|
namespace Web::HTML {
|
|
|
|
class BrowsingContextGroup final : public JS::Cell {
|
|
GC_CELL(BrowsingContextGroup, JS::Cell);
|
|
GC_DECLARE_ALLOCATOR(BrowsingContextGroup);
|
|
|
|
public:
|
|
struct BrowsingContextGroupAndDocument {
|
|
GC::Ref<HTML::BrowsingContextGroup> browsing_context;
|
|
GC::Ref<DOM::Document> document;
|
|
};
|
|
static constexpr bool OVERRIDES_FINALIZE = true;
|
|
|
|
static WebIDL::ExceptionOr<BrowsingContextGroupAndDocument> create_a_new_browsing_context_group_and_document(GC::Ref<Page>);
|
|
|
|
Page& page() { return m_page; }
|
|
Page const& page() const { return m_page; }
|
|
|
|
auto& browsing_context_set() { return m_browsing_context_set; }
|
|
auto const& browsing_context_set() const { return m_browsing_context_set; }
|
|
|
|
void append(BrowsingContext&);
|
|
|
|
private:
|
|
explicit BrowsingContextGroup(GC::Ref<Web::Page>);
|
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
virtual void finalize() override;
|
|
|
|
// https://html.spec.whatwg.org/multipage/browsers.html#browsing-context-group-set
|
|
OrderedHashTable<GC::Ref<BrowsingContext>> m_browsing_context_set;
|
|
|
|
GC::Ref<Page> m_page;
|
|
};
|
|
|
|
}
|