Change CSSParser::sourceSize returning Optional<CSSParser::SourceSize>
authoryoav@yoav.ws <yoav@yoav.ws@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Jul 2016 05:49:36 +0000 (05:49 +0000)
committeryoav@yoav.ws <yoav@yoav.ws@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Jul 2016 05:49:36 +0000 (05:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=159666

Reviewed by Michael Catanzaro.

Source/WebCore:

Tests:
    fast/dom/HTMLImageElement/sizes/image-sizes-invalids.html

* css/CSSGrammar.y.in: Avoid adding SourceSize to source_size_list when the value is a Nullopt.
* css/CSSParser.cpp:
(WebCore::CSSParser::sourceSize): Return a Nullopt when an invalid value is encountered.
* css/CSSParser.h:

LayoutTests:

Added a test to make sure that an invalid source-size value is skipped, but the next one is properly picked.

* fast/dom/HTMLImageElement/sizes/image-sizes-invalids-expected.txt:
* fast/dom/HTMLImageElement/sizes/image-sizes-invalids.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@203269 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/dom/HTMLImageElement/sizes/image-sizes-invalids-expected.txt
LayoutTests/fast/dom/HTMLImageElement/sizes/image-sizes-invalids.html
Source/WebCore/ChangeLog
Source/WebCore/css/CSSGrammar.y.in
Source/WebCore/css/CSSParser.cpp
Source/WebCore/css/CSSParser.h

index 36ebd62..049bb35 100644 (file)
@@ -1,3 +1,15 @@
+2016-07-14  Yoav Weiss  <yoav@yoav.ws>
+
+        Change CSSParser::sourceSize returning Optional<CSSParser::SourceSize>
+        https://bugs.webkit.org/show_bug.cgi?id=159666
+
+        Reviewed by Michael Catanzaro.
+
+        Added a test to make sure that an invalid source-size value is skipped, but the next one is properly picked.
+
+        * fast/dom/HTMLImageElement/sizes/image-sizes-invalids-expected.txt:
+        * fast/dom/HTMLImageElement/sizes/image-sizes-invalids.html:
+
 2016-07-14  Antonio Gomes  <tonikitoo@igalia.com>
 
         [RTL Scrollbars] Frame scrollbars don't move to the right when text direction changes to RTL
index 99a6f58..89b57a4 100644 (file)
@@ -16,7 +16,9 @@ PASS document.getElementById(elementId).clientWidth is 800
 PASS currentSrcFileName(elementId) is "image-set-2x.png"
 PASS document.getElementById(elementId).clientWidth is 800
 PASS currentSrcFileName(elementId) is "image-set-2x.png"
+PASS document.getElementById(elementId).clientWidth is 1600
+PASS currentSrcFileName(elementId) is "image-set-4x.png"
 PASS successfullyParsed is true
 
 TEST COMPLETE
-        
+         
index 6201e7c..18cf2c9 100644 (file)
@@ -12,6 +12,9 @@
             shouldBe('document.getElementById(elementId).clientWidth', '800');
             shouldBe('currentSrcFileName(elementId)', '"image-set-2x.png"');
         }
+        elementId = "crash10";
+        shouldBe('document.getElementById(elementId).clientWidth', '1600');
+        shouldBe('currentSrcFileName(elementId)', '"image-set-4x.png"');
     }, false);
 </script>
 <!-- crash tests -->
@@ -24,3 +27,4 @@
 <img id="crash7" sizes="calc(2px+dfmjbsf,,,skidkk)" srcset="../../../hidpi/resources/image-set-2x.png 800w, ../resources/image-set-4x.png 16000w">
 <img id="crash8" sizes="calc(2px+dfmjbsf,,,skidkk) + 2px, 56px" srcset="../../../hidpi/resources/image-set-2x.png 800w, ../resources/image-set-4x.png 16000w">
 <img id="crash9" sizes="1dpi" srcset="../../../hidpi/resources/image-set-2x.png 800w, ../resources/image-set-4x.png 16000w">
+<img id="crash10" sizes="(max-width: 10px) 1hz, 1600px" srcset="../../../hidpi/resources/image-set-2x.png 800w, ../resources/image-set-4x.png 1600w">
index 97602ca..18d5401 100644 (file)
@@ -1,3 +1,18 @@
+2016-07-14  Yoav Weiss  <yoav@yoav.ws>
+
+        Change CSSParser::sourceSize returning Optional<CSSParser::SourceSize>
+        https://bugs.webkit.org/show_bug.cgi?id=159666
+
+        Reviewed by Michael Catanzaro.
+
+        Tests:
+            fast/dom/HTMLImageElement/sizes/image-sizes-invalids.html
+
+        * css/CSSGrammar.y.in: Avoid adding SourceSize to source_size_list when the value is a Nullopt.
+        * css/CSSParser.cpp:
+        (WebCore::CSSParser::sourceSize): Return a Nullopt when an invalid value is encountered.
+        * css/CSSParser.h:
+
 2016-07-14  Antonio Gomes  <tonikitoo@igalia.com>
 
         [RTL Scrollbars] Frame scrollbars don't move to the right when text direction changes to RTL
index cad1ba7..439f89b 100644 (file)
@@ -576,12 +576,14 @@ webkit_source_size_list:
 source_size_list:
     maybe_source_media_query_expression source_size_length {
         $$ = new Vector<CSSParser::SourceSize>;
-        $$->append(parser->sourceSize(WTFMove(*$1), $2));
+        if (auto result = parser->sourceSize(WTFMove(*$1), $2))
+            $$->append(WTFMove(result.value()));
         delete $1;
     }
     | source_size_list maybe_space ',' maybe_space maybe_source_media_query_expression source_size_length {
         $$ = $1;
-        $$->append(parser->sourceSize(WTFMove(*$5), $6));
+        if (auto result = parser->sourceSize(WTFMove(*$5), $6))
+            $$->append(WTFMove(result.value()));
         delete $5;
     }
     ;
index b8e6330..36868a0 100644 (file)
@@ -1544,7 +1544,7 @@ CSSParser::SourceSize::SourceSize(MediaQueryExpression&& expression, Ref<CSSValu
 {
 }
 
-CSSParser::SourceSize CSSParser::sourceSize(MediaQueryExpression&& expression, CSSParserValue& parserValue)
+Optional<CSSParser::SourceSize> CSSParser::sourceSize(MediaQueryExpression&& expression, CSSParserValue& parserValue)
 {
     RefPtr<CSSValue> value;
     if (isCalculation(parserValue)) {
@@ -1552,12 +1552,11 @@ CSSParser::SourceSize CSSParser::sourceSize(MediaQueryExpression&& expression, C
         if (args && args->size())
             value = CSSCalcValue::create(parserValue.function->name, *args, CalculationRangeNonNegative);
     }
-    if (!value) {
+    if (!value)
         value = parserValue.createCSSValue();
-        if (!value)
-            value = CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_UNKNOWN);
-    }
     destroy(parserValue);
+    if (!value)
+        return Nullopt;
     // FIXME: Calling the constructor explicitly here to work around an MSVC bug.
     // For other compilers, we did not need to define the constructors and we could use aggregate initialization syntax.
     return SourceSize(WTFMove(expression), value.releaseNonNull());
index 235d1e1..9126f27 100644 (file)
@@ -176,7 +176,7 @@ public:
         SourceSize(MediaQueryExpression&&, Ref<CSSValue>&&);
     };
     Vector<SourceSize> parseSizesAttribute(StringView);
-    SourceSize sourceSize(MediaQueryExpression&&, CSSParserValue&);
+    Optional<SourceSize> sourceSize(MediaQueryExpression&&, CSSParserValue&);
 
     bool parseFillImage(CSSParserValueList&, RefPtr<CSSValue>&);