mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 04:09:13 +00:00
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
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:
parent
fa1e02e5d7
commit
3815a7c1eb
Notes:
github-actions[bot]
2025-06-18 07:06:49 +00:00
Author: https://github.com/stelar7
Commit: 3815a7c1eb
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5103
Reviewed-by: https://github.com/shannonbooth
6 changed files with 44 additions and 1 deletions
|
@ -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; }
|
||||
|
|
|
@ -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 transaction’s state to inactive.
|
||||
transaction->set_state(IDBTransaction::TransactionState::Inactive);
|
||||
|
||||
// 2. Clear transaction’s 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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>);
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue