LibWeb/HTML: Enforce quota limit for local and session storage

Fixes a timeout/crash for the two commited WPT tests.
This commit is contained in:
Shannon Booth 2024-12-23 19:10:01 +13:00 committed by Andreas Kling
parent e767029e24
commit f3ecd23a21
Notes: github-actions[bot] 2025-01-02 10:39:50 +00:00
7 changed files with 74 additions and 8 deletions

View file

@ -447,10 +447,13 @@ void Window::fire_a_page_transition_event(FlyString const& event_name, bool pers
// https://html.spec.whatwg.org/multipage/webstorage.html#dom-localstorage
WebIDL::ExceptionOr<GC::Ref<Storage>> Window::local_storage()
{
// See table in: https://storage.spec.whatwg.org/#registered-storage-endpoints
constexpr u64 quota_bytes = 5 * MiB;
// FIXME: Implement according to spec.
static HashMap<URL::Origin, GC::Root<Storage>> local_storage_per_origin;
auto storage = local_storage_per_origin.ensure(associated_document().origin(), [this]() -> GC::Root<Storage> {
return Storage::create(realm());
return Storage::create(realm(), quota_bytes);
});
return GC::Ref { *storage };
}
@ -458,10 +461,13 @@ WebIDL::ExceptionOr<GC::Ref<Storage>> Window::local_storage()
// https://html.spec.whatwg.org/multipage/webstorage.html#dom-sessionstorage
WebIDL::ExceptionOr<GC::Ref<Storage>> Window::session_storage()
{
// See table in: https://storage.spec.whatwg.org/#registered-storage-endpoints
constexpr u64 quota_bytes = 5 * MiB;
// FIXME: Implement according to spec.
static HashMap<URL::Origin, GC::Root<Storage>> session_storage_per_origin;
auto storage = session_storage_per_origin.ensure(associated_document().origin(), [this]() -> GC::Root<Storage> {
return Storage::create(realm());
return Storage::create(realm(), quota_bytes);
});
return GC::Ref { *storage };
}