Bug 1552869: propagate `nsresult` values of various `Append*` calls in `SerializeNodeStart`, `SerializeNodeEnd` r=hsivonen
authorMirko Brodesser <mbrodesser@mozilla.com>
Tue, 21 May 2019 05:38:20 +0000
changeset 474688 2aadfad018d5d63ecdc95c5c2ca15ebf4c9406d9
parent 474687 acf1896be423cca5678a9f10dcd793974b204231
child 474689 d94707ff797ed94e04ab286a6d9e43a4e7e6480e
push id113168
push userrmaries@mozilla.com
push dateTue, 21 May 2019 16:39:23 +0000
treeherdermozilla-inbound@3c0f78074b72 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershsivonen
bugs1552869
milestone69.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 1552869: propagate `nsresult` values of various `Append*` calls in `SerializeNodeStart`, `SerializeNodeEnd` r=hsivonen Might helpt to discover and prevent bugs. Differential Revision: https://phabricator.services.mozilla.com/D31798
dom/base/nsDocumentEncoder.cpp
--- a/dom/base/nsDocumentEncoder.cpp
+++ b/dom/base/nsDocumentEncoder.cpp
@@ -458,56 +458,58 @@ nsresult nsDocumentEncoder::SerializeNod
   if (IsInvisibleNodeAndShouldBeSkipped(aOriginalNode)) {
     return NS_OK;
   }
 
   FixupNodeDeterminer fixupNodeDeterminer{mNodeFixup, aFixupNode,
                                           aOriginalNode};
   nsINode* node = &fixupNodeDeterminer.GetFixupNodeFallBackToOriginalNode();
 
+  nsresult rv = NS_OK;
+
   if (node->IsElement()) {
     if ((mFlags & (nsIDocumentEncoder::OutputPreformatted |
                    nsIDocumentEncoder::OutputDropInvisibleBreak)) &&
         nsLayoutUtils::IsInvisibleBreak(node)) {
-      return NS_OK;
+      return rv;
     }
     Element* originalElement = aOriginalNode.AsElement();
-    mSerializer->AppendElementStart(node->AsElement(), originalElement, aStr);
-    return NS_OK;
+    rv = mSerializer->AppendElementStart(node->AsElement(), originalElement, aStr);
+    return rv;
   }
 
   switch (node->NodeType()) {
     case nsINode::TEXT_NODE: {
-      mSerializer->AppendText(static_cast<nsIContent*>(node), aStartOffset,
+      rv = mSerializer->AppendText(static_cast<nsIContent*>(node), aStartOffset,
                               aEndOffset, aStr);
       break;
     }
     case nsINode::CDATA_SECTION_NODE: {
-      mSerializer->AppendCDATASection(static_cast<nsIContent*>(node),
+      rv = mSerializer->AppendCDATASection(static_cast<nsIContent*>(node),
                                       aStartOffset, aEndOffset, aStr);
       break;
     }
     case nsINode::PROCESSING_INSTRUCTION_NODE: {
-      mSerializer->AppendProcessingInstruction(
+      rv = mSerializer->AppendProcessingInstruction(
           static_cast<ProcessingInstruction*>(node), aStartOffset, aEndOffset,
           aStr);
       break;
     }
     case nsINode::COMMENT_NODE: {
-      mSerializer->AppendComment(static_cast<Comment*>(node), aStartOffset,
+      rv = mSerializer->AppendComment(static_cast<Comment*>(node), aStartOffset,
                                  aEndOffset, aStr);
       break;
     }
     case nsINode::DOCUMENT_TYPE_NODE: {
-      mSerializer->AppendDoctype(static_cast<DocumentType*>(node), aStr);
+      rv = mSerializer->AppendDoctype(static_cast<DocumentType*>(node), aStr);
       break;
     }
   }
 
-  return NS_OK;
+  return rv;
 }
 
 nsresult nsDocumentEncoder::SerializeNodeEnd(nsINode& aNode, nsAString& aStr) {
   if (mNeedsPreformatScanning) {
     if (aNode.IsElement()) {
       mSerializer->ForgetElementForPreformat(aNode.AsElement());
     } else if (aNode.IsText()) {
       const nsCOMPtr<nsINode> parent = aNode.GetParent();
@@ -516,20 +518,23 @@ nsresult nsDocumentEncoder::SerializeNod
       }
     }
   }
 
   if (IsInvisibleNodeAndShouldBeSkipped(aNode)) {
     return NS_OK;
   }
 
+  nsresult rv = NS_OK;
+
   if (aNode.IsElement()) {
-    mSerializer->AppendElementEnd(aNode.AsElement(), aStr);
+    rv = mSerializer->AppendElementEnd(aNode.AsElement(), aStr);
   }
-  return NS_OK;
+
+  return rv;
 }
 
 nsresult nsDocumentEncoder::SerializeToStringRecursive(nsINode* aNode,
                                                        nsAString& aStr,
                                                        bool aDontSerializeRoot,
                                                        uint32_t aMaxLength) {
   if (aMaxLength > 0 && aStr.Length() >= aMaxLength) {
     return NS_OK;
@@ -1306,34 +1311,36 @@ nsHTMLCopyEncoder::EncodeToStringWithCon
     if (mEndDepth) mEndDepth--;
     // and the count
     count--;
   }
 
   i = count;
   while (i > 0) {
     node = mCommonAncestors.ElementAt(--i);
-    SerializeNodeStart(*node, 0, -1, aContextString);
+    rv = SerializeNodeStart(*node, 0, -1, aContextString);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
   // i = 0; guaranteed by above
   while (i < count) {
     node = mCommonAncestors.ElementAt(i++);
-    SerializeNodeEnd(*node, aContextString);
+    rv = SerializeNodeEnd(*node, aContextString);
+    NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // encode range info : the start and end depth of the selection, where the
   // depth is distance down in the parent hierarchy.  Later we will need to add
   // leading/trailing whitespace info to this.
   nsAutoString infoString;
   infoString.AppendInt(mStartDepth);
   infoString.Append(char16_t(','));
   infoString.AppendInt(mEndDepth);
   aInfoString = infoString;
 
-  return NS_OK;
+  return rv;
 }
 
 bool nsHTMLCopyEncoder::IncludeInContext(nsINode* aNode) {
   nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
 
   if (!content) return false;
 
   return content->IsAnyOfHTMLElements(