mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-07 17:41:54 +00:00
LibWeb/IDB: Implement convert_a_value_to_a_key_range
This commit is contained in:
parent
1f0c67cc12
commit
64d251b36c
Notes:
github-actions[bot]
2025-04-29 15:08:06 +00:00
Author: https://github.com/stelar7
Commit: 64d251b36c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4505
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/gmta ✅
2 changed files with 28 additions and 0 deletions
|
@ -1421,4 +1421,31 @@ WebIDL::ExceptionOr<GC::Ptr<Key>> store_a_record_into_an_object_store(JS::Realm&
|
|||
return key;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/IndexedDB/#convert-a-value-to-a-key-range
|
||||
WebIDL::ExceptionOr<GC::Ref<IDBKeyRange>> convert_a_value_to_a_key_range(JS::Realm& realm, Optional<JS::Value> value, bool null_disallowed)
|
||||
{
|
||||
// 1. If value is a key range, return value.
|
||||
if (value.has_value() && value->is_object() && is<IDBKeyRange>(value->as_object())) {
|
||||
return GC::Ref(static_cast<IDBKeyRange&>(value->as_object()));
|
||||
}
|
||||
|
||||
// 2. If value is undefined or is null, then throw a "DataError" DOMException if null disallowed flag is true, or return an unbounded key range otherwise.
|
||||
if (!value.has_value() || (value.has_value() && (value->is_undefined() || value->is_null()))) {
|
||||
if (null_disallowed)
|
||||
return WebIDL::DataError::create(realm, "Value is undefined or null"_string);
|
||||
|
||||
return IDBKeyRange::create(realm, {}, {}, false, false);
|
||||
}
|
||||
|
||||
// 3. Let key be the result of converting a value to a key with value. Rethrow any exceptions.
|
||||
auto key = TRY(convert_a_value_to_a_key(realm, *value));
|
||||
|
||||
// 4. If key is invalid, throw a "DataError" DOMException.
|
||||
if (key->is_invalid())
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue