mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 20:59:16 +00:00
LibWeb/IDB: Use enum flags in IDBCursor
This commit is contained in:
parent
41b060be81
commit
a5023ec053
Notes:
github-actions[bot]
2025-05-13 10:50:42 +00:00
Author: https://github.com/stelar7
Commit: a5023ec053
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4716
4 changed files with 19 additions and 9 deletions
|
@ -16,20 +16,20 @@ GC_DEFINE_ALLOCATOR(IDBCursor);
|
||||||
|
|
||||||
IDBCursor::~IDBCursor() = default;
|
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)
|
: PlatformObject(realm)
|
||||||
, m_position(position)
|
, m_position(position)
|
||||||
, m_direction(direction)
|
, m_direction(direction)
|
||||||
, m_got_value(got_value)
|
, m_got_value(got_value == GotValue::Yes)
|
||||||
, m_key(key)
|
, m_key(key)
|
||||||
, m_value(value)
|
, m_value(value)
|
||||||
, m_source_handle(source_handle)
|
, m_source_handle(source_handle)
|
||||||
, m_range(range)
|
, 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);
|
return realm.create<IDBCursor>(realm, source_handle, position, direction, got_value, key, value, range, key_only);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,19 @@ class IDBCursor : public Bindings::PlatformObject {
|
||||||
WEB_PLATFORM_OBJECT(IDBCursor, Bindings::PlatformObject);
|
WEB_PLATFORM_OBJECT(IDBCursor, Bindings::PlatformObject);
|
||||||
GC_DECLARE_ALLOCATOR(IDBCursor);
|
GC_DECLARE_ALLOCATOR(IDBCursor);
|
||||||
|
|
||||||
|
enum class GotValue {
|
||||||
|
No,
|
||||||
|
Yes,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum class KeyOnly {
|
||||||
|
No,
|
||||||
|
Yes,
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~IDBCursor() override;
|
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]] CursorSourceHandle source_handle() { return m_source_handle; }
|
||||||
[[nodiscard]] Bindings::IDBCursorDirection direction() { return m_direction; }
|
[[nodiscard]] Bindings::IDBCursorDirection direction() { return m_direction; }
|
||||||
|
@ -55,7 +65,7 @@ public:
|
||||||
WebIDL::ExceptionOr<void> continue_(JS::Value);
|
WebIDL::ExceptionOr<void> continue_(JS::Value);
|
||||||
|
|
||||||
protected:
|
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 initialize(JS::Realm&) override;
|
||||||
virtual void visit_edges(Visitor& visitor) override;
|
virtual void visit_edges(Visitor& visitor) override;
|
||||||
|
|
||||||
|
|
|
@ -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));
|
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.
|
// 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.
|
// 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> {
|
auto operation = GC::Function<WebIDL::ExceptionOr<JS::Value>()>::create(realm.heap(), [&realm, cursor] -> WebIDL::ExceptionOr<JS::Value> {
|
||||||
|
|
|
@ -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,
|
// 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.
|
// 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.
|
// 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> {
|
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));
|
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.
|
// 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.
|
// 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> {
|
auto operation = GC::Function<WebIDL::ExceptionOr<JS::Value>()>::create(realm.heap(), [&realm, cursor] -> WebIDL::ExceptionOr<JS::Value> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue