1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-08 05:27:14 +09:00

LibWeb/IDB: Improve error messages related to transaction state

This commit is contained in:
stelar7 2025-04-29 17:24:30 +02:00 committed by Jelle Raaijmakers
parent 6237824d99
commit 0890b10d11
Notes: github-actions[bot] 2025-05-06 09:18:32 +00:00
3 changed files with 9 additions and 7 deletions

View file

@ -109,7 +109,7 @@ WebIDL::ExceptionOr<GC::Ref<IDBObjectStore>> IDBDatabase::create_object_store(St
// 3. If transactions state is not active, then throw a "TransactionInactiveError" DOMException.
if (transaction->state() != IDBTransaction::TransactionState::Active)
return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active"_string);
return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while creating object store"_string);
// 4. Let keyPath be optionss keyPath member if it is not undefined or null, or null otherwise.
auto key_path = options.key_path;
@ -171,7 +171,7 @@ WebIDL::ExceptionOr<void> IDBDatabase::delete_object_store(String const& name)
// 3. If transactions state is not active, then throw a "TransactionInactiveError" DOMException.
if (transaction->state() != IDBTransaction::TransactionState::Active)
return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active"_string);
return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while deleting object store"_string);
// 4. Let store be the object store named name in database, or throw a "NotFoundError" DOMException if none.
auto store = database->object_store_with_name(name);

View file

@ -62,7 +62,7 @@ WebIDL::ExceptionOr<void> IDBIndex::set_name(String const& value)
// 5. If transactions state is not active, then throw a "TransactionInactiveError" DOMException.
if (transaction->state() != IDBTransaction::TransactionState::Active)
return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active"_string);
return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while updating index name"_string);
// FIXME: 6. If index or indexs object store has been deleted, throw an "InvalidStateError" DOMException.

View file

@ -85,7 +85,7 @@ WebIDL::ExceptionOr<void> IDBObjectStore::set_name(String const& value)
// 6. If transactions state is not active, throw a "TransactionInactiveError" DOMException.
if (transaction->state() != IDBTransaction::TransactionState::Active)
return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active"_string);
return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while updating object store name"_string);
// 7. If stores name is equal to name, terminate these steps.
if (store->name() == name)
@ -193,6 +193,8 @@ WebIDL::ExceptionOr<GC::Ref<IDBIndex>> IDBObjectStore::index(String const& name)
// https://w3c.github.io/IndexedDB/#dom-idbobjectstore-deleteindex
WebIDL::ExceptionOr<void> IDBObjectStore::delete_index(String const& name)
{
auto& realm = this->realm();
// 1. Let transaction be thiss transaction.
auto transaction = this->transaction();
@ -201,18 +203,18 @@ WebIDL::ExceptionOr<void> IDBObjectStore::delete_index(String const& name)
// 3. If transaction is not an upgrade transaction, throw an "InvalidStateError" DOMException.
if (transaction->mode() != Bindings::IDBTransactionMode::Versionchange)
return WebIDL::InvalidStateError::create(realm(), "Transaction is not an upgrade transaction"_string);
return WebIDL::InvalidStateError::create(realm, "Transaction is not an upgrade transaction"_string);
// FIXME: 4. If store has been deleted, throw an "InvalidStateError" DOMException.
// 5. If transactions state is not active, then throw a "TransactionInactiveError" DOMException.
if (transaction->state() != IDBTransaction::TransactionState::Active)
return WebIDL::TransactionInactiveError::create(realm(), "Transaction is not active"_string);
return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while deleting index"_string);
// 6. Let index be the index named name in store if one exists, or throw a "NotFoundError" DOMException otherwise.
auto index = m_indexes.get(name);
if (!index.has_value())
return WebIDL::NotFoundError::create(realm(), "Index not found"_string);
return WebIDL::NotFoundError::create(realm, "Index not found"_string);
// 7. Remove index from thiss index set.
m_indexes.remove(name);