mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
LibWeb/IDB: Improve error messages slightly
This commit is contained in:
Notes:
github-actions[bot]
2025-05-08 13:14:39 +00:00
Author: https://github.com/stelar7 Commit: https://github.com/LadybirdBrowser/ladybird/commit/1fe6060ff9d Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4650 Reviewed-by: https://github.com/AtkinsSJ ✅
@@ -189,16 +189,19 @@ WebIDL::ExceptionOr<void> IDBDatabase::delete_object_store(String const& name)
|
||||
return {};
|
||||
}
|
||||
|
||||
// https://w3c.github.io/IndexedDB/#dom-idbdatabase-transaction
|
||||
WebIDL::ExceptionOr<GC::Ref<IDBTransaction>> IDBDatabase::transaction(Variant<String, Vector<String>> store_names, Bindings::IDBTransactionMode mode, IDBTransactionOptions options)
|
||||
{
|
||||
auto& realm = this->realm();
|
||||
|
||||
// 1. If a live upgrade transaction is associated with the connection, throw an "InvalidStateError" DOMException.
|
||||
auto database = associated_database();
|
||||
if (database->upgrade_transaction())
|
||||
return WebIDL::InvalidStateError::create(realm(), "Upgrade transaction is live"_string);
|
||||
return WebIDL::InvalidStateError::create(realm, "Upgrade transaction is live"_string);
|
||||
|
||||
// 2. If this's close pending flag is true, then throw an "InvalidStateError" DOMException.
|
||||
if (close_pending())
|
||||
return WebIDL::InvalidStateError::create(realm(), "Close pending"_string);
|
||||
return WebIDL::InvalidStateError::create(realm, "Close pending"_string);
|
||||
|
||||
// 3. Let scope be the set of unique strings in storeNames if it is a sequence, or a set containing one string equal to storeNames otherwise.
|
||||
Vector<String> scope;
|
||||
@@ -211,12 +214,12 @@ WebIDL::ExceptionOr<GC::Ref<IDBTransaction>> IDBDatabase::transaction(Variant<St
|
||||
// 4. If any string in scope is not the name of an object store in the connected database, throw a "NotFoundError" DOMException.
|
||||
for (auto const& store_name : scope) {
|
||||
if (!database->object_store_with_name(store_name))
|
||||
return WebIDL::NotFoundError::create(realm(), "Object store not found"_string);
|
||||
return WebIDL::NotFoundError::create(realm, "Provided object store names does not exist in database"_string);
|
||||
}
|
||||
|
||||
// 5. If scope is empty, throw an "InvalidAccessError" DOMException.
|
||||
if (scope.is_empty())
|
||||
return WebIDL::InvalidAccessError::create(realm(), "Scope is empty"_string);
|
||||
return WebIDL::InvalidAccessError::create(realm, "Scope is empty"_string);
|
||||
|
||||
// 6. If mode is not "readonly" or "readwrite", throw a TypeError.
|
||||
if (mode != Bindings::IDBTransactionMode::Readonly && mode != Bindings::IDBTransactionMode::Readwrite)
|
||||
@@ -229,7 +232,7 @@ WebIDL::ExceptionOr<GC::Ref<IDBTransaction>> IDBDatabase::transaction(Variant<St
|
||||
scope_stores.append(*store);
|
||||
}
|
||||
|
||||
auto transaction = IDBTransaction::create(realm(), *this, mode, options.durability, scope_stores);
|
||||
auto transaction = IDBTransaction::create(realm, *this, mode, options.durability, scope_stores);
|
||||
|
||||
// 8. Set transaction’s cleanup event loop to the current event loop.
|
||||
transaction->set_cleanup_event_loop(HTML::main_thread_event_loop());
|
||||
|
||||
Reference in New Issue
Block a user