Changeset 235345 in webkit


Ignore:
Timestamp:
Aug 26, 2018 7:44:15 PM (6 years ago)
Author:
youenn@apple.com
Message:

Make IDBCursor::m_request a WeakPtr
https://bugs.webkit.org/show_bug.cgi?id=188938

Reviewed by Alex Christensen.

Make m_request a WeakPtr so that if m_request is destroyed, the related cursor will not use the invalid pointer.

Covered by existing tests.

  • Modules/indexeddb/IDBCursor.cpp:

(WebCore::IDBCursor::continuePrimaryKey): Other continue and advance methods that are calling uncheckedIterateCursor do check for m_request.
Apply the same check for continuePrimaryKey.
(WebCore::IDBCursor::uncheckedIterateCursor):

  • Modules/indexeddb/IDBCursor.h:

(WebCore::IDBCursor::setRequest):
(WebCore::IDBCursor::clearRequest):
(WebCore::IDBCursor::request):

  • Modules/indexeddb/IDBRequest.h:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r235344 r235345  
     12018-08-26  Youenn Fablet  <youenn@apple.com>
     2
     3        Make IDBCursor::m_request a WeakPtr
     4        https://bugs.webkit.org/show_bug.cgi?id=188938
     5
     6        Reviewed by Alex Christensen.
     7
     8        Make m_request a WeakPtr so that if m_request is destroyed, the related cursor will not use the invalid pointer.
     9
     10        Covered by existing tests.
     11
     12        * Modules/indexeddb/IDBCursor.cpp:
     13        (WebCore::IDBCursor::continuePrimaryKey): Other continue and advance methods that are calling uncheckedIterateCursor do check for m_request.
     14        Apply the same check for continuePrimaryKey.
     15        (WebCore::IDBCursor::uncheckedIterateCursor):
     16        * Modules/indexeddb/IDBCursor.h:
     17        (WebCore::IDBCursor::setRequest):
     18        (WebCore::IDBCursor::clearRequest):
     19        (WebCore::IDBCursor::request):
     20        * Modules/indexeddb/IDBRequest.h:
     21
    1222018-08-26  Youenn Fablet  <youenn@apple.com>
    223
  • trunk/Source/WebCore/Modules/indexeddb/IDBCursor.cpp

    r235344 r235345  
    168168ExceptionOr<void> IDBCursor::continuePrimaryKey(ExecState& state, JSValue keyValue, JSValue primaryKeyValue)
    169169{
     170    if (!m_request)
     171        return Exception { InvalidStateError };
     172
    170173    if (!transaction().isActive())
    171174        return Exception { TransactionInactiveError, "Failed to execute 'continuePrimaryKey' on 'IDBCursor': The transaction is inactive or finished."_s };
     
    261264void IDBCursor::uncheckedIterateCursor(const IDBKeyData& key, unsigned count)
    262265{
     266    ASSERT(m_request);
    263267    ASSERT(&effectiveObjectStore().transaction().database().originThread() == &Thread::current());
    264268
     
    269273void IDBCursor::uncheckedIterateCursor(const IDBKeyData& key, const IDBKeyData& primaryKey)
    270274{
     275    ASSERT(m_request);
    271276    ASSERT(&effectiveObjectStore().transaction().database().originThread() == &Thread::current());
    272277
  • trunk/Source/WebCore/Modules/indexeddb/IDBCursor.h

    r235344 r235345  
    3333#include <JavaScriptCore/Strong.h>
    3434#include <wtf/Variant.h>
     35#include <wtf/WeakPtr.h>
    3536
    3637namespace WebCore {
     
    6667    const IDBCursorInfo& info() const { return m_info; }
    6768
    68     void setRequest(IDBRequest& request) { m_request = &request; }
    69     void clearRequest() { m_request = nullptr; }
    70     IDBRequest* request() { return m_request; }
     69    void setRequest(IDBRequest& request) { m_request = makeWeakPtr(&request); }
     70    void clearRequest() { m_request.clear(); }
     71    IDBRequest* request() { return m_request.get(); }
    7172
    7273    void setGetResult(IDBRequest&, const IDBGetResult&);
     
    8889    IDBCursorInfo m_info;
    8990    Source m_source;
    90     IDBRequest* m_request { nullptr };
     91    WeakPtr<IDBRequest> m_request;
    9192
    9293    bool m_gotValue { false };
  • trunk/Source/WebCore/Modules/indexeddb/IDBRequest.h

    r235344 r235345  
    3737#include <wtf/Function.h>
    3838#include <wtf/Scope.h>
     39#include <wtf/WeakPtr.h>
    3940
    4041namespace WebCore {
     
    5758}
    5859
    59 class IDBRequest : public EventTargetWithInlineData, public IDBActiveDOMObject, public RefCounted<IDBRequest> {
     60class IDBRequest : public EventTargetWithInlineData, public IDBActiveDOMObject, public RefCounted<IDBRequest>, public CanMakeWeakPtr<IDBRequest> {
    6061public:
    6162    static Ref<IDBRequest> create(ScriptExecutionContext&, IDBObjectStore&, IDBTransaction&);
Note: See TracChangeset for help on using the changeset viewer.