Title: [232156] trunk
Revision
232156
Author
[email protected]
Date
2018-05-24 11:10:05 -0700 (Thu, 24 May 2018)

Log Message

[iOS WK2] Layout Test imported/w3c/web-platform-tests/service-workers/service-worker/update-after-navigation-fetch-event.https.html is a flaky failure
https://bugs.webkit.org/show_bug.cgi?id=181499
<rdar://problem/36443428>

Reviewed by Youenn Fablet.

Source/WebCore:

After resolving a registration promise, we send an IPC back to the StorageProcess
for synchronization purposes, to make sure the registration does not get updated
before the promise's JS code has been executed. However, resolving a promise
schedules a microtask to run the JS and we would therefore send the IPC back too
early, thus causing flakiness. We now only send the IPC back back only after that
microtask has run and the JS has been executed.

* bindings/js/JSDOMPromiseDeferred.cpp:
(WebCore::DeferredPromise::callFunction):
(WebCore::DeferredPromise::whenSettled):
* bindings/js/JSDOMPromiseDeferred.h:
* workers/service/ServiceWorkerContainer.cpp:
(WebCore::ServiceWorkerContainer::jobResolvedWithRegistration):

LayoutTests:

Unskip test that should no longer be flaky.

* platform/ios/TestExpectations:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (232155 => 232156)


--- trunk/LayoutTests/ChangeLog	2018-05-24 17:09:59 UTC (rev 232155)
+++ trunk/LayoutTests/ChangeLog	2018-05-24 18:10:05 UTC (rev 232156)
@@ -1,3 +1,15 @@
+2018-05-24  Chris Dumez  <[email protected]>
+
+        [iOS WK2] Layout Test imported/w3c/web-platform-tests/service-workers/service-worker/update-after-navigation-fetch-event.https.html is a flaky failure
+        https://bugs.webkit.org/show_bug.cgi?id=181499
+        <rdar://problem/36443428>
+
+        Reviewed by Youenn Fablet.
+
+        Unskip test that should no longer be flaky.
+
+        * platform/ios/TestExpectations:
+
 2018-05-24  Jinho Bang  <[email protected]>
 
         [PaymentRequest] Remove currencySystem member

Modified: trunk/LayoutTests/platform/ios/TestExpectations (232155 => 232156)


--- trunk/LayoutTests/platform/ios/TestExpectations	2018-05-24 17:09:59 UTC (rev 232155)
+++ trunk/LayoutTests/platform/ios/TestExpectations	2018-05-24 18:10:05 UTC (rev 232156)
@@ -3267,8 +3267,6 @@
 webkit.org/b/180062 fast/text/user-installed-fonts/shadow.html [ ImageOnlyFailure ]
 webkit.org/b/180062 fast/text/user-installed-fonts/shadow-postscript-family.html [ ImageOnlyFailure ]
 
-webkit.org/b/181499 [ Release ] imported/w3c/web-platform-tests/service-workers/service-worker/update-after-navigation-fetch-event.https.html [ Pass Failure ]
-
 webkit.org/b/181838 js/slow-stress/Int32Array-alloc-huge-long-lived.html [ Slow ]
 
 webkit.org/b/182422 imported/w3c/web-platform-tests/2dcontext/imagebitmap/createImageBitmap-origin.sub.html [ Skip ]

Modified: trunk/Source/WebCore/ChangeLog (232155 => 232156)


--- trunk/Source/WebCore/ChangeLog	2018-05-24 17:09:59 UTC (rev 232155)
+++ trunk/Source/WebCore/ChangeLog	2018-05-24 18:10:05 UTC (rev 232156)
@@ -1,3 +1,25 @@
+2018-05-24  Chris Dumez  <[email protected]>
+
+        [iOS WK2] Layout Test imported/w3c/web-platform-tests/service-workers/service-worker/update-after-navigation-fetch-event.https.html is a flaky failure
+        https://bugs.webkit.org/show_bug.cgi?id=181499
+        <rdar://problem/36443428>
+
+        Reviewed by Youenn Fablet.
+
+        After resolving a registration promise, we send an IPC back to the StorageProcess
+        for synchronization purposes, to make sure the registration does not get updated
+        before the promise's JS code has been executed. However, resolving a promise
+        schedules a microtask to run the JS and we would therefore send the IPC back too
+        early, thus causing flakiness. We now only send the IPC back back only after that
+        microtask has run and the JS has been executed.
+
+        * bindings/js/JSDOMPromiseDeferred.cpp:
+        (WebCore::DeferredPromise::callFunction):
+        (WebCore::DeferredPromise::whenSettled):
+        * bindings/js/JSDOMPromiseDeferred.h:
+        * workers/service/ServiceWorkerContainer.cpp:
+        (WebCore::ServiceWorkerContainer::jobResolvedWithRegistration):
+
 2018-05-24  Jinho Bang  <[email protected]>
 
         [PaymentRequest] Remove currencySystem member

Modified: trunk/Source/WebCore/bindings/js/JSDOMPromise.cpp (232155 => 232156)


--- trunk/Source/WebCore/bindings/js/JSDOMPromise.cpp	2018-05-24 17:09:59 UTC (rev 232155)
+++ trunk/Source/WebCore/bindings/js/JSDOMPromise.cpp	2018-05-24 18:10:05 UTC (rev 232156)
@@ -53,16 +53,20 @@
 
 void DOMPromise::whenSettled(std::function<void()>&& callback)
 {
-    auto& state = *globalObject()->globalExec();
+    whenPromiseIsSettled(globalObject(), promise(), WTFMove(callback));
+}
+
+void DOMPromise::whenPromiseIsSettled(JSDOMGlobalObject* globalObject, JSC::JSObject* promise, std::function<void()>&& callback)
+{
+    auto& state = *globalObject->globalExec();
     auto& vm = state.vm();
     JSLockHolder lock(vm);
-    auto* handler = JSC::JSNativeStdFunction::create(vm, globalObject(), 1, String { }, [callback = WTFMove(callback)] (ExecState*) mutable {
+    auto* handler = JSC::JSNativeStdFunction::create(vm, globalObject, 1, String { }, [callback = WTFMove(callback)] (ExecState*) mutable {
         callback();
         return JSC::JSValue::encode(JSC::jsUndefined());
     });
 
     const JSC::Identifier& privateName = vm.propertyNames->builtinNames().thenPrivateName();
-    auto* promise = this->promise();
     auto thenFunction = promise->get(&state, privateName);
     ASSERT(thenFunction.isFunction(vm));
 

Modified: trunk/Source/WebCore/bindings/js/JSDOMPromise.h (232155 => 232156)


--- trunk/Source/WebCore/bindings/js/JSDOMPromise.h	2018-05-24 17:09:59 UTC (rev 232155)
+++ trunk/Source/WebCore/bindings/js/JSDOMPromise.h	2018-05-24 18:10:05 UTC (rev 232156)
@@ -50,6 +50,8 @@
     enum class Status { Pending, Fulfilled, Rejected };
     Status status() const;
 
+    static void whenPromiseIsSettled(JSDOMGlobalObject*, JSC::JSObject* promise, std::function<void()>&&);
+
 private:
     DOMPromise(JSDOMGlobalObject& globalObject, JSC::JSPromise& promise)
         : DOMGuarded<JSC::JSPromise>(globalObject, promise)

Modified: trunk/Source/WebCore/bindings/js/JSDOMPromiseDeferred.cpp (232155 => 232156)


--- trunk/Source/WebCore/bindings/js/JSDOMPromiseDeferred.cpp	2018-05-24 17:09:59 UTC (rev 232155)
+++ trunk/Source/WebCore/bindings/js/JSDOMPromiseDeferred.cpp	2018-05-24 18:10:05 UTC (rev 232156)
@@ -27,6 +27,7 @@
 #include "JSDOMPromiseDeferred.h"
 
 #include "DOMWindow.h"
+#include "JSDOMPromise.h"
 #include "JSDOMWindow.h"
 #include <_javascript_Core/BuiltinNames.h>
 #include <_javascript_Core/Exception.h>
@@ -68,6 +69,11 @@
         clear();
 }
 
+void DeferredPromise::whenSettled(std::function<void()>&& callback)
+{
+    DOMPromise::whenPromiseIsSettled(globalObject(), deferred()->promise(), WTFMove(callback));
+}
+
 void DeferredPromise::reject()
 {
     if (isSuspended())

Modified: trunk/Source/WebCore/bindings/js/JSDOMPromiseDeferred.h (232155 => 232156)


--- trunk/Source/WebCore/bindings/js/JSDOMPromiseDeferred.h	2018-05-24 17:09:59 UTC (rev 232155)
+++ trunk/Source/WebCore/bindings/js/JSDOMPromiseDeferred.h	2018-05-24 18:10:05 UTC (rev 232156)
@@ -134,6 +134,8 @@
 
     JSC::JSValue promise() const;
 
+    void whenSettled(std::function<void()>&&);
+
 private:
     DeferredPromise(JSDOMGlobalObject& globalObject, JSC::JSPromiseDeferred& deferred, Mode mode)
         : DOMGuarded<JSC::JSPromiseDeferred>(globalObject, deferred)
@@ -144,6 +146,7 @@
     JSC::JSPromiseDeferred* deferred() const { return guarded(); }
 
     WEBCORE_EXPORT void callFunction(JSC::ExecState&, JSC::JSValue function, JSC::JSValue resolution);
+
     void resolve(JSC::ExecState& state, JSC::JSValue resolution) { callFunction(state, deferred()->resolve(), resolution); }
     void reject(JSC::ExecState& state, JSC::JSValue resolution) { callFunction(state, deferred()->reject(), resolution); }
 

Modified: trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp (232155 => 232156)


--- trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp	2018-05-24 17:09:59 UTC (rev 232155)
+++ trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp	2018-05-24 18:10:05 UTC (rev 232156)
@@ -419,10 +419,10 @@
         CONTAINER_RELEASE_LOG_IF_ALLOWED("jobResolvedWithRegistration: Update job %" PRIu64 " succeeded", job.identifier().toUInt64());
     }
 
-    WTF::Function<void()> notifyWhenResolvedIfNeeded = [] { };
+    std::function<void()> notifyWhenResolvedIfNeeded;
     if (shouldNotifyWhenResolved == ShouldNotifyWhenResolved::Yes) {
-        notifyWhenResolvedIfNeeded = [connection = m_swConnection, registrationKey = data.key.isolatedCopy()]() mutable {
-            callOnMainThread([connection = WTFMove(connection), registrationKey = WTFMove(registrationKey)] {
+        notifyWhenResolvedIfNeeded = [connection = m_swConnection, registrationKey = data.key]() mutable {
+            callOnMainThread([connection = WTFMove(connection), registrationKey = registrationKey.isolatedCopy()] {
                 connection->didResolveRegistrationPromise(registrationKey);
             });
         };
@@ -429,18 +429,21 @@
     }
 
     if (isStopped()) {
-        notifyWhenResolvedIfNeeded();
+        if (notifyWhenResolvedIfNeeded)
+            notifyWhenResolvedIfNeeded();
         return;
     }
 
     if (!job.promise()) {
-        notifyWhenResolvedIfNeeded();
+        if (notifyWhenResolvedIfNeeded)
+            notifyWhenResolvedIfNeeded();
         return;
     }
 
     scriptExecutionContext()->postTask([this, protectedThis = makeRef(*this), job = makeRef(job), data = "" notifyWhenResolvedIfNeeded = WTFMove(notifyWhenResolvedIfNeeded)](ScriptExecutionContext& context) mutable {
         if (isStopped() || !context.sessionID().isValid()) {
-            notifyWhenResolvedIfNeeded();
+            if (notifyWhenResolvedIfNeeded)
+                notifyWhenResolvedIfNeeded();
             return;
         }
 
@@ -448,9 +451,13 @@
 
         CONTAINER_RELEASE_LOG_IF_ALLOWED("jobResolvedWithRegistration: Resolving promise for job %" PRIu64 ". Registration ID: %" PRIu64, job->identifier().toUInt64(), registration->identifier().toUInt64());
 
+        if (notifyWhenResolvedIfNeeded) {
+            job->promise()->whenSettled([notifyWhenResolvedIfNeeded = WTFMove(notifyWhenResolvedIfNeeded)] {
+                notifyWhenResolvedIfNeeded();
+            });
+        }
+
         job->promise()->resolve<IDLInterface<ServiceWorkerRegistration>>(WTFMove(registration));
-
-        notifyWhenResolvedIfNeeded();
     });
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to