Bug 1464784. Hold a strong ref to the document in callers of ConvertNodesOrStringsIntoNode. r=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Sat, 02 Jun 2018 01:26:00 -0400
changeset 420969 4aed3a8d30d84131ff5af1900ea4e2d6a6fc7d1d
parent 420968 3398f70632d6afa9c6de0ec89903fe5833573761
child 420970 bb85c5ee5afc151be0d07ecc48318dc69cfef446
push id34083
push userapavel@mozilla.com
push dateSat, 02 Jun 2018 23:03:25 +0000
treeherdermozilla-central@1f62ecdf59b6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1464784
milestone62.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 1464784. Hold a strong ref to the document in callers of ConvertNodesOrStringsIntoNode. r=smaug
dom/base/nsINode.cpp
dom/base/nsINode.h
--- a/dom/base/nsINode.cpp
+++ b/dom/base/nsINode.cpp
@@ -1441,17 +1441,17 @@ GetNodeFromNodeOrString(const OwningNode
   MOZ_CRASH("Impossible type");
 }
 
 /**
  * Implement the algorithm specified at
  * https://dom.spec.whatwg.org/#converting-nodes-into-a-node for |prepend()|,
  * |append()|, |before()|, |after()|, and |replaceWith()| APIs.
  */
-static already_AddRefed<nsINode>
+MOZ_CAN_RUN_SCRIPT static already_AddRefed<nsINode>
 ConvertNodesOrStringsIntoNode(const Sequence<OwningNodeOrString>& aNodes,
                               nsIDocument* aDocument,
                               ErrorResult& aRv)
 {
   if (aNodes.Length() == 1) {
     return GetNodeFromNodeOrString(aNodes[0], aDocument);
   }
 
@@ -1524,18 +1524,18 @@ nsINode::Before(const Sequence<OwningNod
   nsCOMPtr<nsINode> parent = GetParentNode();
   if (!parent) {
     return;
   }
 
   nsCOMPtr<nsINode> viablePreviousSibling =
     FindViablePreviousSibling(*this, aNodes);
 
-  nsCOMPtr<nsINode> node =
-    ConvertNodesOrStringsIntoNode(aNodes, OwnerDoc(), aRv);
+  nsCOMPtr<nsIDocument> doc = OwnerDoc();
+  nsCOMPtr<nsINode> node = ConvertNodesOrStringsIntoNode(aNodes, doc, aRv);
   if (aRv.Failed()) {
     return;
   }
 
   viablePreviousSibling = viablePreviousSibling ?
     viablePreviousSibling->GetNextSibling() : parent->GetFirstChild();
 
   parent->InsertBefore(*node, viablePreviousSibling, aRv);
@@ -1547,18 +1547,18 @@ nsINode::After(const Sequence<OwningNode
 {
   nsCOMPtr<nsINode> parent = GetParentNode();
   if (!parent) {
     return;
   }
 
   nsCOMPtr<nsINode> viableNextSibling = FindViableNextSibling(*this, aNodes);
 
-  nsCOMPtr<nsINode> node =
-    ConvertNodesOrStringsIntoNode(aNodes, OwnerDoc(), aRv);
+  nsCOMPtr<nsIDocument> doc = OwnerDoc();
+  nsCOMPtr<nsINode> node = ConvertNodesOrStringsIntoNode(aNodes, doc, aRv);
   if (aRv.Failed()) {
     return;
   }
 
   parent->InsertBefore(*node, viableNextSibling, aRv);
 }
 
 void
@@ -1567,18 +1567,18 @@ nsINode::ReplaceWith(const Sequence<Owni
 {
   nsCOMPtr<nsINode> parent = GetParentNode();
   if (!parent) {
     return;
   }
 
   nsCOMPtr<nsINode> viableNextSibling = FindViableNextSibling(*this, aNodes);
 
-  nsCOMPtr<nsINode> node =
-    ConvertNodesOrStringsIntoNode(aNodes, OwnerDoc(), aRv);
+  nsCOMPtr<nsIDocument> doc = OwnerDoc();
+  nsCOMPtr<nsINode> node = ConvertNodesOrStringsIntoNode(aNodes, doc, aRv);
   if (aRv.Failed()) {
     return;
   }
 
   if (parent == GetParentNode()) {
     parent->ReplaceChild(*node, *this, aRv);
   } else {
     parent->InsertBefore(*node, viableNextSibling, aRv);
@@ -1623,32 +1623,32 @@ nsINode::GetLastElementChild() const
 
   return nullptr;
 }
 
 void
 nsINode::Prepend(const Sequence<OwningNodeOrString>& aNodes,
                  ErrorResult& aRv)
 {
-  nsCOMPtr<nsINode> node =
-    ConvertNodesOrStringsIntoNode(aNodes, OwnerDoc(), aRv);
+  nsCOMPtr<nsIDocument> doc = OwnerDoc();
+  nsCOMPtr<nsINode> node = ConvertNodesOrStringsIntoNode(aNodes, doc, aRv);
   if (aRv.Failed()) {
     return;
   }
 
   nsCOMPtr<nsINode> refNode = mFirstChild;
   InsertBefore(*node, refNode, aRv);
 }
 
 void
 nsINode::Append(const Sequence<OwningNodeOrString>& aNodes,
                  ErrorResult& aRv)
 {
-  nsCOMPtr<nsINode> node =
-    ConvertNodesOrStringsIntoNode(aNodes, OwnerDoc(), aRv);
+  nsCOMPtr<nsIDocument> doc = OwnerDoc();
+  nsCOMPtr<nsINode> node = ConvertNodesOrStringsIntoNode(aNodes, doc, aRv);
   if (aRv.Failed()) {
     return;
   }
 
   AppendChild(*node, aRv);
 }
 
 void
--- a/dom/base/nsINode.h
+++ b/dom/base/nsINode.h
@@ -1854,31 +1854,35 @@ public:
     parent->RemoveChild(*this, rv);
     return rv.StealNSResult();
   }
 
   // ChildNode methods
   mozilla::dom::Element* GetPreviousElementSibling() const;
   mozilla::dom::Element* GetNextElementSibling() const;
 
-  void Before(const Sequence<OwningNodeOrString>& aNodes, ErrorResult& aRv);
-  void After(const Sequence<OwningNodeOrString>& aNodes, ErrorResult& aRv);
-  void ReplaceWith(const Sequence<OwningNodeOrString>& aNodes,
-                   ErrorResult& aRv);
+  MOZ_CAN_RUN_SCRIPT void Before(const Sequence<OwningNodeOrString>& aNodes,
+                                 ErrorResult& aRv);
+  MOZ_CAN_RUN_SCRIPT void After(const Sequence<OwningNodeOrString>& aNodes,
+                                ErrorResult& aRv);
+  MOZ_CAN_RUN_SCRIPT void ReplaceWith(const Sequence<OwningNodeOrString>& aNodes,
+                                      ErrorResult& aRv);
   /**
    * Remove this node from its parent, if any.
    */
   void Remove();
 
   // ParentNode methods
   mozilla::dom::Element* GetFirstElementChild() const;
   mozilla::dom::Element* GetLastElementChild() const;
 
-  void Prepend(const Sequence<OwningNodeOrString>& aNodes, ErrorResult& aRv);
-  void Append(const Sequence<OwningNodeOrString>& aNodes, ErrorResult& aRv);
+  MOZ_CAN_RUN_SCRIPT void Prepend(const Sequence<OwningNodeOrString>& aNodes,
+                                  ErrorResult& aRv);
+  MOZ_CAN_RUN_SCRIPT void Append(const Sequence<OwningNodeOrString>& aNodes,
+                                 ErrorResult& aRv);
 
   void GetBoxQuads(const BoxQuadOptions& aOptions,
                    nsTArray<RefPtr<DOMQuad> >& aResult,
                    CallerType aCallerType,
                    ErrorResult& aRv);
 
   already_AddRefed<DOMQuad> ConvertQuadFromNode(DOMQuad& aQuad,
                                                 const TextOrElementOrDocument& aFrom,