1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-08 13:37:10 +09:00

LibWeb: Implement abort_a_transaction for IndexedDB

This commit is contained in:
stelar7 2024-12-01 21:57:32 +01:00 committed by Jelle Raaijmakers
parent 609f7aa659
commit 2954278e37
Notes: github-actions[bot] 2024-12-14 22:04:24 +00:00
6 changed files with 66 additions and 2 deletions

View file

@ -326,7 +326,9 @@ void upgrade_a_database(JS::Realm& realm, GC::Ref<IDBDatabase> connection, u64 v
request->set_result(connection);
// 2. Set requests transaction to transaction.
// NOTE: We need to do a two-way binding here.
request->set_transaction(transaction);
transaction->set_associated_request(request);
// 3. Set requests done flag to true.
request->set_done(true);
@ -422,4 +424,60 @@ WebIDL::ExceptionOr<u64> delete_a_database(JS::Realm& realm, StorageAPI::Storage
return version;
}
// https://w3c.github.io/IndexedDB/#abort-a-transaction
void abort_a_transaction(IDBTransaction& transaction, GC::Ptr<WebIDL::DOMException> error)
{
// FIXME: 1. All the changes made to the database by the transaction are reverted.
// For upgrade transactions this includes changes to the set of object stores and indexes, as well as the change to the version.
// Any object stores and indexes which were created during the transaction are now considered deleted for the purposes of other algorithms.
// FIXME: 2. If transaction is an upgrade transaction, run the steps to abort an upgrade transaction with transaction.
// if (transaction.is_upgrade_transaction())
// abort_an_upgrade_transaction(transaction);
// 3. Set transactions state to finished.
transaction.set_state(IDBTransaction::TransactionState::Finished);
// 4. If error is not null, set transactions error to error.
if (error)
transaction.set_error(error);
// FIXME: 5. For each request of transactions request list, abort the steps to asynchronously execute a request for request,
// set requests processed flag to true, and queue a task to run these steps:
// FIXME: 1. Set requests done flag to true.
// FIXME: 2. Set requests result to undefined.
// FIXME: 3. Set requests error to a newly created "AbortError" DOMException.
// FIXME: 4. Fire an event named error at request with its bubbles and cancelable attributes initialized to true.
// 6. Queue a task to run these steps:
HTML::queue_a_task(HTML::Task::Source::DatabaseAccess, nullptr, nullptr, GC::create_function(transaction.realm().vm().heap(), [&transaction]() {
// 1. If transaction is an upgrade transaction, then set transactions connection's associated database's upgrade transaction to null.
if (transaction.is_upgrade_transaction())
transaction.connection()->associated_database()->set_upgrade_transaction(nullptr);
// 2. Fire an event named abort at transaction with its bubbles attribute initialized to true.
transaction.dispatch_event(DOM::Event::create(transaction.realm(), HTML::EventNames::abort, { .bubbles = true }));
// 3. If transaction is an upgrade transaction, then:
if (transaction.is_upgrade_transaction()) {
// 1. Let request be the open request associated with transaction.
auto request = transaction.associated_request();
// 2. Set requests transaction to null.
// NOTE: Clear the two-way binding.
request->set_transaction(nullptr);
transaction.set_associated_request(nullptr);
// 3. Set requests result to undefined.
request->set_result(JS::js_undefined());
// 4. Set requests processed flag to false.
request->set_processed(false);
// 5. Set requests done flag to false.
request->set_done(false);
}
}));
}
}