LibWeb: Implement cleanup_indexed_database_transactions
Some checks are pending
CI / macOS, arm64, Sanitizer_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, Clang (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run

This commit is contained in:
stelar7 2025-06-16 16:41:29 +02:00 committed by Shannon Booth
commit 3815a7c1eb
Notes: github-actions[bot] 2025-06-18 07:06:49 +00:00
6 changed files with 44 additions and 1 deletions

View file

@ -21,6 +21,7 @@
#include <LibWeb/HTML/Window.h>
#include <LibWeb/HighResolutionTime/Performance.h>
#include <LibWeb/HighResolutionTime/TimeOrigin.h>
#include <LibWeb/IndexedDB/Internal/Algorithms.h>
#include <LibWeb/Page/Page.h>
#include <LibWeb/Painting/PaintableBox.h>
#include <LibWeb/Painting/ViewportPaintable.h>
@ -599,7 +600,8 @@ void EventLoop::perform_a_microtask_checkpoint()
global->notify_about_rejected_promises({});
}
// FIXME: 5. Cleanup Indexed Database transactions.
// 5. Cleanup Indexed Database transactions.
IndexedDB::cleanup_indexed_database_transactions(*this);
// 6. Perform ClearKeptObjects().
vm().finish_execution_generation();

View file

@ -47,6 +47,7 @@ public:
[[nodiscard]] RequestList& request_list() { return m_request_list; }
[[nodiscard]] ReadonlySpan<GC::Ref<ObjectStore>> scope() const { return m_scope; }
[[nodiscard]] String uuid() const { return m_uuid; }
[[nodiscard]] GC::Ptr<HTML::EventLoop> cleanup_event_loop() const { return m_cleanup_event_loop; }
void set_mode(Bindings::IDBTransactionMode mode) { m_mode = mode; }
void set_error(GC::Ptr<WebIDL::DOMException> error) { m_error = error; }

View file

@ -2051,4 +2051,32 @@ void queue_a_database_task(GC::Ref<GC::Function<void()>> steps)
HTML::queue_a_task(HTML::Task::Source::DatabaseAccess, nullptr, nullptr, steps);
}
// https://w3c.github.io/IndexedDB/#cleanup-indexed-database-transactions
bool cleanup_indexed_database_transactions(GC::Ref<HTML::EventLoop> event_loop)
{
bool has_matching_event_loop = false;
Database::for_each_database([&has_matching_event_loop, event_loop](GC::Root<Database> const& database) {
for (auto const& connection : database->associated_connections()) {
for (auto const& transaction : connection->transactions()) {
// 2. For each transaction transaction with cleanup event loop matching the current event loop:
if (transaction->cleanup_event_loop() == event_loop) {
has_matching_event_loop = true;
// 1. Set transactions state to inactive.
transaction->set_state(IDBTransaction::TransactionState::Inactive);
// 2. Clear transactions cleanup event loop.
transaction->set_cleanup_event_loop(nullptr);
}
}
}
});
// 1. If there are no transactions with cleanup event loop matching the current event loop, return false.
// 3. Return true.
return has_matching_event_loop;
}
}

View file

@ -57,5 +57,6 @@ JS::Value retrieve_a_value_from_an_index(JS::Realm&, GC::Ref<Index>, GC::Ref<IDB
GC::Ref<JS::Array> retrieve_multiple_referenced_values_from_an_index(JS::Realm&, GC::Ref<Index>, GC::Ref<IDBKeyRange>, Optional<WebIDL::UnsignedLong>);
GC::Ref<JS::Array> retrieve_multiple_values_from_an_index(JS::Realm&, GC::Ref<Index>, GC::Ref<IDBKeyRange>, Optional<WebIDL::UnsignedLong>);
void queue_a_database_task(GC::Ref<GC::Function<void()>>);
bool cleanup_indexed_database_transactions(GC::Ref<HTML::EventLoop>);
}

View file

@ -14,6 +14,15 @@ namespace Web::IndexedDB {
using IDBDatabaseMapping = HashMap<StorageAPI::StorageKey, HashMap<String, GC::Root<Database>>>;
static IDBDatabaseMapping m_databases;
void Database::for_each_database(AK::Function<void(GC::Root<Database> const&)> const& visitor)
{
for (auto const& [key, mapping] : m_databases) {
for (auto const& database_mapping : mapping) {
visitor(database_mapping.value);
}
}
}
GC_DEFINE_ALLOCATOR(Database);
Database::~Database() = default;

View file

@ -53,6 +53,8 @@ public:
[[nodiscard]] static ErrorOr<GC::Root<Database>> create_for_key_and_name(JS::Realm&, StorageAPI::StorageKey&, String&);
[[nodiscard]] static ErrorOr<void> delete_for_key_and_name(StorageAPI::StorageKey&, String&);
static void for_each_database(AK::Function<void(GC::Root<Database> const&)> const& visitor);
[[nodiscard]] static GC::Ref<Database> create(JS::Realm&, String const&);
virtual ~Database();