LibWeb/IDB: Use enum flags in IDBCursor

This commit is contained in:
stelar7 2025-05-13 09:09:34 +02:00 committed by Shannon Booth
commit a5023ec053
Notes: github-actions[bot] 2025-05-13 10:50:42 +00:00
4 changed files with 19 additions and 9 deletions

View file

@ -16,20 +16,20 @@ GC_DEFINE_ALLOCATOR(IDBCursor);
IDBCursor::~IDBCursor() = default;
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)
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_position(position)
, m_direction(direction)
, m_got_value(got_value)
, 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)
, m_key_only(key_only == KeyOnly::Yes)
{
}
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)
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)
{
return realm.create<IDBCursor>(realm, source_handle, position, direction, got_value, key, value, range, key_only);
}

View file

@ -25,9 +25,19 @@ class IDBCursor : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(IDBCursor, Bindings::PlatformObject);
GC_DECLARE_ALLOCATOR(IDBCursor);
enum class GotValue {
No,
Yes,
};
enum class KeyOnly {
No,
Yes,
};
public:
virtual ~IDBCursor() override;
[[nodiscard]] static GC::Ref<IDBCursor> create(JS::Realm&, CursorSourceHandle, GC::Ptr<Key>, Bindings::IDBCursorDirection, bool, GC::Ptr<Key>, JS::Value, GC::Ref<IDBKeyRange>, bool);
[[nodiscard]] static GC::Ref<IDBCursor> create(JS::Realm&, CursorSourceHandle, GC::Ptr<Key>, Bindings::IDBCursorDirection, GotValue, GC::Ptr<Key>, JS::Value, GC::Ref<IDBKeyRange>, KeyOnly);
[[nodiscard]] CursorSourceHandle source_handle() { return m_source_handle; }
[[nodiscard]] Bindings::IDBCursorDirection direction() { return m_direction; }
@ -55,7 +65,7 @@ public:
WebIDL::ExceptionOr<void> continue_(JS::Value);
protected:
explicit IDBCursor(JS::Realm&, CursorSourceHandle, GC::Ptr<Key>, Bindings::IDBCursorDirection, bool, GC::Ptr<Key>, JS::Value, GC::Ref<IDBKeyRange>, bool);
explicit IDBCursor(JS::Realm&, CursorSourceHandle, GC::Ptr<Key>, Bindings::IDBCursorDirection, GotValue, GC::Ptr<Key>, JS::Value, GC::Ref<IDBKeyRange>, KeyOnly);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Visitor& visitor) override;

View file

@ -123,7 +123,7 @@ WebIDL::ExceptionOr<GC::Ref<IDBRequest>> IDBIndex::open_cursor(JS::Value query,
auto range = TRY(convert_a_value_to_a_key_range(realm, query));
// 6. Let cursor be a new cursor with its source handle set to this, undefined position, direction set to direction, got value flag set to false, undefined key and value, range set to range, and key only flag set to false.
auto cursor = IDBCursor::create(realm, GC::Ref(*this), {}, direction, false, {}, {}, range, false);
auto cursor = IDBCursor::create(realm, GC::Ref(*this), {}, direction, IDBCursor::GotValue::No, {}, {}, range, IDBCursor::KeyOnly::No);
// 7. Let operation be an algorithm to run iterate a cursor with the current Realm record and cursor.
auto operation = GC::Function<WebIDL::ExceptionOr<JS::Value>()>::create(realm.heap(), [&realm, cursor] -> WebIDL::ExceptionOr<JS::Value> {

View file

@ -442,7 +442,7 @@ WebIDL::ExceptionOr<GC::Ref<IDBRequest>> IDBObjectStore::open_cursor(JS::Value q
// 6. Let cursor be a new cursor with its source handle set to this, undefined position, direction set to direction,
// got value flag set to false, undefined key and value, range set to range, and key only flag set to false.
auto cursor = IDBCursor::create(realm, GC::Ref(*this), {}, direction, false, {}, {}, range, false);
auto cursor = IDBCursor::create(realm, GC::Ref(*this), {}, direction, IDBCursor::GotValue::No, {}, {}, range, IDBCursor::KeyOnly::No);
// 7. Let operation be an algorithm to run iterate a cursor with the current Realm record and cursor.
auto operation = GC::Function<WebIDL::ExceptionOr<JS::Value>()>::create(realm.heap(), [&realm, cursor] -> WebIDL::ExceptionOr<JS::Value> {
@ -610,7 +610,7 @@ WebIDL::ExceptionOr<GC::Ref<IDBRequest>> IDBObjectStore::open_key_cursor(JS::Val
auto range = TRY(convert_a_value_to_a_key_range(realm, query));
// 6. Let cursor be a new cursor with its source handle set to this, undefined position, direction set to direction, got value flag set to false, undefined key and value, range set to range, and key only flag set to true.
auto cursor = IDBCursor::create(realm, GC::Ref(*this), {}, direction, false, {}, {}, range, true);
auto cursor = IDBCursor::create(realm, GC::Ref(*this), {}, direction, IDBCursor::GotValue::No, {}, {}, range, IDBCursor::KeyOnly::Yes);
// 7. Let operation be an algorithm to run iterate a cursor with the current Realm record and cursor.
auto operation = GC::Function<WebIDL::ExceptionOr<JS::Value>()>::create(realm.heap(), [&realm, cursor] -> WebIDL::ExceptionOr<JS::Value> {