Bug 616421 - Better distinguish invalid mOpCode values in nsHtml5TreeOperation::Perform. r=hsivonen.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 02 Jun 2016 17:49:44 +1000
changeset 339117 2313feadbdaf1e2a6a92ef5f6c0d0e6bd34121b2
parent 339116 cd31d578be5865d5646f59a123b0b9056d9d93c9
child 339118 c62262afd761e9936348b2e30fb82adf7e1ecc74
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsivonen
bugs616421
milestone49.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 616421 - Better distinguish invalid mOpCode values in nsHtml5TreeOperation::Perform. r=hsivonen. This patch: - Removes eTreeOpAddError{Atom,TwoAtoms}, which are unused. - Adds a MOZ_CRASHing case for eTreeOpUninitialized. - Reorders the cases in the switch to match the enum declaration order, which makes it easier to see that all opcodes are now covered.
parser/html/nsHtml5TreeOperation.cpp
parser/html/nsHtml5TreeOperation.h
--- a/parser/html/nsHtml5TreeOperation.cpp
+++ b/parser/html/nsHtml5TreeOperation.cpp
@@ -635,16 +635,19 @@ nsHtml5TreeOperation::MarkMalformedIfScr
   }
 }
 
 nsresult
 nsHtml5TreeOperation::Perform(nsHtml5TreeOpExecutor* aBuilder,
                               nsIContent** aScriptElement)
 {
   switch(mOpCode) {
+    case eTreeOpUninitialized: {
+      MOZ_CRASH("eTreeOpUninitialized");
+    }
     case eTreeOpAppend: {
       nsIContent* node = *(mOne.node);
       nsIContent* parent = *(mTwo.node);
       return Append(node, parent, aBuilder);
     }
     case eTreeOpDetach: {
       nsIContent* node = *(mOne.node);
       Detach(node, aBuilder);
@@ -665,16 +668,20 @@ nsHtml5TreeOperation::Perform(nsHtml5Tre
       nsIContent* node = *(mOne.node);
       return AppendToDocument(node, aBuilder);
     }
     case eTreeOpAddAttributes: {
       nsIContent* node = *(mOne.node);
       nsHtml5HtmlAttributes* attributes = mTwo.attributes;
       return AddAttributes(node, attributes, aBuilder);
     }
+    case eTreeOpDocumentMode: {
+      aBuilder->SetDocumentMode(mOne.mode);
+      return NS_OK;
+    }
     case eTreeOpCreateElementNetwork:
     case eTreeOpCreateElementNotNetwork: {
       nsIContent** target = mOne.node;
       int32_t ns = mFour.integer;
       nsCOMPtr<nsIAtom> name = Reget(mTwo.atom);
       nsHtml5HtmlAttributes* attributes = mThree.attributes;
       nsIContent* intendedParent = mFive.node ? *(mFive.node) : nullptr;
 
@@ -813,24 +820,16 @@ nsHtml5TreeOperation::Perform(nsHtml5Tre
       nsIContent* node = *(mOne.node);
       MarkMalformedIfScript(node);
       return NS_OK;
     }
     case eTreeOpStreamEnded: {
       aBuilder->DidBuildModel(false); // this causes a notifications flush anyway
       return NS_OK;
     }
-    case eTreeOpStartLayout: {
-      aBuilder->StartLayout(); // this causes a notification flush anyway
-      return NS_OK;
-    }
-    case eTreeOpDocumentMode: {
-      aBuilder->SetDocumentMode(mOne.mode);
-      return NS_OK;
-    }
     case eTreeOpSetStyleLineNumber: {
       nsIContent* node = *(mOne.node);
       nsCOMPtr<nsIStyleSheetLinkingElement> ssle = do_QueryInterface(node);
       NS_ASSERTION(ssle, "Node didn't QI to style.");
       ssle->SetLineNumber(mFour.integer);
       return NS_OK;
     }
     case eTreeOpSetScriptLineNumberAndFreeze: {
@@ -864,24 +863,16 @@ nsHtml5TreeOperation::Perform(nsHtml5Tre
         klass.Append(' ');
         klass.Append(depStr);
         node->SetAttr(kNameSpaceID_None, nsGkAtoms::_class, klass, true);
       } else {
         node->SetAttr(kNameSpaceID_None, nsGkAtoms::_class, depStr, true);
       }
       return NS_OK;
     }
-    case eTreeOpAddLineNumberId: {
-      nsIContent* node = *(mOne.node);
-      int32_t lineNumber = mFour.integer;
-      nsAutoString val(NS_LITERAL_STRING("line"));
-      val.AppendInt(lineNumber);
-      node->SetAttr(kNameSpaceID_None, nsGkAtoms::id, val, true);
-      return NS_OK;
-    }
     case eTreeOpAddViewSourceHref: {
       nsIContent* node = *mOne.node;
       char16_t* buffer = mTwo.unicharPtr;
       int32_t length = mFour.integer;
 
       nsDependentString relative(buffer, length);
 
       nsIDocument* doc = aBuilder->GetDocument();
@@ -927,16 +918,23 @@ nsHtml5TreeOperation::Perform(nsHtml5Tre
       viewSourceUrl.Append(spec);
 
       nsAutoString utf16;
       CopyUTF8toUTF16(viewSourceUrl, utf16);
 
       node->SetAttr(kNameSpaceID_None, nsGkAtoms::href, utf16, true);
       return rv;
     }
+    case eTreeOpAddViewSourceBase: {
+      char16_t* buffer = mTwo.unicharPtr;
+      int32_t length = mFour.integer;
+      nsDependentString baseUrl(buffer, length);
+      aBuilder->AddBase(baseUrl);
+      return NS_OK;
+    }
     case eTreeOpAddError: {
       nsIContent* node = *(mOne.node);
       char* msgId = mTwo.charPtr;
       nsCOMPtr<nsIAtom> atom = Reget(mThree.atom);
       nsCOMPtr<nsIAtom> otherAtom = Reget(mFour.atom);
       // See viewsource.css for the possible classes in addition to "error".
       nsAutoString klass;
       node->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, klass);
@@ -975,21 +973,26 @@ nsHtml5TreeOperation::Perform(nsHtml5Tre
         title.Append('\n');
         title.Append(message);
         node->SetAttr(kNameSpaceID_None, nsGkAtoms::title, title, true);
       } else {
         node->SetAttr(kNameSpaceID_None, nsGkAtoms::title, message, true);
       }
       return rv;
     }
-    case eTreeOpAddViewSourceBase: {
-      char16_t* buffer = mTwo.unicharPtr;
-      int32_t length = mFour.integer;
-      nsDependentString baseUrl(buffer, length);
-      aBuilder->AddBase(baseUrl);
+    case eTreeOpAddLineNumberId: {
+      nsIContent* node = *(mOne.node);
+      int32_t lineNumber = mFour.integer;
+      nsAutoString val(NS_LITERAL_STRING("line"));
+      val.AppendInt(lineNumber);
+      node->SetAttr(kNameSpaceID_None, nsGkAtoms::id, val, true);
+      return NS_OK;
+    }
+    case eTreeOpStartLayout: {
+      aBuilder->StartLayout(); // this causes a notification flush anyway
       return NS_OK;
     }
     default: {
       MOZ_CRASH("Bogus tree op");
     }
   }
   return NS_OK; // keep compiler happy
 }
--- a/parser/html/nsHtml5TreeOperation.h
+++ b/parser/html/nsHtml5TreeOperation.h
@@ -53,18 +53,16 @@ enum eHtml5TreeOperation {
   eTreeOpSetScriptLineNumberAndFreeze,
   eTreeOpSvgLoad,
   eTreeOpMaybeComplainAboutCharset,
   eTreeOpAddClass,
   eTreeOpAddViewSourceHref,
   eTreeOpAddViewSourceBase,
   eTreeOpAddError,
   eTreeOpAddLineNumberId,
-  eTreeOpAddErrorAtom,
-  eTreeOpAddErrorTwoAtoms,
   eTreeOpStartLayout
 };
 
 class nsHtml5TreeOperationStringPair {
   private:
     nsString mPublicId;
     nsString mSystemId;
   public: