IDBCursor does not need to be an ActiveDOMObject
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Aug 2018 02:43:26 +0000 (02:43 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Aug 2018 02:43:26 +0000 (02:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=188937

Reviewed by Alex Christensen.

Remove ActiveDOMObject from IDBCursor IDL.
Update constructors and call sites accordingly.
This allows removing m_outstandingRequestCount and related code in IDBRequest.

Covered by existing tests.

* Modules/indexeddb/IDBCursor.cpp:
(WebCore::IDBCursor::create):
(WebCore::IDBCursor::IDBCursor):
(WebCore::IDBCursor::update):
(WebCore::IDBCursor::uncheckedIterateCursor):
(WebCore::IDBCursor::deleteFunction):
(WebCore::IDBCursor::activeDOMObjectName const): Deleted.
(WebCore::IDBCursor::canSuspendForDocumentSuspension const): Deleted.
(WebCore::IDBCursor::hasPendingActivity const): Deleted.
(WebCore::IDBCursor::decrementOutstandingRequestCount): Deleted.
* Modules/indexeddb/IDBCursor.h:
* Modules/indexeddb/IDBCursor.idl:
* Modules/indexeddb/IDBCursorWithValue.cpp:
(WebCore::IDBCursorWithValue::create):
(WebCore::IDBCursorWithValue::IDBCursorWithValue):
* Modules/indexeddb/IDBCursorWithValue.h:
* Modules/indexeddb/IDBCursorWithValue.idl:
* Modules/indexeddb/IDBRequest.cpp:
(WebCore::IDBRequest::setSource):
(WebCore::IDBRequest::dispatchEvent):
(WebCore::IDBRequest::willIterateCursor):
(WebCore::IDBRequest::didOpenOrIterateCursor):
* Modules/indexeddb/IDBRequest.h:
* Modules/indexeddb/IDBTransaction.cpp:
(WebCore::IDBTransaction::requestOpenCursor):
* WebCore.xcodeproj/project.pbxproj:

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBCursor.cpp
Source/WebCore/Modules/indexeddb/IDBCursor.h
Source/WebCore/Modules/indexeddb/IDBCursor.idl
Source/WebCore/Modules/indexeddb/IDBCursorWithValue.cpp
Source/WebCore/Modules/indexeddb/IDBCursorWithValue.h
Source/WebCore/Modules/indexeddb/IDBCursorWithValue.idl
Source/WebCore/Modules/indexeddb/IDBRequest.cpp
Source/WebCore/Modules/indexeddb/IDBRequest.h
Source/WebCore/Modules/indexeddb/IDBTransaction.cpp

index 845e8d2..1a4b0b1 100644 (file)
@@ -1,3 +1,43 @@
+2018-08-26  Youenn Fablet  <youenn@apple.com>
+
+        IDBCursor does not need to be an ActiveDOMObject
+        https://bugs.webkit.org/show_bug.cgi?id=188937
+
+        Reviewed by Alex Christensen.
+
+        Remove ActiveDOMObject from IDBCursor IDL.
+        Update constructors and call sites accordingly.
+        This allows removing m_outstandingRequestCount and related code in IDBRequest.
+
+        Covered by existing tests.
+
+        * Modules/indexeddb/IDBCursor.cpp:
+        (WebCore::IDBCursor::create):
+        (WebCore::IDBCursor::IDBCursor):
+        (WebCore::IDBCursor::update):
+        (WebCore::IDBCursor::uncheckedIterateCursor):
+        (WebCore::IDBCursor::deleteFunction):
+        (WebCore::IDBCursor::activeDOMObjectName const): Deleted.
+        (WebCore::IDBCursor::canSuspendForDocumentSuspension const): Deleted.
+        (WebCore::IDBCursor::hasPendingActivity const): Deleted.
+        (WebCore::IDBCursor::decrementOutstandingRequestCount): Deleted.
+        * Modules/indexeddb/IDBCursor.h:
+        * Modules/indexeddb/IDBCursor.idl:
+        * Modules/indexeddb/IDBCursorWithValue.cpp:
+        (WebCore::IDBCursorWithValue::create):
+        (WebCore::IDBCursorWithValue::IDBCursorWithValue):
+        * Modules/indexeddb/IDBCursorWithValue.h:
+        * Modules/indexeddb/IDBCursorWithValue.idl:
+        * Modules/indexeddb/IDBRequest.cpp:
+        (WebCore::IDBRequest::setSource):
+        (WebCore::IDBRequest::dispatchEvent):
+        (WebCore::IDBRequest::willIterateCursor):
+        (WebCore::IDBRequest::didOpenOrIterateCursor):
+        * Modules/indexeddb/IDBRequest.h:
+        * Modules/indexeddb/IDBTransaction.cpp:
+        (WebCore::IDBTransaction::requestOpenCursor):
+        * WebCore.xcodeproj/project.pbxproj:
+
 2018-08-26  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         [Attachment Support] Dropping and pasting images should insert inline image elements with _WKAttachments
index 05db834..dccf9c8 100644 (file)
 namespace WebCore {
 using namespace JSC;
 
-Ref<IDBCursor> IDBCursor::create(IDBTransaction& transaction, IDBObjectStore& objectStore, const IDBCursorInfo& info)
+Ref<IDBCursor> IDBCursor::create(IDBObjectStore& objectStore, const IDBCursorInfo& info)
 {
-    return adoptRef(*new IDBCursor(transaction, objectStore, info));
+    return adoptRef(*new IDBCursor(objectStore, info));
 }
 
-Ref<IDBCursor> IDBCursor::create(IDBTransaction& transaction, IDBIndex& index, const IDBCursorInfo& info)
+Ref<IDBCursor> IDBCursor::create(IDBIndex& index, const IDBCursorInfo& info)
 {
-    return adoptRef(*new IDBCursor(transaction, index, info));
+    return adoptRef(*new IDBCursor(index, info));
 }
 
-IDBCursor::IDBCursor(IDBTransaction& transaction, IDBObjectStore& objectStore, const IDBCursorInfo& info)
-    : ActiveDOMObject(transaction.scriptExecutionContext())
-    , m_info(info)
+IDBCursor::IDBCursor(IDBObjectStore& objectStore, const IDBCursorInfo& info)
+    : m_info(info)
     , m_source(&objectStore)
 {
     ASSERT(&effectiveObjectStore().transaction().database().originThread() == &Thread::current());
-
-    suspendIfNeeded();
 }
 
-IDBCursor::IDBCursor(IDBTransaction& transaction, IDBIndex& index, const IDBCursorInfo& info)
-    : ActiveDOMObject(transaction.scriptExecutionContext())
-    , m_info(info)
+IDBCursor::IDBCursor(IDBIndex& index, const IDBCursorInfo& info)
+    : m_info(info)
     , m_source(&index)
 {
     ASSERT(&effectiveObjectStore().transaction().database().originThread() == &Thread::current());
-
-    suspendIfNeeded();
 }
 
 IDBCursor::~IDBCursor()
@@ -140,7 +134,6 @@ ExceptionOr<Ref<IDBRequest>> IDBCursor::update(ExecState& state, JSValue value)
 
     auto request = putResult.releaseReturnValue();
     request->setSource(*this);
-    ++m_outstandingRequestCount;
 
     return WTFMove(request);
 }
@@ -269,8 +262,6 @@ void IDBCursor::uncheckedIterateCursor(const IDBKeyData& key, unsigned count)
 {
     ASSERT(&effectiveObjectStore().transaction().database().originThread() == &Thread::current());
 
-    ++m_outstandingRequestCount;
-
     m_request->willIterateCursor(*this);
     transaction().iterateCursor(*this, { key, { }, count });
 }
@@ -279,8 +270,6 @@ void IDBCursor::uncheckedIterateCursor(const IDBKeyData& key, const IDBKeyData&
 {
     ASSERT(&effectiveObjectStore().transaction().database().originThread() == &Thread::current());
 
-    ++m_outstandingRequestCount;
-
     m_request->willIterateCursor(*this);
     transaction().iterateCursor(*this, { key, primaryKey, 0 });
 }
@@ -311,7 +300,6 @@ ExceptionOr<Ref<WebCore::IDBRequest>> IDBCursor::deleteFunction(ExecState& state
 
     auto request = result.releaseReturnValue();
     request->setSource(*this);
-    ++m_outstandingRequestCount;
 
     return WTFMove(request);
 }
@@ -357,27 +345,6 @@ void IDBCursor::setGetResult(IDBRequest& request, const IDBGetResult& getResult)
     m_gotValue = true;
 }
 
-const char* IDBCursor::activeDOMObjectName() const
-{
-    return "IDBCursor";
-}
-
-bool IDBCursor::canSuspendForDocumentSuspension() const
-{
-    return false;
-}
-
-bool IDBCursor::hasPendingActivity() const
-{
-    return m_outstandingRequestCount;
-}
-
-void IDBCursor::decrementOutstandingRequestCount()
-{
-    ASSERT(m_outstandingRequestCount);
-    --m_outstandingRequestCount;
-}
-
 } // namespace WebCore
 
 #endif // ENABLE(INDEXED_DATABASE)
index 4903056..b2e043d 100644 (file)
@@ -27,7 +27,6 @@
 
 #if ENABLE(INDEXED_DATABASE)
 
-#include "ActiveDOMObject.h"
 #include "ExceptionOr.h"
 #include "IDBCursorDirection.h"
 #include "IDBCursorInfo.h"
@@ -41,10 +40,10 @@ class IDBIndex;
 class IDBObjectStore;
 class IDBTransaction;
 
-class IDBCursor : public ScriptWrappable, public RefCounted<IDBCursor>, public ActiveDOMObject {
+class IDBCursor : public ScriptWrappable, public RefCounted<IDBCursor> {
 public:
-    static Ref<IDBCursor> create(IDBTransaction&, IDBObjectStore&, const IDBCursorInfo&);
-    static Ref<IDBCursor> create(IDBTransaction&, IDBIndex&, const IDBCursorInfo&);
+    static Ref<IDBCursor> create(IDBObjectStore&, const IDBCursorInfo&);
+    static Ref<IDBCursor> create(IDBIndex&, const IDBCursorInfo&);
     
     virtual ~IDBCursor();
 
@@ -74,18 +73,11 @@ public:
 
     virtual bool isKeyCursorWithValue() const { return false; }
 
-    void decrementOutstandingRequestCount();
-
-    bool hasPendingActivity() const final;
-
 protected:
-    IDBCursor(IDBTransaction&, IDBObjectStore&, const IDBCursorInfo&);
-    IDBCursor(IDBTransaction&, IDBIndex&, const IDBCursorInfo&);
+    IDBCursor(IDBObjectStore&, const IDBCursorInfo&);
+    IDBCursor(IDBIndex&, const IDBCursorInfo&);
 
 private:
-    const char* activeDOMObjectName() const final;
-    bool canSuspendForDocumentSuspension() const final;
-
     bool sourcesDeleted() const;
     IDBObjectStore& effectiveObjectStore() const;
     IDBTransaction& transaction() const;
@@ -93,9 +85,6 @@ private:
     void uncheckedIterateCursor(const IDBKeyData&, unsigned count);
     void uncheckedIterateCursor(const IDBKeyData&, const IDBKeyData&);
 
-    // Cursors are created with an outstanding iteration request.
-    unsigned m_outstandingRequestCount { 1 };
-
     IDBCursorInfo m_info;
     Source m_source;
     IDBRequest* m_request { nullptr };
index 867fa46..bc2b8f2 100644 (file)
@@ -24,7 +24,6 @@
  */
 
 [
-    ActiveDOMObject,
     Conditional=INDEXED_DATABASE,
     CustomToJSObject,
     JSCustomMarkFunction,
index 444f315..810c3d4 100644 (file)
 
 namespace WebCore {
 
-Ref<IDBCursorWithValue> IDBCursorWithValue::create(IDBTransaction& transaction, IDBObjectStore& objectStore, const IDBCursorInfo& info)
+Ref<IDBCursorWithValue> IDBCursorWithValue::create(IDBObjectStore& objectStore, const IDBCursorInfo& info)
 {
-    return adoptRef(*new IDBCursorWithValue(transaction, objectStore, info));
+    return adoptRef(*new IDBCursorWithValue(objectStore, info));
 }
 
-Ref<IDBCursorWithValue> IDBCursorWithValue::create(IDBTransaction& transaction, IDBIndex& index, const IDBCursorInfo& info)
+Ref<IDBCursorWithValue> IDBCursorWithValue::create(IDBIndex& index, const IDBCursorInfo& info)
 {
-    return adoptRef(*new IDBCursorWithValue(transaction, index, info));
+    return adoptRef(*new IDBCursorWithValue(index, info));
 }
 
-IDBCursorWithValue::IDBCursorWithValue(IDBTransaction& transaction, IDBObjectStore& objectStore, const IDBCursorInfo& info)
-    : IDBCursor(transaction, objectStore, info)
+IDBCursorWithValue::IDBCursorWithValue(IDBObjectStore& objectStore, const IDBCursorInfo& info)
+    : IDBCursor(objectStore, info)
 {
 }
 
-IDBCursorWithValue::IDBCursorWithValue(IDBTransaction& transaction, IDBIndex& index, const IDBCursorInfo& info)
-    : IDBCursor(transaction, index, info)
+IDBCursorWithValue::IDBCursorWithValue(IDBIndex& index, const IDBCursorInfo& info)
+    : IDBCursor(index, info)
 {
 }
 
index f78891b..e403f77 100644 (file)
@@ -34,16 +34,16 @@ namespace WebCore {
 
 class IDBCursorWithValue final : public IDBCursor {
 public:
-    static Ref<IDBCursorWithValue> create(IDBTransaction&, IDBObjectStore&, const IDBCursorInfo&);
-    static Ref<IDBCursorWithValue> create(IDBTransaction&, IDBIndex&, const IDBCursorInfo&);
+    static Ref<IDBCursorWithValue> create(IDBObjectStore&, const IDBCursorInfo&);
+    static Ref<IDBCursorWithValue> create(IDBIndex&, const IDBCursorInfo&);
 
     virtual ~IDBCursorWithValue();
 
     bool isKeyCursorWithValue() const  override { return true; }
 
 private:
-    IDBCursorWithValue(IDBTransaction&, IDBObjectStore&, const IDBCursorInfo&);
-    IDBCursorWithValue(IDBTransaction&, IDBIndex&, const IDBCursorInfo&);
+    IDBCursorWithValue(IDBObjectStore&, const IDBCursorInfo&);
+    IDBCursorWithValue(IDBIndex&, const IDBCursorInfo&);
 };
 
 } // namespace WebCore
index 422a1bc..5b047d5 100644 (file)
@@ -25,7 +25,6 @@
 
 [
     Conditional=INDEXED_DATABASE,
-    ActiveDOMObject,
     SkipVTableValidation,
     JSCustomMarkFunction,
 ] interface IDBCursorWithValue : IDBCursor {
index 2c27dfd..3593286 100644 (file)
@@ -174,13 +174,8 @@ ExceptionOr<DOMException*> IDBRequest::error() const
 void IDBRequest::setSource(IDBCursor& cursor)
 {
     ASSERT(&originThread() == &Thread::current());
-    ASSERT(!m_cursorRequestNotifier);
 
     m_source = Source { &cursor };
-    m_cursorRequestNotifier = std::make_unique<WTF::ScopeExit<WTF::Function<void()>>>([this]() {
-        ASSERT(WTF::holds_alternative<RefPtr<IDBCursor>>(m_source.value()));
-        WTF::get<RefPtr<IDBCursor>>(m_source.value())->decrementOutstandingRequestCount();
-    });
 }
 
 void IDBRequest::setVersionChangeTransaction(IDBTransaction& transaction)
@@ -318,8 +313,6 @@ void IDBRequest::dispatchEvent(Event& event)
 
     m_hasPendingActivity = false;
 
-    m_cursorRequestNotifier = nullptr;
-
     {
         TransactionActivator activator(m_transaction.get());
         EventDispatcher::dispatchEvent(targets, event);
@@ -474,7 +467,6 @@ void IDBRequest::willIterateCursor(IDBCursor& cursor)
     ASSERT(m_transaction);
     ASSERT(!m_pendingCursor);
     ASSERT(&cursor == resultCursor());
-    ASSERT(!m_cursorRequestNotifier);
 
     m_pendingCursor = &cursor;
     m_hasPendingActivity = true;
@@ -482,10 +474,6 @@ void IDBRequest::willIterateCursor(IDBCursor& cursor)
     m_readyState = ReadyState::Pending;
     m_domError = nullptr;
     m_idbError = IDBError { };
-
-    m_cursorRequestNotifier = std::make_unique<WTF::ScopeExit<WTF::Function<void()>>>([this]() {
-        m_pendingCursor->decrementOutstandingRequestCount();
-    });
 }
 
 void IDBRequest::didOpenOrIterateCursor(const IDBResultData& resultData)
@@ -501,7 +489,6 @@ void IDBRequest::didOpenOrIterateCursor(const IDBResultData& resultData)
             m_result = Result { m_pendingCursor };
     }
 
-    m_cursorRequestNotifier = nullptr;
     m_pendingCursor = nullptr;
 
     completeRequestAndDispatchEvent(resultData);
index e914344..dd8b4d6 100644 (file)
@@ -173,8 +173,6 @@ private:
 
     RefPtr<IDBCursor> m_pendingCursor;
 
-    std::unique_ptr<WTF::ScopeExit<WTF::Function<void()>>> m_cursorRequestNotifier;
-
     Ref<IDBClient::IDBConnectionProxy> m_connectionProxy;
 };
 
index 4811c7c..6121584 100644 (file)
@@ -800,9 +800,9 @@ Ref<IDBRequest> IDBTransaction::requestOpenCursor(ExecState& state, IDBObjectSto
     ASSERT(&m_database->originThread() == &Thread::current());
 
     if (info.cursorType() == IndexedDB::CursorType::KeyOnly)
-        return doRequestOpenCursor(state, IDBCursor::create(*this, objectStore, info));
+        return doRequestOpenCursor(state, IDBCursor::create(objectStore, info));
 
-    return doRequestOpenCursor(state, IDBCursorWithValue::create(*this, objectStore, info));
+    return doRequestOpenCursor(state, IDBCursorWithValue::create(objectStore, info));
 }
 
 Ref<IDBRequest> IDBTransaction::requestOpenCursor(ExecState& state, IDBIndex& index, const IDBCursorInfo& info)
@@ -811,9 +811,9 @@ Ref<IDBRequest> IDBTransaction::requestOpenCursor(ExecState& state, IDBIndex& in
     ASSERT(&m_database->originThread() == &Thread::current());
 
     if (info.cursorType() == IndexedDB::CursorType::KeyOnly)
-        return doRequestOpenCursor(state, IDBCursor::create(*this, index, info));
+        return doRequestOpenCursor(state, IDBCursor::create(index, info));
 
-    return doRequestOpenCursor(state, IDBCursorWithValue::create(*this, index, info));
+    return doRequestOpenCursor(state, IDBCursorWithValue::create(index, info));
 }
 
 Ref<IDBRequest> IDBTransaction::doRequestOpenCursor(ExecState& state, Ref<IDBCursor>&& cursor)