Changeset 274269 in webkit


Ignore:
Timestamp:
Mar 11, 2021 12:41:24 AM (17 months ago)
Author:
sihui_liu@apple.com
Message:

Indexed DB transactions outdated immediately after it just created
https://bugs.webkit.org/show_bug.cgi?id=216769
<rdar://problem/69321075>

Reviewed by Ryosuke Niwa.

Source/WebCore:

Test: storage/indexeddb/transaction-state-active-after-creation.html

Set transaction inactive in microtask checkpoint according to spec:
https://html.spec.whatwg.org/#perform-a-microtask-checkpoint

  • Modules/indexeddb/IDBTransaction.cpp:

(WebCore::IDBTransaction::IDBTransaction):

  • dom/EventLoop.cpp:

(WebCore::EventLoopTaskGroup::runAtEndOfMicrotaskCheckpoint):

  • dom/EventLoop.h:
  • dom/Microtasks.cpp:

(WebCore::MicrotaskQueue::performMicrotaskCheckpoint):
(WebCore::MicrotaskQueue::addCheckpointTask):

  • dom/Microtasks.h:
  • dom/TaskSource.h:

LayoutTests:

  • storage/indexeddb/transaction-state-active-after-creation-expected.txt: Added.
  • storage/indexeddb/transaction-state-active-after-creation.html: Added.
Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r274267 r274269  
     12021-03-11  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Indexed DB transactions outdated immediately after it just created
     4        https://bugs.webkit.org/show_bug.cgi?id=216769
     5        <rdar://problem/69321075>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        * storage/indexeddb/transaction-state-active-after-creation-expected.txt: Added.
     10        * storage/indexeddb/transaction-state-active-after-creation.html: Added.
     11
    1122021-03-10  Rob Buis  <rbuis@igalia.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r274267 r274269  
     12021-03-11  Sihui Liu  <sihui_liu@apple.com>
     2
     3        Indexed DB transactions outdated immediately after it just created
     4        https://bugs.webkit.org/show_bug.cgi?id=216769
     5        <rdar://problem/69321075>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Test: storage/indexeddb/transaction-state-active-after-creation.html
     10
     11        Set transaction inactive in microtask checkpoint according to spec:
     12        https://html.spec.whatwg.org/#perform-a-microtask-checkpoint
     13
     14        * Modules/indexeddb/IDBTransaction.cpp:
     15        (WebCore::IDBTransaction::IDBTransaction):
     16        * dom/EventLoop.cpp:
     17        (WebCore::EventLoopTaskGroup::runAtEndOfMicrotaskCheckpoint):
     18        * dom/EventLoop.h:
     19        * dom/Microtasks.cpp:
     20        (WebCore::MicrotaskQueue::performMicrotaskCheckpoint):
     21        (WebCore::MicrotaskQueue::addCheckpointTask):
     22        * dom/Microtasks.h:
     23        * dom/TaskSource.h:
     24
    1252021-03-10  Rob Buis  <rbuis@igalia.com>
    226
  • trunk/Source/WebCore/Modules/indexeddb/IDBTransaction.cpp

    r273138 r274269  
    3434#include "Event.h"
    3535#include "EventDispatcher.h"
     36#include "EventLoop.h"
    3637#include "EventNames.h"
    3738#include "EventQueue.h"
     
    9899        ASSERT(context);
    99100
    100         JSC::VM& vm = context->vm();
    101         vm.whenIdle([protectedThis = makeRef(*this)]() {
     101        context->eventLoop().runAtEndOfMicrotaskCheckpoint([protectedThis = makeRef(*this)] {
    102102            protectedThis->deactivate();
    103103        });
  • trunk/Source/WebCore/dom/EventLoop.cpp

    r269227 r274269  
    181181}
    182182
     183void EventLoopTaskGroup::runAtEndOfMicrotaskCheckpoint(EventLoop::TaskFunction&& function)
     184{
     185    if (m_state == State::Stopped || !m_eventLoop)
     186        return;
     187
     188    microtaskQueue().addCheckpointTask(makeUnique<EventLoopFunctionDispatchTask>(TaskSource::IndexedDB, *this, WTFMove(function)));
     189}
     190
    183191} // namespace WebCore
  • trunk/Source/WebCore/dom/EventLoop.h

    r269275 r274269  
    183183    void performMicrotaskCheckpoint();
    184184
     185    void runAtEndOfMicrotaskCheckpoint(EventLoop::TaskFunction&&);
     186
    185187private:
    186188    enum class State : uint8_t { Running, Suspended, ReadyToStop, Stopped };
  • trunk/Source/WebCore/dom/Microtasks.cpp

    r253091 r274269  
    6868    vm().finalizeSynchronousJSExecution();
    6969    m_microtaskQueue = WTFMove(toKeep);
     70
     71    auto checkpointTasks = std::exchange(m_checkpointTasks, { });
     72    for (auto& checkpointTask : checkpointTasks) {
     73        auto* group = checkpointTask->group();
     74        if (!group || group->isStoppedPermanently())
     75            continue;
     76
     77        if (group->isSuspended()) {
     78            m_checkpointTasks.append(WTFMove(checkpointTask));
     79            continue;
     80        }
     81
     82        checkpointTask->execute();
     83    }
     84}
     85
     86void MicrotaskQueue::addCheckpointTask(std::unique_ptr<EventLoopTask>&& task)
     87{
     88    m_checkpointTasks.append(WTFMove(task));
    7089}
    7190
  • trunk/Source/WebCore/dom/Microtasks.h

    r253091 r274269  
    4242    WEBCORE_EXPORT void performMicrotaskCheckpoint();
    4343
     44    WEBCORE_EXPORT void addCheckpointTask(std::unique_ptr<EventLoopTask>&&);
     45
    4446private:
    4547    JSC::VM& vm() const { return m_vm.get(); }
     
    4951    // For the main thread the VM lives forever. For workers it's lifetime is tied to our owning WorkerGlobalScope. Regardless, we retain the VM here to be safe.
    5052    Ref<JSC::VM> m_vm;
     53
     54    Vector<std::unique_ptr<EventLoopTask>> m_checkpointTasks;
    5155};
    5256
  • trunk/Source/WebCore/dom/TaskSource.h

    r269348 r274269  
    3434    FontLoading,
    3535    IdleTask,
     36    IndexedDB,
    3637    MediaElement,
    3738    Microtask,
    3839    Networking,
    3940    PostedMessageQueue,
     41    Speech,
    4042    UserInteraction,
    4143    WebGL,
    4244    WebXR,
    43     Speech,
    4445
    4546    // Internal to WebCore
Note: See TracChangeset for help on using the changeset viewer.