diff --git a/Libraries/LibWeb/HTML/Storage.cpp b/Libraries/LibWeb/HTML/Storage.cpp
index d8c1d60ff8b..c4adf5f045a 100644
--- a/Libraries/LibWeb/HTML/Storage.cpp
+++ b/Libraries/LibWeb/HTML/Storage.cpp
@@ -15,13 +15,14 @@ namespace Web::HTML {
GC_DEFINE_ALLOCATOR(Storage);
-GC::Ref Storage::create(JS::Realm& realm, u64 quota_bytes)
+GC::Ref Storage::create(JS::Realm& realm, Type type, u64 quota_bytes)
{
- return realm.create(realm, quota_bytes);
+ return realm.create(realm, type, quota_bytes);
}
-Storage::Storage(JS::Realm& realm, u64 quota_bytes)
+Storage::Storage(JS::Realm& realm, Type type, u64 quota_bytes)
: Bindings::PlatformObject(realm)
+ , m_type(type)
, m_quota_bytes(quota_bytes)
{
m_legacy_platform_object_flags = LegacyPlatformObjectFlags {
diff --git a/Libraries/LibWeb/HTML/Storage.h b/Libraries/LibWeb/HTML/Storage.h
index 4dd9a9e18e8..d066ec90416 100644
--- a/Libraries/LibWeb/HTML/Storage.h
+++ b/Libraries/LibWeb/HTML/Storage.h
@@ -13,12 +13,20 @@
namespace Web::HTML {
+// https://html.spec.whatwg.org/multipage/webstorage.html#storage-2
class Storage : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(Storage, Bindings::PlatformObject);
GC_DECLARE_ALLOCATOR(Storage);
public:
- [[nodiscard]] static GC::Ref create(JS::Realm&, u64 quota_bytes);
+ // https://html.spec.whatwg.org/multipage/webstorage.html#concept-storage-type
+ enum class Type {
+ Local,
+ Session,
+ };
+
+ [[nodiscard]] static GC::Ref create(JS::Realm&, Type, u64 quota_bytes);
+
~Storage();
size_t length() const;
@@ -29,11 +37,12 @@ public:
void clear();
auto const& map() const { return m_map; }
+ Type type() const { return m_type; }
void dump() const;
private:
- explicit Storage(JS::Realm&, u64 quota_limit);
+ Storage(JS::Realm&, Type, u64 quota_limit);
virtual void initialize(JS::Realm&) override;
@@ -49,6 +58,7 @@ private:
void broadcast(StringView key, StringView old_value, StringView new_value);
OrderedHashMap m_map;
+ Type m_type {};
u64 m_quota_bytes { 0 };
u64 m_stored_bytes { 0 };
};
diff --git a/Libraries/LibWeb/HTML/Window.cpp b/Libraries/LibWeb/HTML/Window.cpp
index 47628470802..470f52fe791 100644
--- a/Libraries/LibWeb/HTML/Window.cpp
+++ b/Libraries/LibWeb/HTML/Window.cpp
@@ -453,7 +453,7 @@ WebIDL::ExceptionOr> Window::local_storage()
// FIXME: Implement according to spec.
static HashMap> local_storage_per_origin;
auto storage = local_storage_per_origin.ensure(associated_document().origin(), [this]() -> GC::Root {
- return Storage::create(realm(), quota_bytes);
+ return Storage::create(realm(), Storage::Type::Local, quota_bytes);
});
return GC::Ref { *storage };
}
@@ -467,7 +467,7 @@ WebIDL::ExceptionOr> Window::session_storage()
// FIXME: Implement according to spec.
static HashMap> session_storage_per_origin;
auto storage = session_storage_per_origin.ensure(associated_document().origin(), [this]() -> GC::Root {
- return Storage::create(realm(), quota_bytes);
+ return Storage::create(realm(), Storage::Type::Session, quota_bytes);
});
return GC::Ref { *storage };
}