mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-22 02:09:24 +00:00
LibWeb/IDB: Implement IDBDatabase::deleteObjectStore
This commit is contained in:
parent
b11276e5c4
commit
209d05fcb4
Notes:
github-actions[bot]
2025-03-27 15:48:47 +00:00
Author: https://github.com/stelar7
Commit: 209d05fcb4
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4077
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/gmta ✅
6 changed files with 49 additions and 7 deletions
|
@ -116,7 +116,7 @@ WebIDL::ExceptionOr<GC::Ref<IDBObjectStore>> IDBDatabase::create_object_store(St
|
|||
return WebIDL::SyntaxError::create(realm, "Invalid key path"_string);
|
||||
|
||||
// 6. If an object store named name already exists in database throw a "ConstraintError" DOMException.
|
||||
if (database->has_object_store_named(name))
|
||||
if (database->object_store_with_name(name))
|
||||
return WebIDL::ConstraintError::create(realm, "Object store already exists"_string);
|
||||
|
||||
// 7. Let autoIncrement be options’s autoIncrement member.
|
||||
|
@ -150,4 +150,37 @@ GC::Ref<HTML::DOMStringList> IDBDatabase::object_store_names()
|
|||
return create_a_sorted_name_list(realm(), names);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/IndexedDB/#dom-idbdatabase-deleteobjectstore
|
||||
WebIDL::ExceptionOr<void> IDBDatabase::delete_object_store(String const& name)
|
||||
{
|
||||
auto& realm = this->realm();
|
||||
|
||||
// 1. Let database be this's associated database.
|
||||
auto database = associated_database();
|
||||
|
||||
// 2. Let transaction be database’s upgrade transaction if it is not null, or throw an "InvalidStateError" DOMException otherwise.
|
||||
auto transaction = database->upgrade_transaction();
|
||||
if (!transaction)
|
||||
return WebIDL::InvalidStateError::create(realm, "Upgrade transaction is null"_string);
|
||||
|
||||
// 3. 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);
|
||||
|
||||
// 4. Let store be the object store named name in database, or throw a "NotFoundError" DOMException if none.
|
||||
auto store = database->object_store_with_name(name);
|
||||
if (!store)
|
||||
return WebIDL::NotFoundError::create(realm, "Object store not found"_string);
|
||||
|
||||
// 5. Remove store from this's object store set.
|
||||
this->remove_from_object_store_set(*store);
|
||||
|
||||
// FIXME: 6. If there is an object store handle associated with store and transaction, remove all entries from its index set.
|
||||
|
||||
// 7. Destroy store.
|
||||
database->remove_object_store(*store);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue