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

@ -8,7 +8,7 @@
#include <AK/HashMap.h>
#include <AK/String.h>
#include <LibWeb/Forward.h>
#include <LibGC/Ptr.h>
#include <LibWeb/StorageAPI/StorageBottle.h>
#include <LibWeb/StorageAPI/StorageType.h>
@ -16,12 +16,24 @@ namespace Web::StorageAPI {
// https://storage.spec.whatwg.org/#storage-shelf
// A storage shelf exists for each storage key within a storage shed. It holds a bucket map, which is a map of strings to storage buckets.
using BucketMap = OrderedHashMap<String, StorageBucket>;
using BucketMap = OrderedHashMap<String, GC::Ref<StorageBucket>>;
struct StorageShelf {
class StorageShelf : public GC::Cell {
GC_CELL(StorageShelf, GC::Cell);
GC_DECLARE_ALLOCATOR(StorageShelf);
public:
static GC::Ref<StorageShelf> create(GC::Heap& heap, StorageType type) { return heap.allocate<StorageShelf>(type); }
BucketMap& bucket_map() { return m_bucket_map; }
BucketMap const& bucket_map() const { return m_bucket_map; }
virtual void visit_edges(GC::Cell::Visitor& visitor) override;
private:
explicit StorageShelf(StorageType);
BucketMap bucket_map;
BucketMap m_bucket_map;
};
}