LibWeb/IDB: Dont go back to inactive if we finished during upgrade

This commit is contained in:
stelar7 2025-04-10 00:33:05 +02:00 committed by Andrew Kaster
commit 0a298dba27
Notes: github-actions[bot] 2025-04-11 01:13:36 +00:00

View file

@ -401,21 +401,25 @@ GC::Ref<IDBTransaction> upgrade_a_database(JS::Realm& realm, GC::Ref<IDBDatabase
// 5. Let didThrow be the result of firing a version change event named upgradeneeded at request with old version and version. // 5. Let didThrow be the result of firing a version change event named upgradeneeded at request with old version and version.
auto did_throw = fire_a_version_change_event(realm, HTML::EventNames::upgradeneeded, request, old_version, version); auto did_throw = fire_a_version_change_event(realm, HTML::EventNames::upgradeneeded, request, old_version, version);
// 6. Set transactions state to inactive. // AD-HOC: If the transaction was aborted by the event, then DONT set the transaction back to inactive.
transaction->set_state(IDBTransaction::TransactionState::Inactive); // https://github.com/w3c/IndexedDB/issues/436#issuecomment-2791113467
if (transaction->state() != IDBTransaction::TransactionState::Finished) {
// 7. If didThrow is true, run abort a transaction with transaction and a newly created "AbortError" DOMException. // 6. Set transactions state to inactive.
if (did_throw) transaction->set_state(IDBTransaction::TransactionState::Inactive);
abort_a_transaction(*transaction, WebIDL::AbortError::create(realm, "Version change event threw an exception"_string));
// AD-HOC: // 7. If didThrow is true, run abort a transaction with transaction and a newly created "AbortError" DOMException.
// https://github.com/w3c/IndexedDB/issues/436 if (did_throw)
// The implementation must attempt to commit a transaction when all requests placed against the transaction have completed abort_a_transaction(transaction, WebIDL::AbortError::create(realm, "Version change event threw an exception"_string));
// and their returned results handled,
// no new requests have been placed against the transaction, // AD-HOC:
// and the transaction has not been aborted. // The implementation must attempt to commit a transaction when all requests placed against the transaction have completed
if (transaction->state() == IDBTransaction::TransactionState::Inactive && transaction->request_list().is_empty() && !transaction->aborted()) // and their returned results handled,
commit_a_transaction(realm, transaction); // 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);
}
})); }));
// 11. Wait for transaction to finish. // 11. Wait for transaction to finish.