WebKit Bugzilla
Attachment 347034 Details for
Bug 188475
: [IntersectionObserver] Validate threshold values
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-188475-20180813164659.patch (text/plain), 10.21 KB, created by
Ali Juma
on 2018-08-13 13:47:00 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Ali Juma
Created:
2018-08-13 13:47:00 PDT
Size:
10.21 KB
patch
obsolete
>Subversion Revision: 234761 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 03f2c3eb684786b0fadaafaf2abf677b7f344639..df7745e0126ad0e4b72e7538392661be7f288493 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,21 @@ >+2018-08-13 Ali Juma <ajuma@chromium.org> >+ >+ [IntersectionObserver] Validate threshold values >+ https://bugs.webkit.org/show_bug.cgi?id=188475 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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-10 Ali Juma <ajuma@chromium.org> > > [IntersectionObserver] Implement rootMargin parsing >diff --git a/Source/WebCore/page/IntersectionObserver.cpp b/Source/WebCore/page/IntersectionObserver.cpp >index fa7a2cb422d213bcda46afea0396da933850d11a..604dbcc05463b1c2f1c0e3784387702c6fab8f76 100644 >--- a/Source/WebCore/page/IntersectionObserver.cpp >+++ b/Source/WebCore/page/IntersectionObserver.cpp >@@ -87,18 +87,28 @@ ExceptionOr<Ref<IntersectionObserver>> IntersectionObserver::create(Ref<Intersec > 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 >diff --git a/Source/WebCore/page/IntersectionObserver.h b/Source/WebCore/page/IntersectionObserver.h >index 1d3f01201aad081e7c52d81786db36b82f65ccaa..b04cfb21162855b21b670450130895349a2e14e2 100644 >--- a/Source/WebCore/page/IntersectionObserver.h >+++ b/Source/WebCore/page/IntersectionObserver.h >@@ -59,7 +59,7 @@ public: > 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; >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index 0f41a0f369e1693c4628e2e06c9f4f9cd09edb31..9f308c984d9c9dd09c17bc39900e35a1a943ad76 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,15 @@ >+2018-08-13 Ali Juma <ajuma@chromium.org> >+ >+ [IntersectionObserver] Validate threshold values >+ https://bugs.webkit.org/show_bug.cgi?id=188475 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Add test coverage for interesting floating point threshold values. >+ >+ * intersection-observer/intersection-observer-interface-expected.txt: >+ * intersection-observer/intersection-observer-interface.html: >+ > 2018-08-10 Ali Juma <ajuma@chromium.org> > > [IntersectionObserver] Implement rootMargin parsing >diff --git a/LayoutTests/imported/w3c/ChangeLog b/LayoutTests/imported/w3c/ChangeLog >index cb3cafc97e2609826c46fd97b1263f5687eb7ae7..55cc3f68281ec191f3268a95886188c50d885810 100644 >--- a/LayoutTests/imported/w3c/ChangeLog >+++ b/LayoutTests/imported/w3c/ChangeLog >@@ -1,3 +1,15 @@ >+2018-08-13 Ali Juma <ajuma@chromium.org> >+ >+ [IntersectionObserver] Validate threshold values >+ https://bugs.webkit.org/show_bug.cgi?id=188475 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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-10 Ali Juma <ajuma@chromium.org> > > [IntersectionObserver] Implement rootMargin parsing >diff --git a/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/observer-exceptions-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/observer-exceptions-expected.txt >index 69880cc7471a6be0299eee54e3dda1b2ef2d784b..4a0581818921ac8e0237287630698b66a766b4d2 100644 >--- a/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/observer-exceptions-expected.txt >+++ b/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/observer-exceptions-expected.txt >@@ -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)" } >diff --git a/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/observer-exceptions.html b/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/observer-exceptions.html >index d4f178be51c394ba98225f359eb02cd78f45259e..5d29234bbf32505a98ad132571c6d5467ce44d51 100644 >--- a/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/observer-exceptions.html >+++ b/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/observer-exceptions.html >@@ -19,7 +19,7 @@ test(function () { > 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() { >diff --git a/LayoutTests/intersection-observer/intersection-observer-interface-expected.txt b/LayoutTests/intersection-observer/intersection-observer-interface-expected.txt >index 16b615092954dd49d3b58709f62a5d6eee81bc78..60690dd9da48e0ec9d34dda7ddab2ff3ea6d16c3 100644 >--- a/LayoutTests/intersection-observer/intersection-observer-interface-expected.txt >+++ b/LayoutTests/intersection-observer/intersection-observer-interface-expected.txt >@@ -10,4 +10,11 @@ PASS ExplicitFourArgumentRootMargin > PASS ExplicitRoot > PASS ExplicitThreshold > PASS ExplicitThresholds >+PASS SmallPositiveThreshold >+PASS SmallNegativeThreshold >+PASS LargePositiveThreshold >+PASS LargeNegativeThreshold >+PASS PositiveInfinityThreshold >+PASS NegativeInfinityThreshold >+PASS NaNThreshold > >diff --git a/LayoutTests/intersection-observer/intersection-observer-interface.html b/LayoutTests/intersection-observer/intersection-observer-interface.html >index 39fa59e69e0d00a602c0727e323c8ef56d679740..90d24ffa17c684ec9a1976d75e4ef1428186a9d5 100644 >--- a/LayoutTests/intersection-observer/intersection-observer-interface.html >+++ b/LayoutTests/intersection-observer/intersection-observer-interface.html >@@ -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>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 188475
:
346912
| 347034