diff --git a/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp b/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp index 588740fd9ca..63d5ece9902 100644 --- a/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp +++ b/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp @@ -50,21 +50,11 @@ void IDBObjectStore::visit_edges(Visitor& visitor) visitor.visit(m_indexes); } -// https://w3c.github.io/IndexedDB/#dom-idbobjectstore-keypath -JS::Value IDBObjectStore::key_path() const +// https://w3c.github.io/IndexedDB/#dom-idbobjectstore-name +String IDBObjectStore::name() const { - if (!m_store->key_path().has_value()) - return JS::js_null(); - - return m_store->key_path().value().visit( - [&](String const& value) -> JS::Value { - return JS::PrimitiveString::create(realm().vm(), value); - }, - [&](Vector const& value) -> JS::Value { - return JS::Array::create_from(realm(), value.span(), [&](auto const& entry) -> JS::Value { - return JS::PrimitiveString::create(realm().vm(), entry); - }); - }); + // The name getter steps are to return this’s name. + return m_name; } // https://w3c.github.io/IndexedDB/#dom-idbobjectstore-name @@ -108,6 +98,49 @@ WebIDL::ExceptionOr IDBObjectStore::set_name(String const& value) return {}; } +// https://w3c.github.io/IndexedDB/#dom-idbobjectstore-keypath +JS::Value IDBObjectStore::key_path() const +{ + if (!m_store->key_path().has_value()) + return JS::js_null(); + + return m_store->key_path().value().visit( + [&](String const& value) -> JS::Value { + return JS::PrimitiveString::create(realm().vm(), value); + }, + [&](Vector const& value) -> JS::Value { + return JS::Array::create_from(realm(), value.span(), [&](auto const& entry) -> JS::Value { + return JS::PrimitiveString::create(realm().vm(), entry); + }); + }); +} + +// 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); +} + +// https://w3c.github.io/IndexedDB/#dom-idbobjectstore-transaction +GC::Ref IDBObjectStore::transaction() const +{ + // The transaction getter steps are to return this’s transaction. + return m_transaction; +} + +// https://w3c.github.io/IndexedDB/#dom-idbobjectstore-autoincrement +bool IDBObjectStore::auto_increment() const +{ + // The autoIncrement getter steps are to return true if this’s object store has a key generator, and false otherwise. + return m_store->uses_a_key_generator(); +} + // https://w3c.github.io/IndexedDB/#dom-idbobjectstore-createindex WebIDL::ExceptionOr> IDBObjectStore::create_index(String const& name, KeyPath key_path, IDBIndexParameters options) { @@ -158,18 +191,6 @@ 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); -} - // https://w3c.github.io/IndexedDB/#dom-idbobjectstore-index WebIDL::ExceptionOr> IDBObjectStore::index(String const& name) { diff --git a/Libraries/LibWeb/IndexedDB/IDBObjectStore.h b/Libraries/LibWeb/IndexedDB/IDBObjectStore.h index 681201aca29..cfabf6e903a 100644 --- a/Libraries/LibWeb/IndexedDB/IDBObjectStore.h +++ b/Libraries/LibWeb/IndexedDB/IDBObjectStore.h @@ -31,33 +31,33 @@ public: virtual ~IDBObjectStore() override; [[nodiscard]] static GC::Ref create(JS::Realm&, GC::Ref, GC::Ref); - // https://w3c.github.io/IndexedDB/#dom-idbobjectstore-autoincrement - // The autoIncrement getter steps are to return true if this’s object store has a key generator, and false otherwise. - bool auto_increment() const { return m_store->uses_a_key_generator(); } - JS::Value key_path() const; - String name() const { return m_name; } + String name() const; WebIDL::ExceptionOr set_name(String const& value); - GC::Ref transaction() const { return m_transaction; } - GC::Ref store() const { return m_store; } - AK::HashMap>& index_set() { return m_indexes; } - - WebIDL::ExceptionOr> create_index(String const&, KeyPath, IDBIndexParameters options); + JS::Value key_path() const; [[nodiscard]] GC::Ref index_names(); - WebIDL::ExceptionOr> index(String const&); - WebIDL::ExceptionOr delete_index(String const&); + GC::Ref transaction() const; + bool auto_increment() const; - [[nodiscard]] WebIDL::ExceptionOr> add_or_put(GC::Ref, JS::Value, Optional const&, bool); - [[nodiscard]] WebIDL::ExceptionOr> add(JS::Value value, Optional const& key); [[nodiscard]] WebIDL::ExceptionOr> put(JS::Value value, Optional const& key); - [[nodiscard]] WebIDL::ExceptionOr> count(Optional); - [[nodiscard]] WebIDL::ExceptionOr> get(JS::Value); - [[nodiscard]] WebIDL::ExceptionOr> open_cursor(JS::Value, Bindings::IDBCursorDirection = Bindings::IDBCursorDirection::Next); + [[nodiscard]] WebIDL::ExceptionOr> add(JS::Value value, Optional const& key); [[nodiscard]] WebIDL::ExceptionOr> delete_(JS::Value); [[nodiscard]] WebIDL::ExceptionOr> clear(); + [[nodiscard]] WebIDL::ExceptionOr> get(JS::Value); [[nodiscard]] WebIDL::ExceptionOr> get_key(JS::Value); [[nodiscard]] WebIDL::ExceptionOr> get_all(Optional, Optional); - [[nodiscard]] WebIDL::ExceptionOr> open_key_cursor(JS::Value, Bindings::IDBCursorDirection = Bindings::IDBCursorDirection::Next); [[nodiscard]] WebIDL::ExceptionOr> get_all_keys(Optional, Optional); + [[nodiscard]] WebIDL::ExceptionOr> count(Optional); + [[nodiscard]] WebIDL::ExceptionOr> open_cursor(JS::Value, Bindings::IDBCursorDirection = Bindings::IDBCursorDirection::Next); + [[nodiscard]] WebIDL::ExceptionOr> open_key_cursor(JS::Value, Bindings::IDBCursorDirection = Bindings::IDBCursorDirection::Next); + + WebIDL::ExceptionOr> index(String const&); + + WebIDL::ExceptionOr> create_index(String const&, KeyPath, IDBIndexParameters options); + WebIDL::ExceptionOr delete_index(String const&); + + AK::HashMap>& index_set() { return m_indexes; } + WebIDL::ExceptionOr> add_or_put(GC::Ref, JS::Value, Optional const&, bool); + GC::Ref store() const { return m_store; } protected: explicit IDBObjectStore(JS::Realm&, GC::Ref, GC::Ref);