From 8fcb54dadac55a108c594f0358d3458ccf149f70 Mon Sep 17 00:00:00 2001 From: stelar7 Date: Wed, 9 Apr 2025 23:18:18 +0200 Subject: [PATCH] LibWeb/IDB: Abort requests in the transactions request list --- .../LibWeb/IndexedDB/Internal/Algorithms.cpp | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp index 6ed7f2060da..aa37c794520 100644 --- a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp +++ b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp @@ -547,12 +547,28 @@ void abort_a_transaction(GC::Ref transaction, GC::Ptrset_error(error); - // FIXME: 5. For each request of transaction’s request list, abort the steps to asynchronously execute a request for request, - // set request’s processed flag to true, and queue a task to run these steps: - // FIXME: 1. Set request’s done flag to true. - // FIXME: 2. Set request’s result to undefined. - // FIXME: 3. Set request’s 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. + // 5. For each request of transaction’s request list, + for (auto const& request : transaction->request_list()) { + // FIXME: abort the steps to asynchronously execute a request for request, + + // set request’s processed flag to true + request->set_processed(true); + + // and queue a task to run these steps: + HTML::queue_a_task(HTML::Task::Source::DatabaseAccess, nullptr, nullptr, GC::create_function(transaction->realm().vm().heap(), [request]() { + // 1. Set request’s done flag to true. + request->set_done(true); + + // 2. Set request’s result to undefined. + request->set_result(JS::js_undefined()); + + // 3. Set request’s error to a newly created "AbortError" DOMException. + request->set_error(WebIDL::AbortError::create(request->realm(), "Transaction was aborted"_string)); + + // 4. Fire an event named error at request with its bubbles and cancelable attributes initialized to true. + request->dispatch_event(DOM::Event::create(request->realm(), HTML::EventNames::error, { .bubbles = true, .cancelable = 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]() {