Bug 1454233: Remove nsINode::eDOCUMENT. r=bz
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sun, 15 Apr 2018 11:43:15 +0200
changeset 414714 faf615fcb4c11e8d4efe4c3eade10d308b0c74e1
parent 414713 44d8f7cb36e3ae473d0b958edf305947b9014e22
child 414715 67ddc6418466b2033a12029533d3abd19123ce2f
push id33876
push userdluca@mozilla.com
push dateFri, 20 Apr 2018 23:00:46 +0000
treeherdermozilla-central@39ccabfd7d07 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1454233
milestone61.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 1454233: Remove nsINode::eDOCUMENT. r=bz MozReview-Commit-ID: ItjdI79zme7
accessible/base/Logging.cpp
accessible/base/nsAccessibilityService.cpp
accessible/windows/sdn/sdnAccessible.cpp
dom/base/nsContentList.cpp
dom/base/nsContentUtils.cpp
dom/base/nsDocument.cpp
dom/base/nsINode.cpp
dom/base/nsINode.h
dom/base/nsNodeUtils.cpp
dom/base/nsRange.cpp
dom/base/nsXMLContentSerializer.cpp
dom/events/IMEContentObserver.cpp
dom/xslt/xslt/txMozillaStylesheetCompiler.cpp
dom/xslt/xslt/txMozillaXSLTProcessor.cpp
editor/libeditor/EditorEventListener.cpp
editor/libeditor/HTMLEditor.cpp
layout/inspector/InspectorUtils.cpp
layout/printing/nsPrintJob.cpp
layout/style/ServoStyleSet.cpp
--- a/accessible/base/Logging.cpp
+++ b/accessible/base/Logging.cpp
@@ -824,17 +824,17 @@ logging::Node(const char* aDescr, nsINod
 {
   printf("    ");
 
   if (!aNode) {
     printf("%s: null\n", aDescr);
     return;
   }
 
-  if (aNode->IsNodeOfType(nsINode::eDOCUMENT)) {
+  if (aNode->IsDocument()) {
     printf("%s: %p, document\n", aDescr, static_cast<void*>(aNode));
     return;
   }
 
   nsINode* parentNode = aNode->GetParentNode();
   int32_t idxInParent = parentNode ? parentNode->ComputeIndexOf(aNode) : - 1;
 
   if (aNode->IsText()) {
@@ -903,17 +903,17 @@ logging::AccessibleInfo(const char* aDes
   }
 
   printf(", idx: %d", aAccessible->IndexInParent());
 
   nsINode* node = aAccessible->GetNode();
   if (!node) {
     printf(", node: null\n");
   }
-  else if (node->IsNodeOfType(nsINode::eDOCUMENT)) {
+  else if (node->IsDocument()) {
     printf(", document node: %p\n", static_cast<void*>(node));
   }
   else if (node->IsText()) {
     printf(", text node: %p\n", static_cast<void*>(node));
   }
   else if (node->IsElement()) {
     dom::Element* el = node->AsElement();
 
--- a/accessible/base/nsAccessibilityService.cpp
+++ b/accessible/base/nsAccessibilityService.cpp
@@ -1039,21 +1039,20 @@ nsAccessibilityService::CreateAccessible
 
   if (aIsSubtreeHidden)
     *aIsSubtreeHidden = false;
 
   DocAccessible* document = aContext->Document();
   MOZ_ASSERT(!document->GetAccessible(aNode),
              "We already have an accessible for this node.");
 
-  if (aNode->IsNodeOfType(nsINode::eDOCUMENT)) {
+  if (aNode->IsDocument()) {
     // If it's document node then ask accessible document loader for
     // document accessible, otherwise return null.
-    nsCOMPtr<nsIDocument> document(do_QueryInterface(aNode));
-    return GetDocAccessible(document);
+    return GetDocAccessible(aNode->AsDocument());
   }
 
   // We have a content node.
   if (!aNode->GetComposedDoc()) {
     NS_WARNING("Creating accessible for node with no document");
     return nullptr;
   }
 
--- a/accessible/windows/sdn/sdnAccessible.cpp
+++ b/accessible/windows/sdn/sdnAccessible.cpp
@@ -218,17 +218,17 @@ sdnAccessible::get_computedStyle(unsigne
   if (!aStyleProperties || aStyleValues || !aNumStyleProperties)
     return E_INVALIDARG;
 
   if (IsDefunct())
     return CO_E_OBJNOTCONNECTED;
 
   *aNumStyleProperties = 0;
 
-  if (mNode->IsNodeOfType(nsINode::eDOCUMENT))
+  if (mNode->IsDocument())
     return S_FALSE;
 
   nsCOMPtr<nsICSSDeclaration> cssDecl =
     nsWinUtils::GetComputedStyleDeclaration(mNode->AsContent());
   NS_ENSURE_TRUE(cssDecl, E_FAIL);
 
   uint32_t length = cssDecl->Length();
 
@@ -261,17 +261,17 @@ sdnAccessible::get_computedStyleForPrope
                                               BSTR __RPC_FAR* aStyleValues)
 {
   if (!aStyleProperties || !aStyleValues)
     return E_INVALIDARG;
 
   if (IsDefunct())
     return CO_E_OBJNOTCONNECTED;
 
-  if (mNode->IsNodeOfType(nsINode::eDOCUMENT))
+  if (mNode->IsDocument())
     return S_FALSE;
 
   nsCOMPtr<nsICSSDeclaration> cssDecl =
     nsWinUtils::GetComputedStyleDeclaration(mNode->AsContent());
   NS_ENSURE_TRUE(cssDecl, E_FAIL);
 
   uint32_t index = 0;
   for (index = 0; index < aNumStyleProperties; index++) {
--- a/dom/base/nsContentList.cpp
+++ b/dom/base/nsContentList.cpp
@@ -988,23 +988,19 @@ nsContentList::AssertInSync()
   if (!mRootNode) {
     NS_ASSERTION(mElements.Length() == 0 && mState == LIST_DIRTY,
                  "Empty iterator isn't quite empty?");
     return;
   }
 
   // XXX This code will need to change if nsContentLists can ever match
   // elements that are outside of the document element.
-  nsIContent *root;
-  if (mRootNode->IsNodeOfType(nsINode::eDOCUMENT)) {
-    root = static_cast<nsIDocument*>(mRootNode)->GetRootElement();
-  }
-  else {
-    root = static_cast<nsIContent*>(mRootNode);
-  }
+  nsIContent* root = mRootNode->IsDocument()
+    ? mRootNode->AsDocument()->GetRootElement()
+    : mRootNode->AsContent();
 
   nsCOMPtr<nsIContentIterator> iter;
   if (mDeep) {
     iter = NS_NewPreContentIterator();
     iter->Init(root);
     iter->First();
   }
 
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -2205,21 +2205,21 @@ nsContentUtils::IsAbsoluteURL(const nsAC
 
 //static
 bool
 nsContentUtils::InProlog(nsINode *aNode)
 {
   NS_PRECONDITION(aNode, "missing node to nsContentUtils::InProlog");
 
   nsINode* parent = aNode->GetParentNode();
-  if (!parent || !parent->IsNodeOfType(nsINode::eDOCUMENT)) {
+  if (!parent || !parent->IsDocument()) {
     return false;
   }
 
-  nsIDocument* doc = static_cast<nsIDocument*>(parent);
+  nsIDocument* doc = parent->AsDocument();
   nsIContent* root = doc->GetRootElement();
 
   return !root || doc->ComputeIndexOf(aNode) < doc->ComputeIndexOf(root);
 }
 
 nsIDocument*
 nsContentUtils::GetDocumentFromCaller()
 {
@@ -2407,20 +2407,21 @@ nsContentUtils::GetCrossDocParentNode(ns
 {
   NS_PRECONDITION(aChild, "The child is null!");
 
   nsINode* parent = aChild->GetParentNode();
   if (parent && parent->IsContent() && aChild->IsContent()) {
     parent = aChild->AsContent()->GetFlattenedTreeParent();
   }
 
-  if (parent || !aChild->IsNodeOfType(nsINode::eDOCUMENT))
+  if (parent || !aChild->IsDocument()) {
     return parent;
-
-  nsIDocument* doc = static_cast<nsIDocument*>(aChild);
+  }
+
+  nsIDocument* doc = aChild->AsDocument();
   nsIDocument* parentDoc = doc->GetParentDocument();
   return parentDoc ? parentDoc->FindContentForSubDocument(doc) : nullptr;
 }
 
 // static
 bool
 nsContentUtils::ContentIsDescendantOf(const nsINode* aPossibleDescendant,
                                       const nsINode* aPossibleAncestor)
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -4155,17 +4155,17 @@ nsIDocument::FindContentForSubDocument(n
     }
   }
   return nullptr;
 }
 
 bool
 nsIDocument::IsNodeOfType(uint32_t aFlags) const
 {
-  return !(aFlags & ~eDOCUMENT);
+  return false;
 }
 
 Element*
 nsIDocument::GetRootElement() const
 {
   return (mCachedRootElement && mCachedRootElement->GetParentNode() == this) ?
          mCachedRootElement : GetRootElementInternal();
 }
--- a/dom/base/nsINode.cpp
+++ b/dom/base/nsINode.cpp
@@ -339,18 +339,18 @@ static nsIContent* GetRootForContentSubt
   return aContent;
 }
 
 nsIContent*
 nsINode::GetSelectionRootContent(nsIPresShell* aPresShell)
 {
   NS_ENSURE_TRUE(aPresShell, nullptr);
 
-  if (IsNodeOfType(eDOCUMENT))
-    return static_cast<nsIDocument*>(this)->GetRootElement();
+  if (IsDocument())
+    return AsDocument()->GetRootElement();
   if (!IsContent())
     return nullptr;
 
   if (GetComposedDoc() != aPresShell->GetDocument()) {
     return nullptr;
   }
 
   if (static_cast<nsIContent*>(this)->HasIndependentSelection()) {
@@ -1334,18 +1334,17 @@ nsINode::doInsertChildAt(nsIContent* aKi
   bool isAppend = (aIndex == childCount);
 
   nsresult rv = aChildArray.InsertChildAt(aKid, aIndex);
   NS_ENSURE_SUCCESS(rv, rv);
   if (aIndex == 0) {
     mFirstChild = aKid;
   }
 
-  nsIContent* parent =
-    IsNodeOfType(eDOCUMENT) ? nullptr : static_cast<nsIContent*>(this);
+  nsIContent* parent = IsContent() ? AsContent() : nullptr;
 
   rv = aKid->BindToTree(doc, parent,
                         parent ? parent->GetBindingParent() : nullptr,
                         true);
   if (NS_FAILED(rv)) {
     if (GetFirstChild() == aKid) {
       mFirstChild = aKid->GetNextSibling();
     }
@@ -1678,17 +1677,17 @@ nsINode::doRemoveChildAt(uint32_t aIndex
 // latter case it may be null.
 static
 bool IsAllowedAsChild(nsIContent* aNewChild, nsINode* aParent,
                       bool aIsReplace, nsINode* aRefChild)
 {
   MOZ_ASSERT(aNewChild, "Must have new child");
   MOZ_ASSERT_IF(aIsReplace, aRefChild);
   MOZ_ASSERT(aParent);
-  MOZ_ASSERT(aParent->IsNodeOfType(nsINode::eDOCUMENT) ||
+  MOZ_ASSERT(aParent->IsDocument() ||
              aParent->IsNodeOfType(nsINode::eDOCUMENT_FRAGMENT) ||
              aParent->IsElement(),
              "Nodes that are not documents, document fragments or elements "
              "can't be parents!");
 
   // A common case is that aNewChild has no kids, in which case
   // aParent can't be a descendant of aNewChild unless they're
   // actually equal to each other.  Fast-path that case, since aParent
@@ -1713,22 +1712,22 @@ bool IsAllowedAsChild(nsIContent* aNewCh
     return true;
   case nsINode::TEXT_NODE :
   case nsINode::CDATA_SECTION_NODE :
   case nsINode::ENTITY_REFERENCE_NODE :
     // Allowed under Elements and DocumentFragments
     return aParent->NodeType() != nsINode::DOCUMENT_NODE;
   case nsINode::ELEMENT_NODE :
     {
-      if (!aParent->IsNodeOfType(nsINode::eDOCUMENT)) {
+      if (!aParent->IsDocument()) {
         // Always ok to have elements under other elements or document fragments
         return true;
       }
 
-      nsIDocument* parentDocument = static_cast<nsIDocument*>(aParent);
+      nsIDocument* parentDocument = aParent->AsDocument();
       Element* rootElement = parentDocument->GetRootElement();
       if (rootElement) {
         // Already have a documentElement, so this is only OK if we're
         // replacing it.
         return aIsReplace && rootElement == aRefChild;
       }
 
       // We don't have a documentElement yet.  Our one remaining constraint is
@@ -1750,22 +1749,22 @@ bool IsAllowedAsChild(nsIContent* aNewCh
       // Now we're OK in the following two cases only:
       // 1) We're replacing something that's not before the doctype
       // 2) We're inserting before something that comes after the doctype
       return aIsReplace ? (insertIndex >= doctypeIndex) :
         insertIndex > doctypeIndex;
     }
   case nsINode::DOCUMENT_TYPE_NODE :
     {
-      if (!aParent->IsNodeOfType(nsINode::eDOCUMENT)) {
+      if (!aParent->IsDocument()) {
         // doctypes only allowed under documents
         return false;
       }
 
-      nsIDocument* parentDocument = static_cast<nsIDocument*>(aParent);
+      nsIDocument* parentDocument = aParent->AsDocument();
       nsIContent* docTypeContent = parentDocument->GetDoctype();
       if (docTypeContent) {
         // Already have a doctype, so this is only OK if we're replacing it
         return aIsReplace && docTypeContent == aRefChild;
       }
 
       // We don't have a doctype yet.  Our one remaining constraint is
       // that the doctype must come before the documentElement.
@@ -1790,17 +1789,17 @@ bool IsAllowedAsChild(nsIContent* aNewCh
     }
   case nsINode::DOCUMENT_FRAGMENT_NODE :
     {
       // Note that for now we only allow nodes inside document fragments if
       // they're allowed inside elements.  If we ever change this to allow
       // doctype nodes in document fragments, we'll need to update this code.
       // Also, there's a version of this code in ReplaceOrInsertBefore.  If you
       // change this code, change that too.
-      if (!aParent->IsNodeOfType(nsINode::eDOCUMENT)) {
+      if (!aParent->IsDocument()) {
         // All good here
         return true;
       }
 
       bool sawElement = false;
       for (nsIContent* child = aNewChild->GetFirstChild();
            child;
            child = child->GetNextSibling()) {
@@ -1841,17 +1840,17 @@ nsINode::EnsurePreInsertionValidity(nsIN
   }
   EnsurePreInsertionValidity2(false, aNewChild, aRefChild, aError);
 }
 
 void
 nsINode::EnsurePreInsertionValidity1(nsINode& aNewChild, nsINode* aRefChild,
                                      ErrorResult& aError)
 {
-  if ((!IsNodeOfType(eDOCUMENT) &&
+  if ((!IsDocument() &&
        !IsNodeOfType(eDOCUMENT_FRAGMENT) &&
        !IsElement()) ||
       !aNewChild.IsContent()) {
     aError.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
     return;
   }
 }
 
@@ -2100,17 +2099,17 @@ nsINode::ReplaceOrInsertBefore(bool aRep
       } else {
         nodeToInsertBefore = aRefChild;
       }
 
       // 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 (IsNodeOfType(nsINode::eDOCUMENT)) {
+      if (IsDocument()) {
         bool sawElement = false;
         for (uint32_t i = 0; i < count; ++i) {
           nsIContent* child = fragChildren->ElementAt(i);
           if (child->IsElement()) {
             if (sawElement) {
               // No good
               aError.Throw(NS_ERROR_DOM_HIERARCHY_REQUEST_ERR);
               return nullptr;
@@ -2197,18 +2196,17 @@ nsINode::ReplaceOrInsertBefore(bool aRep
       mutationBatch->SetNextSibling(GetChildAt_Deprecated(insPos));
     }
 
     uint32_t count = fragChildren->Length();
     if (!count) {
       return result;
     }
 
-    bool appending =
-      !IsNodeOfType(eDOCUMENT) && uint32_t(insPos) == GetChildCount();
+    bool appending = !IsDocument() && uint32_t(insPos) == GetChildCount();
     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) {
       // XXXbz how come no reparenting here?  That seems odd...
       // Insert the child.
       aError = InsertChildAt_Deprecated(fragChildren->ElementAt(i), insPos,
@@ -2444,17 +2442,18 @@ struct SelectorMatchInfo {
 template<bool onlyFirstMatch, class T>
 inline static void
 FindMatchingElementsWithId(const nsAString& aId, nsINode* aRoot,
                            SelectorMatchInfo* aMatchInfo,
                            T& aList)
 {
   MOZ_ASSERT(aRoot->IsInUncomposedDoc(),
              "Don't call me if the root is not in the document");
-  MOZ_ASSERT(aRoot->IsElement() || aRoot->IsNodeOfType(nsINode::eDOCUMENT),
+  // FIXME(emilio): It'd be nice to optimize this for shadow roots too.
+  MOZ_ASSERT(aRoot->IsElement() || aRoot->IsDocument(),
              "The optimization below to check ContentIsDescendantOf only for "
              "elements depends on aRoot being either an element or a "
              "document if it's in the document.  Note that document fragments "
              "can't be IsInUncomposedDoc(), so should never show up here.");
 
   const nsTArray<Element*>* elements = aRoot->OwnerDoc()->GetAllElementsForId(aId);
   if (!elements) {
     // Nothing to do; we're done
--- a/dom/base/nsINode.h
+++ b/dom/base/nsINode.h
@@ -406,18 +406,16 @@ public:
 #endif
 
   virtual ~nsINode();
 
   /**
    * Bit-flags to pass (or'ed together) to IsNodeOfType()
    */
   enum {
-    /** nsIDocument nodes */
-    eDOCUMENT            = 1 << 1,
     /** nsIAttribute nodes */
     eATTRIBUTE           = 1 << 2,
     /** xml processing instructions */
     ePROCESSING_INSTRUCTION = 1 << 4,
     /** comment nodes */
     eCOMMENT             = 1 << 5,
     /** form control elements */
     eHTML_FORM_CONTROL   = 1 << 6,
--- a/dom/base/nsNodeUtils.cpp
+++ b/dom/base/nsNodeUtils.cpp
@@ -205,31 +205,29 @@ nsNodeUtils::NativeAnonymousChildListCha
                             (aContent, aIsRemove),
                             isRemove);
 }
 
 void
 nsNodeUtils::ContentInserted(nsINode* aContainer,
                              nsIContent* aChild)
 {
-  NS_PRECONDITION(aContainer->IsContent() ||
-                  aContainer->IsNodeOfType(nsINode::eDOCUMENT),
+  NS_PRECONDITION(aContainer->IsContent() || aContainer->IsDocument(),
                   "container must be an nsIContent or an nsIDocument");
   nsIDocument* doc = aContainer->OwnerDoc();
   IMPL_MUTATION_NOTIFICATION(ContentInserted, aContainer, (aChild),
                              IsRemoveNotification::No);
 }
 
 void
 nsNodeUtils::ContentRemoved(nsINode* aContainer,
                             nsIContent* aChild,
                             nsIContent* aPreviousSibling)
 {
-  NS_PRECONDITION(aContainer->IsContent() ||
-                  aContainer->IsNodeOfType(nsINode::eDOCUMENT),
+  NS_PRECONDITION(aContainer->IsContent() || aContainer->IsDocument(),
                   "container must be an nsIContent or an nsIDocument");
   nsIDocument* doc = aContainer->OwnerDoc();
   MOZ_ASSERT(aChild->GetParentNode() == aContainer,
              "We expect the parent link to be still around at this point");
   IMPL_MUTATION_NOTIFICATION(ContentRemoved, aContainer,
                              (aChild, aPreviousSibling),
                              IsRemoveNotification::Yes);
 }
@@ -304,21 +302,21 @@ nsNodeUtils::LastRelease(nsINode* aNode)
     }
 
     delete slots;
     aNode->mSlots = nullptr;
   }
 
   // Kill properties first since that may run external code, so we want to
   // be in as complete state as possible at that time.
-  if (aNode->IsNodeOfType(nsINode::eDOCUMENT)) {
+  if (aNode->IsDocument()) {
     // Delete all properties before tearing down the document. Some of the
     // properties are bound to nsINode objects and the destructor functions of
     // the properties may want to use the owner document of the nsINode.
-    static_cast<nsIDocument*>(aNode)->DeleteAllProperties();
+    aNode->AsDocument()->DeleteAllProperties();
   }
   else {
     if (aNode->HasProperties()) {
       // Strong reference to the document so that deleting properties can't
       // delete the document.
       nsCOMPtr<nsIDocument> document = aNode->OwnerDoc();
       document->DeleteAllPropertiesFor(aNode);
     }
@@ -484,17 +482,17 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNod
       // parent.
       rv = aParent->AppendChildTo(static_cast<nsIContent*>(clone.get()),
                                   false);
       if (NS_WARN_IF(NS_FAILED(rv))) {
         aError.Throw(rv);
         return nullptr;
       }
     }
-    else if (aDeep && clone->IsNodeOfType(nsINode::eDOCUMENT)) {
+    else if (aDeep && clone->IsDocument()) {
       // After cloning the document itself, we want to clone the children into
       // the cloned document (somewhat like cloning and importing them into the
       // cloned document).
       nodeInfoManager = clone->mNodeInfo->NodeInfoManager();
     }
   }
   else if (nodeInfoManager) {
     nsIDocument* oldDoc = aNode->OwnerDoc();
--- a/dom/base/nsRange.cpp
+++ b/dom/base/nsRange.cpp
@@ -976,17 +976,17 @@ nsRange::DoSetRange(const RawRangeBounda
   NS_PRECONDITION(!aRoot ||
                   (aStart.Container()->IsContent() &&
                    aEnd.Container()->IsContent() &&
                    aRoot ==
                     static_cast<nsIContent*>(aStart.Container())->GetBindingParent() &&
                    aRoot ==
                     static_cast<nsIContent*>(aEnd.Container())->GetBindingParent()) ||
                   (!aRoot->GetParentNode() &&
-                   (aRoot->IsNodeOfType(nsINode::eDOCUMENT) ||
+                   (aRoot->IsDocument() ||
                     aRoot->IsNodeOfType(nsINode::eATTRIBUTE) ||
                     aRoot->IsNodeOfType(nsINode::eDOCUMENT_FRAGMENT) ||
                      /*For backward compatibility*/
                     aRoot->IsContent())),
                   "Bad root");
   if (mRoot != aRoot) {
     if (mRoot) {
       mRoot->RemoveMutationObserver(this);
@@ -1203,17 +1203,17 @@ nsRange::ComputeRootNode(nsINode* aNode,
   // text nodes in document, in document fragment or in attribute.
   nsINode* root = aNode->GetUncomposedDoc();
   if (root) {
     return root;
   }
 
   root = aNode->SubtreeRoot();
 
-  NS_ASSERTION(!root->IsNodeOfType(nsINode::eDOCUMENT),
+  NS_ASSERTION(!root->IsDocument(),
                "GetUncomposedDoc should have returned a doc");
 
   // We allow this because of backward compatibility.
   return root;
 }
 
 /* static */
 bool
--- a/dom/base/nsXMLContentSerializer.cpp
+++ b/dom/base/nsXMLContentSerializer.cpp
@@ -1267,17 +1267,17 @@ nsXMLContentSerializer::MaybeAddNewlineF
   return true;
 }
 
 void
 nsXMLContentSerializer::MaybeFlagNewlineForRootNode(nsINode* aNode)
 {
   nsINode* parent = aNode->GetParentNode();
   if (parent) {
-    mAddNewlineForRootNode = parent->IsNodeOfType(nsINode::eDOCUMENT);
+    mAddNewlineForRootNode = parent->IsDocument();
   }
 }
 
 void
 nsXMLContentSerializer::MaybeEnterInPreContent(nsIContent* aNode)
 {
   // support of the xml:space attribute
   nsAutoString space;
--- a/dom/events/IMEContentObserver.cpp
+++ b/dom/events/IMEContentObserver.cpp
@@ -359,17 +359,17 @@ IMEContentObserver::InitWithEditor(nsPre
       return false;
     }
 
     mRootContent = selRange->GetStartContainer()->
                      GetSelectionRootContent(presShell);
   } else {
     mRootContent = mEditableNode->GetSelectionRootContent(presShell);
   }
-  if (!mRootContent && mEditableNode->IsNodeOfType(nsINode::eDOCUMENT)) {
+  if (!mRootContent && mEditableNode->IsDocument()) {
     // The document node is editable, but there are no contents, this document
     // is not editable.
     return false;
   }
 
   if (NS_WARN_IF(!mRootContent)) {
     return false;
   }
--- a/dom/xslt/xslt/txMozillaStylesheetCompiler.cpp
+++ b/dom/xslt/xslt/txMozillaStylesheetCompiler.cpp
@@ -566,17 +566,17 @@ handleNode(nsINode* aNode, txStylesheetC
         NS_ENSURE_SUCCESS(rv, rv);
     }
     else if (dom::Text* text = aNode->GetAsText()) {
         nsAutoString chars;
         text->AppendTextTo(chars);
         rv = aCompiler->characters(chars);
         NS_ENSURE_SUCCESS(rv, rv);
     }
-    else if (aNode->IsNodeOfType(nsINode::eDOCUMENT)) {
+    else if (aNode->IsDocument()) {
         for (nsIContent* child = aNode->GetFirstChild();
              child;
              child = child->GetNextSibling()) {
 
             rv = handleNode(child, aCompiler);
             NS_ENSURE_SUCCESS(rv, rv);
         }
     }
@@ -670,20 +670,19 @@ TX_CompileStylesheet(nsINode* aNode, txM
                      txStylesheet** aStylesheet)
 {
     // If we move GetBaseURI to nsINode this can be simplified.
     nsCOMPtr<nsIDocument> doc = aNode->OwnerDoc();
 
     nsCOMPtr<nsIURI> uri;
     if (aNode->IsContent()) {
       uri = aNode->AsContent()->GetBaseURI();
-    }
-    else {
-      NS_ASSERTION(aNode->IsNodeOfType(nsINode::eDOCUMENT), "not a doc");
-      uri = static_cast<nsIDocument*>(aNode)->GetBaseURI();
+    } else {
+      NS_ASSERTION(aNode->IsDocument(), "not a doc");
+      uri = aNode->AsDocument()->GetBaseURI();
     }
     NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE);
 
     nsAutoCString spec;
     uri->GetSpec(spec);
     NS_ConvertUTF8toUTF16 baseURI(spec);
 
     nsIURI* docUri = doc->GetDocumentURI();
--- a/dom/xslt/xslt/txMozillaXSLTProcessor.cpp
+++ b/dom/xslt/xslt/txMozillaXSLTProcessor.cpp
@@ -588,18 +588,17 @@ txMozillaXSLTProcessor::ImportStylesheet
         return;
     }
 
     if (!nsContentUtils::SubjectPrincipalOrSystemIfNativeCaller()->Subsumes(aStyle.NodePrincipal())) {
         aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
         return;
     }
 
-    if (NS_WARN_IF(!aStyle.IsElement() &&
-                   !aStyle.IsNodeOfType(nsINode::eDOCUMENT))) {
+    if (NS_WARN_IF(!aStyle.IsElement() && !aStyle.IsDocument())) {
         aRv.Throw(NS_ERROR_INVALID_ARG);
         return;
     }
 
     nsresult rv = TX_CompileStylesheet(&aStyle, this,
                                        getter_AddRefs(mStylesheet));
     // XXX set up exception context, bug 204658
     if (NS_WARN_IF(NS_FAILED(rv))) {
--- a/editor/libeditor/EditorEventListener.cpp
+++ b/editor/libeditor/EditorEventListener.cpp
@@ -1068,18 +1068,17 @@ EditorEventListener::Focus(InternalFocus
   }
 
   nsIDOMEventTarget* target = aFocusEvent->GetOriginalDOMEventTarget();
   nsCOMPtr<nsINode> node = do_QueryInterface(target);
   NS_ENSURE_TRUE(node, NS_ERROR_UNEXPECTED);
 
   // If the target is a document node but it's not editable, we should ignore
   // it because actual focused element's event is going to come.
-  if (node->IsNodeOfType(nsINode::eDOCUMENT) &&
-      !node->HasFlag(NODE_IS_EDITABLE)) {
+  if (node->IsDocument() && !node->HasFlag(NODE_IS_EDITABLE)) {
     return NS_OK;
   }
 
   if (node->IsContent()) {
     nsIContent* content =
       node->AsContent()->FindFirstNonChromeOnlyAccessContent();
     // XXX If the focus event target is a form control in contenteditable
     // element, perhaps, the parent HTML editor should do nothing by this
--- a/editor/libeditor/HTMLEditor.cpp
+++ b/editor/libeditor/HTMLEditor.cpp
@@ -386,18 +386,17 @@ HTMLEditor::UpdateRootElement()
 
 already_AddRefed<nsIContent>
 HTMLEditor::FindSelectionRoot(nsINode* aNode)
 {
   if (NS_WARN_IF(!aNode)) {
     return nullptr;
   }
 
-  NS_PRECONDITION(aNode->IsNodeOfType(nsINode::eDOCUMENT) ||
-                  aNode->IsContent(),
+  NS_PRECONDITION(aNode->IsDocument() || aNode->IsContent(),
                   "aNode must be content or document node");
 
   nsCOMPtr<nsIDocument> doc = aNode->GetComposedDoc();
   if (!doc) {
     return nullptr;
   }
 
   nsCOMPtr<nsIContent> content;
--- a/layout/inspector/InspectorUtils.cpp
+++ b/layout/inspector/InspectorUtils.cpp
@@ -121,19 +121,18 @@ InspectorUtils::IsIgnorableWhitespace(Ch
 
 /* static */ nsINode*
 InspectorUtils::GetParentForNode(nsINode& aNode,
                                  bool aShowingAnonymousContent)
 {
   // First do the special cases -- document nodes and anonymous content
   nsINode* parent = nullptr;
 
-  if (aNode.IsNodeOfType(nsINode::eDOCUMENT)) {
-    auto& doc = static_cast<nsIDocument&>(aNode);
-    parent = inLayoutUtils::GetContainerFor(doc);
+  if (aNode.IsDocument()) {
+    parent = inLayoutUtils::GetContainerFor(*aNode.AsDocument());
   } else if (aShowingAnonymousContent) {
     if (aNode.IsContent()) {
       parent = aNode.AsContent()->GetFlattenedTreeParent();
     }
   }
 
   if (!parent) {
     // Ok, just get the normal DOM parent node
--- a/layout/printing/nsPrintJob.cpp
+++ b/layout/printing/nsPrintJob.cpp
@@ -2535,17 +2535,17 @@ GetCorrespondingNodeInDocument(const nsI
   nsTArray<int32_t> indexArray;
   const nsINode* child = aNode;
   while (const nsINode* parent = child->GetParentNode()) {
     int32_t index = parent->ComputeIndexOf(child);
     MOZ_ASSERT(index >= 0);
     indexArray.AppendElement(index);
     child = parent;
   }
-  MOZ_ASSERT(child->IsNodeOfType(nsINode::eDOCUMENT));
+  MOZ_ASSERT(child->IsDocument());
 
   nsINode* correspondingNode = aDoc;
   for (int32_t i = indexArray.Length() - 1; i >= 0; --i) {
     correspondingNode = correspondingNode->GetChildAt_Deprecated(indexArray[i]);
     NS_ENSURE_TRUE(correspondingNode, nullptr);
   }
 
   return correspondingNode;
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -1515,17 +1515,17 @@ ServoStyleSet::MayTraverseFrom(const Ele
 {
   MOZ_ASSERT(aElement->IsInComposedDoc());
   nsINode* parent = aElement->GetFlattenedTreeParentNodeForStyle();
   if (!parent) {
     return false;
   }
 
   if (!parent->IsElement()) {
-    MOZ_ASSERT(parent->IsNodeOfType(nsINode::eDOCUMENT));
+    MOZ_ASSERT(parent->IsDocument());
     return true;
   }
 
   if (!parent->AsElement()->HasServoData()) {
     return false;
   }
 
   return !Servo_Element_IsDisplayNone(parent->AsElement());