mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-23 09:22:30 +00:00
LibWeb/IDB: Implement IDBObjectStore::index
This commit is contained in:
parent
fba7ad6969
commit
fce936e05a
Notes:
github-actions[bot]
2025-04-09 17:50:32 +00:00
Author: https://github.com/stelar7
Commit: fce936e05a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4178
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/AtkinsSJ
3 changed files with 26 additions and 1 deletions
|
@ -165,4 +165,28 @@ GC::Ref<HTML::DOMStringList> IDBObjectStore::index_names()
|
||||||
return create_a_sorted_name_list(realm(), names);
|
return create_a_sorted_name_list(realm(), names);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/IndexedDB/#dom-idbobjectstore-index
|
||||||
|
WebIDL::ExceptionOr<GC::Ref<IDBIndex>> IDBObjectStore::index(String const& name)
|
||||||
|
{
|
||||||
|
// 1. Let transaction be this’s transaction.
|
||||||
|
auto transaction = this->transaction();
|
||||||
|
|
||||||
|
// 2. Let store be this’s object store.
|
||||||
|
[[maybe_unused]] auto store = this->store();
|
||||||
|
|
||||||
|
// FIXME: 3. If store has been deleted, throw an "InvalidStateError" DOMException.
|
||||||
|
|
||||||
|
// 4. If transaction’s state is finished, then throw an "InvalidStateError" DOMException.
|
||||||
|
if (transaction->state() == IDBTransaction::TransactionState::Finished)
|
||||||
|
return WebIDL::InvalidStateError::create(realm(), "Transaction is finished"_string);
|
||||||
|
|
||||||
|
// 5. Let index be the index named name in this’s index set if one exists, or throw a "NotFoundError" DOMException otherwise.
|
||||||
|
auto index = m_indexes.get(name);
|
||||||
|
if (!index.has_value())
|
||||||
|
return WebIDL::NotFoundError::create(realm(), "Index not found"_string);
|
||||||
|
|
||||||
|
// 6. Return an index handle associated with index and this.
|
||||||
|
return IDBIndex::create(realm(), *index, *this);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ public:
|
||||||
|
|
||||||
WebIDL::ExceptionOr<GC::Ref<IDBIndex>> create_index(String const&, KeyPath, IDBIndexParameters options);
|
WebIDL::ExceptionOr<GC::Ref<IDBIndex>> create_index(String const&, KeyPath, IDBIndexParameters options);
|
||||||
[[nodiscard]] GC::Ref<HTML::DOMStringList> index_names();
|
[[nodiscard]] GC::Ref<HTML::DOMStringList> index_names();
|
||||||
|
WebIDL::ExceptionOr<GC::Ref<IDBIndex>> index(String const&);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit IDBObjectStore(JS::Realm&, GC::Ref<ObjectStore>, GC::Ref<IDBTransaction>);
|
explicit IDBObjectStore(JS::Realm&, GC::Ref<ObjectStore>, GC::Ref<IDBTransaction>);
|
||||||
|
|
|
@ -21,7 +21,7 @@ interface IDBObjectStore {
|
||||||
[FIXME, NewObject] IDBRequest count(optional any query);
|
[FIXME, NewObject] IDBRequest count(optional any query);
|
||||||
[FIXME, NewObject] IDBRequest openCursor(optional any query, optional IDBCursorDirection direction = "next");
|
[FIXME, NewObject] IDBRequest openCursor(optional any query, optional IDBCursorDirection direction = "next");
|
||||||
[FIXME, NewObject] IDBRequest openKeyCursor(optional any query, optional IDBCursorDirection direction = "next");
|
[FIXME, NewObject] IDBRequest openKeyCursor(optional any query, optional IDBCursorDirection direction = "next");
|
||||||
[FIXME] IDBIndex index(DOMString name);
|
IDBIndex index(DOMString name);
|
||||||
[NewObject] IDBIndex createIndex(DOMString name, (DOMString or sequence<DOMString>) keyPath, optional IDBIndexParameters options = {});
|
[NewObject] IDBIndex createIndex(DOMString name, (DOMString or sequence<DOMString>) keyPath, optional IDBIndexParameters options = {});
|
||||||
[FIXME] undefined deleteIndex(DOMString name);
|
[FIXME] undefined deleteIndex(DOMString name);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue