mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-01 21:59:07 +00:00
LibWeb/IDB: Implement IDBObjectStore::deleteIndex
This commit is contained in:
parent
fce936e05a
commit
718c805e95
Notes:
github-actions[bot]
2025-04-09 17:50:24 +00:00
Author: https://github.com/stelar7
Commit: 718c805e95
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4178
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/AtkinsSJ
3 changed files with 35 additions and 1 deletions
|
@ -189,4 +189,37 @@ WebIDL::ExceptionOr<GC::Ref<IDBIndex>> IDBObjectStore::index(String const& name)
|
||||||
return IDBIndex::create(realm(), *index, *this);
|
return IDBIndex::create(realm(), *index, *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://w3c.github.io/IndexedDB/#dom-idbobjectstore-deleteindex
|
||||||
|
WebIDL::ExceptionOr<void> IDBObjectStore::delete_index(String const& name)
|
||||||
|
{
|
||||||
|
// 1. Let transaction be this’s transaction.
|
||||||
|
auto transaction = this->transaction();
|
||||||
|
|
||||||
|
// 2. Let store be this’s object store.
|
||||||
|
auto store = this->store();
|
||||||
|
|
||||||
|
// 3. If transaction is not an upgrade transaction, throw an "InvalidStateError" DOMException.
|
||||||
|
if (transaction->mode() != Bindings::IDBTransactionMode::Versionchange)
|
||||||
|
return WebIDL::InvalidStateError::create(realm(), "Transaction is not an upgrade transaction"_string);
|
||||||
|
|
||||||
|
// FIXME: 4. If store has been deleted, throw an "InvalidStateError" DOMException.
|
||||||
|
|
||||||
|
// 5. If transaction’s state is not active, then throw a "TransactionInactiveError" DOMException.
|
||||||
|
if (transaction->state() != IDBTransaction::TransactionState::Active)
|
||||||
|
return WebIDL::TransactionInactiveError::create(realm(), "Transaction is not active"_string);
|
||||||
|
|
||||||
|
// 6. Let index be the index named name in store if one exists, or throw a "NotFoundError" DOMException otherwise.
|
||||||
|
auto index = m_indexes.get(name);
|
||||||
|
if (!index.has_value())
|
||||||
|
return WebIDL::NotFoundError::create(realm(), "Index not found"_string);
|
||||||
|
|
||||||
|
// 7. Remove index from this’s index set.
|
||||||
|
m_indexes.remove(name);
|
||||||
|
|
||||||
|
// 8. Destroy index.
|
||||||
|
store->index_set().remove(name);
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ public:
|
||||||
WebIDL::ExceptionOr<GC::Ref<IDBIndex>> create_index(String const&, KeyPath, IDBIndexParameters options);
|
WebIDL::ExceptionOr<GC::Ref<IDBIndex>> create_index(String const&, KeyPath, IDBIndexParameters options);
|
||||||
[[nodiscard]] GC::Ref<HTML::DOMStringList> index_names();
|
[[nodiscard]] GC::Ref<HTML::DOMStringList> index_names();
|
||||||
WebIDL::ExceptionOr<GC::Ref<IDBIndex>> index(String const&);
|
WebIDL::ExceptionOr<GC::Ref<IDBIndex>> index(String const&);
|
||||||
|
WebIDL::ExceptionOr<void> delete_index(String const&);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
explicit IDBObjectStore(JS::Realm&, GC::Ref<ObjectStore>, GC::Ref<IDBTransaction>);
|
explicit IDBObjectStore(JS::Realm&, GC::Ref<ObjectStore>, GC::Ref<IDBTransaction>);
|
||||||
|
|
|
@ -23,7 +23,7 @@ interface IDBObjectStore {
|
||||||
[FIXME, NewObject] IDBRequest openKeyCursor(optional any query, optional IDBCursorDirection direction = "next");
|
[FIXME, NewObject] IDBRequest openKeyCursor(optional any query, optional IDBCursorDirection direction = "next");
|
||||||
IDBIndex index(DOMString name);
|
IDBIndex index(DOMString name);
|
||||||
[NewObject] IDBIndex createIndex(DOMString name, (DOMString or sequence<DOMString>) keyPath, optional IDBIndexParameters options = {});
|
[NewObject] IDBIndex createIndex(DOMString name, (DOMString or sequence<DOMString>) keyPath, optional IDBIndexParameters options = {});
|
||||||
[FIXME] undefined deleteIndex(DOMString name);
|
undefined deleteIndex(DOMString name);
|
||||||
};
|
};
|
||||||
|
|
||||||
dictionary IDBIndexParameters {
|
dictionary IDBIndexParameters {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue