diff --git a/Libraries/LibWeb/IndexedDB/IDBCursor.cpp b/Libraries/LibWeb/IndexedDB/IDBCursor.cpp index dfa7cd58264..1e57d5ef61a 100644 --- a/Libraries/LibWeb/IndexedDB/IDBCursor.cpp +++ b/Libraries/LibWeb/IndexedDB/IDBCursor.cpp @@ -116,7 +116,7 @@ WebIDL::ExceptionOr IDBCursor::continue_(JS::Value key) auto transaction = this->transaction(); // 2. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while continuing cursor"_string); // FIXME: 3. If this's source or effective object store has been deleted, throw an "InvalidStateError" DOMException @@ -207,7 +207,7 @@ WebIDL::ExceptionOr IDBCursor::advance(WebIDL::UnsignedLong count) auto transaction = this->transaction(); // 3. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while advancing cursor"_string); // FIXME: 4. If this’s source or effective object store has been deleted, throw an "InvalidStateError" DOMException. @@ -249,7 +249,7 @@ WebIDL::ExceptionOr IDBCursor::continue_primary_key(JS::Value key_param, J auto transaction = this->transaction(); // 2. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while continuing cursor"_string); // FIXME: 3. If this’s source or effective object store has been deleted, throw an "InvalidStateError" DOMException. @@ -349,7 +349,7 @@ WebIDL::ExceptionOr> IDBCursor::update(JS::Value value) auto transaction = this->transaction(); // 2. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while updating cursor"_string); // 3. If transaction is a read-only transaction, throw a "ReadOnlyError" DOMException. @@ -415,7 +415,7 @@ WebIDL::ExceptionOr> IDBCursor::delete_() auto transaction = this->transaction(); // 2. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while deleting cursor"_string); // 3. If transaction is a read-only transaction, throw a "ReadOnlyError" DOMException. diff --git a/Libraries/LibWeb/IndexedDB/IDBDatabase.cpp b/Libraries/LibWeb/IndexedDB/IDBDatabase.cpp index 4aff5790ba7..cd7ba71f716 100644 --- a/Libraries/LibWeb/IndexedDB/IDBDatabase.cpp +++ b/Libraries/LibWeb/IndexedDB/IDBDatabase.cpp @@ -108,7 +108,7 @@ WebIDL::ExceptionOr> IDBDatabase::create_object_store(St return WebIDL::InvalidStateError::create(realm, "Upgrade transaction is null"_string); // 3. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) 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. @@ -170,7 +170,7 @@ WebIDL::ExceptionOr IDBDatabase::delete_object_store(String const& name) return WebIDL::InvalidStateError::create(realm, "Upgrade transaction is null"_string); // 3. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) 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. diff --git a/Libraries/LibWeb/IndexedDB/IDBIndex.cpp b/Libraries/LibWeb/IndexedDB/IDBIndex.cpp index 4fa89c4916e..0b129efc5a0 100644 --- a/Libraries/LibWeb/IndexedDB/IDBIndex.cpp +++ b/Libraries/LibWeb/IndexedDB/IDBIndex.cpp @@ -63,7 +63,7 @@ WebIDL::ExceptionOr IDBIndex::set_name(String const& value) return WebIDL::InvalidStateError::create(realm, "Transaction is not an upgrade transaction"_string); // 5. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) 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. @@ -117,7 +117,7 @@ WebIDL::ExceptionOr> IDBIndex::open_cursor(JS::Value query, // FIXME: 3. If index or index’s object store has been deleted, throw an "InvalidStateError" DOMException. // 4. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while opening cursor"_string); // 5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions. @@ -155,7 +155,7 @@ WebIDL::ExceptionOr> IDBIndex::get(JS::Value query) // FIXME: 3. If index or index’s object store has been deleted, throw an "InvalidStateError" DOMException. // 4. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while getting"_string); // 5. Let range be the result of converting a value to a key range with query and true. Rethrow any exceptions. @@ -186,7 +186,7 @@ WebIDL::ExceptionOr> IDBIndex::get_key(JS::Value query) // FIXME: 3. If index or index’s object store has been deleted, throw an "InvalidStateError" DOMException. // 4. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while getting key"_string); // 5. Let range be the result of converting a value to a key range with query and true. Rethrow any exceptions. @@ -217,7 +217,7 @@ WebIDL::ExceptionOr> IDBIndex::get_all(Optional q // FIXME: 3. If index or index’s object store has been deleted, throw an "InvalidStateError" DOMException. // 4. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while getting all"_string); // 5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions. @@ -248,7 +248,7 @@ WebIDL::ExceptionOr> IDBIndex::get_all_keys(Optionalstate() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while getting all keys"_string); // 5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions. @@ -279,7 +279,7 @@ WebIDL::ExceptionOr> IDBIndex::count(JS::Value query) // FIXME: 3. If index or index’s object store has been deleted, throw an "InvalidStateError" DOMException. // 4. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while counting"_string); // 5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions. @@ -310,7 +310,7 @@ WebIDL::ExceptionOr> IDBIndex::open_key_cursor(JS::Value que // FIXME: 3. If index or index’s object store has been deleted, throw an "InvalidStateError" DOMException. // 4. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while opening key cursor"_string); // 5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions. diff --git a/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp b/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp index c0ec08f73b7..61043d8ad1e 100644 --- a/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp +++ b/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp @@ -79,7 +79,7 @@ WebIDL::ExceptionOr IDBObjectStore::set_name(String const& value) return WebIDL::InvalidStateError::create(realm, "Attempted to set name outside of version change"_string); // 6. If transaction’s state is not active, throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) 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. @@ -160,7 +160,7 @@ WebIDL::ExceptionOr> IDBObjectStore::create_index(String const // FIXME: 4. If store has been deleted, throw an "InvalidStateError" DOMException. // 5. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while creating index"_string); // 6. If an index named name already exists in store, throw a "ConstraintError" DOMException. @@ -234,7 +234,7 @@ WebIDL::ExceptionOr IDBObjectStore::delete_index(String const& name) // FIXME: 4. If store has been deleted, throw an "InvalidStateError" DOMException. // 5. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) 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. @@ -265,7 +265,7 @@ WebIDL::ExceptionOr> IDBObjectStore::add_or_put(GC::Refstate() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while running add/put"_string); // 5. If transaction is a read-only transaction, throw a "ReadOnlyError" DOMException. @@ -373,7 +373,7 @@ WebIDL::ExceptionOr> IDBObjectStore::count(Optionalstate() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while doing count"_string); // 5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions. @@ -404,7 +404,7 @@ WebIDL::ExceptionOr> IDBObjectStore::get(JS::Value query) // FIXME: 3. If store has been deleted, throw an "InvalidStateError" DOMException. // 4. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while getting"_string); // 5. Let range be the result of converting a value to a key range with query and true. Rethrow any exceptions. @@ -435,7 +435,7 @@ WebIDL::ExceptionOr> IDBObjectStore::open_cursor(JS::Value q // FIXME: 3. If store has been deleted, throw an "InvalidStateError" DOMException. // 4. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while opening cursor"_string); // 5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions. @@ -475,7 +475,7 @@ WebIDL::ExceptionOr> IDBObjectStore::delete_(JS::Value query // FIXME: 3. If store has been deleted, throw an "InvalidStateError" DOMException. // 4. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while deleting object store"_string); // 5. If transaction is a read-only transaction, throw a "ReadOnlyError" DOMException. @@ -510,7 +510,7 @@ WebIDL::ExceptionOr> IDBObjectStore::clear() // FIXME: 3. If store has been deleted, throw an "InvalidStateError" DOMException. // 4. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while clearing object store"_string); // 5. If transaction is a read-only transaction, throw a "ReadOnlyError" DOMException. @@ -542,7 +542,7 @@ WebIDL::ExceptionOr> IDBObjectStore::get_key(JS::Value query // FIXME: 3. If store has been deleted, throw an "InvalidStateError" DOMException. // 4. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while getting key"_string); // 5. Let range be the result of converting a value to a key range with query and true. Rethrow any exceptions. @@ -573,7 +573,7 @@ WebIDL::ExceptionOr> IDBObjectStore::get_all(Optionalstate() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while getting all"_string); // 5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions. @@ -604,7 +604,7 @@ WebIDL::ExceptionOr> IDBObjectStore::open_key_cursor(JS::Val // FIXME: 3. If store has been deleted, throw an "InvalidStateError" DOMException. // 4. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException. - if (transaction->state() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while opening key cursor"_string); // 5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions. @@ -643,7 +643,7 @@ WebIDL::ExceptionOr> IDBObjectStore::get_all_keys(Optionalstate() != IDBTransaction::TransactionState::Active) + if (!transaction->is_active()) return WebIDL::TransactionInactiveError::create(realm, "Transaction is not active while getting all keys"_string); // 5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions. diff --git a/Libraries/LibWeb/IndexedDB/IDBTransaction.h b/Libraries/LibWeb/IndexedDB/IDBTransaction.h index a058c61db5b..08040edede4 100644 --- a/Libraries/LibWeb/IndexedDB/IDBTransaction.h +++ b/Libraries/LibWeb/IndexedDB/IDBTransaction.h @@ -59,6 +59,9 @@ public: [[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; } + [[nodiscard]] bool is_active() const { return m_state == TransactionState::Active; } + [[nodiscard]] bool is_inactive() const { return m_state == TransactionState::Inactive; } + [[nodiscard]] bool is_committing() const { return m_state == TransactionState::Committing; } GC::Ptr object_store_named(String const& name) const; void add_to_scope(GC::Ref object_store) { m_scope.append(object_store); }