Modern IDB: Add thread identifiers and assertions to IDB DOM objects.
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 May 2016 22:13:58 +0000 (22:13 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 May 2016 22:13:58 +0000 (22:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=157329

Reviewed by Alex Christensen.

No new tests (No current change in behavior, will be tested as bug 149953 makes progress).

* Modules/indexeddb/IDBCursor.cpp:
(WebCore::IDBCursor::IDBCursor):
(WebCore::IDBCursor::~IDBCursor):
(WebCore::IDBCursor::sourcesDeleted):
(WebCore::IDBCursor::transaction):
(WebCore::IDBCursor::direction):
(WebCore::IDBCursor::update):
(WebCore::IDBCursor::advance):
(WebCore::IDBCursor::continueFunction):
(WebCore::IDBCursor::uncheckedIterateCursor):
(WebCore::IDBCursor::deleteFunction):
(WebCore::IDBCursor::setGetResult):

* Modules/indexeddb/IDBDatabase.cpp:
(WebCore::IDBDatabase::~IDBDatabase):
(WebCore::IDBDatabase::hasPendingActivity):
(WebCore::IDBDatabase::name):
(WebCore::IDBDatabase::version):
(WebCore::IDBDatabase::objectStoreNames):
(WebCore::IDBDatabase::createObjectStore):
(WebCore::IDBDatabase::transaction):
(WebCore::IDBDatabase::deleteObjectStore):
(WebCore::IDBDatabase::close):
(WebCore::IDBDatabase::maybeCloseInServer):
(WebCore::IDBDatabase::activeDOMObjectName):
(WebCore::IDBDatabase::canSuspendForDocumentSuspension):
(WebCore::IDBDatabase::stop):
(WebCore::IDBDatabase::startVersionChangeTransaction):
(WebCore::IDBDatabase::didStartTransaction):
(WebCore::IDBDatabase::willCommitTransaction):
(WebCore::IDBDatabase::didCommitTransaction):
(WebCore::IDBDatabase::willAbortTransaction):
(WebCore::IDBDatabase::didAbortTransaction):
(WebCore::IDBDatabase::didCommitOrAbortTransaction):
(WebCore::IDBDatabase::fireVersionChangeEvent):
(WebCore::IDBDatabase::dispatchEvent):
(WebCore::IDBDatabase::didCreateIndexInfo):
(WebCore::IDBDatabase::didDeleteIndexInfo):
* Modules/indexeddb/IDBDatabase.h:
(WebCore::IDBDatabase::originThreadID):

* Modules/indexeddb/IDBIndex.cpp:
(WebCore::IDBIndex::IDBIndex):
(WebCore::IDBIndex::~IDBIndex):
(WebCore::IDBIndex::name):
(WebCore::IDBIndex::objectStore):
(WebCore::IDBIndex::keyPath):
(WebCore::IDBIndex::unique):
(WebCore::IDBIndex::multiEntry):
(WebCore::IDBIndex::openCursor):
(WebCore::IDBIndex::doCount):
(WebCore::IDBIndex::openKeyCursor):
(WebCore::IDBIndex::doGet):
(WebCore::IDBIndex::doGetKey):
(WebCore::IDBIndex::markAsDeleted):

* Modules/indexeddb/IDBObjectStore.cpp:
(WebCore::IDBObjectStore::IDBObjectStore):
(WebCore::IDBObjectStore::~IDBObjectStore):
(WebCore::IDBObjectStore::name):
(WebCore::IDBObjectStore::keyPath):
(WebCore::IDBObjectStore::indexNames):
(WebCore::IDBObjectStore::transaction):
(WebCore::IDBObjectStore::autoIncrement):
(WebCore::IDBObjectStore::openCursor):
(WebCore::IDBObjectStore::get):
(WebCore::IDBObjectStore::putOrAdd):
(WebCore::IDBObjectStore::doDelete):
(WebCore::IDBObjectStore::clear):
(WebCore::IDBObjectStore::createIndex):
(WebCore::IDBObjectStore::index):
(WebCore::IDBObjectStore::deleteIndex):
(WebCore::IDBObjectStore::doCount):
(WebCore::IDBObjectStore::markAsDeleted):
(WebCore::IDBObjectStore::rollbackInfoForVersionChangeAbort):

* Modules/indexeddb/IDBOpenDBRequest.cpp:
(WebCore::IDBOpenDBRequest::~IDBOpenDBRequest):
(WebCore::IDBOpenDBRequest::onError):
(WebCore::IDBOpenDBRequest::versionChangeTransactionDidFinish):
(WebCore::IDBOpenDBRequest::fireSuccessAfterVersionChangeCommit):
(WebCore::IDBOpenDBRequest::fireErrorAfterVersionChangeCompletion):
(WebCore::IDBOpenDBRequest::dispatchEvent):
(WebCore::IDBOpenDBRequest::onSuccess):
(WebCore::IDBOpenDBRequest::onUpgradeNeeded):
(WebCore::IDBOpenDBRequest::onDeleteDatabaseSuccess):
(WebCore::IDBOpenDBRequest::requestCompleted):
(WebCore::IDBOpenDBRequest::requestBlocked):

* Modules/indexeddb/IDBRequest.cpp:
(WebCore::IDBRequest::~IDBRequest):
(WebCore::IDBRequest::errorCode):
(WebCore::IDBRequest::error):
(WebCore::IDBRequest::setSource):
(WebCore::IDBRequest::setVersionChangeTransaction):
(WebCore::IDBRequest::transaction):
(WebCore::IDBRequest::readyState):
(WebCore::IDBRequest::sourceObjectStoreIdentifier):
(WebCore::IDBRequest::sourceIndexIdentifier):
(WebCore::IDBRequest::requestedIndexRecordType):
(WebCore::IDBRequest::eventTargetInterface):
(WebCore::IDBRequest::activeDOMObjectName):
(WebCore::IDBRequest::canSuspendForDocumentSuspension):
(WebCore::IDBRequest::hasPendingActivity):
(WebCore::IDBRequest::stop):
(WebCore::IDBRequest::enqueueEvent):
(WebCore::IDBRequest::dispatchEvent):
(WebCore::IDBRequest::uncaughtExceptionInEventHandler):
(WebCore::IDBRequest::setResult):
(WebCore::IDBRequest::setResultToStructuredClone):
(WebCore::IDBRequest::clearResult):
(WebCore::IDBRequest::setResultToUndefined):
(WebCore::IDBRequest::resultCursor):
(WebCore::IDBRequest::willIterateCursor):
(WebCore::IDBRequest::didOpenOrIterateCursor):
(WebCore::IDBRequest::requestCompleted):
(WebCore::IDBRequest::onError):
(WebCore::IDBRequest::onSuccess):
* Modules/indexeddb/IDBRequest.h:
(WebCore::IDBRequest::originThreadID):

* Modules/indexeddb/IDBTransaction.cpp:
(WebCore::IDBTransaction::IDBTransaction):
(WebCore::IDBTransaction::~IDBTransaction):
(WebCore::IDBTransaction::mode):
(WebCore::IDBTransaction::db):
(WebCore::IDBTransaction::serverConnection):
(WebCore::IDBTransaction::error):
(WebCore::IDBTransaction::objectStore):
(WebCore::IDBTransaction::abortDueToFailedRequest):
(WebCore::IDBTransaction::transitionedToFinishing):
(WebCore::IDBTransaction::abort):
(WebCore::IDBTransaction::abortOnServerAndCancelRequests):
(WebCore::IDBTransaction::activeDOMObjectName):
(WebCore::IDBTransaction::canSuspendForDocumentSuspension):
(WebCore::IDBTransaction::hasPendingActivity):
(WebCore::IDBTransaction::stop):
(WebCore::IDBTransaction::isActive):
(WebCore::IDBTransaction::isFinishedOrFinishing):
(WebCore::IDBTransaction::addRequest):
(WebCore::IDBTransaction::removeRequest):
(WebCore::IDBTransaction::scheduleOperation):
(WebCore::IDBTransaction::scheduleOperationTimer):
(WebCore::IDBTransaction::operationTimerFired):
(WebCore::IDBTransaction::commit):
(WebCore::IDBTransaction::commitOnServer):
(WebCore::IDBTransaction::finishAbortOrCommit):
(WebCore::IDBTransaction::didStart):
(WebCore::IDBTransaction::notifyDidAbort):
(WebCore::IDBTransaction::didAbort):
(WebCore::IDBTransaction::didCommit):
(WebCore::IDBTransaction::fireOnComplete):
(WebCore::IDBTransaction::fireOnAbort):
(WebCore::IDBTransaction::enqueueEvent):
(WebCore::IDBTransaction::dispatchEvent):
(WebCore::IDBTransaction::createObjectStore):
(WebCore::IDBTransaction::createObjectStoreOnServer):
(WebCore::IDBTransaction::didCreateObjectStoreOnServer):
(WebCore::IDBTransaction::createIndex):
(WebCore::IDBTransaction::createIndexOnServer):
(WebCore::IDBTransaction::didCreateIndexOnServer):
(WebCore::IDBTransaction::requestOpenCursor):
(WebCore::IDBTransaction::doRequestOpenCursor):
(WebCore::IDBTransaction::openCursorOnServer):
(WebCore::IDBTransaction::didOpenCursorOnServer):
(WebCore::IDBTransaction::iterateCursor):
(WebCore::IDBTransaction::iterateCursorOnServer):
(WebCore::IDBTransaction::didIterateCursorOnServer):
(WebCore::IDBTransaction::requestGetRecord):
(WebCore::IDBTransaction::requestGetValue):
(WebCore::IDBTransaction::requestGetKey):
(WebCore::IDBTransaction::requestIndexRecord):
(WebCore::IDBTransaction::getRecordOnServer):
(WebCore::IDBTransaction::didGetRecordOnServer):
(WebCore::IDBTransaction::requestCount):
(WebCore::IDBTransaction::getCountOnServer):
(WebCore::IDBTransaction::didGetCountOnServer):
(WebCore::IDBTransaction::requestDeleteRecord):
(WebCore::IDBTransaction::deleteRecordOnServer):
(WebCore::IDBTransaction::didDeleteRecordOnServer):
(WebCore::IDBTransaction::requestClearObjectStore):
(WebCore::IDBTransaction::clearObjectStoreOnServer):
(WebCore::IDBTransaction::didClearObjectStoreOnServer):
(WebCore::IDBTransaction::requestPutOrAdd):
(WebCore::IDBTransaction::putOrAddOnServer):
(WebCore::IDBTransaction::didPutOrAddOnServer):
(WebCore::IDBTransaction::deleteObjectStore):
(WebCore::IDBTransaction::deleteObjectStoreOnServer):
(WebCore::IDBTransaction::didDeleteObjectStoreOnServer):
(WebCore::IDBTransaction::deleteIndex):
(WebCore::IDBTransaction::deleteIndexOnServer):
(WebCore::IDBTransaction::didDeleteIndexOnServer):
(WebCore::IDBTransaction::operationDidComplete):
(WebCore::IDBTransaction::establishOnServer):
(WebCore::IDBTransaction::activate):
(WebCore::IDBTransaction::deactivate):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@200483 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBCursor.cpp
Source/WebCore/Modules/indexeddb/IDBDatabase.cpp
Source/WebCore/Modules/indexeddb/IDBDatabase.h
Source/WebCore/Modules/indexeddb/IDBIndex.cpp
Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp
Source/WebCore/Modules/indexeddb/IDBOpenDBRequest.cpp
Source/WebCore/Modules/indexeddb/IDBRequest.cpp
Source/WebCore/Modules/indexeddb/IDBRequest.h
Source/WebCore/Modules/indexeddb/IDBTransaction.cpp

index 6151885..fb3d4f5 100644 (file)
@@ -1,3 +1,209 @@
+2016-05-04  Brady Eidson  <beidson@apple.com>
+
+        Modern IDB: Add thread identifiers and assertions to IDB DOM objects.
+        https://bugs.webkit.org/show_bug.cgi?id=157329
+
+        Reviewed by Alex Christensen.
+
+        No new tests (No current change in behavior, will be tested as bug 149953 makes progress).
+
+        * Modules/indexeddb/IDBCursor.cpp:
+        (WebCore::IDBCursor::IDBCursor):
+        (WebCore::IDBCursor::~IDBCursor):
+        (WebCore::IDBCursor::sourcesDeleted):
+        (WebCore::IDBCursor::transaction):
+        (WebCore::IDBCursor::direction):
+        (WebCore::IDBCursor::update):
+        (WebCore::IDBCursor::advance):
+        (WebCore::IDBCursor::continueFunction):
+        (WebCore::IDBCursor::uncheckedIterateCursor):
+        (WebCore::IDBCursor::deleteFunction):
+        (WebCore::IDBCursor::setGetResult):
+        
+        * Modules/indexeddb/IDBDatabase.cpp:
+        (WebCore::IDBDatabase::~IDBDatabase):
+        (WebCore::IDBDatabase::hasPendingActivity):
+        (WebCore::IDBDatabase::name):
+        (WebCore::IDBDatabase::version):
+        (WebCore::IDBDatabase::objectStoreNames):
+        (WebCore::IDBDatabase::createObjectStore):
+        (WebCore::IDBDatabase::transaction):
+        (WebCore::IDBDatabase::deleteObjectStore):
+        (WebCore::IDBDatabase::close):
+        (WebCore::IDBDatabase::maybeCloseInServer):
+        (WebCore::IDBDatabase::activeDOMObjectName):
+        (WebCore::IDBDatabase::canSuspendForDocumentSuspension):
+        (WebCore::IDBDatabase::stop):
+        (WebCore::IDBDatabase::startVersionChangeTransaction):
+        (WebCore::IDBDatabase::didStartTransaction):
+        (WebCore::IDBDatabase::willCommitTransaction):
+        (WebCore::IDBDatabase::didCommitTransaction):
+        (WebCore::IDBDatabase::willAbortTransaction):
+        (WebCore::IDBDatabase::didAbortTransaction):
+        (WebCore::IDBDatabase::didCommitOrAbortTransaction):
+        (WebCore::IDBDatabase::fireVersionChangeEvent):
+        (WebCore::IDBDatabase::dispatchEvent):
+        (WebCore::IDBDatabase::didCreateIndexInfo):
+        (WebCore::IDBDatabase::didDeleteIndexInfo):
+        * Modules/indexeddb/IDBDatabase.h:
+        (WebCore::IDBDatabase::originThreadID):
+        
+        * Modules/indexeddb/IDBIndex.cpp:
+        (WebCore::IDBIndex::IDBIndex):
+        (WebCore::IDBIndex::~IDBIndex):
+        (WebCore::IDBIndex::name):
+        (WebCore::IDBIndex::objectStore):
+        (WebCore::IDBIndex::keyPath):
+        (WebCore::IDBIndex::unique):
+        (WebCore::IDBIndex::multiEntry):
+        (WebCore::IDBIndex::openCursor):
+        (WebCore::IDBIndex::doCount):
+        (WebCore::IDBIndex::openKeyCursor):
+        (WebCore::IDBIndex::doGet):
+        (WebCore::IDBIndex::doGetKey):
+        (WebCore::IDBIndex::markAsDeleted):
+        
+        * Modules/indexeddb/IDBObjectStore.cpp:
+        (WebCore::IDBObjectStore::IDBObjectStore):
+        (WebCore::IDBObjectStore::~IDBObjectStore):
+        (WebCore::IDBObjectStore::name):
+        (WebCore::IDBObjectStore::keyPath):
+        (WebCore::IDBObjectStore::indexNames):
+        (WebCore::IDBObjectStore::transaction):
+        (WebCore::IDBObjectStore::autoIncrement):
+        (WebCore::IDBObjectStore::openCursor):
+        (WebCore::IDBObjectStore::get):
+        (WebCore::IDBObjectStore::putOrAdd):
+        (WebCore::IDBObjectStore::doDelete):
+        (WebCore::IDBObjectStore::clear):
+        (WebCore::IDBObjectStore::createIndex):
+        (WebCore::IDBObjectStore::index):
+        (WebCore::IDBObjectStore::deleteIndex):
+        (WebCore::IDBObjectStore::doCount):
+        (WebCore::IDBObjectStore::markAsDeleted):
+        (WebCore::IDBObjectStore::rollbackInfoForVersionChangeAbort):
+        
+        * Modules/indexeddb/IDBOpenDBRequest.cpp:
+        (WebCore::IDBOpenDBRequest::~IDBOpenDBRequest):
+        (WebCore::IDBOpenDBRequest::onError):
+        (WebCore::IDBOpenDBRequest::versionChangeTransactionDidFinish):
+        (WebCore::IDBOpenDBRequest::fireSuccessAfterVersionChangeCommit):
+        (WebCore::IDBOpenDBRequest::fireErrorAfterVersionChangeCompletion):
+        (WebCore::IDBOpenDBRequest::dispatchEvent):
+        (WebCore::IDBOpenDBRequest::onSuccess):
+        (WebCore::IDBOpenDBRequest::onUpgradeNeeded):
+        (WebCore::IDBOpenDBRequest::onDeleteDatabaseSuccess):
+        (WebCore::IDBOpenDBRequest::requestCompleted):
+        (WebCore::IDBOpenDBRequest::requestBlocked):
+        
+        * Modules/indexeddb/IDBRequest.cpp:
+        (WebCore::IDBRequest::~IDBRequest):
+        (WebCore::IDBRequest::errorCode):
+        (WebCore::IDBRequest::error):
+        (WebCore::IDBRequest::setSource):
+        (WebCore::IDBRequest::setVersionChangeTransaction):
+        (WebCore::IDBRequest::transaction):
+        (WebCore::IDBRequest::readyState):
+        (WebCore::IDBRequest::sourceObjectStoreIdentifier):
+        (WebCore::IDBRequest::sourceIndexIdentifier):
+        (WebCore::IDBRequest::requestedIndexRecordType):
+        (WebCore::IDBRequest::eventTargetInterface):
+        (WebCore::IDBRequest::activeDOMObjectName):
+        (WebCore::IDBRequest::canSuspendForDocumentSuspension):
+        (WebCore::IDBRequest::hasPendingActivity):
+        (WebCore::IDBRequest::stop):
+        (WebCore::IDBRequest::enqueueEvent):
+        (WebCore::IDBRequest::dispatchEvent):
+        (WebCore::IDBRequest::uncaughtExceptionInEventHandler):
+        (WebCore::IDBRequest::setResult):
+        (WebCore::IDBRequest::setResultToStructuredClone):
+        (WebCore::IDBRequest::clearResult):
+        (WebCore::IDBRequest::setResultToUndefined):
+        (WebCore::IDBRequest::resultCursor):
+        (WebCore::IDBRequest::willIterateCursor):
+        (WebCore::IDBRequest::didOpenOrIterateCursor):
+        (WebCore::IDBRequest::requestCompleted):
+        (WebCore::IDBRequest::onError):
+        (WebCore::IDBRequest::onSuccess):
+        * Modules/indexeddb/IDBRequest.h:
+        (WebCore::IDBRequest::originThreadID):
+        
+        * Modules/indexeddb/IDBTransaction.cpp:
+        (WebCore::IDBTransaction::IDBTransaction):
+        (WebCore::IDBTransaction::~IDBTransaction):
+        (WebCore::IDBTransaction::mode):
+        (WebCore::IDBTransaction::db):
+        (WebCore::IDBTransaction::serverConnection):
+        (WebCore::IDBTransaction::error):
+        (WebCore::IDBTransaction::objectStore):
+        (WebCore::IDBTransaction::abortDueToFailedRequest):
+        (WebCore::IDBTransaction::transitionedToFinishing):
+        (WebCore::IDBTransaction::abort):
+        (WebCore::IDBTransaction::abortOnServerAndCancelRequests):
+        (WebCore::IDBTransaction::activeDOMObjectName):
+        (WebCore::IDBTransaction::canSuspendForDocumentSuspension):
+        (WebCore::IDBTransaction::hasPendingActivity):
+        (WebCore::IDBTransaction::stop):
+        (WebCore::IDBTransaction::isActive):
+        (WebCore::IDBTransaction::isFinishedOrFinishing):
+        (WebCore::IDBTransaction::addRequest):
+        (WebCore::IDBTransaction::removeRequest):
+        (WebCore::IDBTransaction::scheduleOperation):
+        (WebCore::IDBTransaction::scheduleOperationTimer):
+        (WebCore::IDBTransaction::operationTimerFired):
+        (WebCore::IDBTransaction::commit):
+        (WebCore::IDBTransaction::commitOnServer):
+        (WebCore::IDBTransaction::finishAbortOrCommit):
+        (WebCore::IDBTransaction::didStart):
+        (WebCore::IDBTransaction::notifyDidAbort):
+        (WebCore::IDBTransaction::didAbort):
+        (WebCore::IDBTransaction::didCommit):
+        (WebCore::IDBTransaction::fireOnComplete):
+        (WebCore::IDBTransaction::fireOnAbort):
+        (WebCore::IDBTransaction::enqueueEvent):
+        (WebCore::IDBTransaction::dispatchEvent):
+        (WebCore::IDBTransaction::createObjectStore):
+        (WebCore::IDBTransaction::createObjectStoreOnServer):
+        (WebCore::IDBTransaction::didCreateObjectStoreOnServer):
+        (WebCore::IDBTransaction::createIndex):
+        (WebCore::IDBTransaction::createIndexOnServer):
+        (WebCore::IDBTransaction::didCreateIndexOnServer):
+        (WebCore::IDBTransaction::requestOpenCursor):
+        (WebCore::IDBTransaction::doRequestOpenCursor):
+        (WebCore::IDBTransaction::openCursorOnServer):
+        (WebCore::IDBTransaction::didOpenCursorOnServer):
+        (WebCore::IDBTransaction::iterateCursor):
+        (WebCore::IDBTransaction::iterateCursorOnServer):
+        (WebCore::IDBTransaction::didIterateCursorOnServer):
+        (WebCore::IDBTransaction::requestGetRecord):
+        (WebCore::IDBTransaction::requestGetValue):
+        (WebCore::IDBTransaction::requestGetKey):
+        (WebCore::IDBTransaction::requestIndexRecord):
+        (WebCore::IDBTransaction::getRecordOnServer):
+        (WebCore::IDBTransaction::didGetRecordOnServer):
+        (WebCore::IDBTransaction::requestCount):
+        (WebCore::IDBTransaction::getCountOnServer):
+        (WebCore::IDBTransaction::didGetCountOnServer):
+        (WebCore::IDBTransaction::requestDeleteRecord):
+        (WebCore::IDBTransaction::deleteRecordOnServer):
+        (WebCore::IDBTransaction::didDeleteRecordOnServer):
+        (WebCore::IDBTransaction::requestClearObjectStore):
+        (WebCore::IDBTransaction::clearObjectStoreOnServer):
+        (WebCore::IDBTransaction::didClearObjectStoreOnServer):
+        (WebCore::IDBTransaction::requestPutOrAdd):
+        (WebCore::IDBTransaction::putOrAddOnServer):
+        (WebCore::IDBTransaction::didPutOrAddOnServer):
+        (WebCore::IDBTransaction::deleteObjectStore):
+        (WebCore::IDBTransaction::deleteObjectStoreOnServer):
+        (WebCore::IDBTransaction::didDeleteObjectStoreOnServer):
+        (WebCore::IDBTransaction::deleteIndex):
+        (WebCore::IDBTransaction::deleteIndexOnServer):
+        (WebCore::IDBTransaction::didDeleteIndexOnServer):
+        (WebCore::IDBTransaction::operationDidComplete):
+        (WebCore::IDBTransaction::establishOnServer):
+        (WebCore::IDBTransaction::activate):
+        (WebCore::IDBTransaction::deactivate):
+
 2016-05-05  Nan Wang  <n_wang@apple.com>
 
         For keyboard users, activating a fragment URL should transfer focus and caret to the destination
index 013c7f7..68dd8c9 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "ExceptionCode.h"
 #include "IDBBindingUtilities.h"
+#include "IDBDatabase.h"
 #include "IDBDatabaseException.h"
 #include "IDBGetResult.h"
 #include "IDBIndex.h"
@@ -116,6 +117,8 @@ IDBCursor::IDBCursor(IDBTransaction& transaction, IDBObjectStore& objectStore, c
     , m_info(info)
     , m_objectStore(&objectStore)
 {
+    ASSERT(currentThread() == effectiveObjectStore().modernTransaction().database().originThreadID());
+
     suspendIfNeeded();
 }
 
@@ -124,15 +127,20 @@ IDBCursor::IDBCursor(IDBTransaction& transaction, IDBIndex& index, const IDBCurs
     , m_info(info)
     , m_index(&index)
 {
+    ASSERT(currentThread() == effectiveObjectStore().modernTransaction().database().originThreadID());
+
     suspendIfNeeded();
 }
 
 IDBCursor::~IDBCursor()
 {
+    ASSERT(currentThread() == effectiveObjectStore().modernTransaction().database().originThreadID());
 }
 
 bool IDBCursor::sourcesDeleted() const
 {
+    ASSERT(currentThread() == effectiveObjectStore().modernTransaction().database().originThreadID());
+
     if (m_objectStore)
         return m_objectStore->isDeleted();
 
@@ -151,17 +159,20 @@ IDBObjectStore& IDBCursor::effectiveObjectStore() const
 
 IDBTransaction& IDBCursor::transaction() const
 {
+    ASSERT(currentThread() == effectiveObjectStore().modernTransaction().database().originThreadID());
     return effectiveObjectStore().modernTransaction();
 }
 
 const String& IDBCursor::direction() const
 {
+    ASSERT(currentThread() == effectiveObjectStore().modernTransaction().database().originThreadID());
     return directionToString(m_info.cursorDirection());
 }
 
 RefPtr<WebCore::IDBRequest> IDBCursor::update(ExecState& exec, JSValue value, ExceptionCodeWithMessage& ec)
 {
     LOG(IndexedDB, "IDBCursor::update");
+    ASSERT(currentThread() == effectiveObjectStore().modernTransaction().database().originThreadID());
 
     if (sourcesDeleted()) {
         ec.code = IDBDatabaseException::InvalidStateError;
@@ -220,6 +231,7 @@ RefPtr<WebCore::IDBRequest> IDBCursor::update(ExecState& exec, JSValue value, Ex
 void IDBCursor::advance(unsigned count, ExceptionCodeWithMessage& ec)
 {
     LOG(IndexedDB, "IDBCursor::advance");
+    ASSERT(currentThread() == effectiveObjectStore().modernTransaction().database().originThreadID());
 
     if (!m_request) {
         ec.code = IDBDatabaseException::InvalidStateError;
@@ -267,6 +279,7 @@ void IDBCursor::continueFunction(ScriptExecutionContext& context, JSValue keyVal
 void IDBCursor::continueFunction(const IDBKeyData& key, ExceptionCodeWithMessage& ec)
 {
     LOG(IndexedDB, "IDBCursor::continueFunction (to key %s)", key.loggingString().utf8().data());
+    ASSERT(currentThread() == effectiveObjectStore().modernTransaction().database().originThreadID());
 
     if (!m_request) {
         ec.code = IDBDatabaseException::InvalidStateError;
@@ -316,6 +329,8 @@ void IDBCursor::continueFunction(const IDBKeyData& key, ExceptionCodeWithMessage
 
 void IDBCursor::uncheckedIterateCursor(const IDBKeyData& key, unsigned count)
 {
+    ASSERT(currentThread() == effectiveObjectStore().modernTransaction().database().originThreadID());
+
     ++m_outstandingRequestCount;
 
     m_request->willIterateCursor(*this);
@@ -325,6 +340,7 @@ void IDBCursor::uncheckedIterateCursor(const IDBKeyData& key, unsigned count)
 RefPtr<WebCore::IDBRequest> IDBCursor::deleteFunction(ScriptExecutionContext& context, ExceptionCodeWithMessage& ec)
 {
     LOG(IndexedDB, "IDBCursor::deleteFunction");
+    ASSERT(currentThread() == effectiveObjectStore().modernTransaction().database().originThreadID());
 
     if (sourcesDeleted()) {
         ec.code = IDBDatabaseException::InvalidStateError;
@@ -370,6 +386,7 @@ RefPtr<WebCore::IDBRequest> IDBCursor::deleteFunction(ScriptExecutionContext& co
 void IDBCursor::setGetResult(IDBRequest& request, const IDBGetResult& getResult)
 {
     LOG(IndexedDB, "IDBCursor::setGetResult - current key %s", getResult.keyData().loggingString().substring(0, 100).utf8().data());
+    ASSERT(currentThread() == effectiveObjectStore().modernTransaction().database().originThreadID());
 
     auto* context = request.scriptExecutionContext();
     if (!context)
index 12d0c61..3c7e82c 100644 (file)
@@ -62,26 +62,32 @@ IDBDatabase::IDBDatabase(ScriptExecutionContext& context, IDBClient::IDBConnecti
 
 IDBDatabase::~IDBDatabase()
 {
+    ASSERT(currentThread() == m_originThreadID);
     m_connectionProxy->connectionToServer().unregisterDatabaseConnection(*this);
 }
 
 bool IDBDatabase::hasPendingActivity() const
 {
+    ASSERT(currentThread() == m_originThreadID);
     return !m_closedInServer;
 }
 
 const String IDBDatabase::name() const
 {
+    ASSERT(currentThread() == m_originThreadID);
     return m_info.name();
 }
 
 uint64_t IDBDatabase::version() const
 {
+    ASSERT(currentThread() == m_originThreadID);
     return m_info.version();
 }
 
 RefPtr<DOMStringList> IDBDatabase::objectStoreNames() const
 {
+    ASSERT(currentThread() == m_originThreadID);
+
     RefPtr<DOMStringList> objectStoreNames = DOMStringList::create();
     for (auto& name : m_info.objectStoreNames())
         objectStoreNames->append(name);
@@ -99,6 +105,7 @@ RefPtr<WebCore::IDBObjectStore> IDBDatabase::createObjectStore(const String& nam
 {
     LOG(IndexedDB, "IDBDatabase::createObjectStore - (%s %s)", m_info.name().utf8().data(), name.utf8().data());
 
+    ASSERT(currentThread() == m_originThreadID);
     ASSERT(!m_versionChangeTransaction || m_versionChangeTransaction->isVersionChange());
 
     if (!m_versionChangeTransaction) {
@@ -144,6 +151,8 @@ RefPtr<WebCore::IDBTransaction> IDBDatabase::transaction(ScriptExecutionContext*
 {
     LOG(IndexedDB, "IDBDatabase::transaction");
 
+    ASSERT(currentThread() == m_originThreadID);
+
     if (m_closePending) {
         ec.code = IDBDatabaseException::InvalidStateError;
         ec.message = ASCIILiteral("Failed to execute 'transaction' on 'IDBDatabase': The database connection is closing.");
@@ -193,6 +202,8 @@ RefPtr<WebCore::IDBTransaction> IDBDatabase::transaction(ScriptExecutionContext*
 
 RefPtr<WebCore::IDBTransaction> IDBDatabase::transaction(ScriptExecutionContext* context, const String& objectStore, const String& mode, ExceptionCodeWithMessage& ec)
 {
+    ASSERT(currentThread() == m_originThreadID);
+
     Vector<String> objectStores(1);
     objectStores[0] = objectStore;
     return transaction(context, objectStores, mode, ec);
@@ -202,6 +213,8 @@ void IDBDatabase::deleteObjectStore(const String& objectStoreName, ExceptionCode
 {
     LOG(IndexedDB, "IDBDatabase::deleteObjectStore");
 
+    ASSERT(currentThread() == m_originThreadID);
+
     if (!m_versionChangeTransaction) {
         ec.code = IDBDatabaseException::InvalidStateError;
         ec.message = ASCIILiteral("Failed to execute 'deleteObjectStore' on 'IDBDatabase': The database is not running a version change transaction.");
@@ -227,6 +240,8 @@ void IDBDatabase::close()
 {
     LOG(IndexedDB, "IDBDatabase::close - %" PRIu64, m_databaseConnectionIdentifier);
 
+    ASSERT(currentThread() == m_originThreadID);
+
     m_closePending = true;
     maybeCloseInServer();
 }
@@ -235,6 +250,8 @@ void IDBDatabase::maybeCloseInServer()
 {
     LOG(IndexedDB, "IDBDatabase::maybeCloseInServer - %" PRIu64, m_databaseConnectionIdentifier);
 
+    ASSERT(currentThread() == m_originThreadID);
+
     if (m_closedInServer)
         return;
 
@@ -250,11 +267,14 @@ void IDBDatabase::maybeCloseInServer()
 
 const char* IDBDatabase::activeDOMObjectName() const
 {
+    ASSERT(currentThread() == m_originThreadID);
     return "IDBDatabase";
 }
 
 bool IDBDatabase::canSuspendForDocumentSuspension() const
 {
+    ASSERT(currentThread() == m_originThreadID);
+
     // FIXME: This value will sometimes be false when database operations are actually in progress.
     // Such database operations do not yet exist.
     return true;
@@ -264,6 +284,8 @@ void IDBDatabase::stop()
 {
     LOG(IndexedDB, "IDBDatabase::stop - %" PRIu64, m_databaseConnectionIdentifier);
 
+    ASSERT(currentThread() == m_originThreadID);
+
     Vector<IDBResourceIdentifier> transactionIdentifiers;
     transactionIdentifiers.reserveInitialCapacity(m_activeTransactions.size());
 
@@ -283,6 +305,7 @@ Ref<IDBTransaction> IDBDatabase::startVersionChangeTransaction(const IDBTransact
 {
     LOG(IndexedDB, "IDBDatabase::startVersionChangeTransaction %s", info.identifier().loggingString().utf8().data());
 
+    ASSERT(currentThread() == m_originThreadID);
     ASSERT(!m_versionChangeTransaction);
     ASSERT(info.mode() == IndexedDB::TransactionMode::VersionChange);
     ASSERT(!m_closePending);
@@ -300,6 +323,7 @@ void IDBDatabase::didStartTransaction(IDBTransaction& transaction)
 {
     LOG(IndexedDB, "IDBDatabase::didStartTransaction %s", transaction.info().identifier().loggingString().utf8().data());
     ASSERT(!m_versionChangeTransaction);
+    ASSERT(currentThread() == m_originThreadID);
 
     // It is possible for the client to have aborted a transaction before the server replies back that it has started.
     if (m_abortingTransactions.contains(transaction.info().identifier()))
@@ -312,6 +336,8 @@ void IDBDatabase::willCommitTransaction(IDBTransaction& transaction)
 {
     LOG(IndexedDB, "IDBDatabase::willCommitTransaction %s", transaction.info().identifier().loggingString().utf8().data());
 
+    ASSERT(currentThread() == m_originThreadID);
+
     auto refTransaction = m_activeTransactions.take(transaction.info().identifier());
     ASSERT(refTransaction);
     m_committingTransactions.set(transaction.info().identifier(), WTFMove(refTransaction));
@@ -321,6 +347,8 @@ void IDBDatabase::didCommitTransaction(IDBTransaction& transaction)
 {
     LOG(IndexedDB, "IDBDatabase::didCommitTransaction %s", transaction.info().identifier().loggingString().utf8().data());
 
+    ASSERT(currentThread() == m_originThreadID);
+
     if (m_versionChangeTransaction == &transaction)
         m_info.setVersion(transaction.info().newVersion());
 
@@ -331,6 +359,8 @@ void IDBDatabase::willAbortTransaction(IDBTransaction& transaction)
 {
     LOG(IndexedDB, "IDBDatabase::willAbortTransaction %s", transaction.info().identifier().loggingString().utf8().data());
 
+    ASSERT(currentThread() == m_originThreadID);
+
     auto refTransaction = m_activeTransactions.take(transaction.info().identifier());
     if (!refTransaction)
         refTransaction = m_committingTransactions.take(transaction.info().identifier());
@@ -349,6 +379,8 @@ void IDBDatabase::didAbortTransaction(IDBTransaction& transaction)
 {
     LOG(IndexedDB, "IDBDatabase::didAbortTransaction %s", transaction.info().identifier().loggingString().utf8().data());
 
+    ASSERT(currentThread() == m_originThreadID);
+
     if (transaction.isVersionChange()) {
         ASSERT(transaction.originalDatabaseInfo());
         ASSERT(m_info.version() == transaction.originalDatabaseInfo()->version());
@@ -363,6 +395,8 @@ void IDBDatabase::didCommitOrAbortTransaction(IDBTransaction& transaction)
 {
     LOG(IndexedDB, "IDBDatabase::didCommitOrAbortTransaction %s", transaction.info().identifier().loggingString().utf8().data());
 
+    ASSERT(currentThread() == m_originThreadID);
+
     if (m_versionChangeTransaction == &transaction)
         m_versionChangeTransaction = nullptr;
 
@@ -391,6 +425,8 @@ void IDBDatabase::fireVersionChangeEvent(const IDBResourceIdentifier& requestIde
     uint64_t currentVersion = m_info.version();
     LOG(IndexedDB, "IDBDatabase::fireVersionChangeEvent - current version %" PRIu64 ", requested version %" PRIu64 ", connection %" PRIu64, currentVersion, requestedVersion, m_databaseConnectionIdentifier);
 
+    ASSERT(currentThread() == m_originThreadID);
+
     if (!scriptExecutionContext() || m_closePending) {
         serverConnection().didFireVersionChangeEvent(m_databaseConnectionIdentifier, requestIdentifier);
         return;
@@ -404,6 +440,7 @@ void IDBDatabase::fireVersionChangeEvent(const IDBResourceIdentifier& requestIde
 bool IDBDatabase::dispatchEvent(Event& event)
 {
     LOG(IndexedDB, "IDBDatabase::dispatchEvent (%" PRIu64 ")", m_databaseConnectionIdentifier);
+    ASSERT(currentThread() == m_originThreadID);
 
     bool result = EventTargetWithInlineData::dispatchEvent(event);
 
@@ -415,6 +452,8 @@ bool IDBDatabase::dispatchEvent(Event& event)
 
 void IDBDatabase::didCreateIndexInfo(const IDBIndexInfo& info)
 {
+    ASSERT(currentThread() == m_originThreadID);
+
     auto* objectStore = m_info.infoForExistingObjectStore(info.objectStoreIdentifier());
     ASSERT(objectStore);
     objectStore->addExistingIndex(info);
@@ -422,6 +461,8 @@ void IDBDatabase::didCreateIndexInfo(const IDBIndexInfo& info)
 
 void IDBDatabase::didDeleteIndexInfo(const IDBIndexInfo& info)
 {
+    ASSERT(currentThread() == m_originThreadID);
+
     auto* objectStore = m_info.infoForExistingObjectStore(info.objectStoreIdentifier());
     ASSERT(objectStore);
     objectStore->deleteIndex(info.name());
index c9b8d9a..d98d83a 100644 (file)
@@ -101,6 +101,8 @@ public:
 
     bool hasPendingActivity() const final;
 
+    ThreadIdentifier originThreadID() const { return m_originThreadID; }
+
 private:
     IDBDatabase(ScriptExecutionContext&, IDBClient::IDBConnectionProxy&, const IDBResultData&);
 
@@ -119,6 +121,8 @@ private:
     HashMap<IDBResourceIdentifier, RefPtr<IDBTransaction>> m_activeTransactions;
     HashMap<IDBResourceIdentifier, RefPtr<IDBTransaction>> m_committingTransactions;
     HashMap<IDBResourceIdentifier, RefPtr<IDBTransaction>> m_abortingTransactions;
+
+    ThreadIdentifier m_originThreadID { currentThread() };
 };
 
 } // namespace WebCore
index 4895120..2af7ac0 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "IDBBindingUtilities.h"
 #include "IDBCursor.h"
+#include "IDBDatabase.h"
 #include "IDBDatabaseException.h"
 #include "IDBKeyRangeData.h"
 #include "IDBObjectStore.h"
@@ -46,11 +47,14 @@ IDBIndex::IDBIndex(ScriptExecutionContext& context, const IDBIndexInfo& info, ID
     , m_info(info)
     , m_objectStore(objectStore)
 {
+    ASSERT(currentThread() == m_objectStore.modernTransaction().database().originThreadID());
+
     suspendIfNeeded();
 }
 
 IDBIndex::~IDBIndex()
 {
+    ASSERT(currentThread() == m_objectStore.modernTransaction().database().originThreadID());
 }
 
 const char* IDBIndex::activeDOMObjectName() const
@@ -70,32 +74,38 @@ bool IDBIndex::hasPendingActivity() const
 
 const String& IDBIndex::name() const
 {
+    ASSERT(currentThread() == m_objectStore.modernTransaction().database().originThreadID());
     return m_info.name();
 }
 
 RefPtr<IDBObjectStore> IDBIndex::objectStore()
 {
+    ASSERT(currentThread() == m_objectStore.modernTransaction().database().originThreadID());
     return &m_objectStore;
 }
 
 const IDBKeyPath& IDBIndex::keyPath() const
 {
+    ASSERT(currentThread() == m_objectStore.modernTransaction().database().originThreadID());
     return m_info.keyPath();
 }
 
 bool IDBIndex::unique() const
 {
+    ASSERT(currentThread() == m_objectStore.modernTransaction().database().originThreadID());
     return m_info.unique();
 }
 
 bool IDBIndex::multiEntry() const
 {
+    ASSERT(currentThread() == m_objectStore.modernTransaction().database().originThreadID());
     return m_info.multiEntry();
 }
 
 RefPtr<IDBRequest> IDBIndex::openCursor(ScriptExecutionContext& context, IDBKeyRange* range, const String& directionString, ExceptionCodeWithMessage& ec)
 {
     LOG(IndexedDB, "IDBIndex::openCursor");
+    ASSERT(currentThread() == m_objectStore.modernTransaction().database().originThreadID());
 
     if (m_deleted || m_objectStore.isDeleted()) {
         ec.code = IDBDatabaseException::InvalidStateError;
@@ -128,6 +138,8 @@ RefPtr<IDBRequest> IDBIndex::openCursor(ScriptExecutionContext& context, IDBKeyR
 RefPtr<IDBRequest> IDBIndex::openCursor(ScriptExecutionContext& context, JSValue key, const String& direction, ExceptionCodeWithMessage& ec)
 {
     LOG(IndexedDB, "IDBIndex::openCursor");
+    ASSERT(currentThread() == m_objectStore.modernTransaction().database().originThreadID());
+
     RefPtr<IDBKeyRange> keyRange = IDBKeyRange::only(context, key, ec.code);
     if (ec.code) {
         ec.message = ASCIILiteral("Failed to execute 'openCursor' on 'IDBIndex': The parameter is not a valid key.");
@@ -160,6 +172,8 @@ RefPtr<IDBRequest> IDBIndex::count(ScriptExecutionContext& context, JSValue key,
 
 RefPtr<IDBRequest> IDBIndex::doCount(ScriptExecutionContext& context, const IDBKeyRangeData& range, ExceptionCodeWithMessage& ec)
 {
+    ASSERT(currentThread() == m_objectStore.modernTransaction().database().originThreadID());
+
     if (m_deleted || m_objectStore.isDeleted()) {
         ec.code = IDBDatabaseException::InvalidStateError;
         ec.message = ASCIILiteral("Failed to execute 'count' on 'IDBIndex': The index or its object store has been deleted.");
@@ -184,6 +198,7 @@ RefPtr<IDBRequest> IDBIndex::doCount(ScriptExecutionContext& context, const IDBK
 RefPtr<IDBRequest> IDBIndex::openKeyCursor(ScriptExecutionContext& context, IDBKeyRange* range, const String& directionString, ExceptionCodeWithMessage& ec)
 {
     LOG(IndexedDB, "IDBIndex::openKeyCursor");
+    ASSERT(currentThread() == m_objectStore.modernTransaction().database().originThreadID());
 
     if (m_deleted || m_objectStore.isDeleted()) {
         ec.code = IDBDatabaseException::InvalidStateError;
@@ -241,6 +256,8 @@ RefPtr<IDBRequest> IDBIndex::get(ScriptExecutionContext& context, JSValue key, E
 
 RefPtr<IDBRequest> IDBIndex::doGet(ScriptExecutionContext& context, const IDBKeyRangeData& range, ExceptionCodeWithMessage& ec)
 {
+    ASSERT(currentThread() == m_objectStore.modernTransaction().database().originThreadID());
+
     if (m_deleted || m_objectStore.isDeleted()) {
         ec.code = IDBDatabaseException::InvalidStateError;
         ec.message = ASCIILiteral("Failed to execute 'get' on 'IDBIndex': The index or its object store has been deleted.");
@@ -285,6 +302,8 @@ RefPtr<IDBRequest> IDBIndex::getKey(ScriptExecutionContext& context, JSValue key
 
 RefPtr<IDBRequest> IDBIndex::doGetKey(ScriptExecutionContext& context, const IDBKeyRangeData& range, ExceptionCodeWithMessage& ec)
 {
+    ASSERT(currentThread() == m_objectStore.modernTransaction().database().originThreadID());
+
     if (m_deleted || m_objectStore.isDeleted()) {
         ec.code = IDBDatabaseException::InvalidStateError;
         ec.message = ASCIILiteral("Failed to execute 'getKey' on 'IDBIndex': The index or its object store has been deleted.");
@@ -308,6 +327,8 @@ RefPtr<IDBRequest> IDBIndex::doGetKey(ScriptExecutionContext& context, const IDB
 
 void IDBIndex::markAsDeleted()
 {
+    ASSERT(currentThread() == m_objectStore.modernTransaction().database().originThreadID());
+
     ASSERT(!m_deleted);
     m_deleted = true;
 }
index bcd3257..c53a169 100644 (file)
@@ -63,11 +63,14 @@ IDBObjectStore::IDBObjectStore(ScriptExecutionContext& context, const IDBObjectS
     , m_originalInfo(info)
     , m_transaction(transaction)
 {
+    ASSERT(currentThread() == m_transaction->database().originThreadID());
+
     suspendIfNeeded();
 }
 
 IDBObjectStore::~IDBObjectStore()
 {
+    ASSERT(currentThread() == m_transaction->database().originThreadID());
 }
 
 const char* IDBObjectStore::activeDOMObjectName() const
@@ -87,16 +90,20 @@ bool IDBObjectStore::hasPendingActivity() const
 
 const String& IDBObjectStore::name() const
 {
+    ASSERT(currentThread() == m_transaction->database().originThreadID());
     return m_info.name();
 }
 
 const IDBKeyPath& IDBObjectStore::keyPath() const
 {
+    ASSERT(currentThread() == m_transaction->database().originThreadID());
     return m_info.keyPath();
 }
 
 RefPtr<DOMStringList> IDBObjectStore::indexNames() const
 {
+    ASSERT(currentThread() == m_transaction->database().originThreadID());
+
     RefPtr<DOMStringList> indexNames = DOMStringList::create();
     for (auto& name : m_info.indexNames())
         indexNames->append(name);
@@ -107,17 +114,20 @@ RefPtr<DOMStringList> IDBObjectStore::indexNames() const
 
 RefPtr<IDBTransaction> IDBObjectStore::transaction()
 {
+    ASSERT(currentThread() == m_transaction->database().originThreadID());\
     return &m_transaction.get();
 }
 
 bool IDBObjectStore::autoIncrement() const
 {
+    ASSERT(currentThread() == m_transaction->database().originThreadID());
     return m_info.autoIncrement();
 }
 
 RefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext& context, IDBKeyRange* range, const String& directionString, ExceptionCodeWithMessage& ec)
 {
     LOG(IndexedDB, "IDBObjectStore::openCursor");
+    ASSERT(currentThread() == m_transaction->database().originThreadID());
 
     if (m_deleted) {
         ec.code = IDBDatabaseException::InvalidStateError;
@@ -154,6 +164,7 @@ RefPtr<IDBRequest> IDBObjectStore::openCursor(ScriptExecutionContext& context, J
 RefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext& context, JSValue key, ExceptionCodeWithMessage& ec)
 {
     LOG(IndexedDB, "IDBObjectStore::get");
+    ASSERT(currentThread() == m_transaction->database().originThreadID());
 
     if (!m_transaction->isActive()) {
         ec.code = IDBDatabaseException::TransactionInactiveError;
@@ -181,6 +192,7 @@ RefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext& context, JSValue
 RefPtr<IDBRequest> IDBObjectStore::get(ScriptExecutionContext& context, IDBKeyRange* keyRange, ExceptionCodeWithMessage& ec)
 {
     LOG(IndexedDB, "IDBObjectStore::get");
+    ASSERT(currentThread() == m_transaction->database().originThreadID());
 
     if (!m_transaction->isActive()) {
         ec.code = IDBDatabaseException::TransactionInactiveError;
@@ -227,6 +239,7 @@ RefPtr<IDBRequest> IDBObjectStore::putForCursorUpdate(ExecState& state, JSValue
 RefPtr<IDBRequest> IDBObjectStore::putOrAdd(ExecState& state, JSValue value, RefPtr<IDBKey> key, IndexedDB::ObjectStoreOverwriteMode overwriteMode, InlineKeyCheck inlineKeyCheck, ExceptionCodeWithMessage& ec)
 {
     LOG(IndexedDB, "IDBObjectStore::putOrAdd");
+    ASSERT(currentThread() == m_transaction->database().originThreadID());
 
     auto context = scriptExecutionContextFromExecState(&state);
     if (!context) {
@@ -337,6 +350,7 @@ RefPtr<IDBRequest> IDBObjectStore::deleteFunction(ScriptExecutionContext& contex
 RefPtr<IDBRequest> IDBObjectStore::doDelete(ScriptExecutionContext& context, IDBKeyRange* keyRange, ExceptionCodeWithMessage& ec)
 {
     LOG(IndexedDB, "IDBObjectStore::deleteFunction");
+    ASSERT(currentThread() == m_transaction->database().originThreadID());
 
     // The IDB spec for several IDBObjectStore methods states that transaction related exceptions should fire before
     // the exception for an object store being deleted.
@@ -392,6 +406,7 @@ RefPtr<IDBRequest> IDBObjectStore::modernDelete(ScriptExecutionContext& context,
 RefPtr<IDBRequest> IDBObjectStore::clear(ScriptExecutionContext& context, ExceptionCodeWithMessage& ec)
 {
     LOG(IndexedDB, "IDBObjectStore::clear");
+    ASSERT(currentThread() == m_transaction->database().originThreadID());
 
     // The IDB spec for several IDBObjectStore methods states that transaction related exceptions should fire before
     // the exception for an object store being deleted.
@@ -423,6 +438,7 @@ RefPtr<IDBRequest> IDBObjectStore::clear(ScriptExecutionContext& context, Except
 RefPtr<IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext&, const String& name, const IDBKeyPath& keyPath, bool unique, bool multiEntry, ExceptionCodeWithMessage& ec)
 {
     LOG(IndexedDB, "IDBObjectStore::createIndex %s", name.utf8().data());
+    ASSERT(currentThread() == m_transaction->database().originThreadID());
 
     if (m_deleted) {
         ec.code = IDBDatabaseException::InvalidStateError;
@@ -481,6 +497,7 @@ RefPtr<IDBIndex> IDBObjectStore::createIndex(ScriptExecutionContext&, const Stri
 RefPtr<IDBIndex> IDBObjectStore::index(const String& indexName, ExceptionCodeWithMessage& ec)
 {
     LOG(IndexedDB, "IDBObjectStore::index");
+    ASSERT(currentThread() == m_transaction->database().originThreadID());
 
     if (!scriptExecutionContext())
         return nullptr;
@@ -519,6 +536,7 @@ RefPtr<IDBIndex> IDBObjectStore::index(const String& indexName, ExceptionCodeWit
 void IDBObjectStore::deleteIndex(const String& name, ExceptionCodeWithMessage& ec)
 {
     LOG(IndexedDB, "IDBObjectStore::deleteIndex %s", name.utf8().data());
+    ASSERT(currentThread() == m_transaction->database().originThreadID());
 
     if (m_deleted) {
         ec.code = IDBDatabaseException::InvalidStateError;
@@ -585,6 +603,8 @@ RefPtr<IDBRequest> IDBObjectStore::count(ScriptExecutionContext& context, IDBKey
 
 RefPtr<IDBRequest> IDBObjectStore::doCount(ScriptExecutionContext& context, const IDBKeyRangeData& range, ExceptionCodeWithMessage& ec)
 {
+    ASSERT(currentThread() == m_transaction->database().originThreadID());
+
     // The IDB spec for several IDBObjectStore methods states that transaction related exceptions should fire before
     // the exception for an object store being deleted.
     // However, a handful of W3C IDB tests expect the deleted exception even though the transaction inactive exception also applies.
@@ -612,11 +632,13 @@ RefPtr<IDBRequest> IDBObjectStore::doCount(ScriptExecutionContext& context, cons
 
 void IDBObjectStore::markAsDeleted()
 {
+    ASSERT(currentThread() == m_transaction->database().originThreadID());
     m_deleted = true;
 }
 
 void IDBObjectStore::rollbackInfoForVersionChangeAbort()
 {
+    ASSERT(currentThread() == m_transaction->database().originThreadID());
     m_info = m_originalInfo;
 }
 
index ab4c239..931924b 100644 (file)
@@ -62,16 +62,21 @@ IDBOpenDBRequest::IDBOpenDBRequest(ScriptExecutionContext& context, IDBClient::I
 
 IDBOpenDBRequest::~IDBOpenDBRequest()
 {
+    ASSERT(currentThread() == originThreadID());
 }
 
 void IDBOpenDBRequest::onError(const IDBResultData& data)
 {
+    ASSERT(currentThread() == originThreadID());
+
     m_domError = DOMError::create(data.error().name(), data.error().message());
     enqueueEvent(IDBRequestCompletionEvent::create(eventNames().errorEvent, true, true, *this));
 }
 
 void IDBOpenDBRequest::versionChangeTransactionDidFinish()
 {
+    ASSERT(currentThread() == originThreadID());
+
     // 3.3.7 "versionchange" transaction steps
     // When the transaction is finished, after firing complete/abort on the transaction, immediately set request's transaction property to null.
     m_shouldExposeTransactionToDOM = false;
@@ -81,6 +86,7 @@ void IDBOpenDBRequest::fireSuccessAfterVersionChangeCommit()
 {
     LOG(IndexedDB, "IDBOpenDBRequest::fireSuccessAfterVersionChangeCommit()");
 
+    ASSERT(currentThread() == originThreadID());
     ASSERT(hasPendingActivity());
     m_transaction->addRequest(*this);
 
@@ -94,6 +100,7 @@ void IDBOpenDBRequest::fireErrorAfterVersionChangeCompletion()
 {
     LOG(IndexedDB, "IDBOpenDBRequest::fireErrorAfterVersionChangeCompletion()");
 
+    ASSERT(currentThread() == originThreadID());
     ASSERT(hasPendingActivity());
 
     IDBError idbError(IDBDatabaseException::AbortError);
@@ -106,6 +113,8 @@ void IDBOpenDBRequest::fireErrorAfterVersionChangeCompletion()
 
 bool IDBOpenDBRequest::dispatchEvent(Event& event)
 {
+    ASSERT(currentThread() == originThreadID());
+
     bool result = IDBRequest::dispatchEvent(event);
 
     if (m_transaction && m_transaction->isVersionChange() && (event.type() == eventNames().errorEvent || event.type() == eventNames().successEvent))
@@ -118,6 +127,8 @@ void IDBOpenDBRequest::onSuccess(const IDBResultData& resultData)
 {
     LOG(IndexedDB, "IDBOpenDBRequest::onSuccess()");
 
+    ASSERT(currentThread() == originThreadID());
+
     setResult(IDBDatabase::create(*scriptExecutionContext(), connectionProxy(), resultData));
     m_isDone = true;
 
@@ -126,6 +137,8 @@ void IDBOpenDBRequest::onSuccess(const IDBResultData& resultData)
 
 void IDBOpenDBRequest::onUpgradeNeeded(const IDBResultData& resultData)
 {
+    ASSERT(currentThread() == originThreadID());
+
     Ref<IDBDatabase> database = IDBDatabase::create(*scriptExecutionContext(), connectionProxy(), resultData);
     Ref<IDBTransaction> transaction = database->startVersionChangeTransaction(resultData.transactionInfo(), *this);
 
@@ -147,6 +160,8 @@ void IDBOpenDBRequest::onUpgradeNeeded(const IDBResultData& resultData)
 
 void IDBOpenDBRequest::onDeleteDatabaseSuccess(const IDBResultData& resultData)
 {
+    ASSERT(currentThread() == originThreadID());
+
     uint64_t oldVersion = resultData.databaseInfo().version();
 
     LOG(IndexedDB, "IDBOpenDBRequest::onDeleteDatabaseSuccess() - current version is %" PRIu64, oldVersion);
@@ -161,6 +176,8 @@ void IDBOpenDBRequest::requestCompleted(const IDBResultData& data)
 {
     LOG(IndexedDB, "IDBOpenDBRequest::requestCompleted");
 
+    ASSERT(currentThread() == originThreadID());
+
     // If an Open request was completed after the page has navigated, leaving this request
     // with a stopped script execution context, we need to message back to the server so it
     // doesn't hang waiting on a database connection or transaction that will never exist.
@@ -199,6 +216,8 @@ void IDBOpenDBRequest::requestCompleted(const IDBResultData& data)
 
 void IDBOpenDBRequest::requestBlocked(uint64_t oldVersion, uint64_t newVersion)
 {
+    ASSERT(currentThread() == originThreadID());
+
     LOG(IndexedDB, "IDBOpenDBRequest::requestBlocked");
     enqueueEvent(IDBVersionChangeEvent::create(oldVersion, newVersion, eventNames().blockedEvent));
 }
index 89809e4..fdce290 100644 (file)
@@ -119,17 +119,23 @@ IDBRequest::IDBRequest(ScriptExecutionContext& context, IDBIndex& index, Indexed
 
 IDBRequest::~IDBRequest()
 {
+    ASSERT(currentThread() == m_originThreadID);
+
     if (m_cursorResult)
         m_cursorResult->clearRequest();
 }
 
 unsigned short IDBRequest::errorCode(ExceptionCode&) const
 {
+    ASSERT(currentThread() == m_originThreadID);
+
     return 0;
 }
 
 RefPtr<DOMError> IDBRequest::error(ExceptionCodeWithMessage& ec) const
 {
+    ASSERT(currentThread() == m_originThreadID);
+
     if (m_isDone)
         return m_domError;
 
@@ -140,6 +146,7 @@ RefPtr<DOMError> IDBRequest::error(ExceptionCodeWithMessage& ec) const
 
 void IDBRequest::setSource(IDBCursor& cursor)
 {
+    ASSERT(currentThread() == m_originThreadID);
     ASSERT(!m_cursorRequestNotifier);
 
     m_objectStoreSource = nullptr;
@@ -153,6 +160,7 @@ void IDBRequest::setSource(IDBCursor& cursor)
 
 void IDBRequest::setVersionChangeTransaction(IDBTransaction& transaction)
 {
+    ASSERT(currentThread() == m_originThreadID);
     ASSERT(!m_transaction);
     ASSERT(transaction.isVersionChange());
     ASSERT(!transaction.isFinishedOrFinishing());
@@ -162,11 +170,14 @@ void IDBRequest::setVersionChangeTransaction(IDBTransaction& transaction)
 
 RefPtr<WebCore::IDBTransaction> IDBRequest::transaction() const
 {
+    ASSERT(currentThread() == m_originThreadID);
     return m_shouldExposeTransactionToDOM ? m_transaction : nullptr;
 }
 
 const String& IDBRequest::readyState() const
 {
+    ASSERT(currentThread() == m_originThreadID);
+
     static NeverDestroyed<String> pendingString(ASCIILiteral("pending"));
     static NeverDestroyed<String> doneString(ASCIILiteral("done"));
     return m_isDone ? doneString : pendingString;
@@ -174,6 +185,8 @@ const String& IDBRequest::readyState() const
 
 uint64_t IDBRequest::sourceObjectStoreIdentifier() const
 {
+    ASSERT(currentThread() == m_originThreadID);
+
     if (m_objectStoreSource)
         return m_objectStoreSource->info().identifier();
     if (m_indexSource)
@@ -183,6 +196,8 @@ uint64_t IDBRequest::sourceObjectStoreIdentifier() const
 
 uint64_t IDBRequest::sourceIndexIdentifier() const
 {
+    ASSERT(currentThread() == m_originThreadID);
+
     if (!m_indexSource)
         return 0;
     return m_indexSource->info().identifier();
@@ -190,6 +205,7 @@ uint64_t IDBRequest::sourceIndexIdentifier() const
 
 IndexedDB::IndexRecordType IDBRequest::requestedIndexRecordType() const
 {
+    ASSERT(currentThread() == m_originThreadID);
     ASSERT(m_indexSource);
 
     return m_requestedIndexRecordType;
@@ -197,32 +213,40 @@ IndexedDB::IndexRecordType IDBRequest::requestedIndexRecordType() const
 
 EventTargetInterface IDBRequest::eventTargetInterface() const
 {
+    ASSERT(currentThread() == m_originThreadID);
+
     return IDBRequestEventTargetInterfaceType;
 }
 
 const char* IDBRequest::activeDOMObjectName() const
 {
+    ASSERT(currentThread() == m_originThreadID);
+
     return "IDBRequest";
 }
 
 bool IDBRequest::canSuspendForDocumentSuspension() const
 {
+    ASSERT(currentThread() == m_originThreadID);
     return false;
 }
 
 bool IDBRequest::hasPendingActivity() const
 {
+    ASSERT(currentThread() == m_originThreadID);
     return m_hasPendingActivity;
 }
 
 void IDBRequest::stop()
 {
+    ASSERT(currentThread() == m_originThreadID);
     ASSERT(!m_contextStopped);
     m_contextStopped = true;
 }
 
 void IDBRequest::enqueueEvent(Ref<Event>&& event)
 {
+    ASSERT(currentThread() == m_originThreadID);
     if (!scriptExecutionContext() || m_contextStopped)
         return;
 
@@ -234,6 +258,7 @@ bool IDBRequest::dispatchEvent(Event& event)
 {
     LOG(IndexedDB, "IDBRequest::dispatchEvent - %s (%p)", event.type().string().utf8().data(), this);
 
+    ASSERT(currentThread() == m_originThreadID);
     ASSERT(m_hasPendingActivity);
     ASSERT(!m_contextStopped);
 
@@ -281,12 +306,16 @@ void IDBRequest::uncaughtExceptionInEventHandler()
 {
     LOG(IndexedDB, "IDBRequest::uncaughtExceptionInEventHandler");
 
+    ASSERT(currentThread() == m_originThreadID);
+
     if (m_transaction && m_idbError.code() != IDBDatabaseException::AbortError)
         m_transaction->abortDueToFailedRequest(DOMError::create(IDBDatabaseException::getErrorName(IDBDatabaseException::AbortError), ASCIILiteral("IDBTransaction will abort due to uncaught exception in an event handler")));
 }
 
 void IDBRequest::setResult(const IDBKeyData& keyData)
 {
+    ASSERT(currentThread() == m_originThreadID);
+
     auto* context = scriptExecutionContext();
     if (!context)
         return;
@@ -297,6 +326,8 @@ void IDBRequest::setResult(const IDBKeyData& keyData)
 
 void IDBRequest::setResult(uint64_t number)
 {
+    ASSERT(currentThread() == m_originThreadID);
+
     auto* context = scriptExecutionContext();
     if (!context)
         return;
@@ -307,6 +338,8 @@ void IDBRequest::setResult(uint64_t number)
 
 void IDBRequest::setResultToStructuredClone(const IDBValue& value)
 {
+    ASSERT(currentThread() == m_originThreadID);
+
     LOG(IndexedDB, "IDBRequest::setResultToStructuredClone");
 
     auto* context = scriptExecutionContext();
@@ -319,6 +352,8 @@ void IDBRequest::setResultToStructuredClone(const IDBValue& value)
 
 void IDBRequest::clearResult()
 {
+    ASSERT(currentThread() == m_originThreadID);
+
     m_scriptResult = { };
     m_cursorResult = nullptr;
     m_databaseResult = nullptr;
@@ -326,6 +361,8 @@ void IDBRequest::clearResult()
 
 void IDBRequest::setResultToUndefined()
 {
+    ASSERT(currentThread() == m_originThreadID);
+
     auto* context = scriptExecutionContext();
     if (!context)
         return;
@@ -336,11 +373,14 @@ void IDBRequest::setResultToUndefined()
 
 IDBCursor* IDBRequest::resultCursor()
 {
+    ASSERT(currentThread() == m_originThreadID);
+
     return m_cursorResult.get();
 }
 
 void IDBRequest::willIterateCursor(IDBCursor& cursor)
 {
+    ASSERT(currentThread() == m_originThreadID);
     ASSERT(m_isDone);
     ASSERT(scriptExecutionContext());
     ASSERT(m_transaction);
@@ -362,6 +402,7 @@ void IDBRequest::willIterateCursor(IDBCursor& cursor)
 
 void IDBRequest::didOpenOrIterateCursor(const IDBResultData& resultData)
 {
+    ASSERT(currentThread() == m_originThreadID);
     ASSERT(m_pendingCursor);
 
     clearResult();
@@ -380,6 +421,8 @@ void IDBRequest::didOpenOrIterateCursor(const IDBResultData& resultData)
 
 void IDBRequest::requestCompleted(const IDBResultData& resultData)
 {
+    ASSERT(currentThread() == m_originThreadID);
+
     m_isDone = true;
 
     m_idbError = resultData.error();
@@ -393,7 +436,9 @@ void IDBRequest::onError()
 {
     LOG(IndexedDB, "IDBRequest::onError");
 
+    ASSERT(currentThread() == m_originThreadID);
     ASSERT(!m_idbError.isNull());
+
     m_domError = DOMError::create(m_idbError.name(), m_idbError.message());
     enqueueEvent(Event::create(eventNames().errorEvent, true, true));
 }
@@ -401,12 +446,15 @@ void IDBRequest::onError()
 void IDBRequest::onSuccess()
 {
     LOG(IndexedDB, "IDBRequest::onSuccess");
+    ASSERT(currentThread() == m_originThreadID);
 
     enqueueEvent(Event::create(eventNames().successEvent, false, false));
 }
 
 void IDBRequest::setResult(Ref<IDBDatabase>&& database)
 {
+    ASSERT(currentThread() == m_originThreadID);
+
     clearResult();
     m_databaseResult = WTFMove(database);
 }
index e2463e8..0313184 100644 (file)
@@ -104,6 +104,8 @@ public:
 
     bool hasPendingActivity() const final;
 
+    ThreadIdentifier originThreadID() const { return m_originThreadID; }
+
 protected:
     IDBRequest(ScriptExecutionContext&, IDBClient::IDBConnectionProxy&);
 
@@ -170,6 +172,8 @@ private:
     std::unique_ptr<ScopeGuard> m_cursorRequestNotifier;
 
     Ref<IDBClient::IDBConnectionProxy> m_connectionProxy;
+
+    ThreadIdentifier m_originThreadID { currentThread() };
 };
 
 } // namespace WebCore
index f295c74..c898877 100644 (file)
@@ -131,6 +131,7 @@ IDBTransaction::IDBTransaction(IDBDatabase& database, const IDBTransactionInfo&
 
 {
     LOG(IndexedDB, "IDBTransaction::IDBTransaction - %s", m_info.loggingString().utf8().data());
+    ASSERT(currentThread() == m_database->originThreadID());
 
     relaxAdoptionRequirement();
 
@@ -155,10 +156,13 @@ IDBTransaction::IDBTransaction(IDBDatabase& database, const IDBTransactionInfo&
 
 IDBTransaction::~IDBTransaction()
 {
+    ASSERT(currentThread() == m_database->originThreadID());
 }
 
 const String& IDBTransaction::mode() const
 {
+    ASSERT(currentThread() == m_database->originThreadID());
+
     switch (m_info.mode()) {
     case IndexedDB::TransactionMode::ReadOnly:
         return IDBTransaction::modeReadOnly();
@@ -173,22 +177,26 @@ const String& IDBTransaction::mode() const
 
 WebCore::IDBDatabase* IDBTransaction::db()
 {
+    ASSERT(currentThread() == m_database->originThreadID());
     return &m_database.get();
 }
 
 IDBClient::IDBConnectionToServer& IDBTransaction::serverConnection()
 {
+    ASSERT(currentThread() == m_database->originThreadID());
     return m_database->serverConnection();
 }
 
 RefPtr<DOMError> IDBTransaction::error() const
 {
+    ASSERT(currentThread() == m_database->originThreadID());
     return m_domError;
 }
 
 RefPtr<WebCore::IDBObjectStore> IDBTransaction::objectStore(const String& objectStoreName, ExceptionCodeWithMessage& ec)
 {
     LOG(IndexedDB, "IDBTransaction::objectStore");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     if (!scriptExecutionContext())
         return nullptr;
@@ -235,6 +243,8 @@ RefPtr<WebCore::IDBObjectStore> IDBTransaction::objectStore(const String& object
 void IDBTransaction::abortDueToFailedRequest(DOMError& error)
 {
     LOG(IndexedDB, "IDBTransaction::abortDueToFailedRequest");
+    ASSERT(currentThread() == m_database->originThreadID());
+
     if (isFinishedOrFinishing())
         return;
 
@@ -245,6 +255,8 @@ void IDBTransaction::abortDueToFailedRequest(DOMError& error)
 
 void IDBTransaction::transitionedToFinishing(IndexedDB::TransactionState state)
 {
+    ASSERT(currentThread() == m_database->originThreadID());
+
     ASSERT(!isFinishedOrFinishing());
     m_state = state;
     ASSERT(isFinishedOrFinishing());
@@ -254,6 +266,7 @@ void IDBTransaction::transitionedToFinishing(IndexedDB::TransactionState state)
 void IDBTransaction::abort(ExceptionCodeWithMessage& ec)
 {
     LOG(IndexedDB, "IDBTransaction::abort");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     if (isFinishedOrFinishing()) {
         ec.code = IDBDatabaseException::InvalidStateError;
@@ -279,7 +292,7 @@ void IDBTransaction::abort(ExceptionCodeWithMessage& ec)
 void IDBTransaction::abortOnServerAndCancelRequests(IDBClient::TransactionOperation& operation)
 {
     LOG(IndexedDB, "IDBTransaction::abortOnServerAndCancelRequests");
-
+    ASSERT(currentThread() == m_database->originThreadID());
     ASSERT(m_transactionOperationQueue.isEmpty());
 
     serverConnection().abortTransaction(*this);
@@ -297,22 +310,26 @@ void IDBTransaction::abortOnServerAndCancelRequests(IDBClient::TransactionOperat
 
 const char* IDBTransaction::activeDOMObjectName() const
 {
+    ASSERT(currentThread() == m_database->originThreadID());
     return "IDBTransaction";
 }
 
 bool IDBTransaction::canSuspendForDocumentSuspension() const
 {
+    ASSERT(currentThread() == m_database->originThreadID());
     return false;
 }
 
 bool IDBTransaction::hasPendingActivity() const
 {
+    ASSERT(currentThread() == m_database->originThreadID());
     return !m_contextStopped && m_state != IndexedDB::TransactionState::Finished;
 }
 
 void IDBTransaction::stop()
 {
     LOG(IndexedDB, "IDBTransaction::stop");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     // IDBDatabase::stop() calls IDBTransaction::stop() for each of its active transactions.
     // Since the order of calling ActiveDOMObject::stop() is random, we might already have been stopped.
@@ -330,11 +347,14 @@ void IDBTransaction::stop()
 
 bool IDBTransaction::isActive() const
 {
+    ASSERT(currentThread() == m_database->originThreadID());
     return m_state == IndexedDB::TransactionState::Active;
 }
 
 bool IDBTransaction::isFinishedOrFinishing() const
 {
+    ASSERT(currentThread() == m_database->originThreadID());
+
     return m_state == IndexedDB::TransactionState::Committing
         || m_state == IndexedDB::TransactionState::Aborting
         || m_state == IndexedDB::TransactionState::Finished;
@@ -342,11 +362,13 @@ bool IDBTransaction::isFinishedOrFinishing() const
 
 void IDBTransaction::addRequest(IDBRequest& request)
 {
+    ASSERT(currentThread() == m_database->originThreadID());
     m_openRequests.add(&request);
 }
 
 void IDBTransaction::removeRequest(IDBRequest& request)
 {
+    ASSERT(currentThread() == m_database->originThreadID());
     ASSERT(m_openRequests.contains(&request));
     m_openRequests.remove(&request);
 }
@@ -354,6 +376,7 @@ void IDBTransaction::removeRequest(IDBRequest& request)
 void IDBTransaction::scheduleOperation(RefPtr<IDBClient::TransactionOperation>&& operation)
 {
     ASSERT(!m_transactionOperationMap.contains(operation->identifier()));
+    ASSERT(currentThread() == m_database->originThreadID());
 
     m_transactionOperationQueue.append(operation);
     m_transactionOperationMap.set(operation->identifier(), WTFMove(operation));
@@ -363,6 +386,8 @@ void IDBTransaction::scheduleOperation(RefPtr<IDBClient::TransactionOperation>&&
 
 void IDBTransaction::scheduleOperationTimer()
 {
+    ASSERT(currentThread() == m_database->originThreadID());
+
     if (!m_operationTimer.isActive())
         m_operationTimer.startOneShot(0);
 }
@@ -370,6 +395,7 @@ void IDBTransaction::scheduleOperationTimer()
 void IDBTransaction::operationTimerFired()
 {
     LOG(IndexedDB, "IDBTransaction::operationTimerFired (%p)", this);
+    ASSERT(currentThread() == m_database->originThreadID());
 
     if (!m_startedOnServer)
         return;
@@ -391,7 +417,7 @@ void IDBTransaction::operationTimerFired()
 void IDBTransaction::commit()
 {
     LOG(IndexedDB, "IDBTransaction::commit");
-
+    ASSERT(currentThread() == m_database->originThreadID());
     ASSERT(!isFinishedOrFinishing());
 
     transitionedToFinishing(IndexedDB::TransactionState::Committing);
@@ -404,6 +430,8 @@ void IDBTransaction::commit()
 void IDBTransaction::commitOnServer(IDBClient::TransactionOperation& operation)
 {
     LOG(IndexedDB, "IDBTransaction::commitOnServer");
+    ASSERT(currentThread() == m_database->originThreadID());
+
     serverConnection().commitTransaction(*this);
 
     ASSERT(m_transactionOperationMap.contains(operation.identifier()));
@@ -413,12 +441,15 @@ void IDBTransaction::commitOnServer(IDBClient::TransactionOperation& operation)
 void IDBTransaction::finishAbortOrCommit()
 {
     ASSERT(m_state != IndexedDB::TransactionState::Finished);
+    ASSERT(currentThread() == m_database->originThreadID());
+
     m_state = IndexedDB::TransactionState::Finished;
 }
 
 void IDBTransaction::didStart(const IDBError& error)
 {
     LOG(IndexedDB, "IDBTransaction::didStart");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     m_database->didStartTransaction(*this);
 
@@ -436,6 +467,8 @@ void IDBTransaction::didStart(const IDBError& error)
 
 void IDBTransaction::notifyDidAbort(const IDBError& error)
 {
+    ASSERT(currentThread() == m_database->originThreadID());
+
     m_database->didAbortTransaction(*this);
     m_idbError = error;
     fireOnAbort();
@@ -449,6 +482,7 @@ void IDBTransaction::notifyDidAbort(const IDBError& error)
 void IDBTransaction::didAbort(const IDBError& error)
 {
     LOG(IndexedDB, "IDBTransaction::didAbort");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     if (m_state == IndexedDB::TransactionState::Finished)
         return;
@@ -461,7 +495,7 @@ void IDBTransaction::didAbort(const IDBError& error)
 void IDBTransaction::didCommit(const IDBError& error)
 {
     LOG(IndexedDB, "IDBTransaction::didCommit");
-
+    ASSERT(currentThread() == m_database->originThreadID());
     ASSERT(m_state == IndexedDB::TransactionState::Committing);
 
     if (error.isNull()) {
@@ -478,18 +512,21 @@ void IDBTransaction::didCommit(const IDBError& error)
 void IDBTransaction::fireOnComplete()
 {
     LOG(IndexedDB, "IDBTransaction::fireOnComplete");
+    ASSERT(currentThread() == m_database->originThreadID());
     enqueueEvent(Event::create(eventNames().completeEvent, false, false));
 }
 
 void IDBTransaction::fireOnAbort()
 {
     LOG(IndexedDB, "IDBTransaction::fireOnAbort");
+    ASSERT(currentThread() == m_database->originThreadID());
     enqueueEvent(Event::create(eventNames().abortEvent, true, false));
 }
 
 void IDBTransaction::enqueueEvent(Ref<Event>&& event)
 {
     ASSERT(m_state != IndexedDB::TransactionState::Finished);
+    ASSERT(currentThread() == m_database->originThreadID());
 
     if (!scriptExecutionContext() || m_contextStopped)
         return;
@@ -502,6 +539,7 @@ bool IDBTransaction::dispatchEvent(Event& event)
 {
     LOG(IndexedDB, "IDBTransaction::dispatchEvent");
 
+    ASSERT(currentThread() == m_database->originThreadID());
     ASSERT(scriptExecutionContext());
     ASSERT(!m_contextStopped);
     ASSERT(event.target() == this);
@@ -535,6 +573,7 @@ Ref<IDBObjectStore> IDBTransaction::createObjectStore(const IDBObjectStoreInfo&
     LOG(IndexedDB, "IDBTransaction::createObjectStore");
     ASSERT(isVersionChange());
     ASSERT(scriptExecutionContext());
+    ASSERT(currentThread() == m_database->originThreadID());
 
     Ref<IDBObjectStore> objectStore = IDBObjectStore::create(*scriptExecutionContext(), info, *this);
     m_referencedObjectStores.set(info.name(), &objectStore.get());
@@ -548,7 +587,7 @@ Ref<IDBObjectStore> IDBTransaction::createObjectStore(const IDBObjectStoreInfo&
 void IDBTransaction::createObjectStoreOnServer(IDBClient::TransactionOperation& operation, const IDBObjectStoreInfo& info)
 {
     LOG(IndexedDB, "IDBTransaction::createObjectStoreOnServer");
-
+    ASSERT(currentThread() == m_database->originThreadID());
     ASSERT(isVersionChange());
 
     m_database->serverConnection().createObjectStore(operation, info);
@@ -557,7 +596,7 @@ void IDBTransaction::createObjectStoreOnServer(IDBClient::TransactionOperation&
 void IDBTransaction::didCreateObjectStoreOnServer(const IDBResultData& resultData)
 {
     LOG(IndexedDB, "IDBTransaction::didCreateObjectStoreOnServer");
-
+    ASSERT(currentThread() == m_database->originThreadID());
     ASSERT_UNUSED(resultData, resultData.type() == IDBResultType::CreateObjectStoreSuccess || resultData.type() == IDBResultType::Error);
 }
 
@@ -565,6 +604,7 @@ std::unique_ptr<IDBIndex> IDBTransaction::createIndex(IDBObjectStore& objectStor
 {
     LOG(IndexedDB, "IDBTransaction::createIndex");
     ASSERT(isVersionChange());
+    ASSERT(currentThread() == m_database->originThreadID());
 
     if (!scriptExecutionContext())
         return nullptr;
@@ -578,7 +618,7 @@ std::unique_ptr<IDBIndex> IDBTransaction::createIndex(IDBObjectStore& objectStor
 void IDBTransaction::createIndexOnServer(IDBClient::TransactionOperation& operation, const IDBIndexInfo& info)
 {
     LOG(IndexedDB, "IDBTransaction::createIndexOnServer");
-
+    ASSERT(currentThread() == m_database->originThreadID());
     ASSERT(isVersionChange());
 
     m_database->serverConnection().createIndex(operation, info);
@@ -587,6 +627,7 @@ void IDBTransaction::createIndexOnServer(IDBClient::TransactionOperation& operat
 void IDBTransaction::didCreateIndexOnServer(const IDBResultData& resultData)
 {
     LOG(IndexedDB, "IDBTransaction::didCreateIndexOnServer");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     if (resultData.type() == IDBResultType::CreateIndexSuccess)
         return;
@@ -604,6 +645,7 @@ void IDBTransaction::didCreateIndexOnServer(const IDBResultData& resultData)
 Ref<IDBRequest> IDBTransaction::requestOpenCursor(ScriptExecutionContext& context, IDBObjectStore& objectStore, const IDBCursorInfo& info)
 {
     LOG(IndexedDB, "IDBTransaction::requestOpenCursor");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     return doRequestOpenCursor(context, IDBCursorWithValue::create(*this, objectStore, info));
 }
@@ -611,6 +653,7 @@ Ref<IDBRequest> IDBTransaction::requestOpenCursor(ScriptExecutionContext& contex
 Ref<IDBRequest> IDBTransaction::requestOpenCursor(ScriptExecutionContext& context, IDBIndex& index, const IDBCursorInfo& info)
 {
     LOG(IndexedDB, "IDBTransaction::requestOpenCursor");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     if (info.cursorType() == IndexedDB::CursorType::KeyOnly)
         return doRequestOpenCursor(context, IDBCursor::create(*this, index, info));
@@ -621,6 +664,7 @@ Ref<IDBRequest> IDBTransaction::requestOpenCursor(ScriptExecutionContext& contex
 Ref<IDBRequest> IDBTransaction::doRequestOpenCursor(ScriptExecutionContext& context, Ref<IDBCursor>&& cursor)
 {
     ASSERT(isActive());
+    ASSERT(currentThread() == m_database->originThreadID());
 
     Ref<IDBRequest> request = IDBRequest::create(context, cursor.get(), *this);
     addRequest(request.get());
@@ -634,6 +678,7 @@ Ref<IDBRequest> IDBTransaction::doRequestOpenCursor(ScriptExecutionContext& cont
 void IDBTransaction::openCursorOnServer(IDBClient::TransactionOperation& operation, const IDBCursorInfo& info)
 {
     LOG(IndexedDB, "IDBTransaction::openCursorOnServer");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     m_database->serverConnection().openCursor(operation, info);
 }
@@ -641,6 +686,7 @@ void IDBTransaction::openCursorOnServer(IDBClient::TransactionOperation& operati
 void IDBTransaction::didOpenCursorOnServer(IDBRequest& request, const IDBResultData& resultData)
 {
     LOG(IndexedDB, "IDBTransaction::didOpenCursorOnServer");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     request.didOpenOrIterateCursor(resultData);
 }
@@ -650,6 +696,7 @@ void IDBTransaction::iterateCursor(IDBCursor& cursor, const IDBKeyData& key, uns
     LOG(IndexedDB, "IDBTransaction::iterateCursor");
     ASSERT(isActive());
     ASSERT(cursor.request());
+    ASSERT(currentThread() == m_database->originThreadID());
 
     addRequest(*cursor.request());
 
@@ -660,6 +707,7 @@ void IDBTransaction::iterateCursor(IDBCursor& cursor, const IDBKeyData& key, uns
 void IDBTransaction::iterateCursorOnServer(IDBClient::TransactionOperation& operation, const IDBKeyData& key, const unsigned long& count)
 {
     LOG(IndexedDB, "IDBTransaction::iterateCursorOnServer");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     serverConnection().iterateCursor(operation, key, count);
 }
@@ -667,6 +715,7 @@ void IDBTransaction::iterateCursorOnServer(IDBClient::TransactionOperation& oper
 void IDBTransaction::didIterateCursorOnServer(IDBRequest& request, const IDBResultData& resultData)
 {
     LOG(IndexedDB, "IDBTransaction::didIterateCursorOnServer");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     request.didOpenOrIterateCursor(resultData);
 }
@@ -676,6 +725,7 @@ Ref<IDBRequest> IDBTransaction::requestGetRecord(ScriptExecutionContext& context
     LOG(IndexedDB, "IDBTransaction::requestGetRecord");
     ASSERT(isActive());
     ASSERT(!keyRangeData.isNull);
+    ASSERT(currentThread() == m_database->originThreadID());
 
     Ref<IDBRequest> request = IDBRequest::create(context, objectStore, *this);
     addRequest(request.get());
@@ -689,12 +739,16 @@ Ref<IDBRequest> IDBTransaction::requestGetRecord(ScriptExecutionContext& context
 Ref<IDBRequest> IDBTransaction::requestGetValue(ScriptExecutionContext& context, IDBIndex& index, const IDBKeyRangeData& range)
 {
     LOG(IndexedDB, "IDBTransaction::requestGetValue");
+    ASSERT(currentThread() == m_database->originThreadID());
+
     return requestIndexRecord(context, index, IndexedDB::IndexRecordType::Value, range);
 }
 
 Ref<IDBRequest> IDBTransaction::requestGetKey(ScriptExecutionContext& context, IDBIndex& index, const IDBKeyRangeData& range)
 {
     LOG(IndexedDB, "IDBTransaction::requestGetValue");
+    ASSERT(currentThread() == m_database->originThreadID());
+
     return requestIndexRecord(context, index, IndexedDB::IndexRecordType::Key, range);
 }
 
@@ -703,6 +757,7 @@ Ref<IDBRequest> IDBTransaction::requestIndexRecord(ScriptExecutionContext& conte
     LOG(IndexedDB, "IDBTransaction::requestGetValue");
     ASSERT(isActive());
     ASSERT(!range.isNull);
+    ASSERT(currentThread() == m_database->originThreadID());
 
     Ref<IDBRequest> request = IDBRequest::createGet(context, index, type, *this);
     addRequest(request.get());
@@ -716,6 +771,7 @@ Ref<IDBRequest> IDBTransaction::requestIndexRecord(ScriptExecutionContext& conte
 void IDBTransaction::getRecordOnServer(IDBClient::TransactionOperation& operation, const IDBKeyRangeData& keyRange)
 {
     LOG(IndexedDB, "IDBTransaction::getRecordOnServer");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     serverConnection().getRecord(operation, keyRange);
 }
@@ -723,6 +779,7 @@ void IDBTransaction::getRecordOnServer(IDBClient::TransactionOperation& operatio
 void IDBTransaction::didGetRecordOnServer(IDBRequest& request, const IDBResultData& resultData)
 {
     LOG(IndexedDB, "IDBTransaction::didGetRecordOnServer");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     if (resultData.type() == IDBResultType::Error) {
         request.requestCompleted(resultData);
@@ -753,6 +810,7 @@ Ref<IDBRequest> IDBTransaction::requestCount(ScriptExecutionContext& context, ID
     LOG(IndexedDB, "IDBTransaction::requestCount (IDBObjectStore)");
     ASSERT(isActive());
     ASSERT(!range.isNull);
+    ASSERT(currentThread() == m_database->originThreadID());
 
     Ref<IDBRequest> request = IDBRequest::create(context, objectStore, *this);
     addRequest(request.get());
@@ -767,6 +825,7 @@ Ref<IDBRequest> IDBTransaction::requestCount(ScriptExecutionContext& context, ID
     LOG(IndexedDB, "IDBTransaction::requestCount (IDBIndex)");
     ASSERT(isActive());
     ASSERT(!range.isNull);
+    ASSERT(currentThread() == m_database->originThreadID());
 
     Ref<IDBRequest> request = IDBRequest::createCount(context, index, *this);
     addRequest(request.get());
@@ -779,6 +838,7 @@ Ref<IDBRequest> IDBTransaction::requestCount(ScriptExecutionContext& context, ID
 void IDBTransaction::getCountOnServer(IDBClient::TransactionOperation& operation, const IDBKeyRangeData& keyRange)
 {
     LOG(IndexedDB, "IDBTransaction::getCountOnServer");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     serverConnection().getCount(operation, keyRange);
 }
@@ -786,6 +846,7 @@ void IDBTransaction::getCountOnServer(IDBClient::TransactionOperation& operation
 void IDBTransaction::didGetCountOnServer(IDBRequest& request, const IDBResultData& resultData)
 {
     LOG(IndexedDB, "IDBTransaction::didGetCountOnServer");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     request.setResult(resultData.resultInteger());
     request.requestCompleted(resultData);
@@ -796,6 +857,7 @@ Ref<IDBRequest> IDBTransaction::requestDeleteRecord(ScriptExecutionContext& cont
     LOG(IndexedDB, "IDBTransaction::requestDeleteRecord");
     ASSERT(isActive());
     ASSERT(!range.isNull);
+    ASSERT(currentThread() == m_database->originThreadID());
 
     Ref<IDBRequest> request = IDBRequest::create(context, objectStore, *this);
     addRequest(request.get());
@@ -807,6 +869,7 @@ Ref<IDBRequest> IDBTransaction::requestDeleteRecord(ScriptExecutionContext& cont
 void IDBTransaction::deleteRecordOnServer(IDBClient::TransactionOperation& operation, const IDBKeyRangeData& keyRange)
 {
     LOG(IndexedDB, "IDBTransaction::deleteRecordOnServer");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     serverConnection().deleteRecord(operation, keyRange);
 }
@@ -814,6 +877,7 @@ void IDBTransaction::deleteRecordOnServer(IDBClient::TransactionOperation& opera
 void IDBTransaction::didDeleteRecordOnServer(IDBRequest& request, const IDBResultData& resultData)
 {
     LOG(IndexedDB, "IDBTransaction::didDeleteRecordOnServer");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     request.setResultToUndefined();
     request.requestCompleted(resultData);
@@ -823,6 +887,7 @@ Ref<IDBRequest> IDBTransaction::requestClearObjectStore(ScriptExecutionContext&
 {
     LOG(IndexedDB, "IDBTransaction::requestClearObjectStore");
     ASSERT(isActive());
+    ASSERT(currentThread() == m_database->originThreadID());
 
     Ref<IDBRequest> request = IDBRequest::create(context, objectStore, *this);
     addRequest(request.get());
@@ -837,6 +902,7 @@ Ref<IDBRequest> IDBTransaction::requestClearObjectStore(ScriptExecutionContext&
 void IDBTransaction::clearObjectStoreOnServer(IDBClient::TransactionOperation& operation, const uint64_t& objectStoreIdentifier)
 {
     LOG(IndexedDB, "IDBTransaction::clearObjectStoreOnServer");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     serverConnection().clearObjectStore(operation, objectStoreIdentifier);
 }
@@ -844,6 +910,7 @@ void IDBTransaction::clearObjectStoreOnServer(IDBClient::TransactionOperation& o
 void IDBTransaction::didClearObjectStoreOnServer(IDBRequest& request, const IDBResultData& resultData)
 {
     LOG(IndexedDB, "IDBTransaction::didClearObjectStoreOnServer");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     request.setResultToUndefined();
     request.requestCompleted(resultData);
@@ -855,6 +922,7 @@ Ref<IDBRequest> IDBTransaction::requestPutOrAdd(ScriptExecutionContext& context,
     ASSERT(isActive());
     ASSERT(!isReadOnly());
     ASSERT(objectStore.info().autoIncrement() || key);
+    ASSERT(currentThread() == m_database->originThreadID());
 
     Ref<IDBRequest> request = IDBRequest::create(context, objectStore, *this);
     addRequest(request.get());
@@ -868,7 +936,7 @@ Ref<IDBRequest> IDBTransaction::requestPutOrAdd(ScriptExecutionContext& context,
 void IDBTransaction::putOrAddOnServer(IDBClient::TransactionOperation& operation, RefPtr<IDBKey> key, RefPtr<SerializedScriptValue> value, const IndexedDB::ObjectStoreOverwriteMode& overwriteMode)
 {
     LOG(IndexedDB, "IDBTransaction::putOrAddOnServer");
-
+    ASSERT(currentThread() == m_database->originThreadID());
     ASSERT(!isReadOnly());
     ASSERT(value);
 
@@ -897,6 +965,7 @@ void IDBTransaction::putOrAddOnServer(IDBClient::TransactionOperation& operation
 void IDBTransaction::didPutOrAddOnServer(IDBRequest& request, const IDBResultData& resultData)
 {
     LOG(IndexedDB, "IDBTransaction::didPutOrAddOnServer");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     if (auto* result = resultData.resultKey())
         request.setResult(*result);
@@ -908,7 +977,7 @@ void IDBTransaction::didPutOrAddOnServer(IDBRequest& request, const IDBResultDat
 void IDBTransaction::deleteObjectStore(const String& objectStoreName)
 {
     LOG(IndexedDB, "IDBTransaction::deleteObjectStore");
-
+    ASSERT(currentThread() == m_database->originThreadID());
     ASSERT(isVersionChange());
 
     if (auto objectStore = m_referencedObjectStores.take(objectStoreName))
@@ -922,6 +991,7 @@ void IDBTransaction::deleteObjectStoreOnServer(IDBClient::TransactionOperation&
 {
     LOG(IndexedDB, "IDBTransaction::deleteObjectStoreOnServer");
     ASSERT(isVersionChange());
+    ASSERT(currentThread() == m_database->originThreadID());
 
     serverConnection().deleteObjectStore(operation, objectStoreName);
 }
@@ -929,13 +999,14 @@ void IDBTransaction::deleteObjectStoreOnServer(IDBClient::TransactionOperation&
 void IDBTransaction::didDeleteObjectStoreOnServer(const IDBResultData& resultData)
 {
     LOG(IndexedDB, "IDBTransaction::didDeleteObjectStoreOnServer");
+    ASSERT(currentThread() == m_database->originThreadID());
     ASSERT_UNUSED(resultData, resultData.type() == IDBResultType::DeleteObjectStoreSuccess || resultData.type() == IDBResultType::Error);
 }
 
 void IDBTransaction::deleteIndex(uint64_t objectStoreIdentifier, const String& indexName)
 {
     LOG(IndexedDB, "IDBTransaction::deleteIndex");
-
+    ASSERT(currentThread() == m_database->originThreadID());
     ASSERT(isVersionChange());
 
     auto operation = IDBClient::createTransactionOperation(*this, &IDBTransaction::didDeleteIndexOnServer, &IDBTransaction::deleteIndexOnServer, objectStoreIdentifier, indexName);
@@ -946,6 +1017,7 @@ void IDBTransaction::deleteIndexOnServer(IDBClient::TransactionOperation& operat
 {
     LOG(IndexedDB, "IDBTransaction::deleteIndexOnServer");
     ASSERT(isVersionChange());
+    ASSERT(currentThread() == m_database->originThreadID());
 
     serverConnection().deleteIndex(operation, objectStoreIdentifier, indexName);
 }
@@ -953,12 +1025,15 @@ void IDBTransaction::deleteIndexOnServer(IDBClient::TransactionOperation& operat
 void IDBTransaction::didDeleteIndexOnServer(const IDBResultData& resultData)
 {
     LOG(IndexedDB, "IDBTransaction::didDeleteIndexOnServer");
+    ASSERT(currentThread() == m_database->originThreadID());
     ASSERT_UNUSED(resultData, resultData.type() == IDBResultType::DeleteIndexSuccess || resultData.type() == IDBResultType::Error);
 }
 
 void IDBTransaction::operationDidComplete(IDBClient::TransactionOperation& operation)
 {
     ASSERT(m_transactionOperationMap.get(operation.identifier()) == &operation);
+    ASSERT(currentThread() == m_database->originThreadID());
+
     m_transactionOperationMap.remove(operation.identifier());
 
     scheduleOperationTimer();
@@ -967,12 +1042,15 @@ void IDBTransaction::operationDidComplete(IDBClient::TransactionOperation& opera
 void IDBTransaction::establishOnServer()
 {
     LOG(IndexedDB, "IDBTransaction::establishOnServer");
+    ASSERT(currentThread() == m_database->originThreadID());
 
     serverConnection().establishTransaction(*this);
 }
 
 void IDBTransaction::activate()
 {
+    ASSERT(currentThread() == m_database->originThreadID());
+
     if (isFinishedOrFinishing())
         return;
 
@@ -981,6 +1059,8 @@ void IDBTransaction::activate()
 
 void IDBTransaction::deactivate()
 {
+    ASSERT(currentThread() == m_database->originThreadID());
+
     if (m_state == IndexedDB::TransactionState::Active)
         m_state = IndexedDB::TransactionState::Inactive;