diff --git a/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp b/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp index a384ac28932..bf0e206b200 100644 --- a/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp +++ b/Libraries/LibWeb/IndexedDB/IDBObjectStore.cpp @@ -4,6 +4,8 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include +#include #include #include #include @@ -40,4 +42,21 @@ void IDBObjectStore::visit_edges(Visitor& visitor) visitor.visit(m_transaction); } +// 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); + }); + }); +} + } diff --git a/Libraries/LibWeb/IndexedDB/IDBObjectStore.h b/Libraries/LibWeb/IndexedDB/IDBObjectStore.h index 854845e05e7..7551b0ddd82 100644 --- a/Libraries/LibWeb/IndexedDB/IDBObjectStore.h +++ b/Libraries/LibWeb/IndexedDB/IDBObjectStore.h @@ -23,6 +23,8 @@ public: virtual ~IDBObjectStore() override; [[nodiscard]] static GC::Ref create(JS::Realm&, GC::Ref, GC::Ref); + JS::Value key_path() const; + protected: explicit IDBObjectStore(JS::Realm&, GC::Ref, GC::Ref); virtual void initialize(JS::Realm&) override; diff --git a/Libraries/LibWeb/IndexedDB/IDBObjectStore.idl b/Libraries/LibWeb/IndexedDB/IDBObjectStore.idl index de929eb3e24..3e13fb9b03a 100644 --- a/Libraries/LibWeb/IndexedDB/IDBObjectStore.idl +++ b/Libraries/LibWeb/IndexedDB/IDBObjectStore.idl @@ -5,7 +5,7 @@ [Exposed=(Window,Worker)] interface IDBObjectStore { [FIXME] attribute DOMString name; - [FIXME] readonly attribute any keyPath; + readonly attribute any keyPath; [FIXME] readonly attribute DOMStringList indexNames; [FIXME, SameObject] readonly attribute IDBTransaction transaction; [FIXME] readonly attribute boolean autoIncrement;