Bug 1344040: Annotate intentionally-unused SkipDeclaration() & ParseSingleTokenVariant() return values, and mark the functions as MOZ_MUST_USE. r=xidorn
authorDaniel Holbert <dholbert@cs.stanford.edu>
Sun, 05 Mar 2017 20:29:30 -0800
changeset 375073 5c8d8a0742912bc691e11afb44a7e302044abe77
parent 375072 86ba78dc87ce16041ea22671bfe7bc0fd3aa32d4
child 375074 966464a68a2cb3ca1125808e34abb5c1d34e3797
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersxidorn
bugs1344040
milestone54.0a1
Bug 1344040: Annotate intentionally-unused SkipDeclaration() & ParseSingleTokenVariant() return values, and mark the functions as MOZ_MUST_USE. r=xidorn MozReview-Commit-ID: JFBkIBHYdhQ
layout/style/nsCSSParser.cpp
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -3,22 +3,24 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* parsing of CSS stylesheets, based on a token stream from the CSS scanner */
 
 #include "nsCSSParser.h"
 
+#include "mozilla/Attributes.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/Maybe.h"
 #include "mozilla/Move.h"
 #include "mozilla/MathAlgorithms.h"
 #include "mozilla/TypedEnumBits.h"
+#include "mozilla/Unused.h"
 
 #include <algorithm> // for std::stable_sort
 #include <limits> // for std::numeric_limits
 
 #include "nsAlgorithm.h"
 #include "nsCSSProps.h"
 #include "nsCSSKeywords.h"
 #include "nsCSSScanner.h"
@@ -636,17 +638,17 @@ protected:
   void SkipUntilAllOf(const StopSymbolCharStack& aStopSymbolChars);
   // returns true if the stop symbol or EOF is found, and false for an
   // unexpected ')', ']' or '}'; this not safe to call outside variable
   // resolution, as it doesn't handle mismatched content
   bool SkipBalancedContentUntil(char16_t aStopSymbol);
 
   void SkipRuleSet(bool aInsideBraces);
   bool SkipAtRule(bool aInsideBlock);
-  bool SkipDeclaration(bool aCheckForBraces);
+  MOZ_MUST_USE bool SkipDeclaration(bool aCheckForBraces);
 
   void PushGroup(css::GroupRule* aRule);
   void PopGroup();
 
   bool ParseRuleSet(RuleAppendFunc aAppendFunc, void* aProcessData,
                     bool aInsideBraces = false);
   bool ParseAtRule(RuleAppendFunc aAppendFunc, void* aProcessData,
                    bool aInAtRule);
@@ -1213,19 +1215,20 @@ protected:
                                          int32_t aVariantMask,
                                          const KTableEntry aKeywordTable[]);
   CSSParseResult ParseOneOrLargerVariant(nsCSSValue& aValue,
                                          int32_t aVariantMask,
                                          const KTableEntry aKeywordTable[]);
 
   // Variant parsing methods that are guaranteed to UngetToken any token
   // consumed on failure
-  bool ParseSingleTokenVariant(nsCSSValue& aValue,
-                               int32_t aVariantMask,
-                               const KTableEntry aKeywordTable[])
+
+  MOZ_MUST_USE bool ParseSingleTokenVariant(nsCSSValue& aValue,
+                                            int32_t aVariantMask,
+                                            const KTableEntry aKeywordTable[])
   {
     MOZ_ASSERT(!(aVariantMask & VARIANT_MULTIPLE_TOKENS),
                "use ParseVariant for variants in VARIANT_MULTIPLE_TOKENS");
     CSSParseResult result = ParseVariant(aValue, aVariantMask, aKeywordTable);
     MOZ_ASSERT(result != CSSParseResult::Error);
     return result == CSSParseResult::Ok;
   }
   bool ParseSingleTokenVariantWithRestrictions(
@@ -4081,17 +4084,17 @@ CSSParserImpl::ParseFontDescriptor(nsCSS
   nsCSSFontDesc descID = nsCSSProps::LookupFontDesc(descName);
   nsCSSValue value;
 
   if (descID == eCSSFontDesc_UNKNOWN ||
       (descID == eCSSFontDesc_Display &&
        !Preferences::GetBool("layout.css.font-display.enabled"))) {
     if (NonMozillaVendorIdentifier(descName)) {
       // silently skip other vendors' extensions
-      SkipDeclaration(true);
+      Unused << SkipDeclaration(true);
       return true;
     } else {
       REPORT_UNEXPECTED_P(PEUnknownFontDesc, descName);
       return false;
     }
   }
 
   if (!ParseFontDescriptorValue(descID, value)) {
@@ -15485,20 +15488,23 @@ CSSParserImpl::ParseTextEmphasisStyle(ns
 
   if (ParseSingleTokenVariant(aValue, VARIANT_HOS, nullptr)) {
     return true;
   }
 
   nsCSSValue first, second;
   const auto& fillKTable = nsCSSProps::kTextEmphasisStyleFillKTable;
   const auto& shapeKTable = nsCSSProps::kTextEmphasisStyleShapeKTable;
+
+  // Parse a fill value and/or a shape value, in either order.
+  // (Require at least one of them, and treat the second as optional.)
   if (ParseSingleTokenVariant(first, VARIANT_KEYWORD, fillKTable)) {
-    ParseSingleTokenVariant(second, VARIANT_KEYWORD, shapeKTable);
+    Unused << ParseSingleTokenVariant(second, VARIANT_KEYWORD, shapeKTable);
   } else if (ParseSingleTokenVariant(first, VARIANT_KEYWORD, shapeKTable)) {
-    ParseSingleTokenVariant(second, VARIANT_KEYWORD, fillKTable);
+    Unused << ParseSingleTokenVariant(second, VARIANT_KEYWORD, fillKTable);
   } else {
     return false;
   }
 
   auto value = first.GetIntValue();
   if (second.GetUnit() == eCSSUnit_Enumerated) {
     value |= second.GetIntValue();
   }
@@ -17053,18 +17059,18 @@ CSSParserImpl::ParseShadowItem(nsCSSValu
     IndexColor,
     IndexInset    // only for box-shadow
   };
 
   RefPtr<nsCSSValue::Array> val = nsCSSValue::Array::Create(6);
 
   if (aIsBoxShadow) {
     // Optional inset keyword (ignore errors)
-    ParseSingleTokenVariant(val->Item(IndexInset), VARIANT_KEYWORD,
-                            nsCSSProps::kBoxShadowTypeKTable);
+    Unused << ParseSingleTokenVariant(val->Item(IndexInset), VARIANT_KEYWORD,
+                                      nsCSSProps::kBoxShadowTypeKTable);
   }
 
   nsCSSValue xOrColor;
   bool haveColor = false;
   if (ParseVariant(xOrColor, VARIANT_COLOR | VARIANT_LENGTH | VARIANT_CALC,
                    nullptr) != CSSParseResult::Ok) {
     return false;
   }
@@ -17120,19 +17126,19 @@ CSSParserImpl::ParseShadowItem(nsCSSValu
     // Optional color
     if (ParseVariant(val->Item(IndexColor), VARIANT_COLOR, nullptr) ==
         CSSParseResult::Error) {
       return false;
     }
   }
 
   if (aIsBoxShadow && val->Item(IndexInset).GetUnit() == eCSSUnit_Null) {
-    // Optional inset keyword
-    ParseSingleTokenVariant(val->Item(IndexInset), VARIANT_KEYWORD,
-                            nsCSSProps::kBoxShadowTypeKTable);
+    // Optional inset keyword (ignore errors)
+    Unused << ParseSingleTokenVariant(val->Item(IndexInset), VARIANT_KEYWORD,
+                                      nsCSSProps::kBoxShadowTypeKTable);
   }
 
   aValue.SetArrayValue(val, eCSSUnit_Array);
   return true;
 }
 
 bool
 CSSParserImpl::ParseShadowList(nsCSSPropertyID aProperty)