Commit fba45ba9 authored by Stefan Zager's avatar Stefan Zager Committed by Commit Bot

[IntersectionObserver] Fix some edge cases in parsing options

BUG=

Change-Id: Ia3b6dc5f8dfd6036a55a2dd91e76b9c94d6f9535
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2388706Reviewed-by: default avatarvmpstr <vmpstr@chromium.org>
Commit-Queue: Stefan Zager <szager@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803904}
parent 8b5a6752
......@@ -89,6 +89,7 @@ void ParseMargin(String margin_parameter,
CSSTokenizer tokenizer(margin_parameter);
const auto tokens = tokenizer.TokenizeToEOF();
CSSParserTokenRange token_range(tokens);
token_range.ConsumeWhitespace();
while (token_range.Peek().GetType() != kEOFToken &&
!exception_state.HadException()) {
if (margin.size() == 4) {
......@@ -136,6 +137,9 @@ void ParseThresholds(const DoubleOrDoubleSequence& threshold_parameter,
thresholds.push_back(base::MakeClampedNum<float>(threshold_value));
}
if (thresholds.IsEmpty())
thresholds.push_back(0.f);
for (auto threshold_value : thresholds) {
if (std::isnan(threshold_value) || threshold_value < 0.0 ||
threshold_value > 1.0) {
......
......@@ -15,6 +15,15 @@ test(function() {
test(function() { assert_equals(observer.rootMargin, "0px 0px 0px 0px") },
"observer.rootMargin");
observer = new IntersectionObserver(function(e) {}, {
rootMargin: " ",
threshold: []
});
test(function() { assert_array_equals(observer.thresholds, [0]) },
"empty observer.thresholds");
test(function() { assert_equals(observer.rootMargin, "0px 0px 0px 0px") },
"whitespace observer.rootMargin");
var rootDiv = document.getElementById("root");
observer = new IntersectionObserver(function(e) {}, {
root: rootDiv,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment