Changeset 225491 in webkit


Ignore:
Timestamp:
Dec 4, 2017 1:56:25 PM (6 years ago)
Author:
Chris Dumez
Message:

ServiceWorkerGlobalScope::skipWaiting(Ref<DeferredPromise>&&) is unsafe
https://bugs.webkit.org/show_bug.cgi?id=180372

Reviewed by Youenn Fablet.

Ref the WorkerThread and capture it in the lambda. Keep the pending promises in
a HashMap on the ServiceWorkerGlobalScope so that they stay on the worker thread.

  • workers/service/ServiceWorkerGlobalScope.cpp:

(WebCore::ServiceWorkerGlobalScope::skipWaiting):

  • workers/service/ServiceWorkerGlobalScope.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r225490 r225491  
     12017-12-04  Chris Dumez  <cdumez@apple.com>
     2
     3        ServiceWorkerGlobalScope::skipWaiting(Ref<DeferredPromise>&&) is unsafe
     4        https://bugs.webkit.org/show_bug.cgi?id=180372
     5
     6        Reviewed by Youenn Fablet.
     7
     8        Ref the WorkerThread and capture it in the lambda. Keep the pending promises in
     9        a HashMap on the ServiceWorkerGlobalScope so that they stay on the worker thread.
     10
     11        * workers/service/ServiceWorkerGlobalScope.cpp:
     12        (WebCore::ServiceWorkerGlobalScope::skipWaiting):
     13        * workers/service/ServiceWorkerGlobalScope.h:
     14
    1152017-12-04  Brady Eidson  <beidson@apple.com>
    216
  • trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.cpp

    r225460 r225491  
    5151void ServiceWorkerGlobalScope::skipWaiting(Ref<DeferredPromise>&& promise)
    5252{
    53     callOnMainThread([this, protectedThis = makeRef(*this), threadIdentifier = thread().identifier(), promise = WTFMove(promise)]() mutable {
     53    uint64_t requestIdentifier = ++m_lastRequestIdentifier;
     54    m_pendingSkipWaitingPromises.add(requestIdentifier, WTFMove(promise));
     55
     56    callOnMainThread([workerThread = makeRef(thread()), requestIdentifier]() mutable {
    5457        if (auto* connection = SWContextManager::singleton().connection()) {
    55             connection->skipWaiting(threadIdentifier, [this, protectedThis = WTFMove(protectedThis), promise = WTFMove(promise)]() mutable {
    56                 thread().runLoop().postTask([promise = WTFMove(promise), protectedThis = WTFMove(protectedThis)](auto&) {
    57                     promise->resolve();
     58            connection->skipWaiting(workerThread->identifier(), [workerThread = WTFMove(workerThread), requestIdentifier] {
     59                workerThread->runLoop().postTask([requestIdentifier](auto& context) {
     60                    auto& scope = downcast<ServiceWorkerGlobalScope>(context);
     61                    if (auto promise = scope.m_pendingSkipWaitingPromises.take(requestIdentifier))
     62                        promise->resolve();
    5863                });
    5964            });
  • trunk/Source/WebCore/workers/service/ServiceWorkerGlobalScope.h

    r225351 r225491  
    7878    HashMap<ServiceWorkerClientIdentifier, ServiceWorkerClient*> m_clientMap;
    7979    Vector<Ref<ExtendableEvent>> m_extendedEvents;
     80
     81    uint64_t m_lastRequestIdentifier { 0 };
     82    HashMap<uint64_t, RefPtr<DeferredPromise>> m_pendingSkipWaitingPromises;
    8083};
    8184
Note: See TracChangeset for help on using the changeset viewer.