diff --git a/Libraries/LibWeb/IndexedDB/IDBKeyRange.cpp b/Libraries/LibWeb/IndexedDB/IDBKeyRange.cpp index 8ec54b6465a..2b2faadb103 100644 --- a/Libraries/LibWeb/IndexedDB/IDBKeyRange.cpp +++ b/Libraries/LibWeb/IndexedDB/IDBKeyRange.cpp @@ -17,16 +17,16 @@ GC_DEFINE_ALLOCATOR(IDBKeyRange); IDBKeyRange::~IDBKeyRange() = default; -IDBKeyRange::IDBKeyRange(JS::Realm& realm, GC::Ptr lower_bound, GC::Ptr upper_bound, bool lower_open, bool upper_open) +IDBKeyRange::IDBKeyRange(JS::Realm& realm, GC::Ptr lower_bound, GC::Ptr upper_bound, LowerOpen lower_open, UpperOpen upper_open) : PlatformObject(realm) , m_lower_bound(lower_bound) , m_upper_bound(upper_bound) - , m_lower_open(lower_open) - , m_upper_open(upper_open) + , m_lower_open(lower_open == LowerOpen::Yes) + , m_upper_open(upper_open == UpperOpen::Yes) { } -GC::Ref IDBKeyRange::create(JS::Realm& realm, GC::Ptr lower_bound, GC::Ptr upper_bound, bool lower_open, bool upper_open) +GC::Ref IDBKeyRange::create(JS::Realm& realm, GC::Ptr lower_bound, GC::Ptr upper_bound, LowerOpen lower_open, UpperOpen upper_open) { return realm.create(realm, lower_bound, upper_bound, lower_open, upper_open); } @@ -71,7 +71,7 @@ WebIDL::ExceptionOr> IDBKeyRange::only(JS::VM& vm, JS::Valu return WebIDL::DataError::create(realm, "Value is invalid"_string); // 3. Create and return a new key range containing only key. - return IDBKeyRange::create(realm, key, key, false, false); + return IDBKeyRange::create(realm, key, key, IDBKeyRange::LowerOpen::No, IDBKeyRange::UpperOpen::No); } // https://w3c.github.io/IndexedDB/#dom-idbkeyrange-lowerbound @@ -87,7 +87,7 @@ WebIDL::ExceptionOr> IDBKeyRange::lower_bound(JS::VM& vm, J return WebIDL::DataError::create(realm, "Value is invalid"_string); // 3. Create and return a new key range with lower bound set to lowerKey, lower open flag set to open, upper bound set to null, and upper open flag set to true. - return IDBKeyRange::create(realm, key, {}, open, true); + return IDBKeyRange::create(realm, key, {}, open ? IDBKeyRange::LowerOpen::Yes : IDBKeyRange::LowerOpen::No, IDBKeyRange::UpperOpen::Yes); } // https://w3c.github.io/IndexedDB/#dom-idbkeyrange-upperbound @@ -103,7 +103,7 @@ WebIDL::ExceptionOr> IDBKeyRange::upper_bound(JS::VM& vm, J return WebIDL::DataError::create(realm, "Value is invalid"_string); // 3. Create and return a new key range with lower bound set to null, lower open flag set to true, upper bound set to upperKey, and upper open flag set to open. - return IDBKeyRange::create(realm, {}, key, true, open); + return IDBKeyRange::create(realm, {}, key, IDBKeyRange::LowerOpen::Yes, open ? IDBKeyRange::UpperOpen::Yes : IDBKeyRange::UpperOpen::No); } // https://w3c.github.io/IndexedDB/#dom-idbkeyrange-bound @@ -130,7 +130,7 @@ WebIDL::ExceptionOr> IDBKeyRange::bound(JS::VM& vm, JS::Val return WebIDL::DataError::create(realm, "Lower key is greater than upper key"_string); // 6. Create and return a new key range with lower bound set to lowerKey, lower open flag set to lowerOpen, upper bound set to upperKey and upper open flag set to upperOpen. - return IDBKeyRange::create(realm, lower_key, upper_key, lower_open, upper_open); + return IDBKeyRange::create(realm, lower_key, upper_key, lower_open ? IDBKeyRange::LowerOpen::Yes : IDBKeyRange::LowerOpen::No, upper_open ? IDBKeyRange::UpperOpen::Yes : IDBKeyRange::UpperOpen::No); } // https://w3c.github.io/IndexedDB/#dom-idbkeyrange-includes diff --git a/Libraries/LibWeb/IndexedDB/IDBKeyRange.h b/Libraries/LibWeb/IndexedDB/IDBKeyRange.h index 1d7ec778917..915340e6ced 100644 --- a/Libraries/LibWeb/IndexedDB/IDBKeyRange.h +++ b/Libraries/LibWeb/IndexedDB/IDBKeyRange.h @@ -21,9 +21,19 @@ class IDBKeyRange : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(IDBKeyRange, Bindings::PlatformObject); GC_DECLARE_ALLOCATOR(IDBKeyRange); + enum class LowerOpen { + No, + Yes, + }; + + enum class UpperOpen { + No, + Yes, + }; + public: virtual ~IDBKeyRange() override; - [[nodiscard]] static GC::Ref create(JS::Realm&, GC::Ptr lower_bound, GC::Ptr upper_bound, bool lower_open, bool upper_open); + [[nodiscard]] static GC::Ref create(JS::Realm&, GC::Ptr lower_bound, GC::Ptr upper_bound, LowerOpen lower_open, UpperOpen upper_open); [[nodiscard]] JS::Value lower() const; [[nodiscard]] JS::Value upper() const; @@ -42,7 +52,7 @@ public: GC::Ptr upper_key() const { return m_upper_bound; } protected: - explicit IDBKeyRange(JS::Realm&, GC::Ptr lower_bound, GC::Ptr upper_bound, bool lower_open, bool upper_open); + explicit IDBKeyRange(JS::Realm&, GC::Ptr lower_bound, GC::Ptr upper_bound, LowerOpen lower_open, UpperOpen upper_open); virtual void initialize(JS::Realm&) override; virtual void visit_edges(Visitor& visitor) override; diff --git a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp index edf45f05a71..08e8794bca7 100644 --- a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp +++ b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp @@ -1359,7 +1359,7 @@ WebIDL::ExceptionOr> store_a_record_into_an_object_store(JS::Realm& // 3. If a record already exists in store with its key equal to key, then remove the record from store using delete records from an object store. if (has_record) { - auto key_range = IDBKeyRange::create(realm, key, key, false, false); + auto key_range = IDBKeyRange::create(realm, key, key, IDBKeyRange::LowerOpen::No, IDBKeyRange::UpperOpen::No); delete_records_from_an_object_store(store, key_range); } @@ -1438,7 +1438,7 @@ WebIDL::ExceptionOr> convert_a_value_to_a_key_range(JS::Rea if (null_disallowed) return WebIDL::DataError::create(realm, "Value is undefined or null"_string); - return IDBKeyRange::create(realm, {}, {}, false, false); + return IDBKeyRange::create(realm, {}, {}, IDBKeyRange::LowerOpen::No, IDBKeyRange::UpperOpen::No); } // 3. Let key be the result of converting a value to a key with value. Rethrow any exceptions. @@ -1449,7 +1449,7 @@ WebIDL::ExceptionOr> convert_a_value_to_a_key_range(JS::Rea return WebIDL::DataError::create(realm, "Value is invalid"_string); // 5. Return a key range containing only key. - return IDBKeyRange::create(realm, key, key, false, false); + return IDBKeyRange::create(realm, key, key, IDBKeyRange::LowerOpen::No, IDBKeyRange::UpperOpen::No); } // https://w3c.github.io/IndexedDB/#count-the-records-in-a-range