LibWeb/IDB: Keep track of the connection used to start a transaction

This commit is contained in:
stelar7 2025-04-09 22:59:07 +02:00 committed by Andrew Kaster
commit fc93ec135e
Notes: github-actions[bot] 2025-04-11 01:14:28 +00:00
3 changed files with 8 additions and 0 deletions

View file

@ -44,6 +44,7 @@ void IDBDatabase::visit_edges(Visitor& visitor)
Base::visit_edges(visitor);
visitor.visit(m_object_store_set);
visitor.visit(m_associated_database);
visitor.visit(m_transactions);
}
void IDBDatabase::set_onabort(WebIDL::CallbackType* event_handler)

View file

@ -59,6 +59,9 @@ public:
m_object_store_set.remove_first_matching([&](auto& entry) { return entry == object_store; });
}
[[nodiscard]] ReadonlySpan<GC::Ref<IDBTransaction>> transactions() { return m_transactions; }
void add_transaction(GC::Ref<IDBTransaction> transaction) { m_transactions.append(transaction); }
[[nodiscard]] GC::Ref<HTML::DOMStringList> object_store_names();
WebIDL::ExceptionOr<GC::Ref<IDBObjectStore>> create_object_store(String const&, IDBObjectStoreParameters const&);
WebIDL::ExceptionOr<void> delete_object_store(String const&);
@ -98,6 +101,9 @@ private:
// So we stash the one we have when opening a connection.
GC::Ref<Database> m_associated_database;
// NOTE: We need to keep track of what transactions were created by this connection
Vector<GC::Ref<IDBTransaction>> m_transactions;
// NOTE: Used for debug purposes
String m_uuid;
};

View file

@ -24,6 +24,7 @@ IDBTransaction::IDBTransaction(JS::Realm& realm, GC::Ref<IDBDatabase> connection
, m_scope(move(scopes))
{
m_uuid = MUST(Crypto::generate_random_uuid());
connection->add_transaction(*this);
}
GC::Ref<IDBTransaction> IDBTransaction::create(JS::Realm& realm, GC::Ref<IDBDatabase> connection, Bindings::IDBTransactionMode mode, Bindings::IDBTransactionDurability durability = Bindings::IDBTransactionDurability::Default, Vector<GC::Ref<ObjectStore>> scopes = {})