Title: [234818] trunk
Revision
234818
Author
[email protected]
Date
2018-08-13 15:02:45 -0700 (Mon, 13 Aug 2018)

Log Message

[IntersectionObserver] Validate threshold values
https://bugs.webkit.org/show_bug.cgi?id=188475

Reviewed by Simon Fraser.

LayoutTests/imported/w3c:

Update expectation for newly passing test case.

* web-platform-tests/intersection-observer/observer-exceptions-expected.txt:
* web-platform-tests/intersection-observer/observer-exceptions.html: Fix typo already fixed upstream.

Source/WebCore:

Throw an exception if any of an IntersectionObserver's thresholds are outside
the range [0, 1].

Tested by: imported/w3c/web-platform-tests/intersection-observer/observer-exceptions.html
           intersection-observer/intersection-observer-interface.html

* page/IntersectionObserver.cpp:
(WebCore::IntersectionObserver::create):
(WebCore::IntersectionObserver::IntersectionObserver):
* page/IntersectionObserver.h:

LayoutTests:

Add test coverage for interesting floating point threshold values.

* intersection-observer/intersection-observer-interface-expected.txt:
* intersection-observer/intersection-observer-interface.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (234817 => 234818)


--- trunk/LayoutTests/ChangeLog	2018-08-13 21:17:10 UTC (rev 234817)
+++ trunk/LayoutTests/ChangeLog	2018-08-13 22:02:45 UTC (rev 234818)
@@ -1,3 +1,15 @@
+2018-08-13  Ali Juma  <[email protected]>
+
+        [IntersectionObserver] Validate threshold values
+        https://bugs.webkit.org/show_bug.cgi?id=188475
+
+        Reviewed by Simon Fraser.
+
+        Add test coverage for interesting floating point threshold values.
+
+        * intersection-observer/intersection-observer-interface-expected.txt:
+        * intersection-observer/intersection-observer-interface.html:
+
 2018-08-13  Ryan Haddad  <[email protected]>
 
         [iOS] Rebaseline and re-enable svg tests

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (234817 => 234818)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2018-08-13 21:17:10 UTC (rev 234817)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2018-08-13 22:02:45 UTC (rev 234818)
@@ -1,3 +1,15 @@
+2018-08-13  Ali Juma  <[email protected]>
+
+        [IntersectionObserver] Validate threshold values
+        https://bugs.webkit.org/show_bug.cgi?id=188475
+
+        Reviewed by Simon Fraser.
+
+        Update expectation for newly passing test case.
+
+        * web-platform-tests/intersection-observer/observer-exceptions-expected.txt:
+        * web-platform-tests/intersection-observer/observer-exceptions.html: Fix typo already fixed upstream.
+
 2018-08-13  Yusuke Suzuki  <[email protected]>
 
         Expose CloseEvent and CustomEvent to workers

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/observer-exceptions-expected.txt (234817 => 234818)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/observer-exceptions-expected.txt	2018-08-13 21:17:10 UTC (rev 234817)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/observer-exceptions-expected.txt	2018-08-13 22:02:45 UTC (rev 234818)
@@ -1,9 +1,7 @@
 
-FAIL IntersectionObserver constructor with { threshold: [1.1] } assert_throws: function "function () {
-    new IntersectionObserver(e => {}, {threshold: [1.1]})
-  }" did not throw
+PASS IntersectionObserver constructor with { threshold: [1.1] } 
 PASS IntersectionObserver constructor with { threshold: ["foo"] } 
-PASS IntersectionObserver constructor witth { rootMargin: "1" } 
+PASS IntersectionObserver constructor with { rootMargin: "1" } 
 PASS IntersectionObserver constructor with { rootMargin: "2em" } 
 PASS IntersectionObserver constructor with { rootMargin: "auto" } 
 PASS IntersectionObserver constructor with { rootMargin: "calc(1px + 2px)" } 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/observer-exceptions.html (234817 => 234818)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/observer-exceptions.html	2018-08-13 21:17:10 UTC (rev 234817)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/observer-exceptions.html	2018-08-13 22:02:45 UTC (rev 234818)
@@ -19,7 +19,7 @@
   assert_throws("SYNTAX_ERR", function() {
     new IntersectionObserver(e => {}, {rootMargin: "1"})
   })
-}, 'IntersectionObserver constructor witth { rootMargin: "1" }');
+}, 'IntersectionObserver constructor with { rootMargin: "1" }');
 
 test(function () {
   assert_throws("SYNTAX_ERR", function() {

Modified: trunk/LayoutTests/intersection-observer/intersection-observer-interface-expected.txt (234817 => 234818)


--- trunk/LayoutTests/intersection-observer/intersection-observer-interface-expected.txt	2018-08-13 21:17:10 UTC (rev 234817)
+++ trunk/LayoutTests/intersection-observer/intersection-observer-interface-expected.txt	2018-08-13 22:02:45 UTC (rev 234818)
@@ -10,4 +10,11 @@
 PASS ExplicitRoot 
 PASS ExplicitThreshold 
 PASS ExplicitThresholds 
+PASS SmallPositiveThreshold 
+PASS SmallNegativeThreshold 
+PASS LargePositiveThreshold 
+PASS LargeNegativeThreshold 
+PASS PositiveInfinityThreshold 
+PASS NegativeInfinityThreshold 
+PASS NaNThreshold 
 

Modified: trunk/LayoutTests/intersection-observer/intersection-observer-interface.html (234817 => 234818)


--- trunk/LayoutTests/intersection-observer/intersection-observer-interface.html	2018-08-13 21:17:10 UTC (rev 234817)
+++ trunk/LayoutTests/intersection-observer/intersection-observer-interface.html	2018-08-13 22:02:45 UTC (rev 234818)
@@ -53,6 +53,40 @@
         var observer = new IntersectionObserver(function() {},  { threshold: [0, 0.33333678, 0.5, 0.76645] });
         assert_array_equals(observer.thresholds, [0, 0.33333678, 0.5, 0.76645]);
     },'ExplicitThresholds');
+    test(function() {
+        var observer = new IntersectionObserver(function() {},  { threshold: Number.MIN_VALUE });
+        assert_array_equals(observer.thresholds, [Number.MIN_VALUE]);
+    },'SmallPositiveThreshold');
+    test(function() {
+        assert_throws(RangeError(), function() {
+            new IntersectionObserver(function() {},  { threshold: -Number.MIN_VALUE });
+        })
+    },'SmallNegativeThreshold');
+    test(function() {
+        assert_throws(RangeError(), function() {
+            new IntersectionObserver(function() {},  { threshold: Number.MAX_VALUE });
+        })
+    },'LargePositiveThreshold');
+    test(function() {
+        assert_throws(RangeError(), function() {
+            new IntersectionObserver(function() {},  { threshold: -Number.MAX_VALUE });
+        })
+    },'LargeNegativeThreshold');
+    test(function() {
+        assert_throws(TypeError(), function() {
+            new IntersectionObserver(function() {},  { threshold: Number.POSITIVE_INFINITY });
+        })
+    },'PositiveInfinityThreshold');
+    test(function() {
+        assert_throws(TypeError(), function() {
+            new IntersectionObserver(function() {},  { threshold: Number.NEGATIVE_INFINITY });
+        })
+    },'NegativeInfinityThreshold');
+    test(function() {
+        assert_throws(TypeError(), function() {
+            new IntersectionObserver(function() {},  { threshold: Number.NaN });
+        })
+    },'NaNThreshold');
 </script>
 </body>
 </html>

Modified: trunk/Source/WebCore/ChangeLog (234817 => 234818)


--- trunk/Source/WebCore/ChangeLog	2018-08-13 21:17:10 UTC (rev 234817)
+++ trunk/Source/WebCore/ChangeLog	2018-08-13 22:02:45 UTC (rev 234818)
@@ -1,3 +1,21 @@
+2018-08-13  Ali Juma  <[email protected]>
+
+        [IntersectionObserver] Validate threshold values
+        https://bugs.webkit.org/show_bug.cgi?id=188475
+
+        Reviewed by Simon Fraser.
+
+        Throw an exception if any of an IntersectionObserver's thresholds are outside
+        the range [0, 1].
+
+        Tested by: imported/w3c/web-platform-tests/intersection-observer/observer-exceptions.html
+                   intersection-observer/intersection-observer-interface.html
+
+        * page/IntersectionObserver.cpp:
+        (WebCore::IntersectionObserver::create):
+        (WebCore::IntersectionObserver::IntersectionObserver):
+        * page/IntersectionObserver.h:
+
 2018-08-13  Alex Christensen  <[email protected]>
 
         Remove unused CSSSelector::parseNth

Modified: trunk/Source/WebCore/page/IntersectionObserver.cpp (234817 => 234818)


--- trunk/Source/WebCore/page/IntersectionObserver.cpp	2018-08-13 21:17:10 UTC (rev 234817)
+++ trunk/Source/WebCore/page/IntersectionObserver.cpp	2018-08-13 22:02:45 UTC (rev 234818)
@@ -87,18 +87,28 @@
     if (rootMarginOrException.hasException())
         return rootMarginOrException.releaseException();
 
-    return adoptRef(*new IntersectionObserver(WTFMove(callback), WTFMove(init), rootMarginOrException.releaseReturnValue()));
+    Vector<double> thresholds;
+    WTF::switchOn(init.threshold, [&thresholds] (double initThreshold) {
+        thresholds.reserveInitialCapacity(1);
+        thresholds.uncheckedAppend(initThreshold);
+    }, [&thresholds] (Vector<double>& initThresholds) {
+        thresholds = WTFMove(initThresholds);
+    });
+
+    for (auto threshold : thresholds) {
+        if (!(threshold >= 0 && threshold <= 1))
+            return Exception { RangeError, "Failed to construct 'IntersectionObserver': all thresholds must lie in the range [0.0, 1.0]." };
+    }
+
+    return adoptRef(*new IntersectionObserver(WTFMove(callback), WTFMove(init.root), rootMarginOrException.releaseReturnValue(), WTFMove(thresholds)));
 }
 
-IntersectionObserver::IntersectionObserver(Ref<IntersectionObserverCallback>&& callback, Init&& init, LengthBox&& parsedRootMargin)
-    : m_root(init.root)
+IntersectionObserver::IntersectionObserver(Ref<IntersectionObserverCallback>&& callback, RefPtr<Element>&& root, LengthBox&& parsedRootMargin, Vector<double>&& thresholds)
+    : m_root(WTFMove(root))
     , m_rootMargin(WTFMove(parsedRootMargin))
+    , m_thresholds(WTFMove(thresholds))
     , m_callback(WTFMove(callback))
 {
-    if (WTF::holds_alternative<double>(init.threshold))
-        m_thresholds.append(WTF::get<double>(init.threshold));
-    else
-        m_thresholds = WTF::get<Vector<double>>(WTFMove(init.threshold));
 }
 
 String IntersectionObserver::rootMargin() const

Modified: trunk/Source/WebCore/page/IntersectionObserver.h (234817 => 234818)


--- trunk/Source/WebCore/page/IntersectionObserver.h	2018-08-13 21:17:10 UTC (rev 234817)
+++ trunk/Source/WebCore/page/IntersectionObserver.h	2018-08-13 22:02:45 UTC (rev 234818)
@@ -59,7 +59,7 @@
     Vector<RefPtr<IntersectionObserverEntry>> takeRecords();
 
 private:
-    IntersectionObserver(Ref<IntersectionObserverCallback>&&, Init&&, LengthBox&& parsedRootMargin);
+    IntersectionObserver(Ref<IntersectionObserverCallback>&&, RefPtr<Element>&& root, LengthBox&& parsedRootMargin, Vector<double>&& thresholds);
     
     RefPtr<Element> m_root;
     LengthBox m_rootMargin;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to