diff --git a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp index 6fdfcc49f8..b4087d6a26 100644 --- a/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp +++ b/Libraries/LibWeb/IndexedDB/Internal/Algorithms.cpp @@ -1315,9 +1315,6 @@ GC::Ref asynchronously_execute_a_request(JS::Realm& realm, IDBReques // 5. Set request’s processed flag to true. request->set_processed(true); - // Allow the next operation in the queue to proceed. - transaction->request_list().on_request_processed(); - // 6. Queue a database task to run these steps: dbgln_if(IDB_DEBUG, "asynchronously_execute_a_request: step 5.6: request finished without error, queuing task to finish up"); queue_a_database_task(GC::create_function(realm.vm().heap(), [&realm, request, result, transaction]() mutable { @@ -1362,6 +1359,11 @@ GC::Ref asynchronously_execute_a_request(JS::Realm& realm, IDBReques // be fired before the transaction can be committed. transaction->request_list().check_all_processed(); })); + + // Allow the next operation in the queue to proceed. This runs after the above task to ensure that if another + // request is ready, it will run after the success or failure events are fired. Otherwise, the next request may + // throw an error and clobber the result of this request. + transaction->request_list().on_request_processed(); })); // 6. Return request. diff --git a/Tests/LibWeb/Text/expected/indexeddb-commit-error-event-order.txt b/Tests/LibWeb/Text/expected/indexeddb-commit-error-event-order.txt new file mode 100644 index 0000000000..675eff102a --- /dev/null +++ b/Tests/LibWeb/Text/expected/indexeddb-commit-error-event-order.txt @@ -0,0 +1,4 @@ +put:success +add:error +tx:error +tx:abort diff --git a/Tests/LibWeb/Text/expected/wpt-import/IndexedDB/idb-explicit-commit.any.txt b/Tests/LibWeb/Text/expected/wpt-import/IndexedDB/idb-explicit-commit.any.txt index 8893a5f0a8..0ae0ba4486 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/IndexedDB/idb-explicit-commit.any.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/IndexedDB/idb-explicit-commit.any.txt @@ -2,8 +2,7 @@ Harness status: OK Found 12 tests -11 Pass -1 Fail +12 Pass Pass Explicitly committed data can be read back out. Pass commit() on a version change transaction does not cause errors. Pass A committed transaction becomes inactive immediately. @@ -14,5 +13,5 @@ Pass Calling commit on a committed transaction throws. Pass Calling abort on a committed transaction throws and does not prevent persisting the data. Pass Calling txn.commit() when txn is inactive should throw. Pass Transactions with same scope should stay in program order, even if one calls commit. -Fail Transactions that explicitly commit and have errors should abort. +Pass Transactions that explicitly commit and have errors should abort. Pass Transactions that handle all errors properly should behave as expected when an explicit commit is called in an onerror handler. \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/indexeddb-commit-error-event-order.html b/Tests/LibWeb/Text/input/indexeddb-commit-error-event-order.html new file mode 100644 index 0000000000..406dadf9db --- /dev/null +++ b/Tests/LibWeb/Text/input/indexeddb-commit-error-event-order.html @@ -0,0 +1,52 @@ + + + \ No newline at end of file