mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 10:07:15 +02:00
63 lines
1.7 KiB
C++
63 lines
1.7 KiB
C++
/*
|
|
* Copyright (c) 2024-2025, stelar7 <dudedbz@gmail.com>
|
|
*
|
|
* 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>
|
|
#include <LibWeb/IndexedDB/IDBObjectStore.h>
|
|
|
|
namespace Web::IndexedDB {
|
|
|
|
GC_DEFINE_ALLOCATOR(IDBObjectStore);
|
|
|
|
IDBObjectStore::~IDBObjectStore() = default;
|
|
|
|
IDBObjectStore::IDBObjectStore(JS::Realm& realm, GC::Ref<ObjectStore> store, GC::Ref<IDBTransaction> transaction)
|
|
: PlatformObject(realm)
|
|
, m_store(store)
|
|
, m_transaction(transaction)
|
|
{
|
|
}
|
|
|
|
GC::Ref<IDBObjectStore> IDBObjectStore::create(JS::Realm& realm, GC::Ref<ObjectStore> store, GC::Ref<IDBTransaction> transaction)
|
|
{
|
|
return realm.create<IDBObjectStore>(realm, store, transaction);
|
|
}
|
|
|
|
void IDBObjectStore::initialize(JS::Realm& realm)
|
|
{
|
|
Base::initialize(realm);
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(IDBObjectStore);
|
|
}
|
|
|
|
void IDBObjectStore::visit_edges(Visitor& visitor)
|
|
{
|
|
Base::visit_edges(visitor);
|
|
visitor.visit(m_store);
|
|
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);
|
|
});
|
|
});
|
|
}
|
|
|
|
}
|