Bug 1155477 - Convert nsINode::Slots::mChildNodes to an nsRefPtr; r=baku

MSVC 7 is no longer supported, so this can now be an nsRefPtr.
This commit is contained in:
Ehsan Akhgari 2015-04-16 21:39:13 -04:00
parent efb62f9871
commit 3a741c1a97
4 changed files with 53 additions and 60 deletions

View File

@ -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<JSObject*> 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
*/

View File

@ -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;
}

View File

@ -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<JSObject*> 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<nsChildContentList> mChildNodes;
/**
* Weak reference to this node. This is cleared by the destructor of

View File

@ -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.
*/