Changeset 287129 in webkit


Ignore:
Timestamp:
Dec 16, 2021, 3:31:09 AM (4 years ago)
Author:
graouts@webkit.org
Message:

ActiveDOMObject::suspendIfNeeded() should not be called within constructors
https://bugs.webkit.org/show_bug.cgi?id=233945

Reviewed by Darin Adler.

Step 2 where we convert the IDB code to use suspendIfNeeded() only within create() methods. This required
adding such methods and making the constructor private for IDBIndex and IDBObjectStore.

  • Modules/indexeddb/IDBDatabase.cpp:

(WebCore::IDBDatabase::create):
(WebCore::IDBDatabase::IDBDatabase):

  • Modules/indexeddb/IDBDatabaseNameAndVersionRequest.cpp:

(WebCore::IDBDatabaseNameAndVersionRequest::create):
(WebCore::IDBDatabaseNameAndVersionRequest::IDBDatabaseNameAndVersionRequest):

  • Modules/indexeddb/IDBIndex.cpp:

(WebCore::IDBIndex::create):
(WebCore::IDBIndex::IDBIndex):

  • Modules/indexeddb/IDBIndex.h:
  • Modules/indexeddb/IDBObjectStore.cpp:

(WebCore::IDBObjectStore::create):
(WebCore::IDBObjectStore::IDBObjectStore):
(WebCore::IDBObjectStore::index):

  • Modules/indexeddb/IDBObjectStore.h:
  • Modules/indexeddb/IDBOpenDBRequest.cpp:

(WebCore::IDBOpenDBRequest::createDeleteRequest):
(WebCore::IDBOpenDBRequest::createOpenRequest):

  • Modules/indexeddb/IDBRequest.cpp:

(WebCore::IDBRequest::create):
(WebCore::IDBRequest::createObjectStoreGet):
(WebCore::IDBRequest::createIndexGet):
(WebCore::IDBRequest::IDBRequest):

  • Modules/indexeddb/IDBTransaction.cpp:

(WebCore::IDBTransaction::create):
(WebCore::IDBTransaction::IDBTransaction):
(WebCore::IDBTransaction::objectStore):
(WebCore::IDBTransaction::createObjectStore):
(WebCore::IDBTransaction::createIndex):

Location:
trunk/Source/WebCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r287128 r287129  
     12021-12-15  Antoine Quint  <graouts@webkit.org>
     2
     3        ActiveDOMObject::suspendIfNeeded() should not be called within constructors
     4        https://bugs.webkit.org/show_bug.cgi?id=233945
     5
     6        Reviewed by Darin Adler.
     7
     8        Step 2 where we convert the IDB code to use suspendIfNeeded() only within create() methods. This required
     9        adding such methods and making the constructor private for IDBIndex and IDBObjectStore.
     10
     11        * Modules/indexeddb/IDBDatabase.cpp:
     12        (WebCore::IDBDatabase::create):
     13        (WebCore::IDBDatabase::IDBDatabase):
     14        * Modules/indexeddb/IDBDatabaseNameAndVersionRequest.cpp:
     15        (WebCore::IDBDatabaseNameAndVersionRequest::create):
     16        (WebCore::IDBDatabaseNameAndVersionRequest::IDBDatabaseNameAndVersionRequest):
     17        * Modules/indexeddb/IDBIndex.cpp:
     18        (WebCore::IDBIndex::create):
     19        (WebCore::IDBIndex::IDBIndex):
     20        * Modules/indexeddb/IDBIndex.h:
     21        * Modules/indexeddb/IDBObjectStore.cpp:
     22        (WebCore::IDBObjectStore::create):
     23        (WebCore::IDBObjectStore::IDBObjectStore):
     24        (WebCore::IDBObjectStore::index):
     25        * Modules/indexeddb/IDBObjectStore.h:
     26        * Modules/indexeddb/IDBOpenDBRequest.cpp:
     27        (WebCore::IDBOpenDBRequest::createDeleteRequest):
     28        (WebCore::IDBOpenDBRequest::createOpenRequest):
     29        * Modules/indexeddb/IDBRequest.cpp:
     30        (WebCore::IDBRequest::create):
     31        (WebCore::IDBRequest::createObjectStoreGet):
     32        (WebCore::IDBRequest::createIndexGet):
     33        (WebCore::IDBRequest::IDBRequest):
     34        * Modules/indexeddb/IDBTransaction.cpp:
     35        (WebCore::IDBTransaction::create):
     36        (WebCore::IDBTransaction::IDBTransaction):
     37        (WebCore::IDBTransaction::objectStore):
     38        (WebCore::IDBTransaction::createObjectStore):
     39        (WebCore::IDBTransaction::createIndex):
     40
    1412021-12-16  Vitaly Dyachkov  <obyknovenius@me.com>
    242
  • trunk/Source/WebCore/Modules/indexeddb/IDBDatabase.cpp

    r284095 r287129  
    4949Ref<IDBDatabase> IDBDatabase::create(ScriptExecutionContext& context, IDBClient::IDBConnectionProxy& connectionProxy, const IDBResultData& resultData)
    5050{
    51     return adoptRef(*new IDBDatabase(context, connectionProxy, resultData));
     51    auto database = adoptRef(*new IDBDatabase(context, connectionProxy, resultData));
     52    database->suspendIfNeeded();
     53    return database;
    5254}
    5355
     
    6062{
    6163    LOG(IndexedDB, "IDBDatabase::IDBDatabase - Creating database %s with version %" PRIu64 " connection %" PRIu64 " (%p)", m_info.name().utf8().data(), m_info.version(), m_databaseConnectionIdentifier, this);
    62     suspendIfNeeded();
    6364    m_connectionProxy->registerDatabaseConnection(*this);
    6465}
  • trunk/Source/WebCore/Modules/indexeddb/IDBDatabaseNameAndVersionRequest.cpp

    r278253 r287129  
    3737Ref<IDBDatabaseNameAndVersionRequest> IDBDatabaseNameAndVersionRequest::create(ScriptExecutionContext& context, IDBClient::IDBConnectionProxy& connectionProxy, InfoCallback&& callback)
    3838{
    39     return adoptRef(*new IDBDatabaseNameAndVersionRequest(context, connectionProxy, WTFMove(callback)));
     39    auto result = adoptRef(*new IDBDatabaseNameAndVersionRequest(context, connectionProxy, WTFMove(callback)));
     40    result->suspendIfNeeded();
     41    return result;
    4042}
    4143
     
    4749{
    4850    ASSERT(canCurrentThreadAccessThreadLocalData(originThread()));
    49 
    50     suspendIfNeeded();
    5151}
    5252
  • trunk/Source/WebCore/Modules/indexeddb/IDBIndex.cpp

    r284857 r287129  
    4343WTF_MAKE_ISO_ALLOCATED_IMPL(IDBIndex);
    4444
     45UniqueRef<IDBIndex> IDBIndex::create(ScriptExecutionContext& context, const IDBIndexInfo& info, IDBObjectStore& objectStore)
     46{
     47    auto result = UniqueRef(*new IDBIndex(context, info, objectStore));
     48    result->suspendIfNeeded();
     49    return result;
     50}
     51
    4552IDBIndex::IDBIndex(ScriptExecutionContext& context, const IDBIndexInfo& info, IDBObjectStore& objectStore)
    4653    : ActiveDOMObject(&context)
     
    5057{
    5158    ASSERT(canCurrentThreadAccessThreadLocalData(m_objectStore.transaction().database().originThread()));
    52 
    53     suspendIfNeeded();
    5459}
    5560
  • trunk/Source/WebCore/Modules/indexeddb/IDBIndex.h

    r284857 r287129  
    3030#include "IDBRequest.h"
    3131#include <wtf/IsoMalloc.h>
     32#include <wtf/UniqueRef.h>
    3233
    3334namespace JSC {
     
    4445    WTF_MAKE_ISO_ALLOCATED(IDBIndex);
    4546public:
    46     IDBIndex(ScriptExecutionContext&, const IDBIndexInfo&, IDBObjectStore&);
     47    static UniqueRef<IDBIndex> create(ScriptExecutionContext&, const IDBIndexInfo&, IDBObjectStore&);
    4748
    4849    virtual ~IDBIndex();
     
    8687
    8788private:
     89    IDBIndex(ScriptExecutionContext&, const IDBIndexInfo&, IDBObjectStore&);
     90
    8891    ExceptionOr<Ref<IDBRequest>> doCount(const IDBKeyRangeData&);
    8992    ExceptionOr<Ref<IDBRequest>> doGet(ExceptionOr<IDBKeyRangeData>);
  • trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.cpp

    r284857 r287129  
    5656WTF_MAKE_ISO_ALLOCATED_IMPL(IDBObjectStore);
    5757
     58UniqueRef<IDBObjectStore> IDBObjectStore::create(ScriptExecutionContext& context, const IDBObjectStoreInfo& info, IDBTransaction& transaction)
     59{
     60    auto result = UniqueRef(*new IDBObjectStore(context, info, transaction));
     61    result->suspendIfNeeded();
     62    return result;
     63}
     64
    5865IDBObjectStore::IDBObjectStore(ScriptExecutionContext& context, const IDBObjectStoreInfo& info, IDBTransaction& transaction)
    5966    : ActiveDOMObject(&context)
     
    6370{
    6471    ASSERT(canCurrentThreadAccessThreadLocalData(m_transaction.database().originThread()));
    65 
    66     suspendIfNeeded();
    6772}
    6873
     
    521526        return Exception { NotFoundError, "Failed to execute 'index' on 'IDBObjectStore': The specified index was not found."_s };
    522527
    523     auto index = makeUnique<IDBIndex>(*scriptExecutionContext(), *info, *this);
    524 
    525     Ref<IDBIndex> referencedIndex { *index };
    526 
    527     m_referencedIndexes.set(indexName, WTFMove(index));
     528    auto index = IDBIndex::create(*scriptExecutionContext(), *info, *this);
     529
     530    Ref referencedIndex { index.get() };
     531
     532    m_referencedIndexes.set(indexName, index.moveToUniquePtr());
    528533
    529534    return referencedIndex;
  • trunk/Source/WebCore/Modules/indexeddb/IDBObjectStore.h

    r284857 r287129  
    3333#include <wtf/IsoMalloc.h>
    3434#include <wtf/Lock.h>
     35#include <wtf/UniqueRef.h>
    3536
    3637namespace JSC {
     
    6061    WTF_MAKE_ISO_ALLOCATED(IDBObjectStore);
    6162public:
    62     IDBObjectStore(ScriptExecutionContext&, const IDBObjectStoreInfo&, IDBTransaction&);
     63    static UniqueRef<IDBObjectStore> create(ScriptExecutionContext&, const IDBObjectStoreInfo&, IDBTransaction&);
    6364    ~IDBObjectStore();
    6465
     
    114115
    115116private:
     117    IDBObjectStore(ScriptExecutionContext&, const IDBObjectStoreInfo&, IDBTransaction&);
     118
    116119    enum class InlineKeyCheck { Perform, DoNotPerform };
    117120    ExceptionOr<Ref<IDBRequest>> putOrAdd(JSC::JSGlobalObject&, JSC::JSValue, RefPtr<IDBKey>, IndexedDB::ObjectStoreOverwriteMode, InlineKeyCheck, RefPtr<SerializedScriptValue>&& = nullptr);
  • trunk/Source/WebCore/Modules/indexeddb/IDBOpenDBRequest.cpp

    r282755 r287129  
    4747Ref<IDBOpenDBRequest> IDBOpenDBRequest::createDeleteRequest(ScriptExecutionContext& context, IDBClient::IDBConnectionProxy& connectionProxy, const IDBDatabaseIdentifier& databaseIdentifier)
    4848{
    49     return adoptRef(*new IDBOpenDBRequest(context, connectionProxy, databaseIdentifier, 0, IndexedDB::RequestType::Delete));
     49    auto result = adoptRef(*new IDBOpenDBRequest(context, connectionProxy, databaseIdentifier, 0, IndexedDB::RequestType::Delete));
     50    result->suspendIfNeeded();
     51    return result;
    5052}
    5153
    5254Ref<IDBOpenDBRequest> IDBOpenDBRequest::createOpenRequest(ScriptExecutionContext& context, IDBClient::IDBConnectionProxy& connectionProxy, const IDBDatabaseIdentifier& databaseIdentifier, uint64_t version)
    5355{
    54     return adoptRef(*new IDBOpenDBRequest(context, connectionProxy, databaseIdentifier, version, IndexedDB::RequestType::Open));
     56    auto result = adoptRef(*new IDBOpenDBRequest(context, connectionProxy, databaseIdentifier, version, IndexedDB::RequestType::Open));
     57    result->suspendIfNeeded();
     58    return result;
    5559}
    5660   
  • trunk/Source/WebCore/Modules/indexeddb/IDBRequest.cpp

    r284213 r287129  
    5858Ref<IDBRequest> IDBRequest::create(ScriptExecutionContext& context, IDBObjectStore& objectStore, IDBTransaction& transaction)
    5959{
    60     return adoptRef(*new IDBRequest(context, objectStore, transaction));
     60    auto request = adoptRef(*new IDBRequest(context, objectStore, transaction));
     61    request->suspendIfNeeded();
     62    return request;
    6163}
    6264
    6365Ref<IDBRequest> IDBRequest::create(ScriptExecutionContext& context, IDBCursor& cursor, IDBTransaction& transaction)
    6466{
    65     return adoptRef(*new IDBRequest(context, cursor, transaction));
     67    auto request = adoptRef(*new IDBRequest(context, cursor, transaction));
     68    request->suspendIfNeeded();
     69    return request;
    6670}
    6771
    6872Ref<IDBRequest> IDBRequest::create(ScriptExecutionContext& context, IDBIndex& index, IDBTransaction& transaction)
    6973{
    70     return adoptRef(*new IDBRequest(context, index, transaction));
     74    auto request = adoptRef(*new IDBRequest(context, index, transaction));
     75    request->suspendIfNeeded();
     76    return request;
    7177}
    7278
    7379Ref<IDBRequest> IDBRequest::createObjectStoreGet(ScriptExecutionContext& context, IDBObjectStore& objectStore, IndexedDB::ObjectStoreRecordType type, IDBTransaction& transaction)
    7480{
    75     return adoptRef(*new IDBRequest(context, objectStore, type, transaction));
     81    auto request = adoptRef(*new IDBRequest(context, objectStore, type, transaction));
     82    request->suspendIfNeeded();
     83    return request;
    7684}
    7785
    7886Ref<IDBRequest> IDBRequest::createIndexGet(ScriptExecutionContext& context, IDBIndex& index, IndexedDB::IndexRecordType requestedRecordType, IDBTransaction& transaction)
    7987{
    80     return adoptRef(*new IDBRequest(context, index, requestedRecordType, transaction));
     88    auto request = adoptRef(*new IDBRequest(context, index, requestedRecordType, transaction));
     89    request->suspendIfNeeded();
     90    return request;
    8191}
    8292
     
    8898    , m_requestType(requestType)
    8999{
    90     suspendIfNeeded();
    91100}
    92101
     
    99108    , m_connectionProxy(transaction.database().connectionProxy())
    100109{
    101     suspendIfNeeded();
    102110}
    103111
     
    110118    , m_connectionProxy(transaction.database().connectionProxy())
    111119{
    112     suspendIfNeeded();
    113 
    114120    WTF::switchOn(cursor.source(),
    115121        [this] (const auto& value) { this->m_source = IDBRequest::Source { value }; }
     
    127133    , m_connectionProxy(transaction.database().connectionProxy())
    128134{
    129     suspendIfNeeded();
    130135}
    131136
     
    139144    , m_requestedObjectStoreRecordType(type)
    140145{
    141     suspendIfNeeded();
    142146}
    143147
  • trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp

    r284761 r287129  
    6666Ref<IDBTransaction> IDBTransaction::create(IDBDatabase& database, const IDBTransactionInfo& info)
    6767{
    68     return adoptRef(*new IDBTransaction(database, info, nullptr));
     68    auto transaction = adoptRef(*new IDBTransaction(database, info, nullptr));
     69    transaction->suspendIfNeeded();
     70    return transaction;
    6971}
    7072
    7173Ref<IDBTransaction> IDBTransaction::create(IDBDatabase& database, const IDBTransactionInfo& info, IDBOpenDBRequest& request)
    7274{
    73     return adoptRef(*new IDBTransaction(database, info, &request));
     75    auto transaction = adoptRef(*new IDBTransaction(database, info, &request));
     76    transaction->suspendIfNeeded();
     77    return transaction;
    7478}
    7579
     
    103107        establishOnServer();
    104108    }
    105 
    106     suspendIfNeeded();
    107109}
    108110
     
    176178        return Exception { NotFoundError, "Failed to execute 'objectStore' on 'IDBTransaction': The specified object store was not found."_s };
    177179
    178     auto objectStore = makeUnique<IDBObjectStore>(*scriptExecutionContext(), *info, *this);
    179     auto* rawObjectStore = objectStore.get();
    180     m_referencedObjectStores.set(objectStoreName, WTFMove(objectStore));
    181 
    182     return Ref<IDBObjectStore>(*rawObjectStore);
     180    auto objectStore = IDBObjectStore::create(*scriptExecutionContext(), *info, *this);
     181    Ref objectStoreRef { objectStore.get() };
     182    m_referencedObjectStores.set(objectStoreName, objectStore.moveToUniquePtr());
     183
     184    return objectStoreRef;
    183185}
    184186
     
    660662    Locker locker { m_referencedObjectStoreLock };
    661663
    662     auto objectStore = makeUnique<IDBObjectStore>(*scriptExecutionContext(), info, *this);
    663     auto* rawObjectStore = objectStore.get();
    664     m_referencedObjectStores.set(info.name(), WTFMove(objectStore));
     664    auto objectStore = IDBObjectStore::create(*scriptExecutionContext(), info, *this);
     665    Ref objectStoreRef { objectStore.get() };
     666    m_referencedObjectStores.set(info.name(), objectStore.moveToUniquePtr());
    665667
    666668    LOG(IndexedDBOperations, "IDB create object store operation: %s", info.condensedLoggingString().utf8().data());
     
    671673    }), IsWriteOperation::Yes);
    672674
    673     return *rawObjectStore;
     675    return objectStoreRef;
    674676}
    675677
     
    748750    }), IsWriteOperation::Yes);
    749751
    750     return makeUnique<IDBIndex>(*scriptExecutionContext(), info, objectStore);
     752    return IDBIndex::create(*scriptExecutionContext(), info, objectStore).moveToUniquePtr();
    751753}
    752754
Note: See TracChangeset for help on using the changeset viewer.