mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
LibWeb/IDB: Implement IDBDatabase::objectStoreNames
This commit is contained in:
parent
1ad9b3ee6e
commit
b11276e5c4
Notes:
github-actions[bot]
2025-03-27 15:48:55 +00:00
Author: https://github.com/stelar7 Commit: https://github.com/LadybirdBrowser/ladybird/commit/b11276e5c4e Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4077 Reviewed-by: https://github.com/AtkinsSJ Reviewed-by: https://github.com/gmta ✅
3 changed files with 22 additions and 4 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,13 +46,14 @@ public:
|
|||
void set_close_pending(bool close_pending) { m_close_pending = close_pending; }
|
||||
void set_state(ConnectionState state) { m_state = state; }
|
||||
|
||||
[[nodiscard]] GC::Ref<HTML::DOMStringList> object_store_names() { return m_object_store_names; }
|
||||
[[nodiscard]] String name() const { return m_name; }
|
||||
[[nodiscard]] u64 version() const { return m_version; }
|
||||
[[nodiscard]] bool close_pending() const { return m_close_pending; }
|
||||
[[nodiscard]] ConnectionState state() const { return m_state; }
|
||||
[[nodiscard]] GC::Ref<Database> associated_database() { return m_associated_database; }
|
||||
[[nodiscard]] ReadonlySpan<GC::Ref<ObjectStore>> object_store_set() { return m_object_store_set; }
|
||||
|
||||
[[nodiscard]] GC::Ref<HTML::DOMStringList> object_store_names();
|
||||
WebIDL::ExceptionOr<GC::Ref<IDBObjectStore>> create_object_store(String const&, IDBObjectStoreParameters const&);
|
||||
|
||||
void close();
|
||||
|
@ -75,13 +76,17 @@ protected:
|
|||
private:
|
||||
u64 m_version { 0 };
|
||||
String m_name;
|
||||
GC::Ref<HTML::DOMStringList> m_object_store_names;
|
||||
|
||||
// Each connection has a close pending flag which is initially false.
|
||||
bool m_close_pending { false };
|
||||
|
||||
// When a connection is initially created it is in an opened state.
|
||||
ConnectionState m_state { ConnectionState::Open };
|
||||
|
||||
// A connection has an object store set, which is initialized to the set of object stores in the associated database when the connection is created.
|
||||
// The contents of the set will remain constant except when an upgrade transaction is live.
|
||||
Vector<GC::Ref<ObjectStore>> m_object_store_set;
|
||||
|
||||
// NOTE: There is an associated database in the spec, but there is no mention where it is assigned, nor where its from
|
||||
// So we stash the one we have when opening a connection.
|
||||
GC::Ref<Database> m_associated_database;
|
||||
|
|
|
@ -40,6 +40,7 @@ public:
|
|||
return connections;
|
||||
}
|
||||
|
||||
ReadonlySpan<GC::Ref<ObjectStore>> object_stores() { return m_object_stores; }
|
||||
bool has_object_store_named(String const& name) const;
|
||||
void add_object_store(GC::Ref<ObjectStore> object_store) { m_object_stores.append(object_store); }
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue