Bug 1469385 - Remove InsertChildAt_Deprecated and RemoveChildAt_Deprecated, r=bz,smaug
authorcatalin.badea392@gmail.com
Tue, 19 Jun 2018 12:21:18 +0300
changeset 479698 3395984ed40ce4a53e1621fcbeda606ea2c5cb62
parent 479697 4cde573c283a56269a37bcb60066c863ba04ddd9
child 479699 cb86f60d263987d7836f0694acc12106fee5d837
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, smaug
bugs1469385
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 1469385 - Remove InsertChildAt_Deprecated and RemoveChildAt_Deprecated, r=bz,smaug
dom/base/Attr.cpp
dom/base/Attr.h
dom/base/CharacterData.cpp
dom/base/CharacterData.h
dom/base/FragmentOrElement.cpp
dom/base/FragmentOrElement.h
dom/base/nsDocument.cpp
dom/base/nsIDocument.h
dom/base/nsINode.cpp
dom/base/nsINode.h
dom/html/HTMLFieldSetElement.cpp
dom/html/HTMLFieldSetElement.h
dom/html/HTMLOptGroupElement.cpp
dom/html/HTMLOptGroupElement.h
dom/html/HTMLPictureElement.cpp
dom/html/HTMLPictureElement.h
dom/html/HTMLSelectElement.cpp
dom/html/HTMLSelectElement.h
dom/svg/SVGDocument.cpp
dom/svg/SVGDocument.h
dom/svg/SVGSwitchElement.cpp
dom/svg/SVGSwitchElement.h
dom/xul/nsXULElement.cpp
dom/xul/nsXULElement.h
--- a/dom/base/Attr.cpp
+++ b/dom/base/Attr.cpp
@@ -284,28 +284,16 @@ Attr::ComputeIndexOf(const nsINode* aPos
 
 nsresult
 Attr::InsertChildBefore(nsIContent* aKid, nsIContent* aBeforeThis,
                         bool aNotify)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
-nsresult
-Attr::InsertChildAt_Deprecated(nsIContent* aKid, uint32_t aIndex,
-                               bool aNotify)
-{
-  return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-void
-Attr::RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify)
-{
-}
-
 void
 Attr::RemoveChildNode(nsIContent* aKid, bool aNotify)
 {
 }
 
 void
 Attr::GetEventTargetParent(EventChainPreVisitor& aVisitor)
 {
--- a/dom/base/Attr.h
+++ b/dom/base/Attr.h
@@ -58,19 +58,16 @@ public:
 
   // nsINode interface
   virtual bool IsNodeOfType(uint32_t aFlags) const override;
   virtual uint32_t GetChildCount() const override;
   virtual nsIContent *GetChildAt_Deprecated(uint32_t aIndex) const override;
   virtual int32_t ComputeIndexOf(const nsINode* aPossibleChild) const override;
   virtual nsresult InsertChildBefore(nsIContent* aKid, nsIContent* aBeforeThis,
                                      bool aNotify) override;
-  virtual nsresult InsertChildAt_Deprecated(nsIContent* aKid, uint32_t aIndex,
-                                            bool aNotify) override;
-  virtual void RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify) override;
   virtual void RemoveChildNode(nsIContent* aKid, bool aNotify) override;
   virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
                          bool aPreallocateChildren) const override;
   virtual already_AddRefed<nsIURI> GetBaseURI(bool aTryUseXHRDocBaseURI = false) const override;
 
   static void Initialize();
   static void Shutdown();
 
--- a/dom/base/CharacterData.cpp
+++ b/dom/base/CharacterData.cpp
@@ -629,29 +629,16 @@ CharacterData::ComputeIndexOf(const nsIN
 nsresult
 CharacterData::InsertChildBefore(nsIContent* aKid,
                                  nsIContent* aBeforeThis,
                                  bool aNotify)
 {
   return NS_OK;
 }
 
-nsresult
-CharacterData::InsertChildAt_Deprecated(nsIContent* aKid,
-                                        uint32_t aIndex,
-                                        bool aNotify)
-{
-  return NS_OK;
-}
-
-void
-CharacterData::RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify)
-{
-}
-
 void
 CharacterData::RemoveChildNode(nsIContent* aKid, bool aNotify)
 {
 }
 
 nsXBLBinding *
 CharacterData::DoGetXBLBinding() const
 {
--- a/dom/base/CharacterData.h
+++ b/dom/base/CharacterData.h
@@ -100,19 +100,16 @@ public:
                                     ErrorResult& aError) override;
 
   // nsINode methods
   virtual uint32_t GetChildCount() const override;
   virtual nsIContent *GetChildAt_Deprecated(uint32_t aIndex) const override;
   virtual int32_t ComputeIndexOf(const nsINode* aPossibleChild) const override;
   virtual nsresult InsertChildBefore(nsIContent* aKid, nsIContent* aBeforeThis,
                                      bool aNotify) override;
-  virtual nsresult InsertChildAt_Deprecated(nsIContent* aKid, uint32_t aIndex,
-                                            bool aNotify) override;
-  virtual void RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify) override;
   virtual void RemoveChildNode(nsIContent* aKid, bool aNotify) override;
   virtual void GetTextContentInternal(nsAString& aTextContent,
                                       OOMReporter& aError) override
   {
     GetNodeValue(aTextContent);
   }
   virtual void SetTextContentInternal(const nsAString& aTextContent,
                                       nsIPrincipal* aSubjectPrincipal,
--- a/dom/base/FragmentOrElement.cpp
+++ b/dom/base/FragmentOrElement.cpp
@@ -1220,37 +1220,16 @@ FragmentOrElement::InsertChildBefore(nsI
   MOZ_ASSERT(aKid, "null ptr");
 
   int32_t index = aBeforeThis ? ComputeIndexOf(aBeforeThis) : GetChildCount();
   MOZ_ASSERT(index >= 0);
 
   return doInsertChildAt(aKid, index, aNotify, mAttrsAndChildren);
 }
 
-nsresult
-FragmentOrElement::InsertChildAt_Deprecated(nsIContent* aKid,
-                                            uint32_t aIndex,
-                                            bool aNotify)
-{
-  MOZ_ASSERT(aKid, "null ptr");
-
-  return doInsertChildAt(aKid, aIndex, aNotify, mAttrsAndChildren);
-}
-
-void
-FragmentOrElement::RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify)
-{
-  nsCOMPtr<nsIContent> oldKid = mAttrsAndChildren.GetSafeChildAt(aIndex);
-  NS_ASSERTION(oldKid == GetChildAt_Deprecated(aIndex), "Unexpected child in RemoveChildAt_Deprecated");
-
-  if (oldKid) {
-    doRemoveChildAt(aIndex, aNotify, oldKid, mAttrsAndChildren);
-  }
-}
-
 void
 FragmentOrElement::RemoveChildNode(nsIContent* aKid, bool aNotify)
 {
   // Let's keep the node alive.
   nsCOMPtr<nsIContent> kungFuDeathGrip = aKid;
   doRemoveChildAt(ComputeIndexOf(aKid), aNotify, aKid, mAttrsAndChildren);
 }
 
--- a/dom/base/FragmentOrElement.h
+++ b/dom/base/FragmentOrElement.h
@@ -93,19 +93,16 @@ public:
   NS_DECL_ADDSIZEOFEXCLUDINGTHIS
 
   // nsINode interface methods
   virtual uint32_t GetChildCount() const override;
   virtual nsIContent *GetChildAt_Deprecated(uint32_t aIndex) const override;
   virtual int32_t ComputeIndexOf(const nsINode* aPossibleChild) const override;
   virtual nsresult InsertChildBefore(nsIContent* aKid, nsIContent* aBeforeThis,
                                      bool aNotify) override;
-  virtual nsresult InsertChildAt_Deprecated(nsIContent* aKid, uint32_t aIndex,
-                                            bool aNotify) override;
-  virtual void RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify) override;
   virtual void RemoveChildNode(nsIContent* aKid, bool aNotify) override;
   virtual void GetTextContentInternal(nsAString& aTextContent,
                                       mozilla::OOMReporter& aError) override;
   virtual void SetTextContentInternal(const nsAString& aTextContent,
                                       nsIPrincipal* aSubjectPrincipal,
                                       mozilla::ErrorResult& aError) override;
 
   // nsIContent interface methods
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -4104,56 +4104,16 @@ nsIDocument::InsertChildBefore(nsIConten
   }
 
   int32_t index = aBeforeThis ? ComputeIndexOf(aBeforeThis) : GetChildCount();
   MOZ_ASSERT(index >= 0);
 
   return doInsertChildAt(aKid, index, aNotify, mChildren);
 }
 
-nsresult
-nsIDocument::InsertChildAt_Deprecated(nsIContent* aKid,
-                                      uint32_t aIndex,
-                                      bool aNotify)
-{
-  if (aKid->IsElement() && GetRootElement()) {
-    NS_WARNING("Inserting root element when we already have one");
-    return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
-  }
-
-  return doInsertChildAt(aKid, aIndex, aNotify, mChildren);
-}
-
-void
-nsIDocument::RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify)
-{
-  nsCOMPtr<nsIContent> oldKid = GetChildAt_Deprecated(aIndex);
-  if (!oldKid) {
-    return;
-  }
-
-  if (oldKid->IsElement()) {
-    // Destroy the link map up front before we mess with the child list.
-    DestroyElementMaps();
-  }
-
-  // Preemptively clear mCachedRootElement, since we may be about to remove it
-  // from our child list, and we don't want to return this maybe-obsolete value
-  // from any GetRootElement() calls that happen inside of doRemoveChildAt().
-  // (NOTE: for this to be useful, doRemoveChildAt() must NOT trigger any
-  // GetRootElement() calls until after it's removed the child from mChildren.
-  // Any call before that point would restore this soon-to-be-obsolete cached
-  // answer, and our clearing here would be fruitless.)
-  mCachedRootElement = nullptr;
-  doRemoveChildAt(aIndex, aNotify, oldKid, mChildren);
-  MOZ_ASSERT(mCachedRootElement != oldKid,
-             "Stale pointer in mCachedRootElement, after we tried to clear it "
-             "(maybe somebody called GetRootElement() too early?)");
-}
-
 void
 nsIDocument::RemoveChildNode(nsIContent* aKid, bool aNotify)
 {
   if (aKid->IsElement()) {
     // Destroy the link map up front before we mess with the child list.
     DestroyElementMaps();
   }
 
--- a/dom/base/nsIDocument.h
+++ b/dom/base/nsIDocument.h
@@ -543,19 +543,16 @@ public:
 
   uint32_t GetChildCount() const final
   {
     return mChildren.ChildCount();
   }
 
   nsresult InsertChildBefore(nsIContent* aKid, nsIContent* aBeforeThis,
                              bool aNotify) override;
-  nsresult InsertChildAt_Deprecated(nsIContent* aKid, uint32_t aIndex,
-                                    bool aNotify) override;
-  void RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify) final;
   void RemoveChildNode(nsIContent* aKid, bool aNotify) final;
   nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo,
                  nsINode **aResult,
                  bool aPreallocateChildren) const override
   {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
--- a/dom/base/nsINode.cpp
+++ b/dom/base/nsINode.cpp
@@ -528,34 +528,36 @@ void
 nsINode::GetNodeValueInternal(nsAString& aNodeValue)
 {
   SetDOMStringToNull(aNodeValue);
 }
 
 nsINode*
 nsINode::RemoveChild(nsINode& aOldChild, ErrorResult& aError)
 {
-  if (IsCharacterData()) {
+  if (!aOldChild.IsContent()) {
     // aOldChild can't be one of our children.
     aError.Throw(NS_ERROR_DOM_NOT_FOUND_ERR);
     return nullptr;
   }
 
   if (aOldChild.GetParentNode() == this) {
     nsContentUtils::MaybeFireNodeRemoved(&aOldChild, this);
   }
 
-  int32_t index = ComputeIndexOf(&aOldChild);
-  if (index == -1) {
+  // Check again, we may not be the child's parent anymore.
+  // Can be triggered by dom/base/crashtests/293388-1.html
+  if (aOldChild.AsContent()->IsRootOfAnonymousSubtree() ||
+      aOldChild.GetParentNode() != this) {
     // aOldChild isn't one of our children.
     aError.Throw(NS_ERROR_DOM_NOT_FOUND_ERR);
     return nullptr;
   }
 
-  RemoveChildAt_Deprecated(index, true);
+  RemoveChildNode(aOldChild.AsContent(), true);
   return &aOldChild;
 }
 
 void
 nsINode::Normalize()
 {
   // First collect list of nodes to be removed
   AutoTArray<nsCOMPtr<nsIContent>, 50> nodes;
@@ -635,17 +637,17 @@ nsINode::Normalize()
     }
 
     // Remove node
     nsCOMPtr<nsINode> parent = node->GetParentNode();
     NS_ASSERTION(parent || hasRemoveListeners,
                  "Should always have a parent unless "
                  "mutation events messed us up");
     if (parent) {
-      parent->RemoveChildAt_Deprecated(parent->ComputeIndexOf(node), true);
+      parent->RemoveChildNode(node, true);
     }
   }
 }
 
 nsresult
 nsINode::GetBaseURI(nsAString &aURI) const
 {
   nsCOMPtr<nsIURI> baseURI = GetBaseURI();
@@ -1992,58 +1994,54 @@ nsINode::ReplaceOrInsertBefore(bool aRep
   }
 
   EnsurePreInsertionValidity2(aReplace, *aNewChild, aRefChild, aError);
   if (aError.Failed()) {
     return nullptr;
   }
 
   // Record the node to insert before, if any
-  nsINode* nodeToInsertBefore;
+  nsIContent* nodeToInsertBefore;
   if (aReplace) {
     nodeToInsertBefore = aRefChild->GetNextSibling();
   } else {
-    nodeToInsertBefore = aRefChild;
+    // Since aRefChild is our child, it must be an nsIContent object.
+    nodeToInsertBefore = aRefChild ? aRefChild->AsContent() : nullptr;
   }
   if (nodeToInsertBefore == aNewChild) {
     // We're going to remove aNewChild from its parent, so use its next sibling
     // as the node to insert before.
     nodeToInsertBefore = nodeToInsertBefore->GetNextSibling();
   }
 
   Maybe<AutoTArray<nsCOMPtr<nsIContent>, 50> > fragChildren;
 
   // Remove the new child from the old parent if one exists
   nsIContent* newContent = aNewChild->AsContent();
   nsCOMPtr<nsINode> oldParent = newContent->GetParentNode();
   if (oldParent) {
-    int32_t removeIndex = oldParent->ComputeIndexOf(newContent);
-    if (removeIndex < 0) {
-      // newContent is anonymous.  We can't deal with this, so just bail
-      NS_ERROR("How come our flags didn't catch this?");
-      aError.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
-      return nullptr;
-    }
-
     // Hold a strong ref to nodeToInsertBefore across the removal of newContent
     nsCOMPtr<nsINode> kungFuDeathGrip = nodeToInsertBefore;
 
     // Removing a child can run script, via XBL destructors.
     nsMutationGuard guard;
 
     // Scope for the mutation batch and scriptblocker, so they go away
     // while kungFuDeathGrip is still alive.
     {
       mozAutoDocUpdate batch(newContent->GetComposedDoc(), true);
       nsAutoMutationBatch mb(oldParent, true, true);
-      oldParent->RemoveChildAt_Deprecated(removeIndex, true);
+      // ScriptBlocker ensures previous and next stay alive.
+      nsIContent* previous = aNewChild->GetPreviousSibling();
+      nsIContent* next = aNewChild->GetNextSibling();
+      oldParent->RemoveChildNode(aNewChild->AsContent(), true);
       if (nsAutoMutationBatch::GetCurrentBatch() == &mb) {
         mb.RemovalDone();
-        mb.SetPrevSibling(oldParent->GetChildAt_Deprecated(removeIndex - 1));
-        mb.SetNextSibling(oldParent->GetChildAt_Deprecated(removeIndex));
+        mb.SetPrevSibling(previous);
+        mb.SetNextSibling(next);
       }
     }
 
     // We expect one mutation (the removal) to have happened.
     if (guard.Mutated(1)) {
       // XBL destructors, yuck.
 
       // Verify that nodeToInsertBefore, if non-null, is still our child.  If
@@ -2072,17 +2070,17 @@ nsINode::ReplaceOrInsertBefore(bool aRep
             !IsAllowedAsChild(newContent, this, aReplace, aRefChild)) {
           aError.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
           return nullptr;
         }
         // And recompute nodeToInsertBefore, just in case.
         if (aReplace) {
           nodeToInsertBefore = aRefChild->GetNextSibling();
         } else {
-          nodeToInsertBefore = aRefChild;
+          nodeToInsertBefore = aRefChild ? aRefChild->AsContent() : nullptr;
         }
       }
     }
   } else if (nodeType == DOCUMENT_FRAGMENT_NODE) {
     // Make sure to remove all the fragment's kids.  We need to do this before
     // we start inserting anything, so we will run out XBL destructors and
     // binding teardown (GOD, I HATE THESE THINGS) before we insert anything
     // into the DOM.
@@ -2107,18 +2105,18 @@ nsINode::ReplaceOrInsertBefore(bool aRep
     nsMutationGuard guard;
 
     // Scope for the mutation batch and scriptblocker, so they go away
     // while kungFuDeathGrip is still alive.
     {
       mozAutoDocUpdate batch(newContent->GetComposedDoc(), true);
       nsAutoMutationBatch mb(newContent, false, true);
 
-      for (uint32_t i = count; i > 0;) {
-        newContent->RemoveChildAt_Deprecated(--i, true);
+      while (newContent->HasChildren()) {
+        newContent->RemoveChildNode(newContent->GetLastChild(), true);
       }
     }
 
     // We expect |count| removals
     if (guard.Mutated(count)) {
       // XBL destructors, yuck.
 
       // Verify that nodeToInsertBefore, if non-null, is still our child.  If
@@ -2146,17 +2144,18 @@ nsINode::ReplaceOrInsertBefore(bool aRep
         aError.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
         return nullptr;
       }
 
       // Recompute nodeToInsertBefore, just in case.
       if (aReplace) {
         nodeToInsertBefore = aRefChild->GetNextSibling();
       } else {
-        nodeToInsertBefore = aRefChild;
+        // If aRefChild has 'this' as a parent, it must be an nsIContent.
+        nodeToInsertBefore = aRefChild ? aRefChild->AsContent() : nullptr;
       }
 
       // And verify that newContent is still allowed as our child.  Sadly, we
       // need to reimplement the relevant part of IsAllowedAsChild() because
       // now our nodes are in an array and all.  If you change this code,
       // change the code there.
       if (IsDocument()) {
         bool sawElement = false;
@@ -2177,47 +2176,30 @@ nsINode::ReplaceOrInsertBefore(bool aRep
         }
       }
     }
   }
 
   mozAutoDocUpdate batch(GetComposedDoc(), true);
   nsAutoMutationBatch mb;
 
-  // Figure out which index we want to insert at.  Note that we use
-  // nodeToInsertBefore to determine this, because it's possible that
-  // aRefChild == aNewChild, in which case we just removed it from the
-  // parent list.
-  int32_t insPos;
-  if (nodeToInsertBefore) {
-    insPos = ComputeIndexOf(nodeToInsertBefore);
-    if (insPos < 0) {
-      // XXXbz How the heck would _that_ happen, exactly?
-      aError.Throw(NS_ERROR_DOM_NOT_FOUND_ERR);
-      return nullptr;
-    }
-  }
-  else {
-    insPos = GetChildCount();
-  }
-
   // If we're replacing and we haven't removed aRefChild yet, do so now
   if (aReplace && aRefChild != aNewChild) {
     mb.Init(this, true, true);
 
     // Since aRefChild is never null in the aReplace case, we know that at
     // this point nodeToInsertBefore is the next sibling of aRefChild.
     NS_ASSERTION(aRefChild->GetNextSibling() == nodeToInsertBefore,
                  "Unexpected nodeToInsertBefore");
 
-    // An since nodeToInsertBefore is at index insPos, we want to remove
-    // at the previous index.
-    NS_ASSERTION(insPos >= 1, "insPos too small");
-    RemoveChildAt_Deprecated(insPos-1, true);
-    --insPos;
+    nsIContent* toBeRemoved = nodeToInsertBefore ?
+      nodeToInsertBefore->GetPreviousSibling() : GetLastChild();
+    MOZ_ASSERT(toBeRemoved);
+
+    RemoveChildNode(toBeRemoved, true);
   }
 
   // Move new child over to our document if needed. Do this after removing
   // it from its parent so that AdoptNode doesn't fire DOMNodeRemoved
   // DocumentType nodes are the only nodes that can have a null
   // ownerDocument according to the DOM spec, and we need to allow
   // inserting them w/o calling AdoptNode().
   nsIDocument* doc = OwnerDoc();
@@ -2241,35 +2223,36 @@ nsINode::ReplaceOrInsertBefore(bool aRep
   nsINode* result = aReplace ? aRefChild : aNewChild;
   if (nodeType == DOCUMENT_FRAGMENT_NODE) {
     if (!aReplace) {
       mb.Init(this, true, true);
     }
     nsAutoMutationBatch* mutationBatch = nsAutoMutationBatch::GetCurrentBatch();
     if (mutationBatch) {
       mutationBatch->RemovalDone();
-      mutationBatch->SetPrevSibling(GetChildAt_Deprecated(insPos - 1));
-      mutationBatch->SetNextSibling(GetChildAt_Deprecated(insPos));
+      mutationBatch->SetPrevSibling(nodeToInsertBefore ?
+        nodeToInsertBefore->GetPreviousSibling() : GetLastChild());
+      mutationBatch->SetNextSibling(nodeToInsertBefore);
     }
 
     uint32_t count = fragChildren->Length();
     if (!count) {
       return result;
     }
 
-    bool appending = !IsDocument() && uint32_t(insPos) == GetChildCount();
+    bool appending = !IsDocument() && !nodeToInsertBefore;
     nsIContent* firstInsertedContent = fragChildren->ElementAt(0);
 
     // Iterate through the fragment's children, and insert them in the new
     // parent
-    for (uint32_t i = 0; i < count; ++i, ++insPos) {
+    for (uint32_t i = 0; i < count; ++i) {
       // XXXbz how come no reparenting here?  That seems odd...
       // Insert the child.
-      aError = InsertChildAt_Deprecated(fragChildren->ElementAt(i), insPos,
-                                        !appending);
+      aError = InsertChildBefore(fragChildren->ElementAt(i), nodeToInsertBefore,
+                                 !appending);
       if (aError.Failed()) {
         // Make sure to notify on any children that we did succeed to insert
         if (appending && i != 0) {
           nsNodeUtils::ContentAppended(static_cast<nsIContent*>(this),
                                        firstInsertedContent);
         }
         return nullptr;
       }
@@ -2295,23 +2278,23 @@ nsINode::ReplaceOrInsertBefore(bool aRep
   }
   else {
     // Not inserting a fragment but rather a single node.
 
     // FIXME https://bugzilla.mozilla.org/show_bug.cgi?id=544654
     //       We need to reparent here for nodes for which the parent of their
     //       wrapper is not the wrapper for their ownerDocument (XUL elements,
     //       form controls, ...). Also applies in the fragment code above.
-
     if (nsAutoMutationBatch::GetCurrentBatch() == &mb) {
       mb.RemovalDone();
-      mb.SetPrevSibling(GetChildAt_Deprecated(insPos - 1));
-      mb.SetNextSibling(GetChildAt_Deprecated(insPos));
+      mb.SetPrevSibling(nodeToInsertBefore ?
+                        nodeToInsertBefore->GetPreviousSibling() : GetLastChild());
+      mb.SetNextSibling(nodeToInsertBefore);
     }
-    aError = InsertChildAt_Deprecated(newContent, insPos, true);
+    aError = InsertChildBefore(newContent, nodeToInsertBefore, true);
     if (aError.Failed()) {
       return nullptr;
     }
   }
 
   return result;
 }
 
--- a/dom/base/nsINode.h
+++ b/dom/base/nsINode.h
@@ -817,39 +817,16 @@ public:
    * child of |this|.
    *
    * @throws NS_ERROR_OUT_OF_MEMORY in some cases (from BindToTree).
    */
   virtual nsresult InsertChildBefore(nsIContent* aKid, nsIContent* aBeforeThis,
                                      bool aNotify) = 0;
 
   /**
-   * Insert a content node at a particular index.  This method handles calling
-   * BindToTree on the child appropriately.
-   *
-   * @param aKid the content to insert
-   * @param aIndex the index it is being inserted at (the index it will have
-   *        after it is inserted)
-   * @param aNotify whether to notify the document (current document for
-   *        nsIContent, and |this| for nsIDocument) that the insert has
-   *        occurred
-   *
-   * @throws NS_ERROR_DOM_HIERARCHY_REQUEST_ERR if one attempts to have more
-   * than one element node as a child of a document.  Doing this will also
-   * assert -- you shouldn't be doing it!  Check with
-   * nsIDocument::GetRootElement() first if you're not sure.  Apart from this
-   * one constraint, this doesn't do any checking on whether aKid is a valid
-   * child of |this|.
-   *
-   * @throws NS_ERROR_OUT_OF_MEMORY in some cases (from BindToTree).
-   */
-  virtual nsresult InsertChildAt_Deprecated(nsIContent* aKid, uint32_t aIndex,
-                                            bool aNotify) = 0;
-
-  /**
    * Append a content node to the end of the child list.  This method handles
    * calling BindToTree on the child appropriately.
    *
    * @param aKid the content to append
    * @param aNotify whether to notify the document (current document for
    *        nsIContent, and |this| for nsIDocument) that the append has
    *        occurred
    *
@@ -859,36 +836,20 @@ public:
    * nsIDocument::GetRootElement() first if you're not sure.  Apart from this
    * one constraint, this doesn't do any checking on whether aKid is a valid
    * child of |this|.
    *
    * @throws NS_ERROR_OUT_OF_MEMORY in some cases (from BindToTree).
    */
   nsresult AppendChildTo(nsIContent* aKid, bool aNotify)
   {
-    return InsertChildAt_Deprecated(aKid, GetChildCount(), aNotify);
+    return InsertChildBefore(aKid, nullptr, aNotify);
   }
 
   /**
-   * NOTE: this function is going to be removed soon (hopefully!) Don't use it
-   * in new code.
-   *
-   * Remove a child from this node.  This method handles calling UnbindFromTree
-   * on the child appropriately.
-   *
-   * @param aIndex the index of the child to remove
-   * @param aNotify whether to notify the document (current document for
-   *        nsIContent, and |this| for nsIDocument) that the remove has
-   *        occurred
-   *
-   * Note: If there is no child at aIndex, this method will simply do nothing.
-   */
-  virtual void RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify) = 0;
-
-  /**
    * Remove a child from this node.  This method handles calling UnbindFromTree
    * on the child appropriately.
    *
    * @param aKid the content to remove
    * @param aNotify whether to notify the document (current document for
    *        nsIContent, and |this| for nsIDocument) that the remove has
    *        occurred
    */
--- a/dom/html/HTMLFieldSetElement.cpp
+++ b/dom/html/HTMLFieldSetElement.cpp
@@ -166,74 +166,16 @@ HTMLFieldSetElement::InsertChildBefore(n
 
   if (firstLegendHasChanged) {
     NotifyElementsForFirstLegendChange(aNotify);
   }
 
   return rv;
 }
 
-nsresult
-HTMLFieldSetElement::InsertChildAt_Deprecated(nsIContent* aChild,
-                                              uint32_t aIndex,
-                                              bool aNotify)
-{
-  bool firstLegendHasChanged = false;
-
-  if (aChild->IsHTMLElement(nsGkAtoms::legend)) {
-    if (!mFirstLegend) {
-      mFirstLegend = aChild;
-      // We do not want to notify the first time mFirstElement is set.
-    } else {
-      // If mFirstLegend is before aIndex, we do not change it.
-      // Otherwise, mFirstLegend is now aChild.
-      if (int32_t(aIndex) <= ComputeIndexOf(mFirstLegend)) {
-        mFirstLegend = aChild;
-        firstLegendHasChanged = true;
-      }
-    }
-  }
-
-  nsresult rv =
-    nsGenericHTMLFormElement::InsertChildAt_Deprecated(aChild, aIndex, aNotify);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (firstLegendHasChanged) {
-    NotifyElementsForFirstLegendChange(aNotify);
-  }
-
-  return rv;
-}
-
-void
-HTMLFieldSetElement::RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify)
-{
-  bool firstLegendHasChanged = false;
-
-  if (mFirstLegend && (GetChildAt_Deprecated(aIndex) == mFirstLegend)) {
-    // If we are removing the first legend we have to found another one.
-    nsIContent* child = mFirstLegend->GetNextSibling();
-    mFirstLegend = nullptr;
-    firstLegendHasChanged = true;
-
-    for (; child; child = child->GetNextSibling()) {
-      if (child->IsHTMLElement(nsGkAtoms::legend)) {
-        mFirstLegend = child;
-        break;
-      }
-    }
-  }
-
-  nsGenericHTMLFormElement::RemoveChildAt_Deprecated(aIndex, aNotify);
-
-  if (firstLegendHasChanged) {
-    NotifyElementsForFirstLegendChange(aNotify);
-  }
-}
-
 void
 HTMLFieldSetElement::RemoveChildNode(nsIContent* aKid, bool aNotify)
 {
   bool firstLegendHasChanged = false;
 
   if (mFirstLegend && aKid == mFirstLegend) {
     // If we are removing the first legend we have to found another one.
     nsIContent* child = mFirstLegend->GetNextSibling();
--- a/dom/html/HTMLFieldSetElement.h
+++ b/dom/html/HTMLFieldSetElement.h
@@ -37,19 +37,16 @@ public:
   virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
                                 const nsAttrValue* aValue,
                                 const nsAttrValue* aOldValue,
                                 nsIPrincipal* aSubjectPrincipal,
                                 bool aNotify) override;
 
   virtual nsresult InsertChildBefore(nsIContent* aChild, nsIContent* aBeforeThis,
                                      bool aNotify) override;
-  virtual nsresult InsertChildAt_Deprecated(nsIContent* aChild, uint32_t aIndex,
-                                            bool aNotify) override;
-  virtual void RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify) override;
   virtual void RemoveChildNode(nsIContent* aKid, bool aNotify) override;
 
   // nsIFormControl
   NS_IMETHOD Reset() override;
   NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;
   virtual bool IsDisabledForEvents(EventMessage aMessage) override;
   virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
                          bool aPreallocateChildren) const override;
--- a/dom/html/HTMLOptGroupElement.cpp
+++ b/dom/html/HTMLOptGroupElement.cpp
@@ -81,38 +81,16 @@ HTMLOptGroupElement::InsertChildBefore(n
   nsresult rv =
     nsGenericHTMLElement::InsertChildBefore(aKid, aBeforeThis, aNotify);
   if (NS_FAILED(rv)) {
     safeMutation.MutationFailed();
   }
   return rv;
 }
 
-nsresult
-HTMLOptGroupElement::InsertChildAt_Deprecated(nsIContent* aKid,
-                                              uint32_t aIndex,
-                                              bool aNotify)
-{
-  SafeOptionListMutation safeMutation(GetSelect(), this, aKid, aIndex, aNotify);
-  nsresult rv = nsGenericHTMLElement::InsertChildAt_Deprecated(aKid, aIndex,
-                                                               aNotify);
-  if (NS_FAILED(rv)) {
-    safeMutation.MutationFailed();
-  }
-  return rv;
-}
-
-void
-HTMLOptGroupElement::RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify)
-{
-  SafeOptionListMutation safeMutation(GetSelect(), this, nullptr, aIndex,
-                                      aNotify);
-  nsGenericHTMLElement::RemoveChildAt_Deprecated(aIndex, aNotify);
-}
-
 void
 HTMLOptGroupElement::RemoveChildNode(nsIContent* aKid, bool aNotify)
 {
   SafeOptionListMutation safeMutation(GetSelect(), this, nullptr,
                                       ComputeIndexOf(aKid), aNotify);
   nsGenericHTMLElement::RemoveChildNode(aKid, aNotify);
 }
 
--- a/dom/html/HTMLOptGroupElement.h
+++ b/dom/html/HTMLOptGroupElement.h
@@ -23,19 +23,16 @@ public:
 
   // nsISupports
   NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLOptGroupElement,
                                        nsGenericHTMLElement)
 
   // nsINode
   virtual nsresult InsertChildBefore(nsIContent* aKid, nsIContent* aBeforeThis,
                                      bool aNotify) override;
-  virtual nsresult InsertChildAt_Deprecated(nsIContent* aKid, uint32_t aIndex,
-                                            bool aNotify) override;
-  virtual void RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify) override;
   virtual void RemoveChildNode(nsIContent* aKid, bool aNotify) override;
 
   // nsIContent
   void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
 
   virtual nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo, nsINode** aResult,
                          bool aPreallocateChildren) const override;
 
--- a/dom/html/HTMLPictureElement.cpp
+++ b/dom/html/HTMLPictureElement.cpp
@@ -26,42 +26,16 @@ HTMLPictureElement::HTMLPictureElement(a
 
 HTMLPictureElement::~HTMLPictureElement()
 {
 }
 
 NS_IMPL_ELEMENT_CLONE(HTMLPictureElement)
 
 void
-HTMLPictureElement::RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify)
-{
-  nsCOMPtr<nsIContent> child = GetChildAt_Deprecated(aIndex);
-
-  if (child && child->IsHTMLElement(nsGkAtoms::img)) {
-    HTMLImageElement* img = HTMLImageElement::FromNode(child);
-    if (img) {
-      img->PictureSourceRemoved(child->AsContent());
-    }
-  } else if (child && child->IsHTMLElement(nsGkAtoms::source)) {
-    // Find all img siblings after this <source> to notify them of its demise
-    nsCOMPtr<nsIContent> nextSibling = child->GetNextSibling();
-    if (nextSibling && nextSibling->GetParentNode() == this) {
-      do {
-        HTMLImageElement* img = HTMLImageElement::FromNode(nextSibling);
-        if (img) {
-          img->PictureSourceRemoved(child->AsContent());
-        }
-      } while ( (nextSibling = nextSibling->GetNextSibling()) );
-    }
-  }
-
-  nsGenericHTMLElement::RemoveChildAt_Deprecated(aIndex, aNotify);
-}
-
-void
 HTMLPictureElement::RemoveChildNode(nsIContent* aKid, bool aNotify)
 {
   if (aKid && aKid->IsHTMLElement(nsGkAtoms::img)) {
     HTMLImageElement* img = HTMLImageElement::FromNode(aKid);
     if (img) {
       img->PictureSourceRemoved(aKid->AsContent());
     }
   } else if (aKid && aKid->IsHTMLElement(nsGkAtoms::source)) {
@@ -106,45 +80,16 @@ HTMLPictureElement::InsertChildBefore(ns
         }
       } while ( (nextSibling = nextSibling->GetNextSibling()) );
     }
   }
 
   return rv;
 }
 
-nsresult
-HTMLPictureElement::InsertChildAt_Deprecated(nsIContent* aKid, uint32_t aIndex, bool aNotify)
-{
-  nsresult rv = nsGenericHTMLElement::InsertChildAt_Deprecated(aKid, aIndex, aNotify);
-
-  NS_ENSURE_SUCCESS(rv, rv);
-  NS_ENSURE_TRUE(aKid, rv);
-
-  if (aKid->IsHTMLElement(nsGkAtoms::img)) {
-    HTMLImageElement* img = HTMLImageElement::FromNode(aKid);
-    if (img) {
-      img->PictureSourceAdded(aKid->AsContent());
-    }
-  } else if (aKid->IsHTMLElement(nsGkAtoms::source)) {
-    // Find all img siblings after this <source> to notify them of its insertion
-    nsCOMPtr<nsIContent> nextSibling = aKid->GetNextSibling();
-    if (nextSibling && nextSibling->GetParentNode() == this) {
-      do {
-        HTMLImageElement* img = HTMLImageElement::FromNode(nextSibling);
-        if (img) {
-          img->PictureSourceAdded(aKid->AsContent());
-        }
-      } while ( (nextSibling = nextSibling->GetNextSibling()) );
-    }
-  }
-
-  return rv;
-}
-
 JSObject*
 HTMLPictureElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return HTMLPictureElementBinding::Wrap(aCx, this, aGivenProto);
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/html/HTMLPictureElement.h
+++ b/dom/html/HTMLPictureElement.h
@@ -18,22 +18,19 @@ class HTMLPictureElement final : public 
 public:
   explicit HTMLPictureElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
 
   // nsISupports
   NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLPictureElement, nsGenericHTMLElement)
 
   virtual nsresult Clone(mozilla::dom::NodeInfo* aNodeInfo, nsINode** aResult,
                          bool aPreallocateChildren) const override;
-  virtual void RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify) override;
   virtual void RemoveChildNode(nsIContent* aKid, bool aNotify) override;
   virtual nsresult InsertChildBefore(nsIContent* aKid, nsIContent* aBeforeThis,
                                      bool aNotify) override;
-  virtual nsresult InsertChildAt_Deprecated(nsIContent* aKid, uint32_t aIndex,
-                                            bool aNotify) override;
 
 protected:
   virtual ~HTMLPictureElement();
 
   virtual JSObject* WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
 };
 
 } // namespace dom
--- a/dom/html/HTMLSelectElement.cpp
+++ b/dom/html/HTMLSelectElement.cpp
@@ -212,38 +212,16 @@ HTMLSelectElement::InsertChildBefore(nsI
     nsGenericHTMLFormElementWithState::InsertChildBefore(aKid, aBeforeThis,
                                                          aNotify);
   if (NS_FAILED(rv)) {
     safeMutation.MutationFailed();
   }
   return rv;
 }
 
-nsresult
-HTMLSelectElement::InsertChildAt_Deprecated(nsIContent* aKid,
-                                            uint32_t aIndex,
-                                            bool aNotify)
-{
-  SafeOptionListMutation safeMutation(this, this, aKid, aIndex, aNotify);
-  nsresult rv =
-    nsGenericHTMLFormElementWithState::InsertChildAt_Deprecated(aKid, aIndex,
-                                                                aNotify);
-  if (NS_FAILED(rv)) {
-    safeMutation.MutationFailed();
-  }
-  return rv;
-}
-
-void
-HTMLSelectElement::RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify)
-{
-  SafeOptionListMutation safeMutation(this, this, nullptr, aIndex, aNotify);
-  nsGenericHTMLFormElementWithState::RemoveChildAt_Deprecated(aIndex, aNotify);
-}
-
 void
 HTMLSelectElement::RemoveChildNode(nsIContent* aKid, bool aNotify)
 {
   SafeOptionListMutation safeMutation(this, this, nullptr,
                                       ComputeIndexOf(aKid), aNotify);
   nsGenericHTMLFormElementWithState::RemoveChildNode(aKid, aNotify);
 }
 
--- a/dom/html/HTMLSelectElement.h
+++ b/dom/html/HTMLSelectElement.h
@@ -242,19 +242,16 @@ public:
   // nsIContent
   void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
   virtual nsresult PostHandleEvent(
                      EventChainPostVisitor& aVisitor) override;
 
   virtual bool IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable, int32_t* aTabIndex) override;
   virtual nsresult InsertChildBefore(nsIContent* aKid, nsIContent* aBeforeThis,
                                      bool aNotify) override;
-  virtual nsresult InsertChildAt_Deprecated(nsIContent* aKid, uint32_t aIndex,
-                                            bool aNotify) override;
-  virtual void RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify) override;
   virtual void RemoveChildNode(nsIContent* aKid, bool aNotify) override;
 
   // Overriden nsIFormControl methods
   NS_IMETHOD Reset() override;
   NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;
   NS_IMETHOD SaveState() override;
   virtual bool RestoreState(PresState* aState) override;
   virtual bool IsDisabledForEvents(EventMessage aMessage) override;
--- a/dom/svg/SVGDocument.cpp
+++ b/dom/svg/SVGDocument.cpp
@@ -46,33 +46,16 @@ SVGDocument::InsertChildBefore(nsIConten
     // loaded by then.
     EnsureNonSVGUserAgentStyleSheetsLoaded();
   }
 
   return XMLDocument::InsertChildBefore(aKid, aBeforeThis, aNotify);
 }
 
 nsresult
-SVGDocument::InsertChildAt_Deprecated(nsIContent* aKid, uint32_t aIndex,
-                                      bool aNotify)
-{
-  if (aKid->IsElement() && !aKid->IsSVGElement()) {
-    // We can get here when well formed XML with a non-SVG root element is
-    // served with the SVG MIME type, for example. In that case we need to load
-    // the non-SVG UA sheets or else we can get bugs like bug 1016145.  Note
-    // that we have to do this _before_ the
-    // XMLDocument::InsertChildAt_Deprecated call, since that can try to
-    // construct frames, and we need to have the sheets loaded by then.
-    EnsureNonSVGUserAgentStyleSheetsLoaded();
-  }
-
-  return XMLDocument::InsertChildAt_Deprecated(aKid, aIndex, aNotify);
-}
-
-nsresult
 SVGDocument::Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
                    bool aPreallocateChildren) const
 {
   NS_ASSERTION(aNodeInfo->NodeInfoManager() == mNodeInfoManager,
                "Can't import this document into another document!");
 
   RefPtr<SVGDocument> clone = new SVGDocument();
   nsresult rv = CloneDocHelper(clone.get(), aPreallocateChildren);
--- a/dom/svg/SVGDocument.h
+++ b/dom/svg/SVGDocument.h
@@ -30,18 +30,16 @@ public:
     : XMLDocument("image/svg+xml")
     , mHasLoadedNonSVGUserAgentStyleSheets(false)
   {
     mType = eSVG;
   }
 
   virtual nsresult InsertChildBefore(nsIContent* aKid, nsIContent* aBeforeThis,
                                      bool aNotify) override;
-  virtual nsresult InsertChildAt_Deprecated(nsIContent* aKid, uint32_t aIndex,
-                                            bool aNotify) override;
   virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
                          bool aPreallocateChildren) const override;
 
   void SetCurrentContextPaint(const SVGContextPaint* aContextPaint)
   {
     mCurrentContextPaint = aContextPaint;
   }
 
--- a/dom/svg/SVGSwitchElement.cpp
+++ b/dom/svg/SVGSwitchElement.cpp
@@ -88,36 +88,16 @@ SVGSwitchElement::InsertChildBefore(nsIC
   nsresult rv =
     SVGSwitchElementBase::InsertChildBefore(aKid, aBeforeThis, aNotify);
   if (NS_SUCCEEDED(rv)) {
     MaybeInvalidate();
   }
   return rv;
 }
 
-nsresult
-SVGSwitchElement::InsertChildAt_Deprecated(nsIContent* aKid,
-                                           uint32_t aIndex,
-                                           bool aNotify)
-{
-  nsresult rv = SVGSwitchElementBase::InsertChildAt_Deprecated(aKid, aIndex,
-                                                               aNotify);
-  if (NS_SUCCEEDED(rv)) {
-    MaybeInvalidate();
-  }
-  return rv;
-}
-
-void
-SVGSwitchElement::RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify)
-{
-  SVGSwitchElementBase::RemoveChildAt_Deprecated(aIndex, aNotify);
-  MaybeInvalidate();
-}
-
 void
 SVGSwitchElement::RemoveChildNode(nsIContent* aKid, bool aNotify)
 {
   SVGSwitchElementBase::RemoveChildNode(aKid, aNotify);
   MaybeInvalidate();
 }
 
 //----------------------------------------------------------------------
--- a/dom/svg/SVGSwitchElement.h
+++ b/dom/svg/SVGSwitchElement.h
@@ -37,19 +37,16 @@ public:
   // interfaces:
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SVGSwitchElement,
                                            SVGSwitchElementBase)
   // nsINode
   virtual nsresult InsertChildBefore(nsIContent* aKid, nsIContent* aBeforeThis,
                                      bool aNotify) override;
-  virtual nsresult InsertChildAt_Deprecated(nsIContent* aKid, uint32_t aIndex,
-                                            bool aNotify) override;
-  virtual void RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify) override;
   virtual void RemoveChildNode(nsIContent* aKid, bool aNotify) override;
 
   // nsIContent
   NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
 
   virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
                          bool aPreallocateChildren) const override;
 private:
--- a/dom/xul/nsXULElement.cpp
+++ b/dom/xul/nsXULElement.cpp
@@ -823,113 +823,16 @@ nsXULElement::UnbindFromTree(bool aDeep,
         }
         slots->mFrameLoaderOrOpener = nullptr;
     }
 
     nsStyledElement::UnbindFromTree(aDeep, aNullParent);
 }
 
 void
-nsXULElement::RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify)
-{
-    nsCOMPtr<nsIContent> oldKid = mAttrsAndChildren.GetSafeChildAt(aIndex);
-    if (!oldKid) {
-      return;
-    }
-
-    // On the removal of a <treeitem>, <treechildren>, or <treecell> element,
-    // the possibility exists that some of the items in the removed subtree
-    // are selected (and therefore need to be deselected). We need to account for this.
-    nsCOMPtr<nsIDOMXULMultiSelectControlElement> controlElement;
-    nsCOMPtr<nsIListBoxObject> listBox;
-    bool fireSelectionHandler = false;
-
-    // -1 = do nothing, -2 = null out current item
-    // anything else = index to re-set as current
-    int32_t newCurrentIndex = -1;
-
-    if (oldKid->NodeInfo()->Equals(nsGkAtoms::listitem, kNameSpaceID_XUL)) {
-      // This is the nasty case. We have (potentially) a slew of selected items
-      // and cells going away.
-      // First, retrieve the tree.
-      // Check first whether this element IS the tree
-      controlElement = do_QueryObject(this);
-
-      // If it's not, look at our parent
-      if (!controlElement)
-        GetParentTree(getter_AddRefs(controlElement));
-      nsCOMPtr<nsIContent> controlContent(do_QueryInterface(controlElement));
-      RefPtr<nsXULElement> xulElement = FromNodeOrNull(controlContent);
-
-      if (xulElement) {
-        // Iterate over all of the items and find out if they are contained inside
-        // the removed subtree.
-        int32_t length;
-        controlElement->GetSelectedCount(&length);
-        for (int32_t i = 0; i < length; i++) {
-          nsCOMPtr<nsIDOMXULSelectControlItemElement> item;
-          controlElement->MultiGetSelectedItem(i, getter_AddRefs(item));
-          nsCOMPtr<nsINode> node = do_QueryInterface(item);
-          if (node == oldKid &&
-              NS_SUCCEEDED(controlElement->RemoveItemFromSelection(item))) {
-            length--;
-            i--;
-            fireSelectionHandler = true;
-          }
-        }
-
-        nsCOMPtr<nsIDOMXULSelectControlItemElement> curItem;
-        controlElement->GetCurrentItem(getter_AddRefs(curItem));
-        nsCOMPtr<nsIContent> curNode = do_QueryInterface(curItem);
-        if (curNode && nsContentUtils::ContentIsDescendantOf(curNode, oldKid)) {
-            // Current item going away
-            nsCOMPtr<nsIBoxObject> box = xulElement->GetBoxObject(IgnoreErrors());
-            listBox = do_QueryInterface(box);
-            if (listBox) {
-              listBox->GetIndexOfItem(oldKid->AsElement(), &newCurrentIndex);
-            }
-
-            // If any of this fails, we'll just set the current item to null
-            if (newCurrentIndex == -1)
-              newCurrentIndex = -2;
-        }
-      }
-    }
-
-    nsStyledElement::RemoveChildAt_Deprecated(aIndex, aNotify);
-
-    if (newCurrentIndex == -2) {
-        controlElement->SetCurrentItem(nullptr);
-    } else if (newCurrentIndex > -1) {
-        // Make sure the index is still valid
-        int32_t treeRows;
-        listBox->GetRowCount(&treeRows);
-        if (treeRows > 0) {
-            newCurrentIndex = std::min((treeRows - 1), newCurrentIndex);
-            RefPtr<Element> newCurrentItem;
-            listBox->GetItemAtIndex(newCurrentIndex, getter_AddRefs(newCurrentItem));
-            nsCOMPtr<nsIDOMXULSelectControlItemElement> xulCurItem = do_QueryInterface(newCurrentItem);
-            if (xulCurItem)
-                controlElement->SetCurrentItem(xulCurItem);
-        } else {
-            controlElement->SetCurrentItem(nullptr);
-        }
-    }
-
-    nsIDocument* doc;
-    if (fireSelectionHandler && (doc = GetComposedDoc())) {
-      nsContentUtils::DispatchTrustedEvent(doc,
-                                           static_cast<nsIContent*>(this),
-                                           NS_LITERAL_STRING("select"),
-                                           false,
-                                           true);
-    }
-}
-
-void
 nsXULElement::RemoveChildNode(nsIContent* aKid, bool aNotify)
 {
     // On the removal of a <treeitem>, <treechildren>, or <treecell> element,
     // the possibility exists that some of the items in the removed subtree
     // are selected (and therefore need to be deselected). We need to account for this.
     nsCOMPtr<nsIDOMXULMultiSelectControlElement> controlElement;
     nsCOMPtr<nsIListBoxObject> listBox;
     bool fireSelectionHandler = false;
--- a/dom/xul/nsXULElement.h
+++ b/dom/xul/nsXULElement.h
@@ -363,17 +363,16 @@ public:
     void GetEventTargetParent(mozilla::EventChainPreVisitor& aVisitor) override;
     virtual nsresult PreHandleEvent(
                        mozilla::EventChainVisitor& aVisitor) override;
     // nsIContent
     virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
                                 nsIContent* aBindingParent,
                                 bool aCompileEventHandlers) override;
     virtual void UnbindFromTree(bool aDeep, bool aNullParent) override;
-    virtual void RemoveChildAt_Deprecated(uint32_t aIndex, bool aNotify) override;
     virtual void RemoveChildNode(nsIContent* aKid, bool aNotify) override;
     virtual void DestroyContent() override;
 
 #ifdef DEBUG
     virtual void List(FILE* out, int32_t aIndent) const override;
     virtual void DumpContent(FILE* out, int32_t aIndent,bool aDumpAll) const override
     {
     }