mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
LibWeb/IDB: Implement IDBTransaction::objectStore
This commit is contained in:
Notes:
github-actions[bot]
2025-04-11 01:13:48 +00:00
Author: https://github.com/stelar7 Commit: https://github.com/LadybirdBrowser/ladybird/commit/fc06d088c3c Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4306 Reviewed-by: https://github.com/ADKaster ✅
@@ -7,6 +7,7 @@
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/Crypto/Crypto.h>
|
||||
#include <LibWeb/HTML/EventNames.h>
|
||||
#include <LibWeb/IndexedDB/IDBObjectStore.h>
|
||||
#include <LibWeb/IndexedDB/IDBTransaction.h>
|
||||
#include <LibWeb/IndexedDB/Internal/Algorithms.h>
|
||||
|
||||
@@ -118,4 +119,32 @@ WebIDL::ExceptionOr<void> IDBTransaction::commit()
|
||||
return {};
|
||||
}
|
||||
|
||||
GC::Ptr<ObjectStore> 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<GC::Ref<IDBObjectStore>> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user