LibWeb/IDB: Implement IDBObjectStore::createIndex

This commit is contained in:
stelar7 2025-04-01 18:37:23 +02:00 committed by Andrew Kaster
commit 3367352991
Notes: github-actions[bot] 2025-04-09 17:50:46 +00:00
7 changed files with 88 additions and 14 deletions

View file

@ -71,14 +71,16 @@ WebIDL::ExceptionOr<void> IDBIndex::set_name(String const& value)
return {};
// 8. If an index named name already exists in indexs object store, throw a "ConstraintError" DOMException.
for (auto const& existing_index : m_object_store_handle->index_set()) {
if (existing_index->name() == name)
return WebIDL::ConstraintError::create(realm, "An index with the given name already exists"_string);
}
if (index->object_store()->index_set().contains(name))
return WebIDL::ConstraintError::create(realm, "An index with the given name already exists"_string);
// 9. Set indexs name to name.
index->set_name(name);
// NOTE: Update the key in the map so it still matches the name
auto old_value = m_object_store_handle->index_set().take(m_name).release_value();
m_object_store_handle->index_set().set(name, old_value);
// 10. Set thiss name to name.
m_name = name;