Bug 1325494 (part 2) - Remove kFoo constants from nsIParser.h. r=hsivonen.
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 23 Dec 2016 13:51:04 +1100
changeset 458368 8d182cb2af7e90c57ff5ad45f49dd7a1122b3080
parent 458367 0df76d4b7a2744ab8ae900b4605dc6c22a93ca26
child 458369 6e6fbdae596ddd73650db1ccb4e410f76b5ada11
push id40935
push userbmo:cam@mcc.id.au
push dateTue, 10 Jan 2017 07:11:37 +0000
reviewershsivonen
bugs1325494
milestone53.0a1
Bug 1325494 (part 2) - Remove kFoo constants from nsIParser.h. r=hsivonen. Only three of them are used, and those ones aren't used in many places, and they're just renamings of NS_ERROR_* values that obfuscate more than they clarify.
parser/htmlparser/nsExpatDriver.cpp
parser/htmlparser/nsHTMLTokenizer.cpp
parser/htmlparser/nsIParser.h
parser/htmlparser/nsParser.cpp
parser/htmlparser/nsScanner.cpp
--- a/parser/htmlparser/nsExpatDriver.cpp
+++ b/parser/htmlparser/nsExpatDriver.cpp
@@ -1205,17 +1205,17 @@ nsExpatDriver::ConsumeToken(nsScanner& a
 
   aScanner.SetPosition(currentExpatPosition, true);
   aScanner.Mark();
 
   MOZ_LOG(gExpatDriverLog, LogLevel::Debug,
          ("Remaining in expat's buffer: %i, remaining in scanner: %i.",
           mExpatBuffered, Distance(currentExpatPosition, end)));
 
-  return NS_SUCCEEDED(mInternalState) ? kEOF : NS_OK;
+  return NS_SUCCEEDED(mInternalState) ? NS_ERROR_HTMLPARSER_EOF : NS_OK;
 }
 
 NS_IMETHODIMP
 nsExpatDriver::WillBuildModel(const CParserContext& aParserContext,
                               nsITokenizer* aTokenizer,
                               nsIContentSink* aSink)
 {
   mSink = do_QueryInterface(aSink);
--- a/parser/htmlparser/nsHTMLTokenizer.cpp
+++ b/parser/htmlparser/nsHTMLTokenizer.cpp
@@ -51,10 +51,10 @@ nsHTMLTokenizer::WillTokenize(bool aIsFi
  * @param  aFlushTokens An OUT parameter to tell the caller whether it should
  *                      process our queued tokens up to now (e.g., when we
  *                      reach a <script>).
  * @return Success or error
  */
 nsresult
 nsHTMLTokenizer::ConsumeToken(nsScanner& aScanner, bool& aFlushTokens)
 {
-  return kEOF;
+  return NS_ERROR_HTMLPARSER_EOF;
 }
--- a/parser/htmlparser/nsIParser.h
+++ b/parser/htmlparser/nsIParser.h
@@ -237,27 +237,12 @@ class nsIParser : public nsParserBase {
 };
 
 NS_DEFINE_STATIC_IID_ACCESSOR(nsIParser, NS_IPARSER_IID)
 
 /* ===========================================================*
   Some useful constants...
  * ===========================================================*/
 
-#include "nsError.h"
-
-const nsresult  kEOF              = NS_ERROR_HTMLPARSER_EOF;
-const nsresult  kUnknownError     = NS_ERROR_HTMLPARSER_UNKNOWN;
-const nsresult  kCantPropagate    = NS_ERROR_HTMLPARSER_CANTPROPAGATE;
-const nsresult  kContextMismatch  = NS_ERROR_HTMLPARSER_CONTEXTMISMATCH;
-const nsresult  kBadFilename      = NS_ERROR_HTMLPARSER_BADFILENAME;
-const nsresult  kBadURL           = NS_ERROR_HTMLPARSER_BADURL;
-const nsresult  kInvalidParserContext = NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT;
-const nsresult  kBlocked          = NS_ERROR_HTMLPARSER_BLOCK;
-const nsresult  kBadStringLiteral = NS_ERROR_HTMLPARSER_UNTERMINATEDSTRINGLITERAL;
-const nsresult  kHierarchyTooDeep = NS_ERROR_HTMLPARSER_HIERARCHYTOODEEP;
-const nsresult  kFakeEndTag       = NS_ERROR_HTMLPARSER_FAKE_ENDTAG;
-const nsresult  kNotAComment      = NS_ERROR_HTMLPARSER_INVALID_COMMENT;
-
 #define NS_IPARSER_FLAG_XML                  0x00000200
 #define NS_IPARSER_FLAG_HTML                 0x00000400
 
 #endif
--- a/parser/htmlparser/nsParser.cpp
+++ b/parser/htmlparser/nsParser.cpp
@@ -838,17 +838,17 @@ nsParser::CancelParsingEvents()
  * last thing that happens right before parsing, so we
  * can delay until the last moment the resolution of
  * which DTD to use (unless of course we're assigned one).
  */
 nsresult
 nsParser::WillBuildModel(nsString& aFilename)
 {
   if (!mParserContext)
-    return kInvalidParserContext;
+    return NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT;
 
   if (eUnknownDetect != mParserContext->mAutoDetectStatus)
     return NS_OK;
 
   if (eDTDMode_unknown == mParserContext->mDTDMode ||
       eDTDMode_autodetect == mParserContext->mDTDMode) {
     char16_t buf[1025];
     nsFixedString theBuffer(buf, 1024, 0);
@@ -1166,17 +1166,17 @@ NS_IMETHODIMP
 nsParser::Parse(nsIURI* aURL,
                 nsIRequestObserver* aListener,
                 void* aKey,
                 nsDTDMode aMode)
 {
 
   NS_PRECONDITION(aURL, "Error: Null URL given");
 
-  nsresult result=kBadURL;
+  nsresult result = NS_ERROR_HTMLPARSER_BADURL;
   mObserver = aListener;
 
   if (aURL) {
     nsAutoCString spec;
     nsresult rv = aURL->GetSpec(spec);
     if (rv != NS_OK) {
       return rv;
     }
@@ -1463,17 +1463,17 @@ nsParser::ResumeParse(bool allowIteratio
                                       ? Tokenize(aIsFinalChunk)
                                       : NS_OK;
         result = BuildModel();
 
         if (result == NS_ERROR_HTMLPARSER_INTERRUPTED && aIsFinalChunk) {
           PostContinueEvent();
         }
 
-        theIterationIsOk = theTokenizerResult != kEOF &&
+        theIterationIsOk = theTokenizerResult != NS_ERROR_HTMLPARSER_EOF &&
                            result != NS_ERROR_HTMLPARSER_INTERRUPTED;
 
         // Make sure not to stop parsing too early. Therefore, before shutting
         // down the parser, it's important to check whether the input buffer
         // has been scanned to completion (theTokenizerResult should be kEOF).
         // kEOF -> End of buffer.
 
         // If we're told to block the parser, we disable all further parsing
@@ -1490,18 +1490,19 @@ nsParser::ResumeParse(bool allowIteratio
           // Note: Parser Terminate() calls DidBuildModel.
           if (mInternalState != NS_ERROR_HTMLPARSER_STOPPARSING) {
             DidBuildModel(mStreamStatus);
             mInternalState = result;
           }
 
           return NS_OK;
         }
-        if ((NS_OK == result && theTokenizerResult == kEOF) ||
-             result == NS_ERROR_HTMLPARSER_INTERRUPTED) {
+        if ((NS_OK == result &&
+             theTokenizerResult == NS_ERROR_HTMLPARSER_EOF) ||
+            result == NS_ERROR_HTMLPARSER_INTERRUPTED) {
           bool theContextIsStringBased =
             CParserContext::eCTString == mParserContext->mContextType;
 
           if (mParserContext->mStreamListenerState == eOnStop ||
               !mParserContext->mMultipart || theContextIsStringBased) {
             if (!mParserContext->mPrevContext) {
               if (mParserContext->mStreamListenerState == eOnStop) {
                 DidBuildModel(mStreamStatus);
@@ -1523,17 +1524,17 @@ nsParser::ResumeParse(bool allowIteratio
               result = mInternalState;
               aIsFinalChunk = mParserContext &&
                               mParserContext->mStreamListenerState == eOnStop;
               // ...then intentionally fall through to mSink->WillInterrupt()...
             }
           }
         }
 
-        if (theTokenizerResult == kEOF ||
+        if (theTokenizerResult == NS_ERROR_HTMLPARSER_EOF ||
             result == NS_ERROR_HTMLPARSER_INTERRUPTED) {
           result = (result == NS_ERROR_HTMLPARSER_INTERRUPTED) ? NS_OK : result;
           mSink->WillInterrupt();
         }
       }
     } else {
       mInternalState = result = NS_ERROR_HTMLPARSER_UNRESOLVEDDTD;
     }
@@ -1940,17 +1941,17 @@ nsresult nsParser::Tokenize(bool aIsFina
 
     WillTokenize(aIsFinalChunk);
     while (NS_SUCCEEDED(result)) {
       mParserContext->mScanner->Mark();
       result = theTokenizer->ConsumeToken(*mParserContext->mScanner,
                                           flushTokens);
       if (NS_FAILED(result)) {
         mParserContext->mScanner->RewindToMark();
-        if (kEOF == result){
+        if (NS_ERROR_HTMLPARSER_EOF == result) {
           break;
         }
         if (NS_ERROR_HTMLPARSER_STOPPARSING == result) {
           killSink = true;
           result = Terminate();
           break;
         }
       } else if (flushTokens && (mFlags & NS_PARSER_FLAG_OBSERVERS_ENABLED)) {
--- a/parser/htmlparser/nsScanner.cpp
+++ b/parser/htmlparser/nsScanner.cpp
@@ -315,17 +315,17 @@ nsresult nsScanner::Append(const char* a
  *  
  *  @update  gess 3/25/98
  *  @param   
  *  @return  error code reflecting read status
  */
 nsresult nsScanner::GetChar(char16_t& aChar) {
   if (!mSlidingBuffer || mCurrentPosition == mEndPosition) {
     aChar = 0;
-    return kEOF;
+    return NS_ERROR_HTMLPARSER_EOF;
   }
 
   aChar = *mCurrentPosition++;
   --mCountRemaining;
 
   return NS_OK;
 }
 
@@ -337,46 +337,46 @@ nsresult nsScanner::GetChar(char16_t& aC
  *  @update  gess 3/25/98
  *  @param   
  *  @return  
  */
 nsresult nsScanner::Peek(char16_t& aChar, uint32_t aOffset) {
   aChar = 0;
 
   if (!mSlidingBuffer || mCurrentPosition == mEndPosition) {
-    return kEOF;
+    return NS_ERROR_HTMLPARSER_EOF;
   }
 
   if (aOffset > 0) {
     if (mCountRemaining <= aOffset)
-      return kEOF;
+      return NS_ERROR_HTMLPARSER_EOF;
 
     nsScannerIterator pos = mCurrentPosition;
     pos.advance(aOffset);
     aChar=*pos;
   }
   else {
     aChar=*mCurrentPosition;
   }
 
   return NS_OK;
 }
 
 nsresult nsScanner::Peek(nsAString& aStr, int32_t aNumChars, int32_t aOffset)
 {
   if (!mSlidingBuffer || mCurrentPosition == mEndPosition) {
-    return kEOF;
+    return NS_ERROR_HTMLPARSER_EOF;
   }
 
   nsScannerIterator start, end;
 
   start = mCurrentPosition;
 
   if ((int32_t)mCountRemaining <= aOffset) {
-    return kEOF;
+    return NS_ERROR_HTMLPARSER_EOF;
   }
 
   if (aOffset > 0) {
     start.advance(aOffset);
   }
 
   if (mCountRemaining < uint32_t(aNumChars + aOffset)) {
     end = mEndPosition;