From 7c3f44282d52669d8ae4e4bec77a98dfb143927a Mon Sep 17 00:00:00 2001 From: stelar7 Date: Sun, 1 Dec 2024 21:58:42 +0100 Subject: [PATCH] LibWeb: Implement IDBTransaction::abort --- Libraries/LibWeb/IndexedDB/IDBTransaction.cpp | 13 +++++++++++++ Libraries/LibWeb/IndexedDB/IDBTransaction.h | 2 ++ 2 files changed, 15 insertions(+) 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*);