Source/WebCore/ChangeLog

 12018-08-10 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 NOBODY (OOPS!).
 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
 13 * page/IntersectionObserver.cpp:
 14 (WebCore::IntersectionObserver::create):
 15 (WebCore::IntersectionObserver::IntersectionObserver):
 16 * page/IntersectionObserver.h:
 17
1182018-08-10 Ali Juma <ajuma@chromium.org>
219
320 [IntersectionObserver] Implement rootMargin parsing

Source/WebCore/page/IntersectionObserver.cpp

@@ExceptionOr<Ref<IntersectionObserver>> IntersectionObserver::create(Ref<Intersec
8787 if (rootMarginOrException.hasException())
8888 return rootMarginOrException.releaseException();
8989
90  return adoptRef(*new IntersectionObserver(WTFMove(callback), WTFMove(init), rootMarginOrException.releaseReturnValue()));
 90 Vector<double> thresholds;
 91 if (WTF::holds_alternative<double>(init.threshold))
 92 thresholds.append(WTF::get<double>(init.threshold));
 93 else
 94 thresholds = WTF::get<Vector<double>>(WTFMove(init.threshold));
 95
 96 for (auto threshold : thresholds) {
 97 if (threshold < 0 || threshold > 1)
 98 return Exception { RangeError, "Failed to construct 'IntersectionObserver': all thresholds must lie in the range [0.0, 1.0]." };
 99 }
 100
 101 return adoptRef(*new IntersectionObserver(WTFMove(callback), WTFMove(init.root), rootMarginOrException.releaseReturnValue(), WTFMove(thresholds)));
91102}
92103
93 IntersectionObserver::IntersectionObserver(Ref<IntersectionObserverCallback>&& callback, Init&& init, LengthBox&& parsedRootMargin)
94  : m_root(init.root)
 104IntersectionObserver::IntersectionObserver(Ref<IntersectionObserverCallback>&& callback, RefPtr<Element>&& root, LengthBox&& parsedRootMargin, Vector<double>&& thresholds)
 105 : m_root(WTFMove(root))
95106 , m_rootMargin(WTFMove(parsedRootMargin))
 107 , m_thresholds(WTFMove(thresholds))
96108 , m_callback(WTFMove(callback))
97109{
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));
102110}
103111
104112String IntersectionObserver::rootMargin() const

Source/WebCore/page/IntersectionObserver.h

@@public:
5959 Vector<RefPtr<IntersectionObserverEntry>> takeRecords();
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;
6565 LengthBox m_rootMargin;

LayoutTests/imported/w3c/ChangeLog

 12018-08-10 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 NOBODY (OOPS!).
 7
 8 Update expectation for newly passing test case.
 9
 10 * web-platform-tests/intersection-observer/observer-exceptions-expected.txt:
 11
1122018-08-10 Ali Juma <ajuma@chromium.org>
213
314 [IntersectionObserver] Implement rootMargin parsing

LayoutTests/imported/w3c/web-platform-tests/intersection-observer/observer-exceptions-expected.txt

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"] }
64PASS IntersectionObserver constructor witth { rootMargin: "1" }
75PASS IntersectionObserver constructor with { rootMargin: "2em" }