LibWeb: Change Storage{Bottle,Bucket,Shelf} to be GC-allocated

In upcoming changes StorageBottle will own pointers to GC-allocated
objects, so it needs to be a GC-allocated object itself to avoid
introducing more GC roots.
This commit is contained in:
Aliaksandr Kalenik 2025-06-11 18:51:22 +02:00 committed by Alexander Kalenik
commit f53559cb55
Notes: github-actions[bot] 2025-06-12 15:06:02 +00:00
12 changed files with 117 additions and 44 deletions

View file

@ -7,6 +7,7 @@
#pragma once
#include <AK/HashMap.h>
#include <LibGC/Ptr.h>
#include <LibWeb/Forward.h>
#include <LibWeb/StorageAPI/StorageKey.h>
#include <LibWeb/StorageAPI/StorageShelf.h>
@ -16,14 +17,23 @@ namespace Web::StorageAPI {
// https://storage.spec.whatwg.org/#storage-shed
// A storage shed is a map of storage keys to storage shelves. It is initially empty.
class StorageShed {
class StorageShed : public GC::Cell {
GC_CELL(StorageShed, GC::Cell);
GC_DECLARE_ALLOCATOR(StorageShed);
public:
Optional<StorageShelf&> obtain_a_storage_shelf(HTML::EnvironmentSettingsObject const&, StorageType);
static GC::Ref<StorageShed> create(GC::Heap& heap) { return heap.allocate<StorageShed>(); }
GC::Ptr<StorageShelf> obtain_a_storage_shelf(HTML::EnvironmentSettingsObject const&, StorageType);
virtual void visit_edges(GC::Cell::Visitor& visitor) override;
private:
OrderedHashMap<StorageKey, StorageShelf> m_data;
StorageShed() = default;
OrderedHashMap<StorageKey, GC::Ref<StorageShelf>> m_data;
};
StorageShed& user_agent_storage_shed();
GC::Ref<StorageShed> user_agent_storage_shed(GC::Heap&);
}