mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-12 19:19:30 +00:00
LibWeb/IDB: Introduce an Invalid KeyType
This cleans up the code around failure/invalid/exception a bit
This commit is contained in:
parent
61384473ca
commit
facfcd87c2
Notes:
github-actions[bot]
2025-04-28 09:32:57 +00:00
Author: https://github.com/stelar7
Commit: facfcd87c2
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4476
Reviewed-by: https://github.com/gmta ✅
7 changed files with 68 additions and 56 deletions
|
@ -31,6 +31,7 @@ class Key : public JS::Cell {
|
|||
|
||||
// A key has an associated type which is one of: number, date, string, binary, or array.
|
||||
enum KeyType {
|
||||
Invalid,
|
||||
Number,
|
||||
Date,
|
||||
String,
|
||||
|
@ -45,6 +46,8 @@ public:
|
|||
[[nodiscard]] KeyType type() { return m_type; }
|
||||
[[nodiscard]] KeyValue value() { return m_value; }
|
||||
|
||||
[[nodiscard]] bool is_invalid() { return m_type == Invalid; }
|
||||
|
||||
[[nodiscard]] double value_as_double() { return m_value.get<double>(); }
|
||||
[[nodiscard]] AK::String value_as_string() { return m_value.get<AK::String>(); }
|
||||
[[nodiscard]] ByteBuffer value_as_byte_buffer() { return m_value.get<ByteBuffer>(); }
|
||||
|
@ -60,6 +63,7 @@ public:
|
|||
[[nodiscard]] static GC::Ref<Key> create_string(JS::Realm& realm, AK::String const& value) { return create(realm, String, value); }
|
||||
[[nodiscard]] static GC::Ref<Key> create_binary(JS::Realm& realm, ByteBuffer const& value) { return create(realm, Binary, value); }
|
||||
[[nodiscard]] static GC::Ref<Key> create_array(JS::Realm& realm, Vector<GC::Root<Key>> const& value) { return create(realm, Array, value); }
|
||||
[[nodiscard]] static GC::Ref<Key> create_invalid(JS::Realm& realm, AK::String const& value) { return create(realm, Invalid, value); }
|
||||
|
||||
[[nodiscard]] static i8 compare_two_keys(GC::Ref<Key> a, GC::Ref<Key> b);
|
||||
[[nodiscard]] static bool equals(GC::Ref<Key> a, GC::Ref<Key> b) { return compare_two_keys(a, b) == 0; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue