LibWeb/IDB: Implement IDBObjectStore::keyPath

This commit is contained in:
stelar7 2025-03-24 20:50:52 +01:00 committed by Jelle Raaijmakers
parent 1057c88fdd
commit 594ba28c35
Notes: github-actions[bot] 2025-03-27 15:49:32 +00:00
3 changed files with 22 additions and 1 deletions

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/String.h>
#include <LibJS/Runtime/Array.h>
#include <LibWeb/Bindings/IDBObjectStorePrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/EventNames.h>
@ -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<String> const& value) -> JS::Value {
return JS::Array::create_from<String>(realm(), value.span(), [&](auto const& entry) -> JS::Value {
return JS::PrimitiveString::create(realm().vm(), entry);
});
});
}
}

View file

@ -23,6 +23,8 @@ public:
virtual ~IDBObjectStore() override;
[[nodiscard]] static GC::Ref<IDBObjectStore> create(JS::Realm&, GC::Ref<ObjectStore>, GC::Ref<IDBTransaction>);
JS::Value key_path() const;
protected:
explicit IDBObjectStore(JS::Realm&, GC::Ref<ObjectStore>, GC::Ref<IDBTransaction>);
virtual void initialize(JS::Realm&) override;

View file

@ -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;