mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 03:25:13 +00:00
LibWeb/IDB: Implement abort and wait steps for closing a connection
This commit is contained in:
parent
fc93ec135e
commit
b6b00acbd1
Notes:
github-actions[bot]
2025-04-11 01:14:22 +00:00
Author: https://github.com/stelar7 Commit: https://github.com/LadybirdBrowser/ladybird/commit/b6b00acbd13 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4306 Reviewed-by: https://github.com/ADKaster ✅
2 changed files with 29 additions and 3 deletions
|
@ -56,6 +56,7 @@ public:
|
|||
[[nodiscard]] bool is_upgrade_transaction() const { return m_mode == Bindings::IDBTransactionMode::Versionchange; }
|
||||
[[nodiscard]] bool is_readonly() const { return m_mode == Bindings::IDBTransactionMode::Readonly; }
|
||||
[[nodiscard]] bool is_readwrite() const { return m_mode == Bindings::IDBTransactionMode::Readwrite; }
|
||||
[[nodiscard]] bool is_finished() const { return m_state == TransactionState::Finished; }
|
||||
|
||||
WebIDL::ExceptionOr<void> abort();
|
||||
|
||||
|
|
|
@ -315,16 +315,41 @@ ErrorOr<GC::Ref<Key>> convert_a_value_to_a_key(JS::Realm& realm, JS::Value input
|
|||
// https://w3c.github.io/IndexedDB/#close-a-database-connection
|
||||
void close_a_database_connection(GC::Ref<IDBDatabase> connection, bool forced)
|
||||
{
|
||||
auto& realm = connection->realm();
|
||||
|
||||
// 1. Set connection’s close pending flag to true.
|
||||
connection->set_close_pending(true);
|
||||
|
||||
// FIXME: 2. If the forced flag is true, then for each transaction created using connection run abort a transaction with transaction and newly created "AbortError" DOMException.
|
||||
// FIXME: 3. Wait for all transactions created using connection to complete. Once they are complete, connection is closed.
|
||||
// 2. If the forced flag is true, then for each transaction created using connection run abort a transaction with transaction and newly created "AbortError" DOMException.
|
||||
if (forced) {
|
||||
for (auto const& transaction : connection->transactions()) {
|
||||
abort_a_transaction(*transaction, WebIDL::AbortError::create(realm, "Connection was closed"_string));
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Wait for all transactions created using connection to complete. Once they are complete, connection is closed.
|
||||
HTML::main_thread_event_loop().spin_until(GC::create_function(realm.vm().heap(), [connection]() {
|
||||
if constexpr (IDB_DEBUG) {
|
||||
dbgln("close_a_database_connection: waiting for step 3");
|
||||
dbgln("transactions created using connection:");
|
||||
for (auto const& transaction : connection->transactions()) {
|
||||
dbgln(" - {} - {}", transaction->uuid(), (u8)transaction->state());
|
||||
}
|
||||
}
|
||||
|
||||
for (auto const& transaction : connection->transactions()) {
|
||||
if (!transaction->is_finished())
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}));
|
||||
|
||||
connection->set_state(IDBDatabase::ConnectionState::Closed);
|
||||
|
||||
// 4. If the forced flag is true, then fire an event named close at connection.
|
||||
if (forced)
|
||||
connection->dispatch_event(DOM::Event::create(connection->realm(), HTML::EventNames::close));
|
||||
connection->dispatch_event(DOM::Event::create(realm, HTML::EventNames::close));
|
||||
}
|
||||
|
||||
// https://w3c.github.io/IndexedDB/#upgrade-a-database
|
||||
|
|
Loading…
Add table
Reference in a new issue