Changeset 234818 in webkit


Ignore:
Timestamp:
Aug 13, 2018 3:02:45 PM (6 years ago)
Author:
ajuma@chromium.org
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:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r234804 r234818  
     12018-08-13  Ali Juma  <ajuma@chromium.org>
     2
     3        [IntersectionObserver] Validate threshold values
     4        https://bugs.webkit.org/show_bug.cgi?id=188475
     5
     6        Reviewed by Simon Fraser.
     7
     8        Add test coverage for interesting floating point threshold values.
     9
     10        * intersection-observer/intersection-observer-interface-expected.txt:
     11        * intersection-observer/intersection-observer-interface.html:
     12
    1132018-08-13  Ryan Haddad  <ryanhaddad@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r234799 r234818  
     12018-08-13  Ali Juma  <ajuma@chromium.org>
     2
     3        [IntersectionObserver] Validate threshold values
     4        https://bugs.webkit.org/show_bug.cgi?id=188475
     5
     6        Reviewed by Simon Fraser.
     7
     8        Update expectation for newly passing test case.
     9
     10        * web-platform-tests/intersection-observer/observer-exceptions-expected.txt:
     11        * web-platform-tests/intersection-observer/observer-exceptions.html: Fix typo already fixed upstream.
     12
    1132018-08-13  Yusuke Suzuki  <yusukesuzuki@slowstart.org>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/observer-exceptions-expected.txt

    r234761 r234818  
    11
    2 FAIL IntersectionObserver constructor with { threshold: [1.1] } assert_throws: function "function () {
    3     new IntersectionObserver(e => {}, {threshold: [1.1]})
    4   }" did not throw
     2PASS IntersectionObserver constructor with { threshold: [1.1] }
    53PASS IntersectionObserver constructor with { threshold: ["foo"] }
    6 PASS IntersectionObserver constructor witth { rootMargin: "1" }
     4PASS IntersectionObserver constructor with { rootMargin: "1" }
    75PASS IntersectionObserver constructor with { rootMargin: "2em" }
    86PASS IntersectionObserver constructor with { rootMargin: "auto" }
  • trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/observer-exceptions.html

    r234723 r234818  
    2020    new IntersectionObserver(e => {}, {rootMargin: "1"})
    2121  })
    22 }, 'IntersectionObserver constructor witth { rootMargin: "1" }');
     22}, 'IntersectionObserver constructor with { rootMargin: "1" }');
    2323
    2424test(function () {
  • trunk/LayoutTests/intersection-observer/intersection-observer-interface-expected.txt

    r234761 r234818  
    1111PASS ExplicitThreshold
    1212PASS ExplicitThresholds
     13PASS SmallPositiveThreshold
     14PASS SmallNegativeThreshold
     15PASS LargePositiveThreshold
     16PASS LargeNegativeThreshold
     17PASS PositiveInfinityThreshold
     18PASS NegativeInfinityThreshold
     19PASS NaNThreshold
    1320
  • trunk/LayoutTests/intersection-observer/intersection-observer-interface.html

    r234761 r234818  
    5454        assert_array_equals(observer.thresholds, [0, 0.33333678, 0.5, 0.76645]);
    5555    },'ExplicitThresholds');
     56    test(function() {
     57        var observer = new IntersectionObserver(function() {},  { threshold: Number.MIN_VALUE });
     58        assert_array_equals(observer.thresholds, [Number.MIN_VALUE]);
     59    },'SmallPositiveThreshold');
     60    test(function() {
     61        assert_throws(RangeError(), function() {
     62            new IntersectionObserver(function() {},  { threshold: -Number.MIN_VALUE });
     63        })
     64    },'SmallNegativeThreshold');
     65    test(function() {
     66        assert_throws(RangeError(), function() {
     67            new IntersectionObserver(function() {},  { threshold: Number.MAX_VALUE });
     68        })
     69    },'LargePositiveThreshold');
     70    test(function() {
     71        assert_throws(RangeError(), function() {
     72            new IntersectionObserver(function() {},  { threshold: -Number.MAX_VALUE });
     73        })
     74    },'LargeNegativeThreshold');
     75    test(function() {
     76        assert_throws(TypeError(), function() {
     77            new IntersectionObserver(function() {},  { threshold: Number.POSITIVE_INFINITY });
     78        })
     79    },'PositiveInfinityThreshold');
     80    test(function() {
     81        assert_throws(TypeError(), function() {
     82            new IntersectionObserver(function() {},  { threshold: Number.NEGATIVE_INFINITY });
     83        })
     84    },'NegativeInfinityThreshold');
     85    test(function() {
     86        assert_throws(TypeError(), function() {
     87            new IntersectionObserver(function() {},  { threshold: Number.NaN });
     88        })
     89    },'NaNThreshold');
    5690</script>
    5791</body>
  • trunk/Source/WebCore/ChangeLog

    r234817 r234818  
     12018-08-13  Ali Juma  <ajuma@chromium.org>
     2
     3        [IntersectionObserver] Validate threshold values
     4        https://bugs.webkit.org/show_bug.cgi?id=188475
     5
     6        Reviewed by Simon Fraser.
     7
     8        Throw an exception if any of an IntersectionObserver's thresholds are outside
     9        the range [0, 1].
     10
     11        Tested by: imported/w3c/web-platform-tests/intersection-observer/observer-exceptions.html
     12                   intersection-observer/intersection-observer-interface.html
     13
     14        * page/IntersectionObserver.cpp:
     15        (WebCore::IntersectionObserver::create):
     16        (WebCore::IntersectionObserver::IntersectionObserver):
     17        * page/IntersectionObserver.h:
     18
    1192018-08-13  Alex Christensen  <achristensen@webkit.org>
    220
  • trunk/Source/WebCore/page/IntersectionObserver.cpp

    r234761 r234818  
    8888        return rootMarginOrException.releaseException();
    8989
    90     return adoptRef(*new IntersectionObserver(WTFMove(callback), WTFMove(init), rootMarginOrException.releaseReturnValue()));
     90    Vector<double> thresholds;
     91    WTF::switchOn(init.threshold, [&thresholds] (double initThreshold) {
     92        thresholds.reserveInitialCapacity(1);
     93        thresholds.uncheckedAppend(initThreshold);
     94    }, [&thresholds] (Vector<double>& initThresholds) {
     95        thresholds = WTFMove(initThresholds);
     96    });
     97
     98    for (auto threshold : thresholds) {
     99        if (!(threshold >= 0 && threshold <= 1))
     100            return Exception { RangeError, "Failed to construct 'IntersectionObserver': all thresholds must lie in the range [0.0, 1.0]." };
     101    }
     102
     103    return adoptRef(*new IntersectionObserver(WTFMove(callback), WTFMove(init.root), rootMarginOrException.releaseReturnValue(), WTFMove(thresholds)));
    91104}
    92105
    93 IntersectionObserver::IntersectionObserver(Ref<IntersectionObserverCallback>&& callback, Init&& init, LengthBox&& parsedRootMargin)
    94     : m_root(init.root)
     106IntersectionObserver::IntersectionObserver(Ref<IntersectionObserverCallback>&& callback, RefPtr<Element>&& root, LengthBox&& parsedRootMargin, Vector<double>&& thresholds)
     107    : m_root(WTFMove(root))
    95108    , m_rootMargin(WTFMove(parsedRootMargin))
     109    , m_thresholds(WTFMove(thresholds))
    96110    , m_callback(WTFMove(callback))
    97111{
    98     if (WTF::holds_alternative<double>(init.threshold))
    99         m_thresholds.append(WTF::get<double>(init.threshold));
    100     else
    101         m_thresholds = WTF::get<Vector<double>>(WTFMove(init.threshold));
    102112}
    103113
  • trunk/Source/WebCore/page/IntersectionObserver.h

    r234761 r234818  
    6060
    6161private:
    62     IntersectionObserver(Ref<IntersectionObserverCallback>&&, Init&&, LengthBox&& parsedRootMargin);
     62    IntersectionObserver(Ref<IntersectionObserverCallback>&&, RefPtr<Element>&& root, LengthBox&& parsedRootMargin, Vector<double>&& thresholds);
    6363   
    6464    RefPtr<Element> m_root;
Note: See TracChangeset for help on using the changeset viewer.