Changeset 227959 in webkit


Ignore:
Timestamp:
Feb 1, 2018 3:50:47 AM (6 years ago)
Author:
Chris Dumez
Message:

Queue a microtask when a waitUntil() promise is settled
https://bugs.webkit.org/show_bug.cgi?id=182372
<rdar://problem/37101019>

Reviewed by Mark Lam.

LayoutTests/imported/w3c:

Reaseline WPT test now that all checks are passing.

  • web-platform-tests/service-workers/service-worker/extendable-event-async-waituntil.https-expected.txt:

Source/JavaScriptCore:

Export a symbol so it can be used in WebCore.

  • runtime/JSGlobalObject.h:

Source/WebCore:

Queue a microtask when a waitUntil() promise is settled, as per:

Otherwise, we decrement m_pendingPromiseCount too quickly and it may cause
following calls to waitUntil() to throw when they shouldn't.

No new tests, rebaselined existing test.

  • workers/service/ExtendableEvent.cpp:

(WebCore::ExtendableEvent::addExtendLifetimePromise):

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r227958 r227959  
     12018-02-01  Chris Dumez  <cdumez@apple.com>
     2
     3        Queue a microtask when a waitUntil() promise is settled
     4        https://bugs.webkit.org/show_bug.cgi?id=182372
     5        <rdar://problem/37101019>
     6
     7        Reviewed by Mark Lam.
     8
     9        Reaseline WPT test now that all checks are passing.
     10
     11        * web-platform-tests/service-workers/service-worker/extendable-event-async-waituntil.https-expected.txt:
     12
    1132018-02-01  Ms2ger  <Ms2ger@igalia.com>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/extendable-event-async-waituntil.https-expected.txt

    r227425 r227959  
    44PASS Test calling waitUntil in a different microtask without an existing extension throws
    55PASS Test calling waitUntil in a different task with an existing extension succeeds
    6 FAIL Test calling waitUntil with an existing extension promise handler succeeds assert_unreached: unexpected rejection: assert_equals: expected "OK" but got "InvalidStateError" Reached unreachable code
     6PASS Test calling waitUntil with an existing extension promise handler succeeds
    77PASS Test calling waitUntil at the end of the microtask turn throws
    88PASS Test calling waitUntil after the current extension expired in a different task fails
    99PASS Test calling waitUntil on a script constructed ExtendableEvent throws exception
    1010PASS Test calling waitUntil asynchronously with pending respondWith promise.
    11 FAIL Test calling waitUntil synchronously inside microtask of respondWith promise. assert_unreached: unexpected rejection: assert_equals: expected "OK" but got "InvalidStateError" Reached unreachable code
     11PASS Test calling waitUntil synchronously inside microtask of respondWith promise.
    1212PASS Test calling waitUntil asynchronously inside microtask of respondWith promise.
    1313
  • trunk/Source/JavaScriptCore/ChangeLog

    r227952 r227959  
     12018-02-01  Chris Dumez  <cdumez@apple.com>
     2
     3        Queue a microtask when a waitUntil() promise is settled
     4        https://bugs.webkit.org/show_bug.cgi?id=182372
     5        <rdar://problem/37101019>
     6
     7        Reviewed by Mark Lam.
     8
     9        Export a symbol so it can be used in WebCore.
     10
     11        * runtime/JSGlobalObject.h:
     12
    1132018-01-31  Don Olmstead  <don.olmstead@sony.com>
    214
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h

    r227617 r227959  
    833833    static RuntimeFlags javaScriptRuntimeFlags(const JSGlobalObject*) { return RuntimeFlags(); }
    834834
    835     void queueMicrotask(Ref<Microtask>&&);
     835    JS_EXPORT_PRIVATE void queueMicrotask(Ref<Microtask>&&);
    836836
    837837    bool evalEnabled() const { return m_evalEnabled; }
  • trunk/Source/WebCore/ChangeLog

    r227956 r227959  
     12018-02-01  Chris Dumez  <cdumez@apple.com>
     2
     3        Queue a microtask when a waitUntil() promise is settled
     4        https://bugs.webkit.org/show_bug.cgi?id=182372
     5        <rdar://problem/37101019>
     6
     7        Reviewed by Mark Lam.
     8
     9        Queue a microtask when a waitUntil() promise is settled, as per:
     10        - https://w3c.github.io/ServiceWorker/#dom-extendableevent-waituntil (step 5)
     11
     12        Otherwise, we decrement m_pendingPromiseCount too quickly and it may cause
     13        following calls to waitUntil() to throw when they shouldn't.
     14
     15        No new tests, rebaselined existing test.
     16
     17        * workers/service/ExtendableEvent.cpp:
     18        (WebCore::ExtendableEvent::addExtendLifetimePromise):
     19
    1202018-02-01  Antti Koivisto  <antti@apple.com>
    221
  • trunk/Source/WebCore/workers/service/ExtendableEvent.cpp

    r224584 r227959  
    3030
    3131#include "JSDOMPromise.h"
     32#include <runtime/Microtask.h>
    3233
    3334namespace WebCore {
     
    6162}
    6263
     64class FunctionMicrotask final : public JSC::Microtask {
     65public:
     66    static Ref<FunctionMicrotask> create(Function<void()>&& function)
     67    {
     68        return adoptRef(*new FunctionMicrotask(WTFMove(function)));
     69    }
     70
     71private:
     72    explicit FunctionMicrotask(Function<void()>&& function)
     73        : m_function(WTFMove(function))
     74    {
     75    }
     76
     77    void run(JSC::ExecState*) final
     78    {
     79        m_function();
     80    }
     81
     82    Function<void()> m_function;
     83};
     84
    6385void ExtendableEvent::addExtendLifetimePromise(Ref<DOMPromise>&& promise)
    6486{
    65     promise->whenSettled([this, protectedThis = makeRefPtr(this), settledPromise = promise.ptr()] () {
    66         --m_pendingPromiseCount;
     87    promise->whenSettled([this, protectedThis = makeRefPtr(this), settledPromise = promise.ptr()] () mutable {
     88        settledPromise->globalObject()->queueMicrotask(FunctionMicrotask::create([this, protectedThis = WTFMove(protectedThis)] {
     89            --m_pendingPromiseCount;
    6790
    68         // FIXME: Let registration be the context object's relevant global object's associated service worker's containing service worker registration.
    69         // FIXME: If registration's uninstalling flag is set, invoke Try Clear Registration with registration.
    70         // FIXME: If registration is not null, invoke Try Activate with registration.
     91            // FIXME: Let registration be the context object's relevant global object's associated service worker's containing service worker registration.
     92            // FIXME: If registration's uninstalling flag is set, invoke Try Clear Registration with registration.
     93            // FIXME: If registration is not null, invoke Try Activate with registration.
    7194
    72         if (m_pendingPromiseCount)
    73             return;
     95            if (m_pendingPromiseCount)
     96                return;
    7497
    75         auto settledPromises = WTFMove(m_extendLifetimePromises);
    76         if (auto handler = WTFMove(m_whenAllExtendLifetimePromisesAreSettledHandler))
    77             handler(WTFMove(settledPromises));
     98            auto settledPromises = WTFMove(m_extendLifetimePromises);
     99            if (auto handler = WTFMove(m_whenAllExtendLifetimePromisesAreSettledHandler))
     100                handler(WTFMove(settledPromises));
     101        }));
    78102    });
    79103
Note: See TracChangeset for help on using the changeset viewer.