Add null checks for connection in UniqueIDBDatabaseTransaction and UniqueIDBDatabase
https://bugs.webkit.org/show_bug.cgi?id=241792
rdar://95011134
Reviewed by Youenn Fablet.
* Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::startVersionChangeTransaction):
(WebCore::IDBServer::UniqueIDBDatabase::clearTransactionsOnConnection):
(WebCore::IDBServer::UniqueIDBDatabase::openDBRequestCancelled):
(WebCore::IDBServer::UniqueIDBDatabase::commitTransaction):
(WebCore::IDBServer::UniqueIDBDatabase::abortTransaction):
(WebCore::IDBServer::UniqueIDBDatabase::immediateClose):
* Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.cpp:
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::UniqueIDBDatabaseTransaction):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::~UniqueIDBDatabaseTransaction):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::databaseConnection const):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::abort):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::abortWithoutCallback):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::database const):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::commit):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::createObjectStore):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::deleteObjectStore):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::renameObjectStore):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::clearObjectStore):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::createIndex):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::deleteIndex):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::renameIndex):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::putOrAdd):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::getRecord):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::getAllRecords):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::getCount):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::deleteRecord):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::openCursor):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::iterateCursor):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::objectStoreIdentifiers):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::didActivateInBackingStore):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::databaseConnection): Deleted.
* Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.h:
* Source/WebCore/Modules/indexeddb/shared/IDBResultData.cpp:
(WebCore::IDBResultData::openDatabaseUpgradeNeeded):
* Source/WebCore/Modules/indexeddb/shared/IDBResultData.h:
Canonical link: https://commits.webkit.org/251705@main
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@295700 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp b/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp
index 74adeee..1c7f136 100644
--- a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp
+++ b/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp
@@ -446,7 +446,7 @@
if (error.isNull()) {
addOpenDatabaseConnection(*m_versionChangeDatabaseConnection);
m_databaseInfo->setVersion(versionChangeTransactionInfo.newVersion());
- result = IDBResultData::openDatabaseUpgradeNeeded(operation->requestData().requestIdentifier(), *m_versionChangeTransaction);
+ result = IDBResultData::openDatabaseUpgradeNeeded(operation->requestData().requestIdentifier(), *m_versionChangeTransaction, *m_versionChangeDatabaseConnection);
operation->connection().didOpenDatabase(result);
} else {
m_versionChangeDatabaseConnection->abortTransactionWithoutCallback(*m_versionChangeTransaction);
@@ -512,7 +512,7 @@
Deque<RefPtr<UniqueIDBDatabaseTransaction>> pendingTransactions;
while (!m_pendingTransactions.isEmpty()) {
auto transaction = m_pendingTransactions.takeFirst();
- if (&transaction->databaseConnection() != &connection)
+ if (transaction->databaseConnection() != &connection)
pendingTransactions.append(WTFMove(transaction));
else
connection.deleteTransaction(*transaction);
@@ -522,7 +522,7 @@
Deque<RefPtr<UniqueIDBDatabaseTransaction>> transactionsToAbort;
for (auto& transaction : m_inProgressTransactions.values()) {
- if (&transaction->databaseConnection() == &connection)
+ if (transaction->databaseConnection() == &connection)
transactionsToAbort.append(transaction);
}
for (auto& transaction : transactionsToAbort)
@@ -557,8 +557,7 @@
m_currentOpenDBRequest = nullptr;
if (m_versionChangeDatabaseConnection && m_versionChangeDatabaseConnection->openRequestIdentifier() == requestIdentifier) {
- ASSERT(!m_versionChangeTransaction || m_versionChangeTransaction->databaseConnection().openRequestIdentifier() == requestIdentifier);
- ASSERT(!m_versionChangeTransaction || &m_versionChangeTransaction->databaseConnection() == m_versionChangeDatabaseConnection);
+ ASSERT(!m_versionChangeTransaction || m_versionChangeTransaction->databaseConnection() == m_versionChangeDatabaseConnection);
connectionClosedFromClient(*m_versionChangeDatabaseConnection);
}
@@ -1135,14 +1134,14 @@
}
ASSERT(spaceCheckResult == SpaceCheckResult::Pass);
- ASSERT(transaction.databaseConnection().database() == this);
+ ASSERT(transaction.database() == this);
if (!m_backingStore)
return callback(IDBError { InvalidStateError, "Backing store is closed"_s });
auto takenTransaction = m_inProgressTransactions.take(transaction.info().identifier());
if (!takenTransaction) {
- if (!m_openDatabaseConnections.contains(&transaction.databaseConnection()))
+ if (transaction.databaseConnection() && !m_openDatabaseConnections.contains(transaction.databaseConnection()))
return;
callback(IDBError { UnknownError, "Attempt to commit transaction that is not running"_s });
@@ -1174,11 +1173,11 @@
}
ASSERT(spaceCheckResult == SpaceCheckResult::Pass);
- ASSERT(transaction.databaseConnection().database() == this);
+ ASSERT(transaction.database() == this);
auto takenTransaction = m_inProgressTransactions.take(transaction.info().identifier());
if (!takenTransaction) {
- if (!m_openDatabaseConnections.contains(&transaction.databaseConnection()))
+ if (!m_openDatabaseConnections.contains(transaction.databaseConnection()))
return;
callback(IDBError { UnknownError, "Attempt to abort transaction that is not running"_s });
@@ -1195,7 +1194,7 @@
auto transactionIdentifier = transaction.info().identifier();
if (m_versionChangeTransaction && m_versionChangeTransaction->info().identifier() == transactionIdentifier) {
ASSERT(m_versionChangeTransaction == &transaction);
- ASSERT(!m_versionChangeDatabaseConnection || &m_versionChangeTransaction->databaseConnection() == m_versionChangeDatabaseConnection);
+ ASSERT(!m_versionChangeDatabaseConnection || m_versionChangeTransaction->databaseConnection() == m_versionChangeDatabaseConnection);
ASSERT(m_versionChangeTransaction->originalDatabaseInfo());
m_databaseInfo = makeUnique<IDBDatabaseInfo>(*m_versionChangeTransaction->originalDatabaseInfo());
}
@@ -1428,8 +1427,10 @@
// Error out all transactions.
// Pending transactions must be cleared before in-progress transactions,
// or they may get started right away after aborting in-progress transactions.
- for (auto& transaction : m_pendingTransactions)
- transaction->databaseConnection().deleteTransaction(*transaction);
+ for (auto& transaction : m_pendingTransactions) {
+ if (auto* databaseConnection = transaction->databaseConnection())
+ databaseConnection->deleteTransaction(*transaction);
+ }
m_pendingTransactions.clear();
for (auto& identifier : copyToVector(m_inProgressTransactions.keys()))
diff --git a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.cpp b/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.cpp
index 697a4fe..d98e14f 100644
--- a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.cpp
+++ b/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.cpp
@@ -45,26 +45,30 @@
: m_databaseConnection(connection)
, m_transactionInfo(info)
{
- auto database = databaseConnection().database();
- ASSERT(database);
+ ASSERT(database());
if (m_transactionInfo.mode() == IDBTransactionMode::Versionchange)
- m_originalDatabaseInfo = makeUnique<IDBDatabaseInfo>(database->info());
+ m_originalDatabaseInfo = makeUnique<IDBDatabaseInfo>(database()->info());
- if (auto* manager = databaseConnection().manager())
+ if (!m_databaseConnection)
+ return;
+
+ if (auto* manager = m_databaseConnection->manager())
manager->registerTransaction(*this);
}
UniqueIDBDatabaseTransaction::~UniqueIDBDatabaseTransaction()
{
- if (auto* manager = databaseConnection().manager())
+ if (!m_databaseConnection)
+ return;
+
+ if (auto* manager = m_databaseConnection->manager())
manager->unregisterTransaction(*this);
}
-UniqueIDBDatabaseConnection& UniqueIDBDatabaseTransaction::databaseConnection()
+UniqueIDBDatabaseConnection* UniqueIDBDatabaseTransaction::databaseConnection() const
{
- RELEASE_ASSERT(m_databaseConnection);
- return *m_databaseConnection;
+ return m_databaseConnection.get();
}
IDBDatabaseInfo* UniqueIDBDatabaseTransaction::originalDatabaseInfo() const
@@ -77,13 +81,15 @@
{
LOG(IndexedDB, "UniqueIDBDatabaseTransaction::abort");
- auto database = databaseConnection().database();
- ASSERT(database);
+ auto* database = this->database();
+ if (!database)
+ return;
- database->abortTransaction(*this, [this](auto& error) {
+ database->abortTransaction(*this, [this, weakThis = WeakPtr { *this }](auto& error) {
LOG(IndexedDB, "UniqueIDBDatabaseTransaction::abort (callback)");
- databaseConnection().didAbortTransaction(*this, error);
+ if (weakThis && m_databaseConnection)
+ m_databaseConnection->didAbortTransaction(*this, error);
});
}
@@ -91,7 +97,13 @@
{
LOG(IndexedDB, "UniqueIDBDatabaseTransaction::abortWithoutCallback");
- databaseConnection().abortTransactionWithoutCallback(*this);
+ if (m_databaseConnection)
+ m_databaseConnection->abortTransactionWithoutCallback(*this);
+}
+
+UniqueIDBDatabase* UniqueIDBDatabaseTransaction::database() const
+{
+ return m_databaseConnection ? m_databaseConnection->database() : nullptr;
}
bool UniqueIDBDatabaseTransaction::isVersionChange() const
@@ -108,7 +120,9 @@
{
LOG(IndexedDB, "UniqueIDBDatabaseTransaction::commit");
- auto database = databaseConnection().database();
+ auto* database = this->database();
+ if (!database)
+ return;
std::optional<IDBError> errorInPendingRequests;
while (pendingRequestCount--) {
@@ -120,18 +134,20 @@
}
if (errorInPendingRequests) {
- database->abortTransaction(*this, [this, &errorInPendingRequests](auto&) {
+ database->abortTransaction(*this, [this, weakThis = WeakPtr { *this }, &errorInPendingRequests](auto&) {
LOG(IndexedDB, "UniqueIDBDatabaseTransaction::commit with error (callback)");
- m_databaseConnection->didCommitTransaction(*this, *errorInPendingRequests);
+ if (weakThis && m_databaseConnection)
+ m_databaseConnection->didCommitTransaction(*this, *errorInPendingRequests);
});
return;
}
- database->commitTransaction(*this, [this](auto& error) {
+ database->commitTransaction(*this, [this, weakThis = WeakPtr { *this }](auto& error) {
LOG(IndexedDB, "UniqueIDBDatabaseTransaction::commit (callback)");
- databaseConnection().didCommitTransaction(*this, error);
+ if (weakThis && m_databaseConnection)
+ m_databaseConnection->didCommitTransaction(*this, error);
});
}
@@ -142,18 +158,22 @@
ASSERT(isVersionChange());
ASSERT(m_transactionInfo.identifier() == requestData.transactionIdentifier());
- auto database = databaseConnection().database();
- ASSERT(database);
+ auto* database = this->database();
+ if (!database)
+ return;
- database->createObjectStore(*this, info, [this, requestData](auto& error) {
+ database->createObjectStore(*this, info, [this, weakThis = WeakPtr { *this }, requestData](auto& error) {
LOG(IndexedDB, "UniqueIDBDatabaseTransaction::createObjectStore (callback)");
+ if (!weakThis || !m_databaseConnection)
+ return;
+
m_requestResults.append(error);
if (error.isNull())
- databaseConnection().didCreateObjectStore(IDBResultData::createObjectStoreSuccess(requestData.requestIdentifier()));
+ m_databaseConnection->didCreateObjectStore(IDBResultData::createObjectStoreSuccess(requestData.requestIdentifier()));
else
- databaseConnection().didCreateObjectStore(IDBResultData::error(requestData.requestIdentifier(), error));
+ m_databaseConnection->didCreateObjectStore(IDBResultData::error(requestData.requestIdentifier(), error));
});
}
@@ -164,18 +184,22 @@
ASSERT(isVersionChange());
ASSERT(m_transactionInfo.identifier() == requestData.transactionIdentifier());
- auto database = databaseConnection().database();
- ASSERT(database);
+ auto* database = this->database();
+ if (!database)
+ return;
- database->deleteObjectStore(*this, objectStoreName, [this, requestData](const IDBError& error) {
+ database->deleteObjectStore(*this, objectStoreName, [this, weakThis = WeakPtr { *this }, requestData](const IDBError& error) {
LOG(IndexedDB, "UniqueIDBDatabaseTransaction::deleteObjectStore (callback)");
+ if (!weakThis || !m_databaseConnection)
+ return;
+
m_requestResults.append(error);
if (error.isNull())
- databaseConnection().didDeleteObjectStore(IDBResultData::deleteObjectStoreSuccess(requestData.requestIdentifier()));
+ m_databaseConnection->didDeleteObjectStore(IDBResultData::deleteObjectStoreSuccess(requestData.requestIdentifier()));
else
- databaseConnection().didDeleteObjectStore(IDBResultData::error(requestData.requestIdentifier(), error));
+ m_databaseConnection->didDeleteObjectStore(IDBResultData::error(requestData.requestIdentifier(), error));
});
}
@@ -186,18 +210,22 @@
ASSERT(isVersionChange());
ASSERT(m_transactionInfo.identifier() == requestData.transactionIdentifier());
- auto database = databaseConnection().database();
- ASSERT(database);
+ auto* database = this->database();
+ if (!database)
+ return;
- database->renameObjectStore(*this, objectStoreIdentifier, newName, [this, requestData](auto& error) {
+ database->renameObjectStore(*this, objectStoreIdentifier, newName, [this, weakThis = WeakPtr { *this }, requestData](auto& error) {
LOG(IndexedDB, "UniqueIDBDatabaseTransaction::renameObjectStore (callback)");
+ if (!weakThis || !m_databaseConnection)
+ return;
+
m_requestResults.append(error);
if (error.isNull())
- databaseConnection().didRenameObjectStore(IDBResultData::renameObjectStoreSuccess(requestData.requestIdentifier()));
+ m_databaseConnection->didRenameObjectStore(IDBResultData::renameObjectStoreSuccess(requestData.requestIdentifier()));
else
- databaseConnection().didRenameObjectStore(IDBResultData::error(requestData.requestIdentifier(), error));
+ m_databaseConnection->didRenameObjectStore(IDBResultData::error(requestData.requestIdentifier(), error));
});
}
@@ -207,18 +235,22 @@
ASSERT(m_transactionInfo.identifier() == requestData.transactionIdentifier());
- auto database = databaseConnection().database();
- ASSERT(database);
+ auto* database = this->database();
+ if (!database)
+ return;
- database->clearObjectStore(*this, objectStoreIdentifier, [this, requestData](auto& error) {
+ database->clearObjectStore(*this, objectStoreIdentifier, [this, weakThis = WeakPtr { *this }, requestData](auto& error) {
LOG(IndexedDB, "UniqueIDBDatabaseTransaction::clearObjectStore (callback)");
+ if (!weakThis || !m_databaseConnection)
+ return;
+
m_requestResults.append(error);
if (error.isNull())
- databaseConnection().didClearObjectStore(IDBResultData::clearObjectStoreSuccess(requestData.requestIdentifier()));
+ m_databaseConnection->didClearObjectStore(IDBResultData::clearObjectStoreSuccess(requestData.requestIdentifier()));
else
- databaseConnection().didClearObjectStore(IDBResultData::error(requestData.requestIdentifier(), error));
+ m_databaseConnection->didClearObjectStore(IDBResultData::error(requestData.requestIdentifier(), error));
});
}
@@ -229,18 +261,22 @@
ASSERT(isVersionChange());
ASSERT(m_transactionInfo.identifier() == requestData.transactionIdentifier());
- auto database = databaseConnection().database();
- ASSERT(database);
+ auto* database = this->database();
+ if (!database)
+ return;
- database->createIndex(*this, info, [this, requestData](auto& error) {
+ database->createIndex(*this, info, [this, weakThis = WeakPtr { *this }, requestData](auto& error) {
LOG(IndexedDB, "UniqueIDBDatabaseTransaction::createIndex (callback)");
+ if (!weakThis || !m_databaseConnection)
+ return;
+
m_requestResults.append(error);
if (error.isNull())
- databaseConnection().didCreateIndex(IDBResultData::createIndexSuccess(requestData.requestIdentifier()));
+ m_databaseConnection->didCreateIndex(IDBResultData::createIndexSuccess(requestData.requestIdentifier()));
else
- databaseConnection().didCreateIndex(IDBResultData::error(requestData.requestIdentifier(), error));
+ m_databaseConnection->didCreateIndex(IDBResultData::error(requestData.requestIdentifier(), error));
});
}
@@ -251,18 +287,22 @@
ASSERT(isVersionChange());
ASSERT(m_transactionInfo.identifier() == requestData.transactionIdentifier());
- auto database = databaseConnection().database();
- ASSERT(database);
+ auto* database = this->database();
+ if (!database)
+ return;
- database->deleteIndex(*this, objectStoreIdentifier, indexName, [this, requestData](auto& error) {
+ database->deleteIndex(*this, objectStoreIdentifier, indexName, [this, weakThis = WeakPtr { *this }, requestData](auto& error) {
LOG(IndexedDB, "UniqueIDBDatabaseTransaction::createIndex (callback)");
+ if (!weakThis || !m_databaseConnection)
+ return;
+
m_requestResults.append(error);
if (error.isNull())
- databaseConnection().didDeleteIndex(IDBResultData::deleteIndexSuccess(requestData.requestIdentifier()));
+ m_databaseConnection->didDeleteIndex(IDBResultData::deleteIndexSuccess(requestData.requestIdentifier()));
else
- databaseConnection().didDeleteIndex(IDBResultData::error(requestData.requestIdentifier(), error));
+ m_databaseConnection->didDeleteIndex(IDBResultData::error(requestData.requestIdentifier(), error));
});
}
@@ -273,18 +313,22 @@
ASSERT(isVersionChange());
ASSERT(m_transactionInfo.identifier() == requestData.transactionIdentifier());
- auto database = databaseConnection().database();
- ASSERT(database);
+ auto* database = this->database();
+ if (!database)
+ return;
- database->renameIndex(*this, objectStoreIdentifier, indexIdentifier, newName, [this, requestData](auto& error) {
+ database->renameIndex(*this, objectStoreIdentifier, indexIdentifier, newName, [this, weakThis = WeakPtr { *this }, requestData](auto& error) {
LOG(IndexedDB, "UniqueIDBDatabaseTransaction::renameIndex (callback)");
+ if (!weakThis || !m_databaseConnection)
+ return;
+
m_requestResults.append(error);
if (error.isNull())
- databaseConnection().didRenameIndex(IDBResultData::renameIndexSuccess(requestData.requestIdentifier()));
+ m_databaseConnection->didRenameIndex(IDBResultData::renameIndexSuccess(requestData.requestIdentifier()));
else
- databaseConnection().didRenameIndex(IDBResultData::error(requestData.requestIdentifier(), error));
+ m_databaseConnection->didRenameIndex(IDBResultData::error(requestData.requestIdentifier(), error));
});
}
@@ -296,18 +340,22 @@
ASSERT(!isReadOnly());
ASSERT(m_transactionInfo.identifier() == requestData.transactionIdentifier());
- auto database = databaseConnection().database();
- ASSERT(database);
+ auto* database = this->database();
+ if (!database)
+ return;
- database->putOrAdd(requestData, keyData, value, overwriteMode, [this, requestData](auto& error, const IDBKeyData& key) {
+ database->putOrAdd(requestData, keyData, value, overwriteMode, [this, weakThis = WeakPtr { *this }, requestData](auto& error, const IDBKeyData& key) {
LOG(IndexedDB, "UniqueIDBDatabaseTransaction::putOrAdd (callback)");
+ if (!weakThis || !m_databaseConnection)
+ return;
+
m_requestResults.append(error);
if (error.isNull())
- databaseConnection().connectionToClient().didPutOrAdd(IDBResultData::putOrAddSuccess(requestData.requestIdentifier(), key));
+ m_databaseConnection->connectionToClient().didPutOrAdd(IDBResultData::putOrAddSuccess(requestData.requestIdentifier(), key));
else
- databaseConnection().connectionToClient().didPutOrAdd(IDBResultData::error(requestData.requestIdentifier(), error));
+ m_databaseConnection->connectionToClient().didPutOrAdd(IDBResultData::error(requestData.requestIdentifier(), error));
});
}
@@ -317,18 +365,22 @@
ASSERT(m_transactionInfo.identifier() == requestData.transactionIdentifier());
- auto database = databaseConnection().database();
- ASSERT(database);
+ auto* database = this->database();
+ if (!database)
+ return;
- database->getRecord(requestData, getRecordData, [this, requestData](auto& error, const IDBGetResult& result) {
+ database->getRecord(requestData, getRecordData, [this, weakThis = WeakPtr { *this }, requestData](auto& error, const IDBGetResult& result) {
LOG(IndexedDB, "UniqueIDBDatabaseTransaction::getRecord (callback)");
+ if (!weakThis || !m_databaseConnection)
+ return;
+
m_requestResults.append(error);
if (error.isNull())
- databaseConnection().connectionToClient().didGetRecord(IDBResultData::getRecordSuccess(requestData.requestIdentifier(), result));
+ m_databaseConnection->connectionToClient().didGetRecord(IDBResultData::getRecordSuccess(requestData.requestIdentifier(), result));
else
- databaseConnection().connectionToClient().didGetRecord(IDBResultData::error(requestData.requestIdentifier(), error));
+ m_databaseConnection->connectionToClient().didGetRecord(IDBResultData::error(requestData.requestIdentifier(), error));
});
}
@@ -338,18 +390,22 @@
ASSERT(m_transactionInfo.identifier() == requestData.transactionIdentifier());
- auto database = databaseConnection().database();
- ASSERT(database);
+ auto* database = this->database();
+ if (!database)
+ return;
- database->getAllRecords(requestData, getAllRecordsData, [this, requestData](auto& error, const IDBGetAllResult& result) {
+ database->getAllRecords(requestData, getAllRecordsData, [this, weakThis = WeakPtr { *this }, requestData](auto& error, const IDBGetAllResult& result) {
LOG(IndexedDB, "UniqueIDBDatabaseTransaction::getAllRecords (callback)");
+ if (!weakThis || !m_databaseConnection)
+ return;
+
m_requestResults.append(error);
if (error.isNull())
- databaseConnection().connectionToClient().didGetAllRecords(IDBResultData::getAllRecordsSuccess(requestData.requestIdentifier(), result));
+ m_databaseConnection->connectionToClient().didGetAllRecords(IDBResultData::getAllRecordsSuccess(requestData.requestIdentifier(), result));
else
- databaseConnection().connectionToClient().didGetAllRecords(IDBResultData::error(requestData.requestIdentifier(), error));
+ m_databaseConnection->connectionToClient().didGetAllRecords(IDBResultData::error(requestData.requestIdentifier(), error));
});
}
@@ -359,18 +415,22 @@
ASSERT(m_transactionInfo.identifier() == requestData.transactionIdentifier());
- auto database = databaseConnection().database();
- ASSERT(database);
+ auto* database = this->database();
+ if (!database)
+ return;
- database->getCount(requestData, keyRangeData, [this, requestData](auto& error, uint64_t count) {
+ database->getCount(requestData, keyRangeData, [this, weakThis = WeakPtr { *this }, requestData](auto& error, uint64_t count) {
LOG(IndexedDB, "UniqueIDBDatabaseTransaction::getCount (callback)");
+ if (!weakThis || !m_databaseConnection)
+ return;
+
m_requestResults.append(error);
if (error.isNull())
- databaseConnection().connectionToClient().didGetCount(IDBResultData::getCountSuccess(requestData.requestIdentifier(), count));
+ m_databaseConnection->connectionToClient().didGetCount(IDBResultData::getCountSuccess(requestData.requestIdentifier(), count));
else
- databaseConnection().connectionToClient().didGetCount(IDBResultData::error(requestData.requestIdentifier(), error));
+ m_databaseConnection->connectionToClient().didGetCount(IDBResultData::error(requestData.requestIdentifier(), error));
});
}
@@ -380,18 +440,22 @@
ASSERT(m_transactionInfo.identifier() == requestData.transactionIdentifier());
- auto database = databaseConnection().database();
- ASSERT(database);
+ auto* database = this->database();
+ if (!database)
+ return;
- database->deleteRecord(requestData, keyRangeData, [this, requestData](auto& error) {
+ database->deleteRecord(requestData, keyRangeData, [this, weakThis = WeakPtr { *this }, requestData](auto& error) {
LOG(IndexedDB, "UniqueIDBDatabaseTransaction::deleteRecord (callback)");
+ if (!weakThis || !m_databaseConnection)
+ return;
+
m_requestResults.append(error);
if (error.isNull())
- databaseConnection().connectionToClient().didDeleteRecord(IDBResultData::deleteRecordSuccess(requestData.requestIdentifier()));
+ m_databaseConnection->connectionToClient().didDeleteRecord(IDBResultData::deleteRecordSuccess(requestData.requestIdentifier()));
else
- databaseConnection().connectionToClient().didDeleteRecord(IDBResultData::error(requestData.requestIdentifier(), error));
+ m_databaseConnection->connectionToClient().didDeleteRecord(IDBResultData::error(requestData.requestIdentifier(), error));
});
}
@@ -401,18 +465,22 @@
ASSERT(m_transactionInfo.identifier() == requestData.transactionIdentifier());
- auto database = databaseConnection().database();
- ASSERT(database);
-
- database->openCursor(requestData, info, [this, requestData](auto& error, const IDBGetResult& result) {
+ auto* database = this->database();
+ if (!database)
+ return;
+
+ database->openCursor(requestData, info, [this, weakThis = WeakPtr { *this }, requestData](auto& error, const IDBGetResult& result) {
LOG(IndexedDB, "UniqueIDBDatabaseTransaction::openCursor (callback)");
+ if (!weakThis || !m_databaseConnection)
+ return;
+
m_requestResults.append(error);
if (error.isNull())
- databaseConnection().connectionToClient().didOpenCursor(IDBResultData::openCursorSuccess(requestData.requestIdentifier(), result));
+ m_databaseConnection->connectionToClient().didOpenCursor(IDBResultData::openCursorSuccess(requestData.requestIdentifier(), result));
else
- databaseConnection().connectionToClient().didOpenCursor(IDBResultData::error(requestData.requestIdentifier(), error));
+ m_databaseConnection->connectionToClient().didOpenCursor(IDBResultData::error(requestData.requestIdentifier(), error));
});
}
@@ -422,21 +490,25 @@
ASSERT(m_transactionInfo.identifier() == requestData.transactionIdentifier());
- auto database = databaseConnection().database();
- ASSERT(database);
+ auto* database = this->database();
+ if (!database)
+ return;
- database->iterateCursor(requestData, data, [this, requestData, option = data.option](auto& error, const IDBGetResult& result) {
+ database->iterateCursor(requestData, data, [this, weakThis = WeakPtr { *this }, requestData, option = data.option](auto& error, const IDBGetResult& result) {
LOG(IndexedDB, "UniqueIDBDatabaseTransaction::iterateCursor (callback)");
if (option == IndexedDB::CursorIterateOption::DoNotReply)
return;
+ if (!weakThis || !m_databaseConnection)
+ return;
+
m_requestResults.append(error);
if (error.isNull())
- databaseConnection().connectionToClient().didIterateCursor(IDBResultData::iterateCursorSuccess(requestData.requestIdentifier(), result));
+ m_databaseConnection->connectionToClient().didIterateCursor(IDBResultData::iterateCursorSuccess(requestData.requestIdentifier(), result));
else
- databaseConnection().connectionToClient().didIterateCursor(IDBResultData::error(requestData.requestIdentifier(), error));
+ m_databaseConnection->connectionToClient().didIterateCursor(IDBResultData::error(requestData.requestIdentifier(), error));
});
}
@@ -445,7 +517,11 @@
if (!m_objectStoreIdentifiers.isEmpty())
return m_objectStoreIdentifiers;
- auto& info = databaseConnection().database()->info();
+ auto* database = this->database();
+ if (!database)
+ return m_objectStoreIdentifiers;
+
+ auto& info = database->info();
for (const auto& objectStoreName : info.objectStoreNames()) {
auto objectStoreInfo = info.infoForExistingObjectStore(objectStoreName);
ASSERT(objectStoreInfo);
@@ -463,7 +539,8 @@
{
LOG(IndexedDB, "UniqueIDBDatabaseTransaction::didActivateInBackingStore");
- databaseConnection().connectionToClient().didStartTransaction(m_transactionInfo.identifier(), error);
+ if (m_databaseConnection)
+ m_databaseConnection->connectionToClient().didStartTransaction(m_transactionInfo.identifier(), error);
}
} // namespace IDBServer
diff --git a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.h b/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.h
index dd434a2..cdad11e 100644
--- a/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.h
+++ b/Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.h
@@ -49,6 +49,7 @@
namespace IDBServer {
class IDBServer;
+class UniqueIDBDatabase;
class UniqueIDBDatabaseConnection;
class UniqueIDBDatabaseTransaction : public CanMakeWeakPtr<UniqueIDBDatabaseTransaction>, public RefCounted<UniqueIDBDatabaseTransaction> {
@@ -57,7 +58,8 @@
~UniqueIDBDatabaseTransaction();
- UniqueIDBDatabaseConnection& databaseConnection();
+ UniqueIDBDatabaseConnection* databaseConnection() const;
+ UniqueIDBDatabase* database() const;
const IDBTransactionInfo& info() const { return m_transactionInfo; }
WEBCORE_EXPORT bool isVersionChange() const;
bool isReadOnly() const;
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBResultData.cpp b/Source/WebCore/Modules/indexeddb/shared/IDBResultData.cpp
index 19c1715..ea9c2e7 100644
--- a/Source/WebCore/Modules/indexeddb/shared/IDBResultData.cpp
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBResultData.cpp
@@ -114,12 +114,12 @@
}
-IDBResultData IDBResultData::openDatabaseUpgradeNeeded(const IDBResourceIdentifier& requestIdentifier, IDBServer::UniqueIDBDatabaseTransaction& transaction)
+IDBResultData IDBResultData::openDatabaseUpgradeNeeded(const IDBResourceIdentifier& requestIdentifier, IDBServer::UniqueIDBDatabaseTransaction& transaction, IDBServer::UniqueIDBDatabaseConnection& connection)
{
IDBResultData result { requestIdentifier };
result.m_type = IDBResultType::OpenDatabaseUpgradeNeeded;
- result.m_databaseConnectionIdentifier = transaction.databaseConnection().identifier();
- result.m_databaseInfo = makeUnique<IDBDatabaseInfo>(transaction.databaseConnection().database()->info());
+ result.m_databaseConnectionIdentifier = connection.identifier();
+ result.m_databaseInfo = makeUnique<IDBDatabaseInfo>(connection.database()->info());
result.m_transactionInfo = makeUnique<IDBTransactionInfo>(transaction.info());
return result;
}
diff --git a/Source/WebCore/Modules/indexeddb/shared/IDBResultData.h b/Source/WebCore/Modules/indexeddb/shared/IDBResultData.h
index b517c37..91f4323 100644
--- a/Source/WebCore/Modules/indexeddb/shared/IDBResultData.h
+++ b/Source/WebCore/Modules/indexeddb/shared/IDBResultData.h
@@ -69,7 +69,7 @@
public:
static IDBResultData error(const IDBResourceIdentifier&, const IDBError&);
static IDBResultData openDatabaseSuccess(const IDBResourceIdentifier&, IDBServer::UniqueIDBDatabaseConnection&);
- static IDBResultData openDatabaseUpgradeNeeded(const IDBResourceIdentifier&, IDBServer::UniqueIDBDatabaseTransaction&);
+ static IDBResultData openDatabaseUpgradeNeeded(const IDBResourceIdentifier&, IDBServer::UniqueIDBDatabaseTransaction&, IDBServer::UniqueIDBDatabaseConnection&);
static IDBResultData deleteDatabaseSuccess(const IDBResourceIdentifier&, const IDBDatabaseInfo&);
static IDBResultData createObjectStoreSuccess(const IDBResourceIdentifier&);
static IDBResultData deleteObjectStoreSuccess(const IDBResourceIdentifier&);