LibWeb/IDB: Implement auto-commit for IDBTransaction

This commit is contained in:
stelar7 2025-04-09 23:14:10 +02:00
parent 39c7145d10
commit 191342a292
2 changed files with 10 additions and 1 deletions

View file

@ -49,10 +49,10 @@ public:
[[nodiscard]] String uuid() const { return m_uuid; }
void set_mode(Bindings::IDBTransactionMode mode) { m_mode = mode; }
void set_state(TransactionState state) { m_state = state; }
void set_error(GC::Ptr<WebIDL::DOMException> error) { m_error = error; }
void set_associated_request(GC::Ptr<IDBRequest> request) { m_associated_request = request; }
void set_aborted(bool aborted) { m_aborted = aborted; }
void set_state(TransactionState state) { m_state = state; }
[[nodiscard]] bool is_upgrade_transaction() const { return m_mode == Bindings::IDBTransactionMode::Versionchange; }
[[nodiscard]] bool is_readonly() const { return m_mode == Bindings::IDBTransactionMode::Readonly; }

View file

@ -409,6 +409,15 @@ GC::Ref<IDBTransaction> upgrade_a_database(JS::Realm& realm, GC::Ref<IDBDatabase
if (did_throw)
abort_a_transaction(*transaction, WebIDL::AbortError::create(realm, "Version change event threw an exception"_string));
// AD-HOC:
// https://github.com/w3c/IndexedDB/issues/436
// The implementation must attempt to commit a transaction when all requests placed against the transaction have completed
// and their returned results handled,
// no new requests have been placed against the transaction,
// and the transaction has not been aborted.
if (transaction->state() == IDBTransaction::TransactionState::Inactive && transaction->request_list().is_empty() && !transaction->aborted())
commit_a_transaction(realm, transaction);
wait_for_transaction = false;
}));