Bug 501015 - Address code style comments from timeless. r+sr=mrbkap
authorHenri Sivonen <hsivonen@iki.fi>
Wed, 15 Jul 2009 14:30:33 +0300
changeset 30334 712073dde3c0a74c4665e86f8d279de01891b748
parent 30333 439de76c5cc8ce45715356d8c7d4348eb7286c1e
child 30335 f4f94ee39e4b0522445a618e8628ffa66543dcdf
push id8035
push userhsivonen@iki.fi
push dateWed, 15 Jul 2009 11:34:07 +0000
treeherdermozilla-central@c40a68c662da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs501015
milestone1.9.2a1pre
Bug 501015 - Address code style comments from timeless. r+sr=mrbkap
content/base/src/nsContentUtils.cpp
content/base/src/nsHTMLContentSerializer.cpp
content/html/document/src/nsHTMLDocument.cpp
content/html/parser/javasrc/AttributeName.java
content/html/parser/javasrc/ElementName.java
content/html/parser/javasrc/HtmlAttributes.java
content/html/parser/javasrc/MetaScanner.java
content/html/parser/javasrc/TreeBuilder.java
parser/html/nsHtml5AttributeName.cpp
parser/html/nsHtml5ElementName.cpp
parser/html/nsHtml5MetaScanner.cpp
parser/html/nsHtml5Module.cpp
parser/html/nsHtml5Module.h
parser/html/nsHtml5Parser.cpp
parser/html/nsHtml5Portability.cpp
parser/html/nsHtml5TreeBuilder.cpp
parser/html/nsHtml5TreeBuilderCppSupplement.h
parser/htmlparser/public/nsIParser.h
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -3602,19 +3602,19 @@ nsContentUtils::CreateContextualFragment
   // If we don't have a document here, we can't get the right security context
   // for compiling event handlers... so just bail out.
   nsCOMPtr<nsIDocument> document = node->GetOwnerDoc();
   NS_ENSURE_TRUE(document, NS_ERROR_NOT_AVAILABLE);
   
   PRBool bCaseSensitive = document->IsCaseSensitive();
 
   nsCOMPtr<nsIHTMLDocument> htmlDoc(do_QueryInterface(document));
-  PRBool bHTML = htmlDoc && !bCaseSensitive;
-
-  if (bHTML && nsHtml5Module::Enabled) {
+  PRBool isHTML = htmlDoc && !bCaseSensitive;
+
+  if (isHTML && nsHtml5Module::sEnabled) {
     // See if the document has a cached fragment parser. nsHTMLDocument is the
     // only one that should really have one at the moment.
     nsCOMPtr<nsIParser> parser = document->GetFragmentParser();
     if (parser) {
       // Get the parser ready to use.
       parser->Reset();
     }
     else {
@@ -3729,30 +3729,30 @@ nsContentUtils::CreateContextualFragment
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // See if the parser already has a content sink that we can reuse.
   nsCOMPtr<nsIFragmentContentSink> sink;
   nsCOMPtr<nsIContentSink> contentsink = parser->GetContentSink();
   if (contentsink) {
     // Make sure it's the correct type.
-    if (bHTML) {
+    if (isHTML) {
       nsCOMPtr<nsIHTMLContentSink> htmlsink = do_QueryInterface(contentsink);
       sink = do_QueryInterface(htmlsink);
     }
     else {
       nsCOMPtr<nsIXMLContentSink> xmlsink = do_QueryInterface(contentsink);
       sink = do_QueryInterface(xmlsink);
     }
   }
 
   if (!sink) {
     // Either there was no cached content sink or it was the wrong type. Make a
     // new one.
-    if (bHTML) {
+    if (isHTML) {
       rv = NS_NewHTMLFragmentContentSink(getter_AddRefs(sink));
     } else {
       rv = NS_NewXMLFragmentContentSink(getter_AddRefs(sink));
     }
     NS_ENSURE_SUCCESS(rv, rv);
 
     contentsink = do_QueryInterface(sink);
     NS_ASSERTION(contentsink, "Sink doesn't QI to nsIContentSink!");
@@ -3774,17 +3774,17 @@ nsContentUtils::CreateContextualFragment
       mode = eDTDMode_full_standards;
       break;
     default:
       NS_NOTREACHED("unknown mode");
       break;
   }
 
   rv = parser->ParseFragment(aFragment, nsnull, tagStack,
-                             !bHTML, contentType, mode);
+                             !isHTML, contentType, mode);
   if (NS_SUCCEEDED(rv)) {
     rv = sink->GetFragment(aWillOwnFragment, aReturn);
   }
 
   document->SetFragmentParser(parser);
 
   return rv;
 }
--- a/content/base/src/nsHTMLContentSerializer.cpp
+++ b/content/base/src/nsHTMLContentSerializer.cpp
@@ -64,16 +64,17 @@
 #include "nsITextToSubURI.h"
 #include "nsCRT.h"
 #include "nsIParserService.h"
 #include "nsContentUtils.h"
 #include "nsLWBrkCIID.h"
 #include "nsIScriptElement.h"
 #include "nsAttrName.h"
 #include "nsHtml5Module.h"
+#include "nsIHTMLDocument.h"
 
 static const char kMozStr[] = "moz";
 
 static const PRInt32 kLongLineLen = 128;
 
 nsresult NS_NewHTMLContentSerializer(nsIContentSerializer** aSerializer)
 {
   nsHTMLContentSerializer* it = new nsHTMLContentSerializer();
@@ -96,17 +97,16 @@ nsHTMLContentSerializer::~nsHTMLContentS
 
 NS_IMETHODIMP
 nsHTMLContentSerializer::AppendDocumentStart(nsIDOMDocument *aDocument,
                                              nsAString& aStr)
 {
   return NS_OK;
 }
 
-#include "nsIHTMLDocument.h"
 void 
 nsHTMLContentSerializer::SerializeAttributes(nsIContent* aContent,
                                              nsIDOMElement *aOriginalElement,
                                              nsAString& aTagPrefix,
                                              const nsAString& aTagNamespaceURI,
                                              nsIAtom* aTagName,
                                              nsAString& aStr)
 {
@@ -121,17 +121,17 @@ nsHTMLContentSerializer::SerializeAttrib
   // HTML5 parser stored them in the order they were parsed so we want to
   // loop forward in that case.
   nsIDocument* doc = aContent->GetOwnerDocument();
   PRBool caseSensitive = doc && doc->IsCaseSensitive();
   PRBool loopForward = PR_FALSE;
   if (!caseSensitive) {
     nsCOMPtr<nsIHTMLDocument> htmlDoc(do_QueryInterface(doc));
     if (htmlDoc) {
-      loopForward = nsHtml5Module::Enabled;
+      loopForward = nsHtml5Module::sEnabled;
     }
   }
   PRInt32 index, limit, step;
   if (loopForward) {
     index = 0;
     limit = count;
     step = 1;
   }
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -650,34 +650,34 @@ nsresult
 nsHTMLDocument::StartDocumentLoad(const char* aCommand,
                                   nsIChannel* aChannel,
                                   nsILoadGroup* aLoadGroup,
                                   nsISupports* aContainer,
                                   nsIStreamListener **aDocListener,
                                   PRBool aReset,
                                   nsIContentSink* aSink)
 {
-  PRBool loadAsHtml5 = nsHtml5Module::Enabled;
+  PRBool loadAsHtml5 = nsHtml5Module::sEnabled;
   if (aSink) {
     loadAsHtml5 = PR_FALSE;
   }
 
   nsCAutoString contentType;
   aChannel->GetContentType(contentType);
 
   if (contentType.Equals("application/xhtml+xml") &&
       (!aCommand || nsCRT::strcmp(aCommand, "view-source") != 0)) {
     // We're parsing XHTML as XML, remember that.
 
     mIsRegularHTML = PR_FALSE;
     mCompatMode = eCompatibility_FullStandards;
     loadAsHtml5 = PR_FALSE;
   }
   
-  if (!(contentType.Equals("text/html") && aCommand && !nsCRT::strcmp(aCommand, "view"))) {
+  if (!(contentType.EqualsLiteral("text/html") && aCommand && !nsCRT::strcmp(aCommand, "view"))) {
     loadAsHtml5 = PR_FALSE;
   }
 #ifdef DEBUG
   else {
     NS_ASSERTION(mIsRegularHTML,
                  "Hey, someone forgot to reset mIsRegularHTML!!!");
   }
 #endif
@@ -936,17 +936,17 @@ nsHTMLDocument::StartDocumentLoad(const 
 #endif
     mParser->SetDocumentCharset(parserCharset, parserCharsetSource);
     mParser->SetCommand(aCommand);
 
     // create the content sink
     nsCOMPtr<nsIContentSink> sink;
 
     if (aSink) {
-      NS_ASSERTION((!loadAsHtml5), "Panic: We are loading as HTML5 and someone tries to set an external sink!");
+      NS_ASSERTION(!loadAsHtml5, "Panic: We are loading as HTML5 and someone tries to set an external sink!");
       sink = aSink;
     } else {
       if (IsXHTML()) {
         nsCOMPtr<nsIXMLContentSink> xmlsink;
         rv = NS_NewXMLContentSink(getter_AddRefs(xmlsink), this, uri,
                                   docShell, aChannel);
 
         sink = xmlsink;
@@ -1800,17 +1800,17 @@ nsresult
 nsHTMLDocument::OpenCommon(const nsACString& aContentType, PRBool aReplace)
 {
   if (IsXHTML()) {
     // No calling document.open() on XHTML
 
     return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
   }
 
-  PRBool loadAsHtml5 = nsHtml5Module::Enabled;
+  PRBool loadAsHtml5 = nsHtml5Module::sEnabled;
 
   nsresult rv = NS_OK;
 
   // If we already have a parser we ignore the document.open call.
   if (mParser) {
 
     return NS_OK;
   }
--- a/content/html/parser/javasrc/AttributeName.java
+++ b/content/html/parser/javasrc/AttributeName.java
@@ -104,74 +104,74 @@ public final class AttributeName
     private static final @NoLength @Prefix String[] LANG_PREFIX = { null, null,
             null, "xml" };
 
     private static final boolean[] ALL_NCNAME = { true, true, true, true };
 
     private static final boolean[] ALL_NO_NCNAME = { false, false, false, false };
 
     private static @QName String[] COMPUTE_QNAME(String[] local, String[] prefix) {
-        @QName String[] rv = new String[4];
-        for (int i = 0; i < rv.length; i++) {
+        @QName String[] arr = new String[4];
+        for (int i = 0; i < arr.length; i++) {
             if (prefix[i] == null) {
-                rv[i] = local[i];
+                arr[i] = local[i];
             } else {
-                rv[i] = (prefix[i] + ':' + local[i]).intern();
+                arr[i] = (prefix[i] + ':' + local[i]).intern();
             }
         }
-        return rv;
+        return arr;
     }
 
     // ]NOCPP]
 
     private static @NoLength @Local String[] SVG_DIFFERENT(@Local String name,
             @Local String camel) {
-        @NoLength @Local String[] rv = new String[4];
-        rv[0] = name;
-        rv[1] = name;
-        rv[2] = camel;
+        @NoLength @Local String[] arr = new String[4];
+        arr[0] = name;
+        arr[1] = name;
+        arr[2] = camel;
         // [NOCPP[
-        rv[3] = name;
+        arr[3] = name;
         // ]NOCPP]
-        return rv;
+        return arr;
     }
 
     private static @NoLength @Local String[] MATH_DIFFERENT(@Local String name,
             @Local String camel) {
-        @NoLength @Local String[] rv = new String[4];
-        rv[0] = name;
-        rv[1] = camel;
-        rv[2] = name;
+        @NoLength @Local String[] arr = new String[4];
+        arr[0] = name;
+        arr[1] = camel;
+        arr[2] = name;
         // [NOCPP[
-        rv[3] = name;
+        arr[3] = name;
         // ]NOCPP]
-        return rv;
+        return arr;
     }
 
     private static @NoLength @Local String[] COLONIFIED_LOCAL(
             @Local String name, @Local String suffix) {
-        @NoLength @Local String[] rv = new String[4];
-        rv[0] = name;
-        rv[1] = suffix;
-        rv[2] = suffix;
+        @NoLength @Local String[] arr = new String[4];
+        arr[0] = name;
+        arr[1] = suffix;
+        arr[2] = suffix;
         // [NOCPP[
-        rv[3] = name;
+        arr[3] = name;
         // ]NOCPP]
-        return rv;
+        return arr;
     }
 
     private static @NoLength @Local String[] SAME_LOCAL(@Local String name) {
-        @NoLength @Local String[] rv = new String[4];
-        rv[0] = name;
-        rv[1] = name;
-        rv[2] = name;
+        @NoLength @Local String[] arr = new String[4];
+        arr[0] = name;
+        arr[1] = name;
+        arr[2] = name;
         // [NOCPP[
-        rv[3] = name;
+        arr[3] = name;
         // ]NOCPP]
-        return rv;
+        return arr;
     }
 
     /**
      * Returns an attribute name by buffer.
      * 
      * <p>
      * C++ ownership: The return value is either released by the caller if the
      * attribute is a duplicate or the ownership is transferred to
@@ -195,27 +195,27 @@ public final class AttributeName
         if (index < 0) {
             return AttributeName.createAttributeName(
                     Portability.newLocalNameFromBuffer(buf, offset, length)
                     // [NOCPP[
                     , checkNcName
             // ]NOCPP]
             );
         } else {
-            AttributeName rv = AttributeName.ATTRIBUTE_NAMES[index];
-            @Local String name = rv.getLocal(AttributeName.HTML);
+            AttributeName attributeName = AttributeName.ATTRIBUTE_NAMES[index];
+            @Local String name = attributeName.getLocal(AttributeName.HTML);
             if (!Portability.localEqualsBuffer(name, buf, offset, length)) {
                 return AttributeName.createAttributeName(
                         Portability.newLocalNameFromBuffer(buf, offset, length)
                         // [NOCPP[
                         , checkNcName
                 // ]NOCPP]
                 );
             }
-            return rv;
+            return attributeName;
         }
     }
 
     /**
      * This method has to return a unique integer for each well-known
      * lower-cased attribute name.
      * 
      * @param buf
--- a/content/html/parser/javasrc/ElementName.java
+++ b/content/html/parser/javasrc/ElementName.java
@@ -54,23 +54,23 @@ public final class ElementName
     // ]NOCPP]
     
     static ElementName elementNameByBuffer(char[] buf, int offset, int length) {
         int hash = ElementName.bufToHash(buf, length);
         int index = Arrays.binarySearch(ElementName.ELEMENT_HASHES, hash);
         if (index < 0) {
             return new ElementName(Portability.newLocalNameFromBuffer(buf, offset, length));
         } else {
-            ElementName rv = ElementName.ELEMENT_NAMES[index];
-            @Local String name = rv.name;
+            ElementName elementName = ElementName.ELEMENT_NAMES[index];
+            @Local String name = elementName.name;
             if (!Portability.localEqualsBuffer(name, buf, offset, length)) {
                 return new ElementName(Portability.newLocalNameFromBuffer(buf,
                         offset, length));                
             }
-            return rv;
+            return elementName;
         }
     }
 
     /**
      * This method has to return a unique integer for each well-known
      * lower-cased element name.
      * 
      * @param buf
@@ -261,18 +261,18 @@ public final class ElementName
 //            case TreeBuilder.PRE_OR_LISTING:
 //                return "PRE_OR_LISTING";
 //            case TreeBuilder.B_OR_BIG_OR_CODE_OR_EM_OR_I_OR_S_OR_SMALL_OR_STRIKE_OR_STRONG_OR_TT_OR_U:
 //                return "B_OR_BIG_OR_CODE_OR_EM_OR_I_OR_S_OR_SMALL_OR_STRIKE_OR_STRONG_OR_TT_OR_U";
 //            case TreeBuilder.UL_OR_OL_OR_DL:
 //                return "UL_OR_OL_OR_DL";
 //            case TreeBuilder.IFRAME:
 //                return "IFRAME";
-//  case TreeBuilder.NOEMBED:
-//  return "NOEMBED";
+//            case TreeBuilder.NOEMBED:
+//                return "NOEMBED";
 //            case TreeBuilder.EMBED_OR_IMG:
 //                return "EMBED_OR_IMG";
 //            case TreeBuilder.AREA_OR_BASEFONT_OR_BGSOUND_OR_SPACER_OR_WBR:
 //                return "AREA_OR_BASEFONT_OR_BGSOUND_OR_SPACER_OR_WBR";
 //            case TreeBuilder.DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU:
 //                return "DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU";
 //            case TreeBuilder.FIELDSET_OR_ADDRESS_OR_DIR_OR_ARTICLE_OR_ASIDE_OR_DATAGRID_OR_DETAILS_OR_DIALOG_OR_FIGURE_OR_FOOTER_OR_HEADER_OR_NAV_OR_SECTION:
 //                return "FIELDSET_OR_ADDRESS_OR_DIR_OR_ARTICLE_OR_ASIDE_OR_DATAGRID_OR_DETAILS_OR_DIALOG_OR_FIGURE_OR_FOOTER_OR_HEADER_OR_NAV_OR_SECTION";
--- a/content/html/parser/javasrc/HtmlAttributes.java
+++ b/content/html/parser/javasrc/HtmlAttributes.java
@@ -71,19 +71,21 @@ public final class HtmlAttributes implem
 
     private String[] xmlnsValues;
 
     // ]NOCPP]
 
     public HtmlAttributes(int mode) {
         this.mode = mode;
         this.length = 0;
-        this.names = new AttributeName[5]; // covers 98.3% of elements
-                                            // according to
-        // Hixie
+        /*
+         * The length of 5 covers covers 98.3% of elements
+         * according to Hixie
+         */
+        this.names = new AttributeName[5];
         this.values = new String[5];
 
         // [NOCPP[
 
         this.idValue = null;
 
         this.xmlnsLength = 0;
 
--- a/content/html/parser/javasrc/MetaScanner.java
+++ b/content/html/parser/javasrc/MetaScanner.java
@@ -678,19 +678,19 @@ public abstract class MetaScanner {
             candidateEncoding = TreeBuilder.extractCharsetFromContent(attVal);
             Portability.releaseString(attVal);
         } else {
             candidateEncoding = attVal;
         }
         if (candidateEncoding == null) {
             return false;
         }
-        boolean rv = tryCharset(candidateEncoding);
+        boolean success = tryCharset(candidateEncoding);
         Portability.releaseString(candidateEncoding);
         contentIndex = -1;
         charsetIndex = -1;
-        return rv;
+        return success;
     }
     
     protected abstract boolean tryCharset(String encoding) throws SAXException;
 
     
 }
--- a/content/html/parser/javasrc/TreeBuilder.java
+++ b/content/html/parser/javasrc/TreeBuilder.java
@@ -2898,25 +2898,25 @@ public abstract class TreeBuilder<T> imp
                         case ';':
                             end = i;
                             break charsetloop;
                         default:
                             continue;
                     }
             }
         }
-        String rv = null;
+        String charset = null;
         if (start != -1) {
             if (end == -1) {
                 end = buffer.length;
             }
-            rv = Portability.newStringFromBuffer(buffer, start, end - start);
+            charset = Portability.newStringFromBuffer(buffer, start, end - start);
         }
         Portability.releaseArray(buffer);
-        return rv;
+        return charset;
     }
 
     private void checkMetaCharset(HtmlAttributes attributes)
             throws SAXException {
         String content = attributes.getValue(AttributeName.CONTENT);
         String internalCharsetLegacy = null;
         if (content != null) {
             internalCharsetLegacy = TreeBuilder.extractCharsetFromContent(content);
--- a/parser/html/nsHtml5AttributeName.cpp
+++ b/parser/html/nsHtml5AttributeName.cpp
@@ -52,67 +52,67 @@
 #include "nsHtml5Portability.h"
 
 #include "nsHtml5AttributeName.h"
 #include "nsHtml5ReleasableAttributeName.h"
 
 nsIAtom** 
 nsHtml5AttributeName::SVG_DIFFERENT(nsIAtom* name, nsIAtom* camel)
 {
-  nsIAtom** rv = new nsIAtom*[4];
-  rv[0] = name;
-  rv[1] = name;
-  rv[2] = camel;
-  return rv;
+  nsIAtom** arr = new nsIAtom*[4];
+  arr[0] = name;
+  arr[1] = name;
+  arr[2] = camel;
+  return arr;
 }
 
 nsIAtom** 
 nsHtml5AttributeName::MATH_DIFFERENT(nsIAtom* name, nsIAtom* camel)
 {
-  nsIAtom** rv = new nsIAtom*[4];
-  rv[0] = name;
-  rv[1] = camel;
-  rv[2] = name;
-  return rv;
+  nsIAtom** arr = new nsIAtom*[4];
+  arr[0] = name;
+  arr[1] = camel;
+  arr[2] = name;
+  return arr;
 }
 
 nsIAtom** 
 nsHtml5AttributeName::COLONIFIED_LOCAL(nsIAtom* name, nsIAtom* suffix)
 {
-  nsIAtom** rv = new nsIAtom*[4];
-  rv[0] = name;
-  rv[1] = suffix;
-  rv[2] = suffix;
-  return rv;
+  nsIAtom** arr = new nsIAtom*[4];
+  arr[0] = name;
+  arr[1] = suffix;
+  arr[2] = suffix;
+  return arr;
 }
 
 nsIAtom** 
 nsHtml5AttributeName::SAME_LOCAL(nsIAtom* name)
 {
-  nsIAtom** rv = new nsIAtom*[4];
-  rv[0] = name;
-  rv[1] = name;
-  rv[2] = name;
-  return rv;
+  nsIAtom** arr = new nsIAtom*[4];
+  arr[0] = name;
+  arr[1] = name;
+  arr[2] = name;
+  return arr;
 }
 
 nsHtml5AttributeName* 
 nsHtml5AttributeName::nameByBuffer(PRUnichar* buf, PRInt32 offset, PRInt32 length)
 {
   PRInt32 hash = nsHtml5AttributeName::bufToHash(buf, length);
   PRInt32 index = nsHtml5AttributeName::ATTRIBUTE_HASHES.binarySearch(hash);
   if (index < 0) {
     return nsHtml5AttributeName::createAttributeName(nsHtml5Portability::newLocalNameFromBuffer(buf, offset, length));
   } else {
-    nsHtml5AttributeName* rv = nsHtml5AttributeName::ATTRIBUTE_NAMES[index];
-    nsIAtom* name = rv->getLocal(NS_HTML5ATTRIBUTE_NAME_HTML);
+    nsHtml5AttributeName* attributeName = nsHtml5AttributeName::ATTRIBUTE_NAMES[index];
+    nsIAtom* name = attributeName->getLocal(NS_HTML5ATTRIBUTE_NAME_HTML);
     if (!nsHtml5Portability::localEqualsBuffer(name, buf, offset, length)) {
       return nsHtml5AttributeName::createAttributeName(nsHtml5Portability::newLocalNameFromBuffer(buf, offset, length));
     }
-    return rv;
+    return attributeName;
   }
 }
 
 PRInt32 
 nsHtml5AttributeName::bufToHash(PRUnichar* buf, PRInt32 len)
 {
   PRInt32 hash2 = 0;
   PRInt32 hash = len;
--- a/parser/html/nsHtml5ElementName.cpp
+++ b/parser/html/nsHtml5ElementName.cpp
@@ -57,22 +57,22 @@
 nsHtml5ElementName* 
 nsHtml5ElementName::elementNameByBuffer(jArray<PRUnichar,PRInt32> buf, PRInt32 offset, PRInt32 length)
 {
   PRInt32 hash = nsHtml5ElementName::bufToHash(buf, length);
   PRInt32 index = nsHtml5ElementName::ELEMENT_HASHES.binarySearch(hash);
   if (index < 0) {
     return new nsHtml5ReleasableElementName(nsHtml5Portability::newLocalNameFromBuffer(buf, offset, length));
   } else {
-    nsHtml5ElementName* rv = nsHtml5ElementName::ELEMENT_NAMES[index];
-    nsIAtom* name = rv->name;
+    nsHtml5ElementName* elementName = nsHtml5ElementName::ELEMENT_NAMES[index];
+    nsIAtom* name = elementName->name;
     if (!nsHtml5Portability::localEqualsBuffer(name, buf, offset, length)) {
       return new nsHtml5ReleasableElementName(nsHtml5Portability::newLocalNameFromBuffer(buf, offset, length));
     }
-    return rv;
+    return elementName;
   }
 }
 
 PRInt32 
 nsHtml5ElementName::bufToHash(jArray<PRUnichar,PRInt32> buf, PRInt32 len)
 {
   PRInt32 hash = len;
   hash <<= 5;
--- a/parser/html/nsHtml5MetaScanner.cpp
+++ b/parser/html/nsHtml5MetaScanner.cpp
@@ -686,21 +686,21 @@ nsHtml5MetaScanner::tryCharset()
     candidateEncoding = nsHtml5TreeBuilder::extractCharsetFromContent(attVal);
     nsHtml5Portability::releaseString(attVal);
   } else {
     candidateEncoding = attVal;
   }
   if (!candidateEncoding) {
     return PR_FALSE;
   }
-  PRBool rv = tryCharset(candidateEncoding);
+  PRBool success = tryCharset(candidateEncoding);
   nsHtml5Portability::releaseString(candidateEncoding);
   contentIndex = -1;
   charsetIndex = -1;
-  return rv;
+  return success;
 }
 
 void
 nsHtml5MetaScanner::initializeStatics()
 {
 }
 
 void
--- a/parser/html/nsHtml5Module.cpp
+++ b/parser/html/nsHtml5Module.cpp
@@ -43,23 +43,23 @@
 #include "nsHtml5Portability.h"
 #include "nsHtml5StackNode.h"
 #include "nsHtml5Tokenizer.h"
 #include "nsHtml5TreeBuilder.h"
 #include "nsHtml5UTF16Buffer.h"
 #include "nsHtml5Module.h"
 
 // static
-PRBool nsHtml5Module::Enabled = PR_FALSE;
+PRBool nsHtml5Module::sEnabled = PR_FALSE;
 
 // static
 void
 nsHtml5Module::InitializeStatics()
 {
-  nsContentUtils::AddBoolPrefVarCache("html5.enable", &Enabled);
+  nsContentUtils::AddBoolPrefVarCache("html5.enable", &sEnabled);
   nsHtml5Atoms::AddRefAtoms();
   nsHtml5AttributeName::initializeStatics();
   nsHtml5ElementName::initializeStatics();
   nsHtml5HtmlAttributes::initializeStatics();
   nsHtml5NamedCharacters::initializeStatics();
   nsHtml5Portability::initializeStatics();
   nsHtml5StackNode::initializeStatics();
   nsHtml5Tokenizer::initializeStatics();
--- a/parser/html/nsHtml5Module.h
+++ b/parser/html/nsHtml5Module.h
@@ -42,16 +42,16 @@
 
 class nsHtml5Module
 {
   public:
     static void InitializeStatics();
     static void ReleaseStatics();
     static already_AddRefed<nsIParser> NewHtml5Parser();
     static nsresult Initialize(nsIParser* aParser, nsIDocument* aDoc, nsIURI* aURI, nsISupports* aContainer, nsIChannel* aChannel);
-    static PRBool Enabled;
+    static PRBool sEnabled;
 #ifdef DEBUG
   private:
     static PRBool sNsHtml5ModuleInitialized;
 #endif
 };
 
 #endif // nsHtml5Module_h__
--- a/parser/html/nsHtml5Parser.cpp
+++ b/parser/html/nsHtml5Parser.cpp
@@ -60,60 +60,20 @@
 #include "nsHtml5UTF16Buffer.h"
 #include "nsHtml5TreeBuilder.h"
 #include "nsHtml5Parser.h"
 
 static NS_DEFINE_CID(kCharsetAliasCID, NS_CHARSETALIAS_CID);
 
 //-------------- Begin ParseContinue Event Definition ------------------------
 /*
-The parser can be explicitly interrupted by passing a return value of
-NS_ERROR_HTMLPARSER_INTERRUPTED from BuildModel on the DTD. This will cause
+The parser can be explicitly interrupted by calling Suspend(). This will cause
 the parser to stop processing and allow the application to return to the event
-loop. The data which was left at the time of interruption will be processed
-the next time OnDataAvailable is called. If the parser has received its final
-chunk of data then OnDataAvailable will no longer be called by the networking
-module, so the parser will schedule a nsHtml5ParserContinueEvent which will call
+loop. The parser will schedule a nsHtml5ParserContinueEvent which will call
 the parser to process the remaining data after returning to the event loop.
-If the parser is interrupted while processing the remaining data it will
-schedule another ParseContinueEvent. The processing of data followed by
-scheduling of the continue events will proceed until either:
-  1) All of the remaining data can be processed without interrupting
-  2) The parser has been cancelled.
-This capability is currently used in CNavDTD and nsHTMLContentSink. The
-nsHTMLContentSink is notified by CNavDTD when a chunk of tokens is going to be
-processed and when each token is processed. The nsHTML content sink records
-the time when the chunk has started processing and will return
-NS_ERROR_HTMLPARSER_INTERRUPTED if the token processing time has exceeded a
-threshold called max tokenizing processing time. This allows the content sink
-to limit how much data is processed in a single chunk which in turn gates how
-much time is spent away from the event loop. Processing smaller chunks of data
-also reduces the time spent in subsequent reflows.
-This capability is most apparent when loading large documents. If the maximum
-token processing time is set small enough the application will remain
-responsive during document load.
-A side-effect of this capability is that document load is not complete when
-the last chunk of data is passed to OnDataAvailable since  the parser may have
-been interrupted when the last chunk of data arrived. The document is complete
-when all of the document has been tokenized and there aren't any pending
-nsHtml5ParserContinueEvents. This can cause problems if the application assumes
-that it can monitor the load requests to determine when the document load has
-been completed. This is what happens in Mozilla. The document is considered
-completely loaded when all of the load requests have been satisfied. To delay
-the document load until all of the parsing has been completed the
-nsHTMLContentSink adds a dummy parser load request which is not removed until
-the nsHTMLContentSink's DidBuildModel is called. The CNavDTD will not call
-DidBuildModel until the final chunk of data has been passed to the parser
-through the OnDataAvailable and there aren't any pending
-nsHtml5ParserContineEvents.
-Currently the parser is ignores requests to be interrupted during the
-processing of script.  This is because a document.write followed by JavaScript
-calls to manipulate the DOM may fail if the parser was interrupted during the
-document.write.
-For more details @see bugzilla bug 76722
 */
 class nsHtml5ParserContinueEvent : public nsRunnable
 {
 public:
   nsRefPtr<nsHtml5Parser> mParser;
   nsHtml5ParserContinueEvent(nsHtml5Parser* aParser)
     : mParser(aParser)
   {}
@@ -122,18 +82,21 @@ public:
     mParser->HandleParserContinueEvent(this);
     return NS_OK;
   }
 };
 //-------------- End ParseContinue Event Definition ------------------------
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsHtml5Parser)
 
-NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(nsHtml5Parser)                                              \
-  NS_INTERFACE_TABLE_INHERITED3(nsHtml5Parser, nsIParser, nsIStreamListener, nsIContentSink)
+NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(nsHtml5Parser) \
+  NS_INTERFACE_TABLE_INHERITED3(nsHtml5Parser, 
+                                nsIParser, 
+                                nsIStreamListener, 
+                                nsIContentSink)
 NS_INTERFACE_TABLE_TAIL_INHERITING(nsContentSink)
 
 NS_IMPL_ADDREF_INHERITED(nsHtml5Parser, nsContentSink)
 
 NS_IMPL_RELEASE_INHERITED(nsHtml5Parser, nsContentSink)
 
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHtml5Parser, nsContentSink)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mScriptElement)
@@ -147,31 +110,29 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_IN
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mScriptElement)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mRequest)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mObserver)
   NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mUnicodeDecoder)
   tmp->mTreeBuilder->DoUnlink();
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 nsHtml5Parser::nsHtml5Parser()
-  : mRequest(nsnull),
-    mObserver(nsnull),
-    mUnicodeDecoder(nsnull),
-    mFirstBuffer(new nsHtml5UTF16Buffer(NS_HTML5_PARSER_READ_BUFFER_SIZE)), // XXX allocate elsewhere for fragment parser?
+  : mFirstBuffer(new nsHtml5UTF16Buffer(NS_HTML5_PARSER_READ_BUFFER_SIZE)),
+    // XXX avoid allocating the buffer at all for fragment parser?
     mLastBuffer(mFirstBuffer),
     mTreeBuilder(new nsHtml5TreeBuilder(this)),
     mTokenizer(new nsHtml5Tokenizer(mTreeBuilder))
 {
   mTokenizer->setEncodingDeclarationHandler(this);
   // There's a zeroing operator new for everything else
 }
 
 nsHtml5Parser::~nsHtml5Parser()
 {
-  while(mFirstBuffer) {
+  while (mFirstBuffer) {
      nsHtml5UTF16Buffer* old = mFirstBuffer;
      mFirstBuffer = mFirstBuffer->next;
      delete old;
   }
 #ifdef GATHER_DOCWRITE_STATISTICS
   delete mSnapshot;
 #endif
 }
@@ -198,17 +159,18 @@ IsScriptEnabled(nsIDocument *aDoc, nsIDo
   nsContentUtils::GetSecurityManager()->
     CanExecuteScripts(cx, aDoc->NodePrincipal(), &enabled);
   return enabled;
 }
 
 NS_IMETHODIMP_(void)
 nsHtml5Parser::SetContentSink(nsIContentSink* aSink)
 {
-  NS_ASSERTION(aSink == static_cast<nsIContentSink*> (this), "Attempt to set a foreign sink.");
+  NS_ASSERTION(aSink == static_cast<nsIContentSink*> (this), 
+               "Attempt to set a foreign sink.");
 }
 
 NS_IMETHODIMP_(nsIContentSink*)
 nsHtml5Parser::GetContentSink(void)
 {
   return static_cast<nsIContentSink*> (this);
 }
 
@@ -222,17 +184,18 @@ NS_IMETHODIMP_(void)
 nsHtml5Parser::SetCommand(const char* aCommand)
 {
   NS_ASSERTION(!strcmp(aCommand, "view"), "Parser command was not view");
 }
 
 NS_IMETHODIMP_(void)
 nsHtml5Parser::SetCommand(eParserCommands aParserCommand)
 {
-  NS_ASSERTION(aParserCommand == eViewNormal, "Parser command was not eViewNormal.");
+  NS_ASSERTION(aParserCommand == eViewNormal, 
+               "Parser command was not eViewNormal.");
 }
 
 NS_IMETHODIMP_(void)
 nsHtml5Parser::SetDocumentCharset(const nsACString& aCharset, PRInt32 aCharsetSource)
 {
   mCharset = aCharset;
   mCharsetSource = aCharsetSource;
 }
@@ -315,28 +278,29 @@ NS_IMETHODIMP
 nsHtml5Parser::Parse(nsIURI* aURL, // legacy parameter; ignored
                      nsIRequestObserver* aObserver,
                      void* aKey,
                      nsDTDMode aMode) // legacy; ignored
 {
   mObserver = aObserver;
   mRootContextKey = aKey;
   mCanInterruptParser = PR_TRUE;
-  NS_PRECONDITION((mLifeCycle == NOT_STARTED), "Tried to start parse without initializing the parser properly.");
+  NS_PRECONDITION(mLifeCycle == NOT_STARTED, 
+                  "Tried to start parse without initializing the parser properly.");
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsHtml5Parser::Parse(const nsAString& aSourceBuffer,
                      void* aKey,
                      const nsACString& aContentType, // ignored
                      PRBool aLastCall,
                      nsDTDMode aMode) // ignored
 {
-  NS_PRECONDITION((!mFragmentMode), "Document.write called in fragment mode!");
+  NS_PRECONDITION(!mFragmentMode, "Document.write called in fragment mode!");
   // Return early if the parser has processed EOF
   switch (mLifeCycle) {
     case TERMINATED:
       return NS_OK;
     case NOT_STARTED:
       mTreeBuilder->setScriptingEnabled(IsScriptEnabled(mDocument, mDocShell));
       mTokenizer->start();
       mLifeCycle = PARSING;
@@ -380,29 +344,27 @@ nsHtml5Parser::Parse(const nsAString& aS
             mTreeBuilder->Flush();
             mUninterruptibleDocWrite = PR_FALSE;
             ExecuteScript();
           }
           if (mBlocked) {
             // XXX is the tail insertion and script exec in the wrong order?
             WillInterruptImpl();
             break;
-          } else {
-            // Ignore suspensions
-            continue;
           }
+          // Ignore suspension requests
         }
       }
     }
 
     mUninterruptibleDocWrite = PR_FALSE;
 
     if (buffer->hasMore()) {
-      // If we got here, the buffer wasn't parse synchronously to completion
-      // and it's tail needs to go into the chain of pending buffers.
+      // If we got here, the buffer wasn't parsed synchronously to completion
+      // and its tail needs to go into the chain of pending buffers.
       // The script is identified by aKey. If there's nothing in the buffer
       // chain for that key, we'll insert at the head of the queue.
       // When the script leaves something in the queue, a zero-length
       // key-holder "buffer" is inserted in the queue. If the same script
       // leaves something in the chain again, it will be inserted immediately
       // before the old key holder belonging to the same script.
       nsHtml5UTF16Buffer* prevSearchBuf = nsnull;
       nsHtml5UTF16Buffer* searchBuf = mFirstBuffer;
@@ -555,47 +517,47 @@ nsHtml5Parser::CancelParsingEvents()
 {
   mContinueEvent = nsnull;
   return NS_OK;
 }
 
 void
 nsHtml5Parser::Reset()
 {
-    mNeedsCharsetSwitch = PR_FALSE;
-    mLastWasCR = PR_FALSE;
-    mFragmentMode = PR_FALSE;
-    mBlocked = PR_FALSE;
-    mSuspending = PR_FALSE;
-    mLifeCycle = NOT_STARTED;
-    mScriptElement = nsnull;
-    mUninterruptibleDocWrite = PR_FALSE;
-    mRootContextKey = nsnull;
-    mRequest = nsnull;
-    mObserver = nsnull;
-    mContinueEvent = nsnull;  // weak ref
-    // encoding-related stuff
-    mCharsetSource = kCharsetUninitialized;
-    mCharset.Assign("");
-    mPendingCharset.Assign("");
-    mUnicodeDecoder = nsnull;
-    mSniffingBuffer = nsnull;
-    mSniffingLength = 0;
-    mBomState = BOM_SNIFFING_NOT_STARTED;
-    mMetaScanner = nsnull;
-    // Portable parser objects
-    while (mFirstBuffer->next) {
-      nsHtml5UTF16Buffer* oldBuf = mFirstBuffer;
-      mFirstBuffer = mFirstBuffer->next;
-      delete oldBuf;
-    }
-    mFirstBuffer->setStart(0);
-    mFirstBuffer->setEnd(0);
+  mNeedsCharsetSwitch = PR_FALSE;
+  mLastWasCR = PR_FALSE;
+  mFragmentMode = PR_FALSE;
+  mBlocked = PR_FALSE;
+  mSuspending = PR_FALSE;
+  mLifeCycle = NOT_STARTED;
+  mScriptElement = nsnull;
+  mUninterruptibleDocWrite = PR_FALSE;
+  mRootContextKey = nsnull;
+  mRequest = nsnull;
+  mObserver = nsnull;
+  mContinueEvent = nsnull;  // weak ref
+  // encoding-related stuff
+  mCharsetSource = kCharsetUninitialized;
+  mCharset.Truncate();
+  mPendingCharset.Truncate();
+  mUnicodeDecoder = nsnull;
+  mSniffingBuffer = nsnull;
+  mSniffingLength = 0;
+  mBomState = BOM_SNIFFING_NOT_STARTED;
+  mMetaScanner = nsnull;
+  // Portable parser objects
+  while (mFirstBuffer->next) {
+    nsHtml5UTF16Buffer* oldBuf = mFirstBuffer;
+    mFirstBuffer = mFirstBuffer->next;
+    delete oldBuf;
+  }
+  mFirstBuffer->setStart(0);
+  mFirstBuffer->setEnd(0);
 #ifdef DEBUG
-    mStreamListenerState = eNone;
+  mStreamListenerState = eNone;
 #endif
 }
 
 PRBool
 nsHtml5Parser::CanInterrupt()
 {
   return !(mFragmentMode || mUninterruptibleDocWrite);
 }
@@ -611,44 +573,45 @@ nsHtml5Parser::OnStartRequest(nsIRequest
                   "correctly in constructor.");
   if (mObserver) {
     mObserver->OnStartRequest(aRequest, aContext);
   }
 #ifdef DEBUG
   mStreamListenerState = eOnStart;
 #endif
   mRequest = aRequest;
+  
+  if (mCharsetSource < kCharsetFromChannel) {
+    // we aren't ready to commit to an encoding yet
+    // leave converter uninstantiated for now
+    return NS_OK;
+  }
+  
   nsresult rv = NS_OK;
-  if (mCharsetSource >= kCharsetFromChannel) {
-    nsCOMPtr<nsICharsetConverterManager> convManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
-    NS_ENSURE_SUCCESS(rv, rv);
-    rv = convManager->GetUnicodeDecoder(mCharset.get(), getter_AddRefs(mUnicodeDecoder));
-    NS_ENSURE_SUCCESS(rv, rv);
-    mUnicodeDecoder->SetInputErrorBehavior(nsIUnicodeDecoder::kOnError_Recover);
-  }
-  return rv;
+  nsCOMPtr<nsICharsetConverterManager> convManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = convManager->GetUnicodeDecoder(mCharset.get(), getter_AddRefs(mUnicodeDecoder));
+  NS_ENSURE_SUCCESS(rv, rv);
+  mUnicodeDecoder->SetInputErrorBehavior(nsIUnicodeDecoder::kOnError_Recover);
+  return NS_OK;
 }
 
-/**
- *  This is called by the networking library once the last block of data
- *  has been collected from the net.
- */
 nsresult
 nsHtml5Parser::OnStopRequest(nsIRequest* aRequest,
                              nsISupports* aContext,
                              nsresult status)
 {
   mTreeBuilder->MaybeFlush();
   NS_ASSERTION(mRequest == aRequest, "Got Stop on wrong stream.");
   nsresult rv = NS_OK;
   if (!mUnicodeDecoder) {
     PRUint32 writeCount;
     rv = FinalizeSniffing(nsnull, 0, &writeCount, 0);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
-  NS_ENSURE_SUCCESS(rv, rv);
   switch (mLifeCycle) {
     case TERMINATED:
       break;
     case NOT_STARTED:
       mTreeBuilder->setScriptingEnabled(IsScriptEnabled(mDocument, mDocShell));
       mTokenizer->start();
       mLifeCycle = STREAM_ENDING;
       mParser = this;
@@ -664,17 +627,17 @@ nsHtml5Parser::OnStopRequest(nsIRequest*
   mStreamListenerState = eOnStop;
 #endif
   if (!IsScriptExecutingImpl()) {
     ParseUntilSuspend();
   }
   if (mObserver) {
     mObserver->OnStopRequest(aRequest, aContext, status);
   }
-  return rv;
+  return NS_OK;
 }
 
 // nsIStreamListener method:
 /*
  * This function is invoked as a result of a call to a stream's
  * ReadSegments() method. It is called for each contiguous buffer
  * of data in the underlying stream or pipe. Using ReadSegments
  * allows us to avoid copying data to read out of the stream.
@@ -698,18 +661,18 @@ ParserWriteFunc(nsIInputStream* aInStrea
 nsresult
 nsHtml5Parser::OnDataAvailable(nsIRequest* aRequest,
                                nsISupports* aContext,
                                nsIInputStream* aInStream,
                                PRUint32 aSourceOffset,
                                PRUint32 aLength)
 {
   mTreeBuilder->MaybeFlush();
-  NS_PRECONDITION((eOnStart == mStreamListenerState ||
-                   eOnDataAvail == mStreamListenerState),
+  NS_PRECONDITION(eOnStart == mStreamListenerState ||
+                  eOnDataAvail == mStreamListenerState,
             "Error: OnStartRequest() must be called before OnDataAvailable()");
   NS_ASSERTION(mRequest == aRequest, "Got data on wrong stream.");
   PRUint32 totalRead;
   nsresult rv = aInStream->ReadSegments(ParserWriteFunc, static_cast<void*> (this), aLength, &totalRead);
   NS_ASSERTION(totalRead == aLength, "ReadSegments read the wrong number of bytes.");
   if (!IsScriptExecutingImpl()) {
     ParseUntilSuspend();
   }
@@ -718,45 +681,50 @@ nsHtml5Parser::OnDataAvailable(nsIReques
 
 // EncodingDeclarationHandler
 void
 nsHtml5Parser::internalEncodingDeclaration(nsString* aEncoding)
 {
   if (mCharsetSource >= kCharsetFromMetaTag) { // this threshold corresponds to "confident" in the HTML5 spec
     return;
   }
-  nsresult res = NS_OK;
-  nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID, &res));
-  if (NS_FAILED(res)) {
+  nsresult rv = NS_OK;
+  nsCOMPtr<nsICharsetAlias> calias(do_GetService(kCharsetAliasCID, &rv));
+  if (NS_FAILED(rv)) {
     return;
   }
   nsCAutoString newEncoding;
   CopyUTF16toUTF8(*aEncoding, newEncoding);
   PRBool eq;
-  res = calias->Equals(newEncoding, mCharset, &eq);
-  if (NS_FAILED(res)) {
+  rv = calias->Equals(newEncoding, mCharset, &eq);
+  if (NS_FAILED(rv)) {
     return;
   }
   if (eq) {
-    mCharsetSource = kCharsetFromMetaTag; // just becoming confident
+    mCharsetSource = kCharsetFromMetaTag; // become confident
     return;
   }
+  
   // XXX check HTML5 non-IANA aliases here
+
   // The encodings are different. We want to reparse.
-  nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(mRequest,&res));
-    if (NS_SUCCEEDED(res)) {
-      nsCAutoString method;
-      httpChannel->GetRequestMethod(method);
-      if (!method.EqualsLiteral("GET")) {
-        return; // Can't reparse.
-        // XXX does Necko have a way to renavigate POST, etc. without hitting
-        // the network?
+  nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(mRequest, &rv));
+  if (NS_SUCCEEDED(rv)) {
+    nsCAutoString method;
+    httpChannel->GetRequestMethod(method);
+    // XXX does Necko have a way to renavigate POST, etc. without hitting
+    // the network?
+    if (!method.EqualsLiteral("GET")) {
+      // This is the old Gecko behavior but the spec disagrees.
+      // Don't reparse on POST.
+      return;
     }
   }
-  // we are still want to reparse
+  
+  // we still want to reparse
   mNeedsCharsetSwitch = PR_TRUE;
   mPendingCharset.Assign(newEncoding);
 }
 
 // DocumentModeHandler
 void
 nsHtml5Parser::documentMode(nsHtml5DocumentMode m)
 {
@@ -783,17 +751,17 @@ nsHtml5Parser::WillParse()
 {
   NS_NOTREACHED("No one should call this");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
 nsHtml5Parser::WillBuildModel(nsDTDMode aDTDMode)
 {
-  NS_NOTREACHED("No one shuld call this");
+  NS_NOTREACHED("No one should call this");
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 // This is called when the tree construction has ended
 NS_IMETHODIMP
 nsHtml5Parser::DidBuildModel()
 {
   NS_ASSERTION(mLifeCycle == STREAM_ENDING, "Bad life cycle.");
@@ -848,17 +816,17 @@ nsHtml5Parser::SetDocumentCharset(nsACSt
     // the following logic to get muCV is copied from
     // nsHTMLDocument::StartDocumentLoad
     // We need to call muCV->SetPrevDocCharacterSet here in case
     // the charset is detected by parser DetectMetaTag
     nsCOMPtr<nsIMarkupDocumentViewer> muCV;
     nsCOMPtr<nsIContentViewer> cv;
     mDocShell->GetContentViewer(getter_AddRefs(cv));
     if (cv) {
-       muCV = do_QueryInterface(cv);
+      muCV = do_QueryInterface(cv);
     } else {
       // in this block of code, if we get an error result, we return
       // it but if we get a null pointer, that's perfectly legal for
       // parent and parentContentViewer
       nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
         do_QueryInterface(mDocShell);
       NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
       nsCOMPtr<nsIDocShellTreeItem> parentAsItem;
@@ -917,17 +885,17 @@ nsHtml5Parser::SetupDecodingAndWriteSnif
                                                                     PRUint32 aCount,
                                                                     PRUint32* aWriteCount)
 {
   nsresult rv = NS_OK;
   nsCOMPtr<nsICharsetConverterManager> convManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
   rv = convManager->GetUnicodeDecoder(mCharset.get(), getter_AddRefs(mUnicodeDecoder));
   if (rv == NS_ERROR_UCONV_NOCONV) {
-    mCharset.Assign("windows-1252"); // lower case the raw form
+    mCharset.Assign("windows-1252"); // lower case is the raw form
     mCharsetSource = kCharsetFromWeakDocTypeDefault;
     rv = convManager->GetUnicodeDecoderRaw(mCharset.get(), getter_AddRefs(mUnicodeDecoder));
     SetDocumentCharset(mCharset);
   }
   NS_ENSURE_SUCCESS(rv, rv);
   mUnicodeDecoder->SetInputErrorBehavior(nsIUnicodeDecoder::kOnError_Recover);
   return WriteSniffingBufferAndCurrentSegment(aFromSegment, aCount, aWriteCount);
 }
@@ -981,25 +949,29 @@ nsHtml5Parser::FinalizeSniffing(const PR
   // maybe try chardet now; instantiation copied from nsDOMFile
   const nsAdoptingString& detectorName = nsContentUtils::GetLocalizedStringPref("intl.charset.detector");
   if (!detectorName.IsEmpty()) {
     nsCAutoString detectorContractID;
     detectorContractID.AssignLiteral(NS_CHARSET_DETECTOR_CONTRACTID_BASE);
     AppendUTF16toUTF8(detectorName, detectorContractID);
     nsCOMPtr<nsICharsetDetector> detector = do_CreateInstance(detectorContractID.get());
     if (detector) {
-      detector->Init(this);
+      nsresult rv = detector->Init(this);
+      NS_ENSURE_SUCCESS(rv, rv);
       PRBool dontFeed = PR_FALSE;
       if (mSniffingBuffer) {
-        detector->DoIt((const char*)mSniffingBuffer.get(), mSniffingLength, &dontFeed);
+        rv = detector->DoIt((const char*)mSniffingBuffer.get(), mSniffingLength, &dontFeed);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
       if (!dontFeed && aFromSegment) {
-        detector->DoIt((const char*)aFromSegment, aCountToSniffingLimit, &dontFeed);
+        rv = detector->DoIt((const char*)aFromSegment, aCountToSniffingLimit, &dontFeed);
+        NS_ENSURE_SUCCESS(rv, rv);
       }
-      detector->Done();
+      rv = detector->Done();
+      NS_ENSURE_SUCCESS(rv, rv);
       // fall thru; callback may have changed charset
     } else {
       NS_ERROR("Could not instantiate charset detector.");
     }
   }
   if (mCharsetSource == kCharsetUninitialized) {
     // Hopefully this case is never needed, but dealing with it anyway
     mCharset.Assign("windows-1252");
@@ -1032,81 +1004,84 @@ nsHtml5Parser::SniffStreamBytes(const PR
             break;
           default:
             mBomState = BOM_SNIFFING_OVER;
             break;
         }
         break;
       case SEEN_UTF_16_LE_FIRST_BYTE:
         if (aFromSegment[i] == 0xFE) {
-            rv = SetupDecodingFromBom("UTF-16", "UTF-16LE"); // upper case the raw form
-            NS_ENSURE_SUCCESS(rv, rv);
-            PRUint32 count = aCount - (i + 1);
-            rv = WriteStreamBytes(aFromSegment + (i + 1), count, &writeCount);
-            NS_ENSURE_SUCCESS(rv, rv);
-            *aWriteCount = writeCount + (i + 1);
-            return rv;
+          rv = SetupDecodingFromBom("UTF-16", "UTF-16LE"); // upper case is the raw form
+          NS_ENSURE_SUCCESS(rv, rv);
+          PRUint32 count = aCount - (i + 1);
+          rv = WriteStreamBytes(aFromSegment + (i + 1), count, &writeCount);
+          NS_ENSURE_SUCCESS(rv, rv);
+          *aWriteCount = writeCount + (i + 1);
+          return rv;
         }
         mBomState = BOM_SNIFFING_OVER;
         break;
       case SEEN_UTF_16_BE_FIRST_BYTE:
         if (aFromSegment[i] == 0xFF) {
-            rv = SetupDecodingFromBom("UTF-16", "UTF-16BE"); // upper case the raw form
-            NS_ENSURE_SUCCESS(rv, rv);
-            PRUint32 count = aCount - (i + 1);
-            rv = WriteStreamBytes(aFromSegment + (i + 1), count, &writeCount);
-            NS_ENSURE_SUCCESS(rv, rv);
-            *aWriteCount = writeCount + (i + 1);
-            return rv;
+          rv = SetupDecodingFromBom("UTF-16", "UTF-16BE"); // upper case is the raw form
+          NS_ENSURE_SUCCESS(rv, rv);
+          PRUint32 count = aCount - (i + 1);
+          rv = WriteStreamBytes(aFromSegment + (i + 1), count, &writeCount);
+          NS_ENSURE_SUCCESS(rv, rv);
+          *aWriteCount = writeCount + (i + 1);
+          return rv;
         }
         mBomState = BOM_SNIFFING_OVER;
         break;
       case SEEN_UTF_8_FIRST_BYTE:
         if (aFromSegment[i] == 0xBB) {
           mBomState = SEEN_UTF_8_SECOND_BYTE;
         } else {
           mBomState = BOM_SNIFFING_OVER;
         }
         break;
       case SEEN_UTF_8_SECOND_BYTE:
         if (aFromSegment[i] == 0xBF) {
-            rv = SetupDecodingFromBom("UTF-8", "UTF-8"); // upper case the raw form
-            NS_ENSURE_SUCCESS(rv, rv);
-            PRUint32 count = aCount - (i + 1);
-            rv = WriteStreamBytes(aFromSegment + (i + 1), count, &writeCount);
-            NS_ENSURE_SUCCESS(rv, rv);
-            *aWriteCount = writeCount + (i + 1);
-            return rv;
+          rv = SetupDecodingFromBom("UTF-8", "UTF-8"); // upper case is the raw form
+          NS_ENSURE_SUCCESS(rv, rv);
+          PRUint32 count = aCount - (i + 1);
+          rv = WriteStreamBytes(aFromSegment + (i + 1), count, &writeCount);
+          NS_ENSURE_SUCCESS(rv, rv);
+          *aWriteCount = writeCount + (i + 1);
+          return rv;
         }
         mBomState = BOM_SNIFFING_OVER;
         break;
       default:
         goto bom_loop_end;
     }
   }
   // if we get here, there either was no BOM or the BOM sniffing isn't complete yet
   bom_loop_end:
+  
   if (!mMetaScanner) {
     mMetaScanner = new nsHtml5MetaScanner();
   }
+  
   if (mSniffingLength + aCount >= NS_HTML5_PARSER_SNIFFING_BUFFER_SIZE) {
     // this is the last buffer
     PRUint32 countToSniffingLimit = NS_HTML5_PARSER_SNIFFING_BUFFER_SIZE - mSniffingLength;
     nsHtml5ByteReadable readable(aFromSegment, aFromSegment + countToSniffingLimit);
     mMetaScanner->sniff(&readable, getter_AddRefs(mUnicodeDecoder), mCharset);
     if (mUnicodeDecoder) {
       mUnicodeDecoder->SetInputErrorBehavior(nsIUnicodeDecoder::kOnError_Recover);
       // meta scan successful
       mCharsetSource = kCharsetFromMetaPrescan;
       SetDocumentCharset(mCharset);
       mMetaScanner = nsnull;
       return WriteSniffingBufferAndCurrentSegment(aFromSegment, aCount, aWriteCount);
     }
     return FinalizeSniffing(aFromSegment, aCount, aWriteCount, countToSniffingLimit);
   }
+
   // not the last buffer
   nsHtml5ByteReadable readable(aFromSegment, aFromSegment + aCount);
   mMetaScanner->sniff(&readable, getter_AddRefs(mUnicodeDecoder), mCharset);
   if (mUnicodeDecoder) {
     // meta scan successful
     mCharsetSource = kCharsetFromMetaPrescan;
     SetDocumentCharset(mCharset);
     mMetaScanner = nsnull;
@@ -1123,30 +1098,35 @@ nsHtml5Parser::SniffStreamBytes(const PR
 
 nsresult
 nsHtml5Parser::WriteStreamBytes(const PRUint8* aFromSegment,
                                 PRUint32 aCount,
                                 PRUint32* aWriteCount)
 {
   // mLastBuffer always points to a buffer of the size NS_HTML5_PARSER_READ_BUFFER_SIZE.
   if (mLastBuffer->getEnd() == NS_HTML5_PARSER_READ_BUFFER_SIZE) {
-      mLastBuffer = (mLastBuffer->next = new nsHtml5UTF16Buffer(NS_HTML5_PARSER_READ_BUFFER_SIZE));
+    mLastBuffer = (mLastBuffer->next = new nsHtml5UTF16Buffer(NS_HTML5_PARSER_READ_BUFFER_SIZE));
   }
   PRUint32 totalByteCount = 0;
   for (;;) {
     PRInt32 end = mLastBuffer->getEnd();
     PRInt32 byteCount = aCount - totalByteCount;
     PRInt32 utf16Count = NS_HTML5_PARSER_READ_BUFFER_SIZE - end;
+
     NS_ASSERTION(utf16Count, "Trying to convert into a buffer with no free space!");
+
     nsresult convResult = mUnicodeDecoder->Convert((const char*)aFromSegment, &byteCount, mLastBuffer->getBuffer() + end, &utf16Count);
+
     end += utf16Count;
     mLastBuffer->setEnd(end);
     totalByteCount += byteCount;
     aFromSegment += byteCount;
+
     NS_ASSERTION(mLastBuffer->getEnd() <= NS_HTML5_PARSER_READ_BUFFER_SIZE, "The Unicode decoder wrote too much data.");
+
     if (NS_FAILED(convResult)) {
       if (totalByteCount < aCount) { // mimicking nsScanner even though this seems wrong
         ++totalByteCount;
         ++aFromSegment;
       }
       mLastBuffer->getBuffer()[end] = 0xFFFD;
       ++end;
       mLastBuffer->setEnd(end);
@@ -1265,45 +1245,43 @@ nsHtml5Parser::ParseUntilSuspend()
         WillInterruptImpl();
         return;
       }
       if (mSuspending) {
         MaybePostContinueEvent();
         WillInterruptImpl();
         return;
       }
-      continue;
-    } else {
-      continue;
     }
+    continue;
   }
 }
 
 nsresult
 nsHtml5Parser::PerformCharsetSwitch()
 {
   // this code comes from nsObserverBase.cpp
   nsresult rv = NS_OK;
   nsCOMPtr<nsIWebShellServices> wss = do_QueryInterface(mDocShell);
   if (!wss) {
     return NS_ERROR_HTMLPARSER_CONTINUE;
   }
 #ifndef DONT_INFORM_WEBSHELL
   // ask the webshellservice to load the URL
-  if (NS_FAILED( rv = wss->SetRendering(PR_FALSE) )) {
-    // XXX nisheeth, uncomment the following two line to see the reent problem
+  if (NS_FAILED(rv = wss->SetRendering(PR_FALSE))) {
+    // do nothing and fall thru
   } else if (NS_FAILED(rv = wss->StopDocumentLoad())) {
     rv = wss->SetRendering(PR_TRUE); // turn on the rendering so at least we will see something.
   } else if (NS_FAILED(rv = wss->ReloadDocument(mPendingCharset.get(), kCharsetFromMetaTag))) {
     rv = wss->SetRendering(PR_TRUE); // turn on the rendering so at least we will see something.
   } else {
     rv = NS_ERROR_HTMLPARSER_STOPPARSING; // We're reloading a new document...stop loading the current.
   }
 #endif
-   //if our reload request is not accepted, we should tell parser to go on
+  // if our reload request is not accepted, we should tell parser to go on
   if (rv != NS_ERROR_HTMLPARSER_STOPPARSING)
     rv = NS_ERROR_HTMLPARSER_CONTINUE;
   return rv;
 }
 
 /**
  * This method executes a script element set by nsHtml5TreeBuilder. The reason
  * why this code is here and not in the tree builder is to allow the control
@@ -1340,27 +1318,28 @@ nsHtml5Parser::ExecuteScript()
     htmlDocument->ScriptExecuted(sele);
   }
   mScriptElement = nsnull;
 }
 
 void
 nsHtml5Parser::MaybePostContinueEvent()
 {
-  NS_PRECONDITION((mLifeCycle != TERMINATED), "Tried to post continue event when the parser is done.");
+  NS_PRECONDITION(mLifeCycle != TERMINATED, 
+                  "Tried to post continue event when the parser is done.");
   if (mContinueEvent) {
     return; // we already have a pending event
   }
   // This creates a reference cycle between this and the event that is
   // broken when the event fires.
   nsCOMPtr<nsIRunnable> event = new nsHtml5ParserContinueEvent(this);
   if (NS_FAILED(NS_DispatchToCurrentThread(event))) {
-      NS_WARNING("failed to dispatch parser continuation event");
+    NS_WARNING("failed to dispatch parser continuation event");
   } else {
-      mContinueEvent = event;
+    mContinueEvent = event;
   }
 }
 
 void
 nsHtml5Parser::Suspend()
 {
   mSuspending = PR_TRUE;
 }
@@ -1404,18 +1383,18 @@ nsHtml5Parser::ProcessBASETag(nsIContent
 void
 nsHtml5Parser::UpdateStyleSheet(nsIContent* aElement)
 {
   nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(aElement));
   if (ssle) {
     ssle->SetEnableUpdates(PR_TRUE);
     PRBool willNotify;
     PRBool isAlternate;
-    nsresult result = ssle->UpdateStyleSheet(this, &willNotify, &isAlternate);
-    if (NS_SUCCEEDED(result) && willNotify && !isAlternate) {
+    nsresult rv = ssle->UpdateStyleSheet(this, &willNotify, &isAlternate);
+    if (NS_SUCCEEDED(rv) && willNotify && !isAlternate) {
       ++mPendingSheetCount;
       mScriptLoader->AddExecuteBlocker();
     }
   }
 }
 
 void
 nsHtml5Parser::SetScriptElement(nsIContent* aScript)
--- a/parser/html/nsHtml5Portability.cpp
+++ b/parser/html/nsHtml5Portability.cpp
@@ -58,39 +58,39 @@ nsString*
 nsHtml5Portability::newEmptyString()
 {
   return new nsString();
 }
 
 nsString*
 nsHtml5Portability::newStringFromLiteral(const char* literal)
 {
-  nsString* rv = new nsString();
-  rv->AssignASCII(literal);
-  return rv;
+  nsString* str = new nsString();
+  str->AssignASCII(literal);
+  return str;
 }
 
 jArray<PRUnichar,PRInt32>
 nsHtml5Portability::newCharArrayFromLocal(nsIAtom* local)
 {
   nsAutoString temp;
   local->ToString(temp);
   PRInt32 len = temp.Length();
-  jArray<PRUnichar,PRInt32> rv = jArray<PRUnichar,PRInt32>(len);
-  memcpy(rv, temp.BeginReading(), len * sizeof(PRUnichar));
-  return rv;
+  jArray<PRUnichar,PRInt32> arr = jArray<PRUnichar,PRInt32>(len);
+  memcpy(arr, temp.BeginReading(), len * sizeof(PRUnichar));
+  return arr;
 }
 
 jArray<PRUnichar,PRInt32>
 nsHtml5Portability::newCharArrayFromString(nsString* string)
 {
   PRInt32 len = string->Length();
-  jArray<PRUnichar,PRInt32> rv = jArray<PRUnichar,PRInt32>(len);
-  memcpy(rv, string->BeginReading(), len * sizeof(PRUnichar));
-  return rv;
+  jArray<PRUnichar,PRInt32> arr = jArray<PRUnichar,PRInt32>(len);
+  memcpy(arr, string->BeginReading(), len * sizeof(PRUnichar));
+  return arr;
 }
 
 void
 nsHtml5Portability::releaseString(nsString* str)
 {
   delete str;
 }
 
@@ -168,23 +168,23 @@ nsHtml5Portability::literalEqualsString(
     return PR_FALSE;
   }
   return string->EqualsASCII(literal);
 }
 
 jArray<PRUnichar,PRInt32>
 nsHtml5Portability::isIndexPrompt()
 {
-  // Yeah, this whole method is uncool
-  char* literal = "This is a searchable index. Insert your search keywords here: ";
-  jArray<PRUnichar,PRInt32> rv = jArray<PRUnichar,PRInt32>(62);
+  // XXX making this localizable is bug 500631
+  const char* literal = "This is a searchable index. Insert your search keywords here: ";
+  jArray<PRUnichar,PRInt32> arr = jArray<PRUnichar,PRInt32>(62);
   for (PRInt32 i = 0; i < 62; ++i) {
-    rv[i] = literal[i];
+    arr[i] = literal[i];
   }
-  return rv;
+  return arr;
 }
 
 void
 nsHtml5Portability::initializeStatics()
 {
 }
 
 void
--- a/parser/html/nsHtml5TreeBuilder.cpp
+++ b/parser/html/nsHtml5TreeBuilder.cpp
@@ -1846,25 +1846,25 @@ nsHtml5TreeBuilder::extractCharsetFromCo
           default: {
             continue;
           }
         }
       }
     }
   }
   charsetloop_end: ;
-  nsString* rv = nsnull;
+  nsString* charset = nsnull;
   if (start != -1) {
     if (end == -1) {
       end = buffer.length;
     }
-    rv = nsHtml5Portability::newStringFromBuffer(buffer, start, end - start);
+    charset = nsHtml5Portability::newStringFromBuffer(buffer, start, end - start);
   }
   buffer.release();
-  return rv;
+  return charset;
 }
 
 void 
 nsHtml5TreeBuilder::checkMetaCharset(nsHtml5HtmlAttributes* attributes)
 {
   nsString* content = attributes->getValue(nsHtml5AttributeName::ATTR_CONTENT);
   nsString* internalCharsetLegacy = nsnull;
   if (!!content) {
--- a/parser/html/nsHtml5TreeBuilderCppSupplement.h
+++ b/parser/html/nsHtml5TreeBuilderCppSupplement.h
@@ -87,17 +87,16 @@ nsHtml5TreeBuilder::~nsHtml5TreeBuilder(
   if (mFlushTimer) {
     mFlushTimer->Cancel(); // XXX why is this even necessary? it is, though.
   }
 }
 
 nsIContent*
 nsHtml5TreeBuilder::createElement(PRInt32 aNamespace, nsIAtom* aName, nsHtml5HtmlAttributes* aAttributes)
 {
-  // XXX recheck http://mxr.mozilla.org/mozilla-central/source/content/base/src/nsDocument.cpp#6660
   nsIContent* newContent;
   nsCOMPtr<nsINodeInfo> nodeInfo = parser->GetNodeInfoManager()->GetNodeInfo(aName, nsnull, aNamespace);
   NS_ASSERTION(nodeInfo, "Got null nodeinfo.");
   NS_NewElement(&newContent, nodeInfo->NamespaceID(), nodeInfo, PR_TRUE);
   NS_ASSERTION(newContent, "Element creation created null pointer.");
   PRInt32 len = aAttributes->getLength();
   for (PRInt32 i = 0; i < len; ++i) {
     newContent->SetAttr(aAttributes->getURI(i), aAttributes->getLocalName(i), aAttributes->getPrefix(i), *(aAttributes->getValue(i)), PR_FALSE);
@@ -294,22 +293,26 @@ nsHtml5TreeBuilder::end()
 void
 nsHtml5TreeBuilder::appendDoctypeToDocument(nsIAtom* aName, nsString* aPublicId, nsString* aSystemId)
 {
   // Adapted from nsXMLContentSink
   // Create a new doctype node
   nsCOMPtr<nsIDOMDocumentType> docType;
   nsAutoString voidString;
   voidString.SetIsVoid(PR_TRUE);
-  NS_NewDOMDocumentType(getter_AddRefs(docType), parser->GetNodeInfoManager(), nsnull,
-                             aName, nsnull, nsnull, *aPublicId, *aSystemId,
-                             voidString);
-//  if (NS_FAILED(rv) || !docType) {
-//    return rv;
-//  }
+  NS_NewDOMDocumentType(getter_AddRefs(docType),
+                        parser->GetNodeInfoManager(),
+                        nsnull,
+                        aName,
+                        nsnull,
+                        nsnull,
+                        *aPublicId,
+                        *aSystemId,
+                        voidString);
+  NS_ASSERTION(docType, "Doctype creation failed.");
   nsCOMPtr<nsIContent> content = do_QueryInterface(docType);
   NS_ASSERTION(content, "doctype isn't content?");
   nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement();
   // XXX if null, OOM!
   treeOp->Init(eTreeOpAppendToDocument, content);
   // nsXMLContentSink can flush here, but what's the point?
   // It can also interrupt here, but we can't.
 }
@@ -396,17 +399,17 @@ nsHtml5TreeBuilder::elementPopped(PRInt3
       }
       nsEventDispatcher::Dispatch(aElement, ctx, &event);
     }
 #endif
     return;
   }
   // we now have only HTML
   // Some HTML nodes need DoneAddingChildren() called to initialize
-  // properly (eg form state restoration).
+  // properly (e.g. form state restoration).
   // XXX expose ElementName group here and do switch
   if (aName == nsHtml5Atoms::select ||
         aName == nsHtml5Atoms::textarea ||
 #ifdef MOZ_MEDIA
         aName == nsHtml5Atoms::video ||
         aName == nsHtml5Atoms::audio ||
 #endif
         aName == nsHtml5Atoms::object ||
--- a/parser/htmlparser/public/nsIParser.h
+++ b/parser/htmlparser/public/nsIParser.h
@@ -93,18 +93,18 @@ enum eParserDocType {
 #define kCharsetFromWeakDocTypeDefault  1
 #define kCharsetFromUserDefault         2
 #define kCharsetFromDocTypeDefault      3
 #define kCharsetFromCache               4
 #define kCharsetFromParentFrame         5
 #define kCharsetFromBookmarks           6
 #define kCharsetFromAutoDetection       7 
 #define kCharsetFromHintPrevDoc         8 
-#define kCharsetFromMetaPrescan         9 // this one and above: HTML5 Tentative
-#define kCharsetFromMetaTag            10 // this one and below: HTML5 Confident
+#define kCharsetFromMetaPrescan         9 // this one and smaller: HTML5 Tentative
+#define kCharsetFromMetaTag            10 // this one and greater: HTML5 Confident
 #define kCharsetFromByteOrderMark      11
 #define kCharsetFromChannel            12 
 #define kCharsetFromOtherComponent     13
 // Levels below here will be forced onto childframes too
 #define kCharsetFromParentForced       14
 #define kCharsetFromUserForced         15
 #define kCharsetFromPreviousLoading    16