mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-09 17:44:56 +09:00
LibWeb/IDB: Implement retrieve_a_value_from_an_object_store
This commit is contained in:
parent
d5cf2cee41
commit
18a008d073
Notes:
github-actions[bot]
2025-04-29 15:07:46 +00:00
Author: https://github.com/stelar7
Commit: 18a008d073
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4505
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/gmta ✅
4 changed files with 26 additions and 0 deletions
|
@ -1458,4 +1458,21 @@ JS::Value count_the_records_in_a_range(GC::Ref<ObjectStore> source, GC::Ref<IDBK
|
|||
return JS::Value(count);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/IndexedDB/#retrieve-a-value-from-an-object-store
|
||||
WebIDL::ExceptionOr<JS::Value> retrieve_a_value_from_an_object_store(JS::Realm& realm, GC::Ref<ObjectStore> store, GC::Ref<IDBKeyRange> range)
|
||||
{
|
||||
// 1. Let record be the first record in store’s list of records whose key is in range, if any.
|
||||
auto record = store->first_in_range(range);
|
||||
|
||||
// 2. If record was not found, return undefined.
|
||||
if (!record.has_value())
|
||||
return JS::js_undefined();
|
||||
|
||||
// 3. Let serialized be record’s value. If an error occurs while reading the value from the underlying storage, return a newly created "NotReadableError" DOMException.
|
||||
auto serialized = record->value;
|
||||
|
||||
// 4. Return ! StructuredDeserialize(serialized, targetRealm).
|
||||
return MUST(HTML::structured_deserialize(realm.vm(), serialized, realm));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -43,5 +43,6 @@ void delete_records_from_an_object_store(GC::Ref<ObjectStore>, GC::Ref<IDBKeyRan
|
|||
WebIDL::ExceptionOr<GC::Ptr<Key>> store_a_record_into_an_object_store(JS::Realm&, GC::Ref<ObjectStore>, JS::Value, GC::Ptr<Key>, bool);
|
||||
WebIDL::ExceptionOr<GC::Ref<IDBKeyRange>> convert_a_value_to_a_key_range(JS::Realm&, Optional<JS::Value>, bool = false);
|
||||
JS::Value count_the_records_in_a_range(GC::Ref<ObjectStore>, GC::Ref<IDBKeyRange>);
|
||||
WebIDL::ExceptionOr<JS::Value> retrieve_a_value_from_an_object_store(JS::Realm&, GC::Ref<ObjectStore>, GC::Ref<IDBKeyRange>);
|
||||
|
||||
}
|
||||
|
|
|
@ -77,4 +77,11 @@ u64 ObjectStore::count_records_in_range(GC::Ref<IDBKeyRange> range)
|
|||
return count;
|
||||
}
|
||||
|
||||
Optional<Record&> ObjectStore::first_in_range(GC::Ref<IDBKeyRange> range)
|
||||
{
|
||||
return m_records.first_matching([&](auto const& record) {
|
||||
return range->is_in_range(record.key);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ public:
|
|||
bool has_record_with_key(GC::Ref<Key> key);
|
||||
void store_a_record(Record const& record);
|
||||
u64 count_records_in_range(GC::Ref<IDBKeyRange> range);
|
||||
Optional<Record&> first_in_range(GC::Ref<IDBKeyRange> range);
|
||||
|
||||
protected:
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue