mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-10 01:59:31 +00:00
LibWeb/IDB: Implement IDBObjectStore::keyPath
This commit is contained in:
parent
1057c88fdd
commit
594ba28c35
Notes:
github-actions[bot]
2025-03-27 15:49:32 +00:00
Author: https://github.com/stelar7
Commit: 594ba28c35
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 1 deletions
|
@ -4,6 +4,8 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <AK/String.h>
|
||||||
|
#include <LibJS/Runtime/Array.h>
|
||||||
#include <LibWeb/Bindings/IDBObjectStorePrototype.h>
|
#include <LibWeb/Bindings/IDBObjectStorePrototype.h>
|
||||||
#include <LibWeb/Bindings/Intrinsics.h>
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
#include <LibWeb/HTML/EventNames.h>
|
#include <LibWeb/HTML/EventNames.h>
|
||||||
|
@ -40,4 +42,21 @@ void IDBObjectStore::visit_edges(Visitor& visitor)
|
||||||
visitor.visit(m_transaction);
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,8 @@ public:
|
||||||
virtual ~IDBObjectStore() override;
|
virtual ~IDBObjectStore() override;
|
||||||
[[nodiscard]] static GC::Ref<IDBObjectStore> create(JS::Realm&, GC::Ref<ObjectStore>, GC::Ref<IDBTransaction>);
|
[[nodiscard]] static GC::Ref<IDBObjectStore> create(JS::Realm&, GC::Ref<ObjectStore>, GC::Ref<IDBTransaction>);
|
||||||
|
|
||||||
|
JS::Value key_path() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit IDBObjectStore(JS::Realm&, GC::Ref<ObjectStore>, GC::Ref<IDBTransaction>);
|
explicit IDBObjectStore(JS::Realm&, GC::Ref<ObjectStore>, GC::Ref<IDBTransaction>);
|
||||||
virtual void initialize(JS::Realm&) override;
|
virtual void initialize(JS::Realm&) override;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
[Exposed=(Window,Worker)]
|
[Exposed=(Window,Worker)]
|
||||||
interface IDBObjectStore {
|
interface IDBObjectStore {
|
||||||
[FIXME] attribute DOMString name;
|
[FIXME] attribute DOMString name;
|
||||||
[FIXME] readonly attribute any keyPath;
|
readonly attribute any keyPath;
|
||||||
[FIXME] readonly attribute DOMStringList indexNames;
|
[FIXME] readonly attribute DOMStringList indexNames;
|
||||||
[FIXME, SameObject] readonly attribute IDBTransaction transaction;
|
[FIXME, SameObject] readonly attribute IDBTransaction transaction;
|
||||||
[FIXME] readonly attribute boolean autoIncrement;
|
[FIXME] readonly attribute boolean autoIncrement;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue