diff --git a/Libraries/LibWeb/IndexedDB/IDBTransaction.cpp b/Libraries/LibWeb/IndexedDB/IDBTransaction.cpp index b546c7c8f9a..e58115f3edd 100644 --- a/Libraries/LibWeb/IndexedDB/IDBTransaction.cpp +++ b/Libraries/LibWeb/IndexedDB/IDBTransaction.cpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace Web::IndexedDB { @@ -69,4 +70,16 @@ WebIDL::CallbackType* IDBTransaction::onerror() return event_handler_attribute(HTML::EventNames::error); } +WebIDL::ExceptionOr 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 {}; +} + } diff --git a/Libraries/LibWeb/IndexedDB/IDBTransaction.h b/Libraries/LibWeb/IndexedDB/IDBTransaction.h index 1777935abfe..d1fea580ca1 100644 --- a/Libraries/LibWeb/IndexedDB/IDBTransaction.h +++ b/Libraries/LibWeb/IndexedDB/IDBTransaction.h @@ -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 abort(); + void set_onabort(WebIDL::CallbackType*); WebIDL::CallbackType* onabort(); void set_oncomplete(WebIDL::CallbackType*);