LibWeb/IDB: Implement IDBCursorWithValue interface

This commit is contained in:
stelar7 2025-05-13 11:04:55 +02:00 committed by Andrew Kaster
commit 296d9d74d8
Notes: github-actions[bot] 2025-05-13 16:49:47 +00:00
10 changed files with 74 additions and 4 deletions

View file

@ -8,6 +8,7 @@
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/HTML/EventNames.h>
#include <LibWeb/IndexedDB/IDBCursor.h>
#include <LibWeb/IndexedDB/IDBCursorWithValue.h>
#include <LibWeb/IndexedDB/Internal/Algorithms.h>
namespace Web::IndexedDB {
@ -18,11 +19,11 @@ IDBCursor::~IDBCursor() = default;
IDBCursor::IDBCursor(JS::Realm& realm, CursorSourceHandle source_handle, GC::Ptr<Key> position, Bindings::IDBCursorDirection direction, GotValue got_value, GC::Ptr<Key> key, JS::Value value, GC::Ref<IDBKeyRange> range, KeyOnly key_only)
: PlatformObject(realm)
, m_value(value)
, m_position(position)
, m_direction(direction)
, m_got_value(got_value == GotValue::Yes)
, m_key(key)
, m_value(value)
, m_source_handle(source_handle)
, m_range(range)
, m_key_only(key_only == KeyOnly::Yes)
@ -31,6 +32,10 @@ IDBCursor::IDBCursor(JS::Realm& realm, CursorSourceHandle source_handle, GC::Ptr
GC::Ref<IDBCursor> IDBCursor::create(JS::Realm& realm, CursorSourceHandle source_handle, GC::Ptr<Key> position, Bindings::IDBCursorDirection direction, GotValue got_value, GC::Ptr<Key> key, JS::Value value, GC::Ref<IDBKeyRange> range, KeyOnly key_only)
{
// A cursor that has its key only flag set to false implements the IDBCursorWithValue interface as well.
if (key_only == KeyOnly::No)
return realm.create<IDBCursorWithValue>(realm, source_handle, position, direction, got_value, key, value, range, key_only);
return realm.create<IDBCursor>(realm, source_handle, position, direction, got_value, key, value, range, key_only);
}
@ -54,6 +59,26 @@ void IDBCursor::visit_edges(Visitor& visitor)
});
}
GC_DEFINE_ALLOCATOR(IDBCursorWithValue);
IDBCursorWithValue::~IDBCursorWithValue() = default;
IDBCursorWithValue::IDBCursorWithValue(JS::Realm& realm, CursorSourceHandle source_handle, GC::Ptr<Key> position, Bindings::IDBCursorDirection direction, GotValue got_value, GC::Ptr<Key> key, JS::Value value, GC::Ref<IDBKeyRange> range, KeyOnly key_only)
: IDBCursor(realm, source_handle, position, direction, got_value, key, value, range, key_only)
{
}
void IDBCursorWithValue::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(IDBCursorWithValue);
Base::initialize(realm);
}
void IDBCursorWithValue::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
}
// https://w3c.github.io/IndexedDB/#cursor-transaction
GC::Ref<IDBTransaction> IDBCursor::transaction()
{