LibWeb/IDB: Implement recent spec changes

This commit is contained in:
stelar7 2025-05-06 11:36:11 +02:00 committed by Sam Atkins
commit 9d5f6108e4
Notes: github-actions[bot] 2025-05-06 12:31:37 +00:00
9 changed files with 71 additions and 56 deletions

View file

@ -16,23 +16,22 @@ GC_DEFINE_ALLOCATOR(IDBCursor);
IDBCursor::~IDBCursor() = default;
IDBCursor::IDBCursor(JS::Realm& realm, GC::Ref<IDBTransaction> transaction, GC::Ptr<Key> position, Bindings::IDBCursorDirection direction, bool got_value, GC::Ptr<Key> key, JS::Value value, CursorSource source, GC::Ref<IDBKeyRange> range, bool key_only)
IDBCursor::IDBCursor(JS::Realm& realm, CursorSourceHandle source_handle, GC::Ptr<Key> position, Bindings::IDBCursorDirection direction, bool got_value, GC::Ptr<Key> key, JS::Value value, GC::Ref<IDBKeyRange> range, bool key_only)
: PlatformObject(realm)
, m_transaction(transaction)
, m_position(position)
, m_direction(direction)
, m_got_value(got_value)
, m_key(key)
, m_value(value)
, m_source(source)
, m_source_handle(source_handle)
, m_range(range)
, m_key_only(key_only)
{
}
GC::Ref<IDBCursor> IDBCursor::create(JS::Realm& realm, GC::Ref<IDBTransaction> transaction, GC::Ptr<Key> position, Bindings::IDBCursorDirection direction, bool got_value, GC::Ptr<Key> key, JS::Value value, CursorSource source, GC::Ref<IDBKeyRange> range, bool key_only)
GC::Ref<IDBCursor> IDBCursor::create(JS::Realm& realm, CursorSourceHandle source_handle, GC::Ptr<Key> position, Bindings::IDBCursorDirection direction, bool got_value, GC::Ptr<Key> key, JS::Value value, GC::Ref<IDBKeyRange> range, bool key_only)
{
return realm.create<IDBCursor>(realm, transaction, position, direction, got_value, key, value, source, range, key_only);
return realm.create<IDBCursor>(realm, source_handle, position, direction, got_value, key, value, range, key_only);
}
void IDBCursor::initialize(JS::Realm& realm)
@ -44,18 +43,35 @@ void IDBCursor::initialize(JS::Realm& realm)
void IDBCursor::visit_edges(Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_transaction);
visitor.visit(m_position);
visitor.visit(m_object_store_position);
visitor.visit(m_key);
visitor.visit(m_range);
visitor.visit(m_request);
m_source.visit([&](auto& source) {
m_source_handle.visit([&](auto& source) {
visitor.visit(source);
});
}
// https://w3c.github.io/IndexedDB/#cursor-transaction
GC::Ref<IDBTransaction> IDBCursor::transaction()
{
// A cursor has a transaction, which is the transaction from the cursors source handle.
return m_source_handle.visit(
[](GC::Ref<IDBObjectStore> object_store) { return object_store->transaction(); },
[](GC::Ref<IDBIndex> index) { return index->transaction(); });
}
// https://w3c.github.io/IndexedDB/#cursor-source
CursorSource IDBCursor::internal_source()
{
// A cursor has a source, which is an index or an object store from the cursors source handle.
return m_source_handle.visit(
[](GC::Ref<IDBObjectStore> object_store) -> CursorSource { return object_store->store(); },
[](GC::Ref<IDBIndex> index) -> CursorSource { return index->index(); });
}
// https://w3c.github.io/IndexedDB/#dom-idbcursor-key
JS::Value IDBCursor::key()
{
@ -125,8 +141,8 @@ WebIDL::ExceptionOr<void> IDBCursor::continue_(JS::Value key)
return WebIDL::ExceptionOr<JS::Value>(iterate_a_cursor(realm, *this, key_value));
});
// 11. Run asynchronously execute a request with this's source, operation, and request.
asynchronously_execute_a_request(realm, GC::Ref(*this), operation, request);
// 11. Run asynchronously execute a request with thiss source handle, operation, and request.
asynchronously_execute_a_request(realm, source_handle(), operation, request);
dbgln_if(IDB_DEBUG, "Executing request for cursor continue with uuid {}", request->uuid());
return {};