LibWeb/IDB: Implement IDBDatabase::objectStoreNames

This commit is contained in:
stelar7
2025-03-24 21:38:50 +01:00
committed by Jelle Raaijmakers
parent 1ad9b3ee6e
commit b11276e5c4
Notes: github-actions[bot] 2025-03-27 15:48:55 +00:00
3 changed files with 22 additions and 4 deletions

View File

@@ -18,10 +18,10 @@ GC_DEFINE_ALLOCATOR(IDBDatabase);
IDBDatabase::IDBDatabase(JS::Realm& realm, Database& db)
: EventTarget(realm)
, m_name(db.name())
, m_object_store_names(HTML::DOMStringList::create(realm, {}))
, m_associated_database(db)
{
db.associate(*this);
db.object_stores().copy_to(m_object_store_set);
}
IDBDatabase::~IDBDatabase() = default;
@@ -40,7 +40,7 @@ void IDBDatabase::initialize(JS::Realm& realm)
void IDBDatabase::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_object_store_names);
visitor.visit(m_object_store_set);
visitor.visit(m_associated_database);
}
@@ -138,4 +138,16 @@ WebIDL::ExceptionOr<GC::Ref<IDBObjectStore>> IDBDatabase::create_object_store(St
return IDBObjectStore::create(realm, object_store, *transaction);
}
// https://w3c.github.io/IndexedDB/#dom-idbdatabase-objectstorenames
GC::Ref<HTML::DOMStringList> IDBDatabase::object_store_names()
{
// 1. Let names be a list of the names of the object stores in this's object store set.
Vector<String> names;
for (auto const& object_store : this->object_store_set())
names.append(object_store->name());
// 2. Return the result (a DOMStringList) of creating a sorted name list with names.
return create_a_sorted_name_list(realm(), names);
}
}