Bug 1527277 - Part 1: Refactor error reporting logic. r=peterv
authorEric Rahm <erahm@mozilla.com>
Thu, 21 Feb 2019 23:07:05 +0000
changeset 520553 62aba7d6d779e6a5e3a088b94ea0df7eef2d92bd
parent 520552 60c03f3c8c5b67e337887eaf22191c71127687dc
child 520554 7ce2309548dab8af0285f3224cb344640089f59b
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs1527277
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1527277 - Part 1: Refactor error reporting logic. r=peterv Add a common function for reporting an invalid argument. Differential Revision: https://phabricator.services.mozilla.com/D20578
dom/xslt/xslt/txFormatNumberFunctionCall.cpp
dom/xslt/xslt/txXSLTFunctions.h
--- a/dom/xslt/xslt/txFormatNumberFunctionCall.cpp
+++ b/dom/xslt/xslt/txFormatNumberFunctionCall.cpp
@@ -26,16 +26,25 @@ const char16_t txFormatNumberFunctionCal
 
 /*
  * Creates a new format-number function call
  */
 txFormatNumberFunctionCall::txFormatNumberFunctionCall(
     txStylesheet* aStylesheet, txNamespaceMap* aMappings)
     : mStylesheet(aStylesheet), mMappings(aMappings) {}
 
+void txFormatNumberFunctionCall::ReportInvalidArg(txIEvalContext* aContext) {
+  nsAutoString err(INVALID_PARAM_VALUE);
+#ifdef TX_TO_STRING
+  err.AppendLiteral(": ");
+  toString(err);
+#endif
+  aContext->receiveError(err, NS_ERROR_XPATH_INVALID_ARG);
+}
+
 /*
  * Evaluates this Expr based on the given context node and processor state
  * @param context the context node for evaluation of this Expr
  * @param cs the ContextState containing the stack information needed
  * for evaluation
  * @return the result of the evaluation
  */
 nsresult txFormatNumberFunctionCall::evaluate(txIEvalContext* aContext,
@@ -130,34 +139,24 @@ nsresult txFormatNumberFunctionCall::eva
     switch (pState) {
       case Prefix:
       case Suffix:
         if (!inQuote) {
           if (c == format->mPercent) {
             if (multiplier == 1)
               multiplier = 100;
             else {
-              nsAutoString err(INVALID_PARAM_VALUE);
-#ifdef TX_TO_STRING
-              err.AppendLiteral(": ");
-              toString(err);
-#endif
-              aContext->receiveError(err, NS_ERROR_XPATH_INVALID_ARG);
+              ReportInvalidArg(aContext);
               return NS_ERROR_XPATH_INVALID_ARG;
             }
           } else if (c == format->mPerMille) {
             if (multiplier == 1)
               multiplier = 1000;
             else {
-              nsAutoString err(INVALID_PARAM_VALUE);
-#ifdef TX_TO_STRING
-              err.AppendLiteral(": ");
-              toString(err);
-#endif
-              aContext->receiveError(err, NS_ERROR_XPATH_INVALID_ARG);
+              ReportInvalidArg(aContext);
               return NS_ERROR_XPATH_INVALID_ARG;
             }
           } else if (c == format->mDecimalSeparator ||
                      c == format->mGroupingSeparator ||
                      c == format->mZeroDigit || c == format->mDigit ||
                      c == format->mPatternSeparator) {
             pState = pState == Prefix ? IntDigit : Finished;
             pos--;
@@ -220,22 +219,17 @@ nsresult txFormatNumberFunctionCall::eva
       case Finished:
         break;
     }
   }
 
   // Did we manage to parse the entire formatstring and was it valid
   if ((c != format->mPatternSeparator && pos < formatLen) || inQuote ||
       groupSize == 0) {
-    nsAutoString err(INVALID_PARAM_VALUE);
-#ifdef TX_TO_STRING
-    err.AppendLiteral(": ");
-    toString(err);
-#endif
-    aContext->receiveError(err, NS_ERROR_XPATH_INVALID_ARG);
+    ReportInvalidArg(aContext);
     return NS_ERROR_XPATH_INVALID_ARG;
   }
 
   /*
    * FINALLY we're done with the parsing
    * now build the result string
    */
 
--- a/dom/xslt/xslt/txXSLTFunctions.h
+++ b/dom/xslt/xslt/txXSLTFunctions.h
@@ -66,16 +66,19 @@ class txFormatNumberFunctionCall : publi
     IntDigit,
     IntZero,
     FracZero,
     FracDigit,
     Suffix,
     Finished
   };
 
+  // Helper that reports and invalid arg to the provided context.
+  void ReportInvalidArg(txIEvalContext* aContext);
+
   txStylesheet* mStylesheet;
   RefPtr<txNamespaceMap> mMappings;
 };
 
 /**
  * DecimalFormat
  * A representation of the XSLT element <xsl:decimal-format>
  */