LibWeb/IDB: Add some debug output

This commit is contained in:
stelar7 2025-04-02 10:28:04 +02:00 committed by Andrew Kaster
parent 4084a127de
commit 6ec914c7f7
Notes: github-actions[bot] 2025-04-09 17:50:06 +00:00
9 changed files with 75 additions and 0 deletions

View file

@ -36,9 +36,18 @@ WebIDL::ExceptionOr<GC::Ref<IDBDatabase>> open_a_database_connection(JS::Realm&
// 2. Add request to queue.
queue.append(request);
dbgln_if(IDB_DEBUG, "open_a_database_connection: added request {} to queue", request->uuid());
// 3. Wait until all previous requests in queue have been processed.
HTML::main_thread_event_loop().spin_until(GC::create_function(realm.vm().heap(), [queue, request]() {
if constexpr (IDB_DEBUG) {
dbgln("open_a_database_connection: waiting for step 3");
dbgln("requests in queue:");
for (auto const& item : queue) {
dbgln("[{}] - {} = {}", item == request ? "x"sv : " "sv, item->uuid(), item->processed() ? "processed"sv : "not processed"sv);
}
}
return queue.all_previous_requests_processed(request);
}));
@ -71,6 +80,7 @@ WebIDL::ExceptionOr<GC::Ref<IDBDatabase>> open_a_database_connection(JS::Realm&
// 8. Let connection be a new connection to db.
auto connection = IDBDatabase::create(realm, *db);
dbgln_if(IDB_DEBUG, "Created new connection with UUID: {}", connection->uuid());
// 9. Set connections version to version.
connection->set_version(version);
@ -97,6 +107,11 @@ WebIDL::ExceptionOr<GC::Ref<IDBDatabase>> open_a_database_connection(JS::Realm&
// 3. Wait for all of the events to be fired.
HTML::main_thread_event_loop().spin_until(GC::create_function(realm.vm().heap(), [&events_to_fire, &events_fired]() {
if constexpr (IDB_DEBUG) {
dbgln("open_a_database_connection: waiting for step 10.3");
dbgln("events_fired: {}, events_to_fire: {}", events_fired, events_to_fire);
}
return events_fired == events_to_fire;
}));
@ -112,6 +127,14 @@ WebIDL::ExceptionOr<GC::Ref<IDBDatabase>> open_a_database_connection(JS::Realm&
// 5. Wait until all connections in openConnections are closed.
HTML::main_thread_event_loop().spin_until(GC::create_function(realm.vm().heap(), [open_connections]() {
if constexpr (IDB_DEBUG) {
dbgln("open_a_database_connection: waiting for step 10.5");
dbgln("open connections: {}", open_connections.size());
for (auto const& connection : open_connections) {
dbgln(" - {}", connection->uuid());
}
}
for (auto const& entry : open_connections) {
if (entry->state() != IDBDatabase::ConnectionState::Closed) {
return false;
@ -314,6 +337,7 @@ GC::Ref<IDBTransaction> upgrade_a_database(JS::Realm& realm, GC::Ref<IDBDatabase
// 2. Let transaction be a new upgrade transaction with connection used as connection.
// 3. Set transactions scope to connections object store set.
auto transaction = IDBTransaction::create(realm, connection, Bindings::IDBTransactionMode::Versionchange, Bindings::IDBTransactionDurability::Default, Vector<GC::Ref<ObjectStore>> { connection->object_store_set() });
dbgln_if(IDB_DEBUG, "Created new upgrade transaction with UUID: {}", transaction->uuid());
// 4. Set dbs upgrade transaction to transaction.
db->set_upgrade_transaction(transaction);
@ -364,6 +388,7 @@ GC::Ref<IDBTransaction> upgrade_a_database(JS::Realm& realm, GC::Ref<IDBDatabase
// 11. Wait for transaction to finish.
HTML::main_thread_event_loop().spin_until(GC::create_function(realm.vm().heap(), [&wait_for_transaction]() {
dbgln_if(IDB_DEBUG, "upgrade_a_database: waiting for step 11");
return !wait_for_transaction;
}));
@ -378,9 +403,18 @@ WebIDL::ExceptionOr<u64> delete_a_database(JS::Realm& realm, StorageAPI::Storage
// 2. Add request to queue.
queue.append(request);
dbgln_if(IDB_DEBUG, "delete_a_database: added request {} to queue", request->uuid());
// 3. Wait until all previous requests in queue have been processed.
HTML::main_thread_event_loop().spin_until(GC::create_function(realm.vm().heap(), [queue, request]() {
if constexpr (IDB_DEBUG) {
dbgln("delete_a_database: waiting for step 3");
dbgln("requests in queue:");
for (auto const& item : queue) {
dbgln("[{}] - {} = {}", item == request ? "x"sv : " "sv, item->uuid(), item->processed() ? "processed"sv : "not processed"sv);
}
}
return queue.all_previous_requests_processed(request);
}));
@ -411,6 +445,11 @@ WebIDL::ExceptionOr<u64> delete_a_database(JS::Realm& realm, StorageAPI::Storage
// 7. Wait for all of the events to be fired.
HTML::main_thread_event_loop().spin_until(GC::create_function(realm.vm().heap(), [&events_to_fire, &events_fired]() {
if constexpr (IDB_DEBUG) {
dbgln("delete_a_database: waiting for step 7");
dbgln("events_fired: {}, events_to_fire: {}", events_fired, events_to_fire);
}
return events_fired == events_to_fire;
}));
@ -425,6 +464,14 @@ WebIDL::ExceptionOr<u64> delete_a_database(JS::Realm& realm, StorageAPI::Storage
// 9. Wait until all connections in openConnections are closed.
HTML::main_thread_event_loop().spin_until(GC::create_function(realm.vm().heap(), [open_connections]() {
if constexpr (IDB_DEBUG) {
dbgln("delete_a_database: waiting for step 9");
dbgln("open connections: {}", open_connections.size());
for (auto const& connection : open_connections) {
dbgln(" - {}", connection->uuid());
}
}
for (auto const& entry : open_connections) {
if (entry->state() != IDBDatabase::ConnectionState::Closed) {
return false;
@ -451,6 +498,7 @@ void abort_a_transaction(GC::Ref<IDBTransaction> transaction, GC::Ptr<WebIDL::DO
{
// NOTE: This is not spec'ed anywhere, but we need to know IF the transaction was aborted.
transaction->set_aborted(true);
dbgln_if(IDB_DEBUG, "abort_a_transaction: transaction {} is aborting", transaction->uuid());
// 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.