Diff
Modified: trunk/Source/WebCore/ChangeLog (201355 => 201356)
--- trunk/Source/WebCore/ChangeLog 2016-05-24 21:48:20 UTC (rev 201355)
+++ trunk/Source/WebCore/ChangeLog 2016-05-24 21:57:56 UTC (rev 201356)
@@ -1,3 +1,115 @@
+2016-05-24 Brady Eidson <[email protected]>
+
+ Modern IDB: (Workers) Eliminate race in getting the ScriptExecutionContext and using it.
+ https://bugs.webkit.org/show_bug.cgi?id=158038
+
+ Reviewed by Alex Christensen.
+
+ No new tests (Resolves potential flakes in existing tests).
+
+ When the main thread is trying to post a task to a worker thread's ScriptExecutionContext, there is a race
+ between checking that the context still exists and actually using it.
+
+ The solution is to add a new class - IDBActiveDOMObject - which does a few things things:
+ 1 - Remembers its origin thread.
+ 2 - Guards clearing its ScriptExecutionContext with a Lock.
+ 3 - Adds a templated "performCallbackOnOriginThread" that uses the same Lock to make sure posting the task to
+ the ScriptExecutionContext's RunLoop is safe.
+
+ Also, tons of ASSERTions are updated because each object with an originThread no longer keeps its idea in an
+ accessible member variable.
+
+ * Modules/indexeddb/IDBActiveDOMObject.h:
+ (WebCore::IDBActiveDOMObject::originThreadID):
+ (WebCore::IDBActiveDOMObject::performCallbackOnOriginThread):
+ (WebCore::IDBActiveDOMObject::IDBActiveDOMObject):
+
+ * Modules/indexeddb/IDBDatabase.cpp:
+ (WebCore::IDBDatabase::IDBDatabase):
+ (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::didCloseFromServer):
+ (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): Deleted.
+
+ * Modules/indexeddb/IDBRequest.cpp:
+ (WebCore::IDBRequest::IDBRequest):
+ (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): Deleted.
+
+ * Modules/indexeddb/IDBTransaction.cpp:
+ (WebCore::IDBTransaction::IDBTransaction):
+ (WebCore::IDBTransaction::originThreadID): Deleted.
+ * Modules/indexeddb/IDBTransaction.h:
+
+ * Modules/indexeddb/client/IDBConnectionProxy.cpp:
+ (WebCore::IDBClient::IDBConnectionProxy::completeOpenDBRequest):
+ (WebCore::IDBClient::IDBConnectionProxy::completeOperation):
+ (WebCore::IDBClient::IDBConnectionProxy::fireVersionChangeEvent):
+ (WebCore::IDBClient::IDBConnectionProxy::notifyOpenDBRequestBlocked):
+ (WebCore::IDBClient::IDBConnectionProxy::didStartTransaction):
+ (WebCore::IDBClient::IDBConnectionProxy::didCommitTransaction):
+ (WebCore::IDBClient::IDBConnectionProxy::didAbortTransaction):
+ (WebCore::IDBClient::IDBConnectionProxy::didCloseFromServer):
+ (WebCore::IDBClient::performCallbackOnCorrectThread): Deleted.
+
+ * Modules/indexeddb/client/TransactionOperation.cpp:
+ (WebCore::IDBClient::TransactionOperation::scriptExecutionContext): Deleted.
+ * Modules/indexeddb/client/TransactionOperation.h:
+ (WebCore::IDBClient::TransactionOperation::performCompleteOnOriginThread):
+
+ * WebCore.xcodeproj/project.pbxproj:
+
2016-05-23 Ada Chan <[email protected]>
Only set overflow:hidden on -webkit-media-controls when the placeholder is showing.
Copied: trunk/Source/WebCore/Modules/indexeddb/IDBActiveDOMObject.h (from rev 201355, trunk/Source/WebCore/Modules/indexeddb/client/TransactionOperation.cpp) (0 => 201356)
--- trunk/Source/WebCore/Modules/indexeddb/IDBActiveDOMObject.h (rev 0)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBActiveDOMObject.h 2016-05-24 21:57:56 UTC (rev 201356)
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "ActiveDOMObject.h"
+#include "CrossThreadCopier.h"
+#include "ScriptExecutionContext.h"
+#include <wtf/MainThread.h>
+#include <wtf/Threading.h>
+
+#if ENABLE(INDEXED_DATABASE)
+
+namespace WebCore {
+
+class IDBActiveDOMObject : public ActiveDOMObject {
+public:
+ ThreadIdentifier originThreadID() const { return m_originThreadID; }
+
+ void contextDestroyed() final {
+ Locker<Lock> lock(m_scriptExecutionContextLock);
+ ActiveDOMObject::contextDestroyed();
+ }
+
+ template<typename T, typename... Parameters, typename... Arguments>
+ void performCallbackOnOriginThread(T& object, void (T::*method)(Parameters...), Arguments&&... arguments)
+ {
+ ASSERT(originThreadID() == object.originThreadID());
+
+ if (object.originThreadID() == currentThread()) {
+ (object.*method)(arguments...);
+ return;
+ }
+
+ Locker<Lock> lock(m_scriptExecutionContextLock);
+
+ ScriptExecutionContext* context = scriptExecutionContext();
+ if (!context)
+ return;
+
+ context->postCrossThreadTask(object, method, arguments...);
+ }
+
+protected:
+ IDBActiveDOMObject(ScriptExecutionContext* context)
+ : ActiveDOMObject(context)
+ {
+ ASSERT(context);
+ }
+
+private:
+ ThreadIdentifier m_originThreadID { currentThread() };
+ Lock m_scriptExecutionContextLock;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBDatabase.cpp (201355 => 201356)
--- trunk/Source/WebCore/Modules/indexeddb/IDBDatabase.cpp 2016-05-24 21:48:20 UTC (rev 201355)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBDatabase.cpp 2016-05-24 21:57:56 UTC (rev 201356)
@@ -49,7 +49,7 @@
}
IDBDatabase::IDBDatabase(ScriptExecutionContext& context, IDBClient::IDBConnectionProxy& connectionProxy, const IDBResultData& resultData)
- : WebCore::ActiveDOMObject(&context)
+ : IDBActiveDOMObject(&context)
, m_connectionProxy(connectionProxy)
, m_info(resultData.databaseInfo())
, m_databaseConnectionIdentifier(resultData.databaseConnectionIdentifier())
@@ -61,31 +61,31 @@
IDBDatabase::~IDBDatabase()
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
m_connectionProxy->unregisterDatabaseConnection(*this);
}
bool IDBDatabase::hasPendingActivity() const
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
return !m_closedInServer;
}
const String IDBDatabase::name() const
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
return m_info.name();
}
uint64_t IDBDatabase::version() const
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
return m_info.version();
}
RefPtr<DOMStringList> IDBDatabase::objectStoreNames() const
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
RefPtr<DOMStringList> objectStoreNames = DOMStringList::create();
for (auto& name : m_info.objectStoreNames())
@@ -104,7 +104,7 @@
{
LOG(IndexedDB, "IDBDatabase::createObjectStore - (%s %s)", m_info.name().utf8().data(), name.utf8().data());
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
ASSERT(!m_versionChangeTransaction || m_versionChangeTransaction->isVersionChange());
if (!m_versionChangeTransaction) {
@@ -150,7 +150,7 @@
{
LOG(IndexedDB, "IDBDatabase::transaction");
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
if (m_closePending) {
ec.code = IDBDatabaseException::InvalidStateError;
@@ -201,7 +201,7 @@
RefPtr<WebCore::IDBTransaction> IDBDatabase::transaction(ScriptExecutionContext* context, const String& objectStore, const String& mode, ExceptionCodeWithMessage& ec)
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
Vector<String> objectStores(1);
objectStores[0] = objectStore;
@@ -212,7 +212,7 @@
{
LOG(IndexedDB, "IDBDatabase::deleteObjectStore");
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
if (!m_versionChangeTransaction) {
ec.code = IDBDatabaseException::InvalidStateError;
@@ -239,7 +239,7 @@
{
LOG(IndexedDB, "IDBDatabase::close - %" PRIu64, m_databaseConnectionIdentifier);
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
m_closePending = true;
maybeCloseInServer();
@@ -249,7 +249,7 @@
{
LOG(IndexedDB, "IDBDatabase::didCloseFromServer - %" PRIu64, m_databaseConnectionIdentifier);
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
m_closePending = true;
m_closedInServer = true;
@@ -268,7 +268,7 @@
{
LOG(IndexedDB, "IDBDatabase::maybeCloseInServer - %" PRIu64, m_databaseConnectionIdentifier);
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
if (m_closedInServer)
return;
@@ -285,13 +285,13 @@
const char* IDBDatabase::activeDOMObjectName() const
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
return "IDBDatabase";
}
bool IDBDatabase::canSuspendForDocumentSuspension() const
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
// FIXME: This value will sometimes be false when database operations are actually in progress.
// Such database operations do not yet exist.
@@ -302,7 +302,7 @@
{
LOG(IndexedDB, "IDBDatabase::stop - %" PRIu64, m_databaseConnectionIdentifier);
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
removeAllEventListeners();
@@ -325,7 +325,7 @@
{
LOG(IndexedDB, "IDBDatabase::startVersionChangeTransaction %s", info.identifier().loggingString().utf8().data());
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
ASSERT(!m_versionChangeTransaction);
ASSERT(info.mode() == IndexedDB::TransactionMode::VersionChange);
ASSERT(!m_closePending);
@@ -343,7 +343,7 @@
{
LOG(IndexedDB, "IDBDatabase::didStartTransaction %s", transaction.info().identifier().loggingString().utf8().data());
ASSERT(!m_versionChangeTransaction);
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == 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()))
@@ -356,7 +356,7 @@
{
LOG(IndexedDB, "IDBDatabase::willCommitTransaction %s", transaction.info().identifier().loggingString().utf8().data());
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
auto refTransaction = m_activeTransactions.take(transaction.info().identifier());
ASSERT(refTransaction);
@@ -367,7 +367,7 @@
{
LOG(IndexedDB, "IDBDatabase::didCommitTransaction %s", transaction.info().identifier().loggingString().utf8().data());
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
if (m_versionChangeTransaction == &transaction)
m_info.setVersion(transaction.info().newVersion());
@@ -379,7 +379,7 @@
{
LOG(IndexedDB, "IDBDatabase::willAbortTransaction %s", transaction.info().identifier().loggingString().utf8().data());
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
auto refTransaction = m_activeTransactions.take(transaction.info().identifier());
if (!refTransaction)
@@ -399,7 +399,7 @@
{
LOG(IndexedDB, "IDBDatabase::didAbortTransaction %s", transaction.info().identifier().loggingString().utf8().data());
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
if (transaction.isVersionChange()) {
ASSERT(transaction.originalDatabaseInfo());
@@ -415,7 +415,7 @@
{
LOG(IndexedDB, "IDBDatabase::didCommitOrAbortTransaction %s", transaction.info().identifier().loggingString().utf8().data());
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
if (m_versionChangeTransaction == &transaction)
m_versionChangeTransaction = nullptr;
@@ -445,7 +445,7 @@
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);
+ ASSERT(currentThread() == originThreadID());
if (!scriptExecutionContext() || m_closePending) {
connectionProxy().didFireVersionChangeEvent(m_databaseConnectionIdentifier, requestIdentifier);
@@ -460,7 +460,7 @@
bool IDBDatabase::dispatchEvent(Event& event)
{
LOG(IndexedDB, "IDBDatabase::dispatchEvent (%" PRIu64 ")", m_databaseConnectionIdentifier);
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
bool result = EventTargetWithInlineData::dispatchEvent(event);
@@ -472,7 +472,7 @@
void IDBDatabase::didCreateIndexInfo(const IDBIndexInfo& info)
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
auto* objectStore = m_info.infoForExistingObjectStore(info.objectStoreIdentifier());
ASSERT(objectStore);
@@ -481,7 +481,7 @@
void IDBDatabase::didDeleteIndexInfo(const IDBIndexInfo& info)
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
auto* objectStore = m_info.infoForExistingObjectStore(info.objectStoreIdentifier());
ASSERT(objectStore);
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBDatabase.h (201355 => 201356)
--- trunk/Source/WebCore/Modules/indexeddb/IDBDatabase.h 2016-05-24 21:48:20 UTC (rev 201355)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBDatabase.h 2016-05-24 21:57:56 UTC (rev 201356)
@@ -30,6 +30,7 @@
#include "Dictionary.h"
#include "EventTarget.h"
#include "ExceptionCode.h"
+#include "IDBActiveDOMObject.h"
#include "IDBConnectionProxy.h"
#include "IDBConnectionToServer.h"
#include "IDBDatabaseInfo.h"
@@ -43,7 +44,7 @@
class IDBTransaction;
class IDBTransactionInfo;
-class IDBDatabase : public ThreadSafeRefCounted<IDBDatabase>, public EventTargetWithInlineData, public ActiveDOMObject {
+class IDBDatabase : public ThreadSafeRefCounted<IDBDatabase>, public EventTargetWithInlineData, public IDBActiveDOMObject {
public:
static Ref<IDBDatabase> create(ScriptExecutionContext&, IDBClient::IDBConnectionProxy&, const IDBResultData&);
@@ -99,8 +100,6 @@
bool hasPendingActivity() const final;
- ThreadIdentifier originThreadID() const { return m_originThreadID; }
-
private:
IDBDatabase(ScriptExecutionContext&, IDBClient::IDBConnectionProxy&, const IDBResultData&);
@@ -119,8 +118,6 @@
HashMap<IDBResourceIdentifier, RefPtr<IDBTransaction>> m_activeTransactions;
HashMap<IDBResourceIdentifier, RefPtr<IDBTransaction>> m_committingTransactions;
HashMap<IDBResourceIdentifier, RefPtr<IDBTransaction>> m_abortingTransactions;
-
- ThreadIdentifier m_originThreadID { currentThread() };
};
} // namespace WebCore
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBRequest.cpp (201355 => 201356)
--- trunk/Source/WebCore/Modules/indexeddb/IDBRequest.cpp 2016-05-24 21:48:20 UTC (rev 201355)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBRequest.cpp 2016-05-24 21:57:56 UTC (rev 201356)
@@ -70,7 +70,7 @@
}
IDBRequest::IDBRequest(ScriptExecutionContext& context, IDBClient::IDBConnectionProxy& connectionProxy)
- : ActiveDOMObject(&context)
+ : IDBActiveDOMObject(&context)
, m_resourceIdentifier(connectionProxy.serverConnectionIdentifier())
, m_connectionProxy(connectionProxy)
{
@@ -78,7 +78,7 @@
}
IDBRequest::IDBRequest(ScriptExecutionContext& context, IDBObjectStore& objectStore, IDBTransaction& transaction)
- : ActiveDOMObject(&context)
+ : IDBActiveDOMObject(&context)
, m_transaction(&transaction)
, m_resourceIdentifier(transaction.connectionProxy())
, m_objectStoreSource(&objectStore)
@@ -88,7 +88,7 @@
}
IDBRequest::IDBRequest(ScriptExecutionContext& context, IDBCursor& cursor, IDBTransaction& transaction)
- : ActiveDOMObject(&context)
+ : IDBActiveDOMObject(&context)
, m_transaction(&transaction)
, m_resourceIdentifier(transaction.connectionProxy())
, m_objectStoreSource(cursor.objectStore())
@@ -102,7 +102,7 @@
}
IDBRequest::IDBRequest(ScriptExecutionContext& context, IDBIndex& index, IDBTransaction& transaction)
- : ActiveDOMObject(&context)
+ : IDBActiveDOMObject(&context)
, m_transaction(&transaction)
, m_resourceIdentifier(transaction.connectionProxy())
, m_indexSource(&index)
@@ -119,7 +119,7 @@
IDBRequest::~IDBRequest()
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
if (m_cursorResult)
m_cursorResult->clearRequest();
@@ -127,14 +127,14 @@
unsigned short IDBRequest::errorCode(ExceptionCode&) const
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
return 0;
}
RefPtr<DOMError> IDBRequest::error(ExceptionCodeWithMessage& ec) const
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
if (m_isDone)
return m_domError;
@@ -146,7 +146,7 @@
void IDBRequest::setSource(IDBCursor& cursor)
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
ASSERT(!m_cursorRequestNotifier);
m_objectStoreSource = nullptr;
@@ -160,7 +160,7 @@
void IDBRequest::setVersionChangeTransaction(IDBTransaction& transaction)
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
ASSERT(!m_transaction);
ASSERT(transaction.isVersionChange());
ASSERT(!transaction.isFinishedOrFinishing());
@@ -170,13 +170,13 @@
RefPtr<WebCore::IDBTransaction> IDBRequest::transaction() const
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
return m_shouldExposeTransactionToDOM ? m_transaction : nullptr;
}
const String& IDBRequest::readyState() const
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
static NeverDestroyed<String> pendingString(ASCIILiteral("pending"));
static NeverDestroyed<String> doneString(ASCIILiteral("done"));
@@ -185,7 +185,7 @@
uint64_t IDBRequest::sourceObjectStoreIdentifier() const
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
if (m_objectStoreSource)
return m_objectStoreSource->info().identifier();
@@ -196,7 +196,7 @@
uint64_t IDBRequest::sourceIndexIdentifier() const
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
if (!m_indexSource)
return 0;
@@ -205,7 +205,7 @@
IndexedDB::IndexRecordType IDBRequest::requestedIndexRecordType() const
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
ASSERT(m_indexSource);
return m_requestedIndexRecordType;
@@ -213,33 +213,33 @@
EventTargetInterface IDBRequest::eventTargetInterface() const
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
return IDBRequestEventTargetInterfaceType;
}
const char* IDBRequest::activeDOMObjectName() const
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
return "IDBRequest";
}
bool IDBRequest::canSuspendForDocumentSuspension() const
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
return false;
}
bool IDBRequest::hasPendingActivity() const
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
return m_hasPendingActivity;
}
void IDBRequest::stop()
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
ASSERT(!m_contextStopped);
cancelForStop();
@@ -256,7 +256,7 @@
void IDBRequest::enqueueEvent(Ref<Event>&& event)
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
if (!scriptExecutionContext() || m_contextStopped)
return;
@@ -268,7 +268,7 @@
{
LOG(IndexedDB, "IDBRequest::dispatchEvent - %s (%p)", event.type().string().utf8().data(), this);
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
ASSERT(m_hasPendingActivity);
ASSERT(!m_contextStopped);
@@ -316,7 +316,7 @@
{
LOG(IndexedDB, "IDBRequest::uncaughtExceptionInEventHandler");
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == 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")));
@@ -324,7 +324,7 @@
void IDBRequest::setResult(const IDBKeyData& keyData)
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
auto* context = scriptExecutionContext();
if (!context)
@@ -336,7 +336,7 @@
void IDBRequest::setResult(uint64_t number)
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
auto* context = scriptExecutionContext();
if (!context)
@@ -348,7 +348,7 @@
void IDBRequest::setResultToStructuredClone(const IDBValue& value)
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
LOG(IndexedDB, "IDBRequest::setResultToStructuredClone");
@@ -362,7 +362,7 @@
void IDBRequest::clearResult()
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
m_scriptResult = { };
m_cursorResult = nullptr;
@@ -371,7 +371,7 @@
void IDBRequest::setResultToUndefined()
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
auto* context = scriptExecutionContext();
if (!context)
@@ -383,14 +383,14 @@
IDBCursor* IDBRequest::resultCursor()
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
return m_cursorResult.get();
}
void IDBRequest::willIterateCursor(IDBCursor& cursor)
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
ASSERT(m_isDone);
ASSERT(scriptExecutionContext());
ASSERT(m_transaction);
@@ -412,7 +412,7 @@
void IDBRequest::didOpenOrIterateCursor(const IDBResultData& resultData)
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
ASSERT(m_pendingCursor);
clearResult();
@@ -431,7 +431,7 @@
void IDBRequest::requestCompleted(const IDBResultData& resultData)
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
m_isDone = true;
@@ -446,7 +446,7 @@
{
LOG(IndexedDB, "IDBRequest::onError");
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
ASSERT(!m_idbError.isNull());
m_domError = DOMError::create(m_idbError.name(), m_idbError.message());
@@ -456,14 +456,14 @@
void IDBRequest::onSuccess()
{
LOG(IndexedDB, "IDBRequest::onSuccess");
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
enqueueEvent(Event::create(eventNames().successEvent, false, false));
}
void IDBRequest::setResult(Ref<IDBDatabase>&& database)
{
- ASSERT(currentThread() == m_originThreadID);
+ ASSERT(currentThread() == originThreadID());
clearResult();
m_databaseResult = WTFMove(database);
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBRequest.h (201355 => 201356)
--- trunk/Source/WebCore/Modules/indexeddb/IDBRequest.h 2016-05-24 21:48:20 UTC (rev 201355)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBRequest.h 2016-05-24 21:57:56 UTC (rev 201356)
@@ -27,8 +27,8 @@
#if ENABLE(INDEXED_DATABASE)
-#include "ActiveDOMObject.h"
#include "EventTarget.h"
+#include "IDBActiveDOMObject.h"
#include "IDBError.h"
#include "IDBResourceIdentifier.h"
#include "IndexedDB.h"
@@ -52,7 +52,7 @@
class IDBConnectionToServer;
}
-class IDBRequest : public EventTargetWithInlineData, private ActiveDOMObject, public RefCounted<IDBRequest> {
+class IDBRequest : public EventTargetWithInlineData, public IDBActiveDOMObject, public RefCounted<IDBRequest> {
public:
static Ref<IDBRequest> create(ScriptExecutionContext&, IDBObjectStore&, IDBTransaction&);
static Ref<IDBRequest> create(ScriptExecutionContext&, IDBCursor&, IDBTransaction&);
@@ -104,8 +104,6 @@
bool hasPendingActivity() const final;
- ThreadIdentifier originThreadID() const { return m_originThreadID; }
-
protected:
IDBRequest(ScriptExecutionContext&, IDBClient::IDBConnectionProxy&);
@@ -173,8 +171,6 @@
std::unique_ptr<ScopeGuard> m_cursorRequestNotifier;
Ref<IDBClient::IDBConnectionProxy> m_connectionProxy;
-
- ThreadIdentifier m_originThreadID { currentThread() };
};
} // namespace WebCore
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp (201355 => 201356)
--- trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp 2016-05-24 21:48:20 UTC (rev 201355)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp 2016-05-24 21:57:56 UTC (rev 201356)
@@ -123,7 +123,7 @@
}
IDBTransaction::IDBTransaction(IDBDatabase& database, const IDBTransactionInfo& info, IDBOpenDBRequest* request)
- : WebCore::ActiveDOMObject(database.scriptExecutionContext())
+ : IDBActiveDOMObject(database.scriptExecutionContext())
, m_database(database)
, m_info(info)
, m_operationTimer(*this, &IDBTransaction::operationTimerFired)
@@ -1091,11 +1091,6 @@
scheduleOperationTimer();
}
-ThreadIdentifier IDBTransaction::originThreadID() const
-{
- return m_database->originThreadID();
-}
-
void IDBTransaction::connectionClosedFromServer(const IDBError& error)
{
LOG(IndexedDB, "IDBTransaction::connectionClosedFromServer - %s", error.message().utf8().data());
Modified: trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.h (201355 => 201356)
--- trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.h 2016-05-24 21:48:20 UTC (rev 201355)
+++ trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.h 2016-05-24 21:57:56 UTC (rev 201356)
@@ -27,8 +27,8 @@
#if ENABLE(INDEXED_DATABASE)
-#include "ActiveDOMObject.h"
#include "EventTarget.h"
+#include "IDBActiveDOMObject.h"
#include "IDBError.h"
#include "IDBOpenDBRequest.h"
#include "IDBTransactionInfo.h"
@@ -59,7 +59,7 @@
class TransactionOperation;
}
-class IDBTransaction : public ThreadSafeRefCounted<IDBTransaction>, public EventTargetWithInlineData, private ActiveDOMObject {
+class IDBTransaction : public ThreadSafeRefCounted<IDBTransaction>, public EventTargetWithInlineData, public IDBActiveDOMObject {
public:
static const AtomicString& modeReadOnly();
static const AtomicString& modeReadWrite();
@@ -143,8 +143,6 @@
IDBClient::IDBConnectionProxy& connectionProxy();
- ThreadIdentifier originThreadID() const;
-
void connectionClosedFromServer(const IDBError&);
private:
Modified: trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionProxy.cpp (201355 => 201356)
--- trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionProxy.cpp 2016-05-24 21:48:20 UTC (rev 201355)
+++ trunk/Source/WebCore/Modules/indexeddb/client/IDBConnectionProxy.cpp 2016-05-24 21:57:56 UTC (rev 201356)
@@ -41,23 +41,6 @@
namespace WebCore {
namespace IDBClient {
-template<typename T, typename... Parameters, typename... Arguments>
-void performCallbackOnCorrectThread(T& object, void (T::*method)(Parameters...), Arguments&&... arguments)
-{
- ASSERT(isMainThread());
-
- if (object.originThreadID() == currentThread()) {
- (object.*method)(arguments...);
- return;
- }
-
- ScriptExecutionContext* context = object.scriptExecutionContext();
- if (!context)
- return;
-
- context->postCrossThreadTask(object, method, arguments...);
-}
-
IDBConnectionProxy::IDBConnectionProxy(IDBConnectionToServer& connection)
: m_connectionToServer(connection)
, m_serverConnectionIdentifier(connection.identifier())
@@ -142,7 +125,7 @@
ASSERT(request);
- performCallbackOnCorrectThread(*request, &IDBOpenDBRequest::requestCompleted, resultData);
+ request->performCallbackOnOriginThread(*request, &IDBOpenDBRequest::requestCompleted, resultData);
}
void IDBConnectionProxy::createObjectStore(TransactionOperation& operation, const IDBObjectStoreInfo& info)
@@ -252,7 +235,7 @@
if (!operation)
return;
- performCallbackOnCorrectThread(*operation, &TransactionOperation::completed, resultData);
+ operation->performCompleteOnOriginThread(resultData);
}
void IDBConnectionProxy::abortOpenAndUpgradeNeeded(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& transactionIdentifier)
@@ -271,7 +254,7 @@
if (!database)
return;
- performCallbackOnCorrectThread(*database, &IDBDatabase::fireVersionChangeEvent, requestIdentifier, requestedVersion);
+ database->performCallbackOnOriginThread(*database, &IDBDatabase::fireVersionChangeEvent, requestIdentifier, requestedVersion);
}
void IDBConnectionProxy::didFireVersionChangeEvent(uint64_t databaseConnectionIdentifier, const IDBResourceIdentifier& requestIdentifier)
@@ -291,7 +274,7 @@
ASSERT(request);
- performCallbackOnCorrectThread(*request, &IDBOpenDBRequest::requestBlocked, oldVersion, newVersion);
+ request->performCallbackOnOriginThread(*request, &IDBOpenDBRequest::requestBlocked, oldVersion, newVersion);
}
void IDBConnectionProxy::openDBRequestCancelled(const IDBRequestData& requestData)
@@ -320,7 +303,7 @@
ASSERT(transaction);
- performCallbackOnCorrectThread(*transaction, &IDBTransaction::didStart, error);
+ transaction->performCallbackOnOriginThread(*transaction, &IDBTransaction::didStart, error);
}
void IDBConnectionProxy::commitTransaction(IDBTransaction& transaction)
@@ -344,7 +327,7 @@
ASSERT(transaction);
- performCallbackOnCorrectThread(*transaction, &IDBTransaction::didCommit, error);
+ transaction->performCallbackOnOriginThread(*transaction, &IDBTransaction::didCommit, error);
}
void IDBConnectionProxy::abortTransaction(IDBTransaction& transaction)
@@ -368,7 +351,7 @@
ASSERT(transaction);
- performCallbackOnCorrectThread(*transaction, &IDBTransaction::didAbort, error);
+ transaction->performCallbackOnOriginThread(*transaction, &IDBTransaction::didAbort, error);
}
bool IDBConnectionProxy::hasRecordOfTransaction(const IDBTransaction& transaction) const
@@ -404,7 +387,7 @@
return;
}
- performCallbackOnCorrectThread(*database, &IDBDatabase::didCloseFromServer, error);
+ database->performCallbackOnOriginThread(*database, &IDBDatabase::didCloseFromServer, error);
}
void IDBConnectionProxy::confirmDidCloseFromServer(IDBDatabase& database)
Modified: trunk/Source/WebCore/Modules/indexeddb/client/TransactionOperation.cpp (201355 => 201356)
--- trunk/Source/WebCore/Modules/indexeddb/client/TransactionOperation.cpp 2016-05-24 21:48:20 UTC (rev 201355)
+++ trunk/Source/WebCore/Modules/indexeddb/client/TransactionOperation.cpp 2016-05-24 21:57:56 UTC (rev 201356)
@@ -44,11 +44,6 @@
m_cursorIdentifier = std::make_unique<IDBResourceIdentifier>(cursor->info().identifier());
}
-ScriptExecutionContext* TransactionOperation::scriptExecutionContext() const
-{
- return m_transaction->scriptExecutionContext();
-}
-
} // namespace IDBClient
} // namespace WebCore
Modified: trunk/Source/WebCore/Modules/indexeddb/client/TransactionOperation.h (201355 => 201356)
--- trunk/Source/WebCore/Modules/indexeddb/client/TransactionOperation.h 2016-05-24 21:48:20 UTC (rev 201355)
+++ trunk/Source/WebCore/Modules/indexeddb/client/TransactionOperation.h 2016-05-24 21:57:56 UTC (rev 201356)
@@ -31,7 +31,9 @@
#include "IDBRequest.h"
#include "IDBRequestData.h"
#include "IDBResourceIdentifier.h"
+#include "IDBResultData.h"
#include "IDBTransaction.h"
+#include <wtf/MainThread.h>
#include <wtf/Threading.h>
namespace WebCore {
@@ -60,6 +62,16 @@
m_performFunction = { };
}
+ void performCompleteOnOriginThread(const IDBResultData& data)
+ {
+ ASSERT(isMainThread());
+
+ if (m_originThreadID == currentThread())
+ completed(data);
+ else
+ m_transaction->performCallbackOnOriginThread(*this, &TransactionOperation::completed, data);
+ }
+
void completed(const IDBResultData& data)
{
ASSERT(m_originThreadID == currentThread());
@@ -77,8 +89,6 @@
ThreadIdentifier originThreadID() const { return m_originThreadID; }
- ScriptExecutionContext* scriptExecutionContext() const;
-
protected:
TransactionOperation(IDBTransaction& transaction)
: m_transaction(transaction)
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (201355 => 201356)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2016-05-24 21:48:20 UTC (rev 201355)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2016-05-24 21:57:56 UTC (rev 201356)
@@ -2071,6 +2071,7 @@
517139061BF64DEC000D5F01 /* MemoryObjectStoreCursor.h in Headers */ = {isa = PBXBuildFile; fileRef = 517139041BF64DE3000D5F01 /* MemoryObjectStoreCursor.h */; };
517139071BF64DEF000D5F01 /* MemoryCursor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 517139011BF64DE3000D5F01 /* MemoryCursor.cpp */; };
517139081BF64DEF000D5F01 /* MemoryCursor.h in Headers */ = {isa = PBXBuildFile; fileRef = 517139021BF64DE3000D5F01 /* MemoryCursor.h */; };
+ 51714EA81CF4E4B1004723C4 /* IDBActiveDOMObject.h in Headers */ = {isa = PBXBuildFile; fileRef = 51714EA71CF4DE87004723C4 /* IDBActiveDOMObject.h */; settings = {ATTRIBUTES = (Private, ); }; };
51741D0F0B07259A00ED442C /* BackForwardClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 51741D0B0B07259A00ED442C /* BackForwardClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
51741D110B07259A00ED442C /* HistoryItem.h in Headers */ = {isa = PBXBuildFile; fileRef = 51741D0D0B07259A00ED442C /* HistoryItem.h */; settings = {ATTRIBUTES = (Private, ); }; };
51741D120B07259A00ED442C /* HistoryItem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51741D0E0B07259A00ED442C /* HistoryItem.cpp */; };
@@ -9662,6 +9663,7 @@
517139021BF64DE3000D5F01 /* MemoryCursor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryCursor.h; sourceTree = "<group>"; };
517139031BF64DE3000D5F01 /* MemoryObjectStoreCursor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MemoryObjectStoreCursor.cpp; sourceTree = "<group>"; };
517139041BF64DE3000D5F01 /* MemoryObjectStoreCursor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryObjectStoreCursor.h; sourceTree = "<group>"; };
+ 51714EA71CF4DE87004723C4 /* IDBActiveDOMObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDBActiveDOMObject.h; sourceTree = "<group>"; };
51741D0B0B07259A00ED442C /* BackForwardClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BackForwardClient.h; sourceTree = "<group>"; };
51741D0D0B07259A00ED442C /* HistoryItem.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = HistoryItem.h; sourceTree = "<group>"; };
51741D0E0B07259A00ED442C /* HistoryItem.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = HistoryItem.cpp; sourceTree = "<group>"; };
@@ -19566,6 +19568,7 @@
51D7196C181106DF0016DC51 /* DOMWindowIndexedDatabase.cpp */,
51D7196D181106DF0016DC51 /* DOMWindowIndexedDatabase.h */,
51D7196E181106DF0016DC51 /* DOMWindowIndexedDatabase.idl */,
+ 51714EA71CF4DE87004723C4 /* IDBActiveDOMObject.h */,
51645B541B9F88E800F789CE /* IDBCursor.cpp */,
51645B411B9F889B00F789CE /* IDBCursor.h */,
51D71977181106DF0016DC51 /* IDBCursor.idl */,
@@ -25058,6 +25061,7 @@
31DCD29D1AB4FBDE0072E817 /* AnimationTrigger.h in Headers */,
0F580FAF149800D400FB5BD8 /* AnimationUtilities.h in Headers */,
93309DD7099E64920056E581 /* AppendNodeCommand.h in Headers */,
+ 51714EA81CF4E4B1004723C4 /* IDBActiveDOMObject.h in Headers */,
1A8F6BBD0DB55CDC001DB794 /* ApplicationCache.h in Headers */,
1A8F6BBF0DB55CDC001DB794 /* ApplicationCacheGroup.h in Headers */,
24F54EAD101FE914000AE741 /* ApplicationCacheHost.h in Headers */,