Fix for bug 678528 (Traverse mChildNodes (and consolidate node CC code)). r=jst.

This commit is contained in:
Peter Van der Beken 2011-08-28 16:07:24 +02:00
Родитель a6f8e8d438
Коммит 5b5d8e7b5c
13 изменённых файлов: 163 добавлений и 106 удалений

Просмотреть файл

@ -1027,28 +1027,4 @@ public:
NS_DEFINE_STATIC_IID_ACCESSOR(nsIContent, NS_ICONTENT_IID)
// Some cycle-collecting helper macros for nsIContent subclasses
#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_LISTENERMANAGER \
if (tmp->HasFlag(NODE_HAS_LISTENERMANAGER)) { \
nsContentUtils::TraverseListenerManager(tmp, cb); \
}
#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_USERDATA \
if (tmp->HasProperties()) { \
nsNodeUtils::TraverseUserData(tmp, cb); \
}
#define NS_IMPL_CYCLE_COLLECTION_UNLINK_LISTENERMANAGER \
if (tmp->HasFlag(NODE_HAS_LISTENERMANAGER)) { \
nsContentUtils::RemoveListenerManager(tmp); \
tmp->UnsetFlags(NODE_HAS_LISTENERMANAGER); \
}
#define NS_IMPL_CYCLE_COLLECTION_UNLINK_USERDATA \
if (tmp->HasProperties()) { \
nsNodeUtils::UnlinkUserData(tmp); \
}
#endif /* nsIContent_h___ */

Просмотреть файл

@ -801,6 +801,9 @@ public:
// putting a DestroySlots function on nsINode
virtual ~nsSlots();
void Traverse(nsCycleCollectionTraversalCallback &cb);
void Unlink();
/**
* A list of mutation observers
*/
@ -1342,6 +1345,10 @@ protected:
#undef TOUCH_EVENT
#undef EVENT
static void Trace(nsINode *tmp, TraceCallback cb, void *closure);
static bool Traverse(nsINode *tmp, nsCycleCollectionTraversalCallback &cb);
static void Unlink(nsINode *tmp);
nsCOMPtr<nsINodeInfo> mNodeInfo;
nsINode* mParent;

Просмотреть файл

@ -60,7 +60,6 @@
#include "mozAutoDocUpdate.h"
#include "nsMutationEvent.h"
#include "nsPLDOMEvent.h"
#include "nsContentUtils.h" // NS_IMPL_CYCLE_COLLECTION_UNLINK_LISTENERMANAGER
using namespace mozilla::dom;
@ -105,25 +104,25 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMAttribute)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDOMAttribute)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mNodeInfo)
if (!nsINode::Traverse(tmp, cb)) {
return NS_SUCCESS_INTERRUPTED_TRAVERSE;
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(mChild)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_LISTENERMANAGER
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_USERDATA
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsDOMAttribute)
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
nsINode::Trace(tmp, aCallback, aClosure);
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDOMAttribute)
nsINode::Unlink(tmp);
if (tmp->mChild) {
static_cast<nsTextNode*>(tmp->mChild)->UnbindFromAttribute();
NS_RELEASE(tmp->mChild);
tmp->mFirstChild = nsnull;
}
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_UNLINK_LISTENERMANAGER
NS_IMPL_CYCLE_COLLECTION_UNLINK_USERDATA
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
DOMCI_NODE_DATA(Attr, nsDOMAttribute)

Просмотреть файл

@ -1825,7 +1825,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDocument)
// if we're uncollectable.
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
if (nsCCUncollectableMarker::InGeneration(cb, tmp->GetMarkedCCGeneration())) {
if (!nsINode::Traverse(tmp, cb)) {
return NS_SUCCESS_INTERRUPTED_TRAVERSE;
}
@ -1833,16 +1833,12 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsDocument)
tmp->mExternalResourceMap.Traverse(&cb);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mNodeInfo)
// Traverse the mChildren nsAttrAndChildArray.
for (PRInt32 indx = PRInt32(tmp->mChildren.ChildCount()); indx > 0; --indx) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mChildren[i]");
cb.NoteXPCOMChild(tmp->mChildren.ChildAt(indx - 1));
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_USERDATA
// Traverse all nsIDocument pointer members.
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCachedRootElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mSecurityInfo)
@ -1901,7 +1897,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsDocument)
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
nsINode::Trace(tmp, aCallback, aClosure);
NS_IMPL_CYCLE_COLLECTION_TRACE_END
@ -1913,6 +1909,8 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocument)
nsAutoScriptBlocker scriptBlocker;
nsINode::Unlink(tmp);
// Unlink the mChildren nsAttrAndChildArray.
for (PRInt32 indx = PRInt32(tmp->mChildren.ChildCount()) - 1;
indx >= 0; --indx) {
@ -1930,9 +1928,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocument)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOriginalDocument)
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCachedEncoder)
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_UNLINK_USERDATA
tmp->mParentDocument = nsnull;
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mPreloadingImages)

Просмотреть файл

@ -93,7 +93,7 @@ nsGenericDOMDataNode::~nsGenericDOMDataNode()
NS_IMPL_CYCLE_COLLECTION_CLASS(nsGenericDOMDataNode)
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsGenericDOMDataNode)
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
nsINode::Trace(tmp, aCallback, aClosure);
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsGenericDOMDataNode)
@ -101,28 +101,18 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsGenericDOMDataNode)
// if we're uncollectable.
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
nsIDocument* currentDoc = tmp->GetCurrentDoc();
if (currentDoc && nsCCUncollectableMarker::InGeneration(
cb, currentDoc->GetMarkedCCGeneration())) {
if (!nsINode::Traverse(tmp, cb)) {
return NS_SUCCESS_INTERRUPTED_TRAVERSE;
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mNodeInfo)
nsIDocument* ownerDoc = tmp->GetOwnerDoc();
if (ownerDoc) {
ownerDoc->BindingManager()->Traverse(tmp, cb);
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_LISTENERMANAGER
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_USERDATA
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(GetParent())
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGenericDOMDataNode)
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_UNLINK_LISTENERMANAGER
NS_IMPL_CYCLE_COLLECTION_UNLINK_USERDATA
nsINode::Unlink(tmp);
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_INTERFACE_MAP_BEGIN(nsGenericDOMDataNode)

Просмотреть файл

@ -174,6 +174,22 @@ nsINode::nsSlots::~nsSlots()
}
}
void
nsINode::nsSlots::Traverse(nsCycleCollectionTraversalCallback &cb)
{
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mChildNodes");
cb.NoteXPCOMChild(mChildNodes);
}
void
nsINode::nsSlots::Unlink()
{
if (mChildNodes) {
mChildNodes->DropReference();
NS_RELEASE(mChildNodes);
}
}
//----------------------------------------------------------------------
nsINode::~nsINode()
@ -1142,6 +1158,63 @@ nsINode::GetContextForEventHandlers(nsresult* aRv)
return nsContentUtils::GetContextForEventHandlers(this, aRv);
}
/* static */
void
nsINode::Trace(nsINode *tmp, TraceCallback cb, void *closure)
{
nsContentUtils::TraceWrapper(tmp, cb, closure);
}
/* static */
bool
nsINode::Traverse(nsINode *tmp, nsCycleCollectionTraversalCallback &cb)
{
nsIDocument *currentDoc = tmp->GetCurrentDoc();
if (currentDoc &&
nsCCUncollectableMarker::InGeneration(cb, currentDoc->GetMarkedCCGeneration())) {
return false;
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mNodeInfo)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(GetParent())
nsSlots *slots = tmp->GetExistingSlots();
if (slots) {
slots->Traverse(cb);
}
if (tmp->HasProperties()) {
nsNodeUtils::TraverseUserData(tmp, cb);
}
if (tmp->HasFlag(NODE_HAS_LISTENERMANAGER)) {
nsContentUtils::TraverseListenerManager(tmp, cb);
}
return true;
}
/* static */
void
nsINode::Unlink(nsINode *tmp)
{
nsContentUtils::ReleaseWrapper(tmp, tmp);
nsSlots *slots = tmp->GetExistingSlots();
if (slots) {
slots->Unlink();
}
if (tmp->HasFlag(NODE_HAS_LISTENERMANAGER)) {
nsContentUtils::RemoveListenerManager(tmp);
tmp->UnsetFlags(NODE_HAS_LISTENERMANAGER);
}
if (tmp->HasProperties()) {
nsNodeUtils::UnlinkUserData(tmp);
}
}
//----------------------------------------------------------------------
nsEventStates
@ -2192,6 +2265,45 @@ nsGenericElement::nsDOMSlots::~nsDOMSlots()
}
}
void
nsGenericElement::nsDOMSlots::Traverse(nsCycleCollectionTraversalCallback &cb, bool aIsXUL)
{
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mStyle");
cb.NoteXPCOMChild(mStyle.get());
#ifdef MOZ_SMIL
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mSMILOverrideStyle");
cb.NoteXPCOMChild(mSMILOverrideStyle.get());
#endif // MOZ_SMIL
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mAttributeMap");
cb.NoteXPCOMChild(mAttributeMap.get());
if (aIsXUL) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mControllers");
cb.NoteXPCOMChild(mControllers);
}
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mChildrenList");
cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIDOMNodeList*, mChildrenList));
}
void
nsGenericElement::nsDOMSlots::Unlink(bool aIsXUL)
{
mStyle = nsnull;
#ifdef MOZ_SMIL
mSMILOverrideStyle = nsnull;
#endif // MOZ_SMIL
if (mAttributeMap) {
mAttributeMap->DropReference();
mAttributeMap = nsnull;
}
if (aIsXUL)
NS_IF_RELEASE(mControllers);
mChildrenList = nsnull;
}
nsGenericElement::nsGenericElement(already_AddRefed<nsINodeInfo> aNodeInfo)
: Element(aNodeInfo)
{
@ -4110,9 +4222,7 @@ nsINode::IsSameNode(nsIDOMNode* aOther, PRBool* aReturn)
NS_IMPL_CYCLE_COLLECTION_CLASS(nsGenericElement)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGenericElement)
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_UNLINK_LISTENERMANAGER
NS_IMPL_CYCLE_COLLECTION_UNLINK_USERDATA
nsINode::Unlink(tmp);
if (tmp->HasProperties() && tmp->IsXUL()) {
tmp->DeleteProperty(nsGkAtoms::contextmenulistener);
@ -4140,17 +4250,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGenericElement)
{
nsDOMSlots *slots = tmp->GetExistingDOMSlots();
if (slots) {
slots->mStyle = nsnull;
#ifdef MOZ_SMIL
slots->mSMILOverrideStyle = nsnull;
#endif // MOZ_SMIL
if (slots->mAttributeMap) {
slots->mAttributeMap->DropReference();
slots->mAttributeMap = nsnull;
}
if (tmp->IsXUL())
NS_IF_RELEASE(slots->mControllers);
slots->mChildrenList = nsnull;
slots->Unlink(tmp->IsXUL());
}
}
@ -4163,7 +4263,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGenericElement)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsGenericElement)
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
nsINode::Trace(tmp, aCallback, aClosure);
NS_IMPL_CYCLE_COLLECTION_TRACE_END
static const char* kNSURIs[] = {
@ -4204,9 +4304,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGenericElement)
// if we're uncollectable.
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
nsIDocument* currentDoc = tmp->GetCurrentDoc();
if (currentDoc && nsCCUncollectableMarker::InGeneration(
cb, currentDoc->GetMarkedCCGeneration())) {
if (!nsINode::Traverse(tmp, cb)) {
return NS_SUCCESS_INTERRUPTED_TRAVERSE;
}
@ -4215,9 +4313,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGenericElement)
ownerDoc->BindingManager()->Traverse(tmp, cb);
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_LISTENERMANAGER
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_USERDATA
if (tmp->HasProperties() && tmp->IsXUL()) {
nsISupports* property =
static_cast<nsISupports*>
@ -4248,31 +4343,13 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(nsGenericElement)
}
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mNodeInfo)
// Traverse any DOM slots of interest.
{
nsDOMSlots *slots = tmp->GetExistingDOMSlots();
if (slots) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "slots mStyle");
cb.NoteXPCOMChild(slots->mStyle.get());
#ifdef MOZ_SMIL
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "slots mSMILOverrideStyle");
cb.NoteXPCOMChild(slots->mSMILOverrideStyle.get());
#endif // MOZ_SMIL
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "slots mAttributeMap");
cb.NoteXPCOMChild(slots->mAttributeMap.get());
if (tmp->IsXUL())
cb.NoteXPCOMChild(slots->mControllers);
cb.NoteXPCOMChild(
static_cast<nsIDOMNodeList*>(slots->mChildrenList.get()));
slots->Traverse(cb, tmp->IsXUL());
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(GetParent())
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END

Просмотреть файл

@ -826,6 +826,9 @@ public:
nsDOMSlots();
virtual ~nsDOMSlots();
void Traverse(nsCycleCollectionTraversalCallback &cb, bool aIsXUL);
void Unlink(bool aIsXUL);
/**
* The .style attribute (an interface that forwards to the actual
* style rules)

Просмотреть файл

@ -1525,10 +1525,13 @@ nsObjectLoadingContent::RemovedFromDocument()
}
}
/* static */
void
nsObjectLoadingContent::Traverse(nsCycleCollectionTraversalCallback &cb)
nsObjectLoadingContent::Traverse(nsObjectLoadingContent *tmp,
nsCycleCollectionTraversalCallback &cb)
{
cb.NoteXPCOMChild(static_cast<nsIFrameLoader*>(mFrameLoader));
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mFrameLoader");
cb.NoteXPCOMChild(static_cast<nsIFrameLoader*>(tmp->mFrameLoader));
}
// <private>

Просмотреть файл

@ -222,7 +222,8 @@ class nsObjectLoadingContent : public nsImageLoadingContent
*/
void RemovedFromDocument();
void Traverse(nsCycleCollectionTraversalCallback &cb);
static void Traverse(nsObjectLoadingContent *tmp,
nsCycleCollectionTraversalCallback &cb);
void CreateStaticClone(nsObjectLoadingContent* aDest) const;
private:

Просмотреть файл

@ -196,7 +196,7 @@ nsHTMLObjectElement::DoneAddingChildren(PRBool aHaveNotified)
NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLObjectElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLObjectElement,
nsGenericHTMLFormElement)
tmp->Traverse(cb);
nsObjectLoadingContent::Traverse(tmp, cb);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_ADDREF_INHERITED(nsHTMLObjectElement, nsGenericElement)

Просмотреть файл

@ -216,7 +216,7 @@ nsHTMLSharedObjectElement::DoneAddingChildren(PRBool aHaveNotified)
NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLSharedObjectElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLSharedObjectElement,
nsGenericHTMLElement)
tmp->Traverse(cb);
nsObjectLoadingContent::Traverse(tmp, cb);
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_ADDREF_INHERITED(nsHTMLSharedObjectElement, nsGenericElement)

Просмотреть файл

@ -253,6 +253,13 @@ nsXULElement::nsXULSlots::~nsXULSlots()
}
}
void
nsXULElement::nsXULSlots::Traverse(nsCycleCollectionTraversalCallback &cb)
{
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mSlots->mFrameLoader");
cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIFrameLoader*, mFrameLoader));
}
nsINode::nsSlots*
nsXULElement::CreateSlots()
{
@ -372,10 +379,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXULElement,
{
nsXULSlots* slots = static_cast<nsXULSlots*>(tmp->GetExistingSlots());
if (slots) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mFrameLoader");
nsISupports *frameLoader =
static_cast<nsIFrameLoader*>(slots->mFrameLoader);
cb.NoteXPCOMChild(frameLoader);
slots->Traverse(cb);
}
}
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END

Просмотреть файл

@ -593,10 +593,12 @@ protected:
class nsXULSlots : public nsGenericElement::nsDOMSlots
{
public:
nsXULSlots();
virtual ~nsXULSlots();
nsXULSlots();
virtual ~nsXULSlots();
nsRefPtr<nsFrameLoader> mFrameLoader;
void Traverse(nsCycleCollectionTraversalCallback &cb);
nsRefPtr<nsFrameLoader> mFrameLoader;
};
virtual nsINode::nsSlots* CreateSlots();