Title: [243346] trunk
Revision
243346
Author
[email protected]
Date
2019-03-21 16:53:59 -0700 (Thu, 21 Mar 2019)

Log Message

[Web Animations] JS wrapper may be deleted while animation is yet to dispatch its finish event
https://bugs.webkit.org/show_bug.cgi?id=196118
<rdar://problem/46614137>

Reviewed by Ryosuke Niwa.

Source/WebCore:

Test: webanimations/js-wrapper-kept-alive.html

We need to teach WebAnimation to keep its JS wrapper alive if it's relevant or could become relevant again by virtue of having a timeline.

* animation/WebAnimation.cpp:
(WebCore::WebAnimation::stop): Drive-by fix for the missing superclass method call.
(WebCore::WebAnimation::hasPendingActivity const):
* animation/WebAnimation.h:

LayoutTests:

Add a test that starts a short animation, sets a custom property on it, registers a "finish" event listener on it and deletes
the sole reference to it in the JS world before triggering garbage collection. Prior to this fix, this test would time out
because the JS wrapper would be garbage-collected prior to the animation completing and thus the event listener would not
be called. To complete successfully, this test checks that it receives the event and its target is the same animation object
that was originally created by checking the custom property is still set.

* webanimations/js-wrapper-kept-alive-expected.txt: Added.
* webanimations/js-wrapper-kept-alive.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (243345 => 243346)


--- trunk/LayoutTests/ChangeLog	2019-03-21 23:35:39 UTC (rev 243345)
+++ trunk/LayoutTests/ChangeLog	2019-03-21 23:53:59 UTC (rev 243346)
@@ -1,3 +1,20 @@
+2019-03-21  Antoine Quint  <[email protected]>
+
+        [Web Animations] JS wrapper may be deleted while animation is yet to dispatch its finish event
+        https://bugs.webkit.org/show_bug.cgi?id=196118
+        <rdar://problem/46614137>
+
+        Reviewed by Ryosuke Niwa.
+
+        Add a test that starts a short animation, sets a custom property on it, registers a "finish" event listener on it and deletes
+        the sole reference to it in the JS world before triggering garbage collection. Prior to this fix, this test would time out
+        because the JS wrapper would be garbage-collected prior to the animation completing and thus the event listener would not
+        be called. To complete successfully, this test checks that it receives the event and its target is the same animation object
+        that was originally created by checking the custom property is still set.
+
+        * webanimations/js-wrapper-kept-alive-expected.txt: Added.
+        * webanimations/js-wrapper-kept-alive.html: Added.
+
 2019-03-21  Youenn Fablet  <[email protected]>
 
         Cache API and IDB space usages should be initialized on first quota check

Added: trunk/LayoutTests/webanimations/js-wrapper-kept-alive-expected.txt (0 => 243346)


--- trunk/LayoutTests/webanimations/js-wrapper-kept-alive-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/webanimations/js-wrapper-kept-alive-expected.txt	2019-03-21 23:53:59 UTC (rev 243346)
@@ -0,0 +1,10 @@
+This test checks that registering an event listener on an animation whose JS wrapper would otherwise be garbage-collected still fires registered event listeners.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS event.target._isMyAnimation is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/webanimations/js-wrapper-kept-alive.html (0 => 243346)


--- trunk/LayoutTests/webanimations/js-wrapper-kept-alive.html	                        (rev 0)
+++ trunk/LayoutTests/webanimations/js-wrapper-kept-alive.html	2019-03-21 23:53:59 UTC (rev 243346)
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<html>
+<body>
+<div id="target"></div>
+<script src=""
+<script>
+description("This test checks that registering an event listener on an animation whose JS wrapper would otherwise be garbage-collected still fires registered event listeners.");
+
+if (window.internals)
+    jsTestIsAsync = true;
+
+// A longer animation that could not be garbage-collected under any circumstance allows us to finish the test
+// with a reasonable delay without hard-coding a timeout.
+const timeoutAnimation = document.getElementById("target").animate({ marginRight: ["0px", "100px"] }, 1000);
+timeoutAnimation.addEventListener("finish", finishJSTest);
+
+function runTest() {
+    const animation = document.getElementById("target").animate({ marginLeft: ["0px", "100px"] }, 100);
+    animation._isMyAnimation = true;
+    animation.addEventListener("finish", event => {
+        shouldBeTrue("event.target._isMyAnimation");
+        finishJSTest();
+    });
+}
+
+gc();
+runTest();
+gc();
+
+</script>
+<script src=""
+</body>
+</html>
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (243345 => 243346)


--- trunk/Source/WebCore/ChangeLog	2019-03-21 23:35:39 UTC (rev 243345)
+++ trunk/Source/WebCore/ChangeLog	2019-03-21 23:53:59 UTC (rev 243346)
@@ -1,3 +1,20 @@
+2019-03-21  Antoine Quint  <[email protected]>
+
+        [Web Animations] JS wrapper may be deleted while animation is yet to dispatch its finish event
+        https://bugs.webkit.org/show_bug.cgi?id=196118
+        <rdar://problem/46614137>
+
+        Reviewed by Ryosuke Niwa.
+
+        Test: webanimations/js-wrapper-kept-alive.html
+
+        We need to teach WebAnimation to keep its JS wrapper alive if it's relevant or could become relevant again by virtue of having a timeline.
+
+        * animation/WebAnimation.cpp:
+        (WebCore::WebAnimation::stop): Drive-by fix for the missing superclass method call.
+        (WebCore::WebAnimation::hasPendingActivity const):
+        * animation/WebAnimation.h:
+
 2019-03-21  Jer Noble  <[email protected]>
 
         Inband Text Track cues interspersed with Data cues can display out of order.

Modified: trunk/Source/WebCore/animation/WebAnimation.cpp (243345 => 243346)


--- trunk/Source/WebCore/animation/WebAnimation.cpp	2019-03-21 23:35:39 UTC (rev 243345)
+++ trunk/Source/WebCore/animation/WebAnimation.cpp	2019-03-21 23:53:59 UTC (rev 243346)
@@ -1159,10 +1159,16 @@
 
 void WebAnimation::stop()
 {
+    ActiveDOMObject::stop();
     m_isStopped = true;
     removeAllEventListeners();
 }
 
+bool WebAnimation::hasPendingActivity() const
+{
+    return m_timeline || m_isRelevant || ActiveDOMObject::hasPendingActivity();
+}
+
 void WebAnimation::updateRelevance()
 {
     m_isRelevant = computeRelevance();

Modified: trunk/Source/WebCore/animation/WebAnimation.h (243345 => 243346)


--- trunk/Source/WebCore/animation/WebAnimation.h	2019-03-21 23:35:39 UTC (rev 243345)
+++ trunk/Source/WebCore/animation/WebAnimation.h	2019-03-21 23:53:59 UTC (rev 243346)
@@ -117,6 +117,8 @@
     bool isSuspended() const { return m_isSuspended; }
     virtual void remove();
 
+    bool hasPendingActivity() const final;
+
     using RefCounted::ref;
     using RefCounted::deref;
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to