From 3a741c1a97c2f349f511a6d36d49ba399334c2a6 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Thu, 16 Apr 2015 21:39:13 -0400 Subject: [PATCH] Bug 1155477 - Convert nsINode::Slots::mChildNodes to an nsRefPtr; r=baku MSVC 7 is no longer supported, so this can now be an nsRefPtr. --- dom/base/FragmentOrElement.h | 45 ------------------------------ dom/base/nsINode.cpp | 10 ++----- dom/base/nsINode.h | 54 ++++++++++++++++++++++++++++++++---- dom/base/nsINodeList.h | 4 ++- 4 files changed, 53 insertions(+), 60 deletions(-) diff --git a/dom/base/FragmentOrElement.h b/dom/base/FragmentOrElement.h index 73903791679..fdd32af59ff 100644 --- a/dom/base/FragmentOrElement.h +++ b/dom/base/FragmentOrElement.h @@ -17,7 +17,6 @@ #include "nsAttrAndChildArray.h" // member #include "nsCycleCollectionParticipant.h" // NS_DECL_CYCLE_* #include "nsIContent.h" // base class -#include "nsINodeList.h" // base class #include "nsIWeakReference.h" // base class #include "nsNodeUtils.h" // class member nsNodeUtils::CloneNodeImpl #include "nsIHTMLCollection.h" @@ -38,50 +37,6 @@ class Element; } } -/** - * Class that implements the nsIDOMNodeList interface (a list of children of - * the content), by holding a reference to the content and delegating GetLength - * and Item to its existing child list. - * @see nsIDOMNodeList - */ -class nsChildContentList final : public nsINodeList -{ -public: - explicit nsChildContentList(nsINode* aNode) - : mNode(aNode) - { - } - - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(nsChildContentList) - - // nsWrapperCache - virtual JSObject* WrapObject(JSContext *cx, JS::Handle aGivenProto) override; - - // nsIDOMNodeList interface - NS_DECL_NSIDOMNODELIST - - // nsINodeList interface - virtual int32_t IndexOf(nsIContent* aContent) override; - virtual nsIContent* Item(uint32_t aIndex) override; - - void DropReference() - { - mNode = nullptr; - } - - virtual nsINode* GetParentObject() override - { - return mNode; - } - -private: - ~nsChildContentList() {} - - // The node whose children make up the list (weak reference) - nsINode* mNode; -}; - /** * A class that implements nsIWeakReference */ diff --git a/dom/base/nsINode.cpp b/dom/base/nsINode.cpp index c183fd6ed69..cc6cad3aa89 100644 --- a/dom/base/nsINode.cpp +++ b/dom/base/nsINode.cpp @@ -113,7 +113,6 @@ nsINode::nsSlots::~nsSlots() { if (mChildNodes) { mChildNodes->DropReference(); - NS_RELEASE(mChildNodes); } if (mWeakReference) { @@ -133,7 +132,6 @@ nsINode::nsSlots::Unlink() { if (mChildNodes) { mChildNodes->DropReference(); - NS_RELEASE(mChildNodes); } } @@ -369,12 +367,8 @@ nsINodeList* nsINode::ChildNodes() { nsSlots* slots = Slots(); - if (!slots->mChildNodes) { - slots->mChildNodes = new nsChildContentList(this); - if (slots->mChildNodes) { - NS_ADDREF(slots->mChildNodes); - } - } + MOZ_ASSERT(!slots->mChildNodes); + slots->mChildNodes = new nsChildContentList(this); return slots->mChildNodes; } diff --git a/dom/base/nsINode.h b/dom/base/nsINode.h index 3d39235cf8e..daa8da6d9a8 100644 --- a/dom/base/nsINode.h +++ b/dom/base/nsINode.h @@ -11,6 +11,7 @@ #include "nsGkAtoms.h" // for nsGkAtoms::baseURIProperty #include "nsIDOMNode.h" #include "mozilla/dom/NodeInfo.h" // member (in nsCOMPtr) +#include "nsINodeList.h" // base class #include "nsIVariant.h" // for use in GetUserData() #include "nsNodeInfoManager.h" // for use in NodePrincipal() #include "nsPropertyTable.h" // for typedefs @@ -41,7 +42,7 @@ class nsIDOMNodeList; class nsIEditor; class nsIFrame; class nsIMutationObserver; -class nsINodeList; +class nsINode; class nsIPresShell; class nsIPrincipal; class nsIURI; @@ -234,6 +235,50 @@ private: static uint64_t sGeneration; }; +/** + * Class that implements the nsIDOMNodeList interface (a list of children of + * the content), by holding a reference to the content and delegating GetLength + * and Item to its existing child list. + * @see nsIDOMNodeList + */ +class nsChildContentList final : public nsINodeList +{ +public: + explicit nsChildContentList(nsINode* aNode) + : mNode(aNode) + { + } + + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(nsChildContentList) + + // nsWrapperCache + virtual JSObject* WrapObject(JSContext *cx, JS::Handle aGivenProto) override; + + // nsIDOMNodeList interface + NS_DECL_NSIDOMNODELIST + + // nsINodeList interface + virtual int32_t IndexOf(nsIContent* aContent) override; + virtual nsIContent* Item(uint32_t aIndex) override; + + void DropReference() + { + mNode = nullptr; + } + + virtual nsINode* GetParentObject() override + { + return mNode; + } + +private: + ~nsChildContentList() {} + + // The node whose children make up the list (weak reference) + nsINode* mNode; +}; + // This should be used for any nsINode sub-class that has fields of its own // that it needs to measure; any sub-class that doesn't use it will inherit // SizeOfExcludingThis from its super-class. SizeOfIncludingThis() need not be @@ -1021,8 +1066,7 @@ public: { public: nsSlots() - : mChildNodes(nullptr), - mWeakReference(nullptr) + : mWeakReference(nullptr) { } @@ -1042,10 +1086,8 @@ public: * An object implementing nsIDOMNodeList for this content (childNodes) * @see nsIDOMNodeList * @see nsGenericHTMLElement::GetChildNodes - * - * MSVC 7 doesn't like this as an nsRefPtr */ - nsChildContentList* mChildNodes; + nsRefPtr mChildNodes; /** * Weak reference to this node. This is cleared by the destructor of diff --git a/dom/base/nsINodeList.h b/dom/base/nsINodeList.h index ce9e953432c..e101982c7c8 100644 --- a/dom/base/nsINodeList.h +++ b/dom/base/nsINodeList.h @@ -8,13 +8,15 @@ #include "nsIDOMNodeList.h" #include "nsWrapperCache.h" -#include "nsIContent.h" // IID for the nsINodeList interface #define NS_INODELIST_IID \ { 0xadb5e54c, 0x6e96, 0x4102, \ { 0x8d, 0x40, 0xe0, 0x12, 0x3d, 0xcf, 0x48, 0x7a } } +class nsIContent; +class nsINode; + /** * An internal interface for a reasonably fast indexOf. */