LibWeb/IDB: Implement IDBObjectStore::keyPath

This commit is contained in:
stelar7 2025-03-24 20:50:52 +01:00 committed by Jelle Raaijmakers
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);
});
});
}
}