From fe5bb7d77d9d5700c649170114965095069c460a Mon Sep 17 00:00:00 2001 From: stelar7 Date: Tue, 1 Apr 2025 18:38:55 +0200 Subject: [PATCH] LibWeb/IDB: Implement IDBObjectStore::indexNames --- Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp | 12 ++++++++++++ Libraries/LibWeb/IndexedDB/IDBObjectStore.h | 1 + Libraries/LibWeb/IndexedDB/IDBObjectStore.idl | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp b/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp index 35f7ea24f46..255026e319b 100644 --- a/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp +++ b/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp @@ -153,4 +153,16 @@ WebIDL::ExceptionOr> IDBObjectStore::create_index(String const return IDBIndex::create(realm, index, *this); } +// https://w3c.github.io/IndexedDB/#dom-idbobjectstore-indexnames +GC::Ref IDBObjectStore::index_names() +{ + // 1. Let names be a list of the names of the indexes in this's index set. + Vector names; + for (auto const& [name, index] : m_indexes) + names.append(name); + + // 2. Return the result (a DOMStringList) of creating a sorted name list with names. + return create_a_sorted_name_list(realm(), names); +} + } diff --git a/Libraries/LibWeb/IndexedDB/IDBObjectStore.h b/Libraries/LibWeb/IndexedDB/IDBObjectStore.h index df6e0f03efb..8baf4a1869c 100644 --- a/Libraries/LibWeb/IndexedDB/IDBObjectStore.h +++ b/Libraries/LibWeb/IndexedDB/IDBObjectStore.h @@ -40,6 +40,7 @@ public: AK::HashMap>& index_set() { return m_indexes; } WebIDL::ExceptionOr> create_index(String const&, KeyPath, IDBIndexParameters options); + [[nodiscard]] GC::Ref index_names(); protected: explicit IDBObjectStore(JS::Realm&, GC::Ref, GC::Ref); diff --git a/Libraries/LibWeb/IndexedDB/IDBObjectStore.idl b/Libraries/LibWeb/IndexedDB/IDBObjectStore.idl index 4af455b4102..550f7d3c60f 100644 --- a/Libraries/LibWeb/IndexedDB/IDBObjectStore.idl +++ b/Libraries/LibWeb/IndexedDB/IDBObjectStore.idl @@ -6,7 +6,7 @@ interface IDBObjectStore { attribute DOMString name; readonly attribute any keyPath; - [FIXME] readonly attribute DOMStringList indexNames; + readonly attribute DOMStringList indexNames; [SameObject] readonly attribute IDBTransaction transaction; readonly attribute boolean autoIncrement;