LibWeb: Implement IDBTransaction::abort

This commit is contained in:
stelar7 2024-12-01 21:58:42 +01:00 committed by Jelle Raaijmakers
parent 2954278e37
commit 7c3f44282d
Notes: github-actions[bot] 2024-12-14 22:04:18 +00:00
2 changed files with 15 additions and 0 deletions

View file

@ -7,6 +7,7 @@
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/EventNames.h>
#include <LibWeb/IndexedDB/IDBTransaction.h>
#include <LibWeb/IndexedDB/Internal/Algorithms.h>
namespace Web::IndexedDB {
@ -69,4 +70,16 @@ WebIDL::CallbackType* IDBTransaction::onerror()
return event_handler_attribute(HTML::EventNames::error);
}
WebIDL::ExceptionOr<void> IDBTransaction::abort()
{
// 1. If this's state is committing or finished, then throw an "InvalidStateError" DOMException.
if (m_state == TransactionState::Committing || m_state == TransactionState::Finished)
return WebIDL::InvalidStateError::create(realm(), "Transaction is ending"_string);
// 2. Set this's state to inactive and run abort a transaction with this and null.
m_state = TransactionState::Inactive;
abort_a_transaction(*this, nullptr);
return {};
}
}

View file

@ -47,6 +47,8 @@ public:
[[nodiscard]] bool is_readonly() const { return m_mode == Bindings::IDBTransactionMode::Readonly; }
[[nodiscard]] bool is_readwrite() const { return m_mode == Bindings::IDBTransactionMode::Readwrite; }
WebIDL::ExceptionOr<void> abort();
void set_onabort(WebIDL::CallbackType*);
WebIDL::CallbackType* onabort();
void set_oncomplete(WebIDL::CallbackType*);