diff --git a/Libraries/LibWeb/IndexedDB/IDBTransaction.cpp b/Libraries/LibWeb/IndexedDB/IDBTransaction.cpp index 6e58b3ba56c..d73e6bd128c 100644 --- a/Libraries/LibWeb/IndexedDB/IDBTransaction.cpp +++ b/Libraries/LibWeb/IndexedDB/IDBTransaction.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -118,4 +119,32 @@ WebIDL::ExceptionOr IDBTransaction::commit() return {}; } +GC::Ptr IDBTransaction::object_store_named(String const& name) const +{ + for (auto const& store : m_scope) { + if (store->name() == name) + return store; + } + + return nullptr; +} + +// https://w3c.github.io/IndexedDB/#dom-idbtransaction-objectstore +WebIDL::ExceptionOr> IDBTransaction::object_store(String const& name) +{ + auto& realm = this->realm(); + + // 1. If this's state is finished, then throw an "InvalidStateError" DOMException. + if (m_state == TransactionState::Finished) + return WebIDL::InvalidStateError::create(realm, "Transaction is finished"_string); + + // 2. Let store be the object store named name in this's scope, or throw a "NotFoundError" DOMException if none. + auto store = object_store_named(name); + if (!store) + return WebIDL::NotFoundError::create(realm, "Object store not found"_string); + + // 3. Return an object store handle associated with store and this. + return IDBObjectStore::create(realm, *store, *this); +} + } diff --git a/Libraries/LibWeb/IndexedDB/IDBTransaction.h b/Libraries/LibWeb/IndexedDB/IDBTransaction.h index 3913d1c506e..1894771363a 100644 --- a/Libraries/LibWeb/IndexedDB/IDBTransaction.h +++ b/Libraries/LibWeb/IndexedDB/IDBTransaction.h @@ -59,8 +59,11 @@ public: [[nodiscard]] bool is_readwrite() const { return m_mode == Bindings::IDBTransactionMode::Readwrite; } [[nodiscard]] bool is_finished() const { return m_state == TransactionState::Finished; } + GC::Ptr object_store_named(String const& name) const; + WebIDL::ExceptionOr abort(); WebIDL::ExceptionOr commit(); + WebIDL::ExceptionOr> object_store(String const& name); void set_onabort(WebIDL::CallbackType*); WebIDL::CallbackType* onabort(); diff --git a/Libraries/LibWeb/IndexedDB/IDBTransaction.idl b/Libraries/LibWeb/IndexedDB/IDBTransaction.idl index 667d36a6cdd..d31e70bf604 100644 --- a/Libraries/LibWeb/IndexedDB/IDBTransaction.idl +++ b/Libraries/LibWeb/IndexedDB/IDBTransaction.idl @@ -9,7 +9,7 @@ interface IDBTransaction : EventTarget { readonly attribute IDBTransactionDurability durability; [SameObject, ImplementedAs=connection] readonly attribute IDBDatabase db; readonly attribute DOMException? error; - [FIXME] IDBObjectStore objectStore(DOMString name); + IDBObjectStore objectStore(DOMString name); undefined commit(); undefined abort();