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:
parent
6237824d99
commit
0890b10d11
Notes:
github-actions[bot]
2025-05-06 09:18:32 +00:00
Author: https://github.com/stelar7
Commit: 0890b10d11
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4524
Reviewed-by: https://github.com/gmta ✅
3 changed files with 9 additions and 7 deletions
|
@ -109,7 +109,7 @@ WebIDL::ExceptionOr<GC::Ref<IDBObjectStore>> IDBDatabase::create_object_store(St
|
||||||
|
|
||||||
// 3. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException.
|
// 3. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException.
|
||||||
if (transaction->state() != IDBTransaction::TransactionState::Active)
|
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 options’s keyPath member if it is not undefined or null, or null otherwise.
|
// 4. Let keyPath be options’s keyPath member if it is not undefined or null, or null otherwise.
|
||||||
auto key_path = options.key_path;
|
auto key_path = options.key_path;
|
||||||
|
@ -171,7 +171,7 @@ WebIDL::ExceptionOr<void> IDBDatabase::delete_object_store(String const& name)
|
||||||
|
|
||||||
// 3. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException.
|
// 3. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException.
|
||||||
if (transaction->state() != IDBTransaction::TransactionState::Active)
|
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.
|
// 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);
|
auto store = database->object_store_with_name(name);
|
||||||
|
|
|
@ -62,7 +62,7 @@ WebIDL::ExceptionOr<void> IDBIndex::set_name(String const& value)
|
||||||
|
|
||||||
// 5. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException.
|
// 5. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException.
|
||||||
if (transaction->state() != IDBTransaction::TransactionState::Active)
|
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 index’s object store has been deleted, throw an "InvalidStateError" DOMException.
|
// FIXME: 6. If index or index’s object store has been deleted, throw an "InvalidStateError" DOMException.
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ WebIDL::ExceptionOr<void> IDBObjectStore::set_name(String const& value)
|
||||||
|
|
||||||
// 6. If transaction’s state is not active, throw a "TransactionInactiveError" DOMException.
|
// 6. If transaction’s state is not active, throw a "TransactionInactiveError" DOMException.
|
||||||
if (transaction->state() != IDBTransaction::TransactionState::Active)
|
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 store’s name is equal to name, terminate these steps.
|
// 7. If store’s name is equal to name, terminate these steps.
|
||||||
if (store->name() == name)
|
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
|
// https://w3c.github.io/IndexedDB/#dom-idbobjectstore-deleteindex
|
||||||
WebIDL::ExceptionOr<void> IDBObjectStore::delete_index(String const& name)
|
WebIDL::ExceptionOr<void> IDBObjectStore::delete_index(String const& name)
|
||||||
{
|
{
|
||||||
|
auto& realm = this->realm();
|
||||||
|
|
||||||
// 1. Let transaction be this’s transaction.
|
// 1. Let transaction be this’s transaction.
|
||||||
auto transaction = this->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.
|
// 3. If transaction is not an upgrade transaction, throw an "InvalidStateError" DOMException.
|
||||||
if (transaction->mode() != Bindings::IDBTransactionMode::Versionchange)
|
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.
|
// FIXME: 4. If store has been deleted, throw an "InvalidStateError" DOMException.
|
||||||
|
|
||||||
// 5. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException.
|
// 5. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException.
|
||||||
if (transaction->state() != IDBTransaction::TransactionState::Active)
|
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.
|
// 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);
|
auto index = m_indexes.get(name);
|
||||||
if (!index.has_value())
|
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 this’s index set.
|
// 7. Remove index from this’s index set.
|
||||||
m_indexes.remove(name);
|
m_indexes.remove(name);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue