diff --git a/mozilla/content/base/src/nsContentList.cpp b/mozilla/content/base/src/nsContentList.cpp index 03ec806ec94..0f6c322e914 100644 --- a/mozilla/content/base/src/nsContentList.cpp +++ b/mozilla/content/base/src/nsContentList.cpp @@ -78,17 +78,25 @@ nsBaseContentList::~nsBaseContentList() { } +NS_IMPL_CYCLE_COLLECTION_CLASS(nsBaseContentList) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsBaseContentList) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mElements) +NS_IMPL_CYCLE_COLLECTION_UNLINK_END +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsBaseContentList) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mElements) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END // QueryInterface implementation for nsBaseContentList NS_INTERFACE_MAP_BEGIN(nsBaseContentList) NS_INTERFACE_MAP_ENTRY(nsIDOMNodeList) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNodeList) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(NodeList) + NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsBaseContentList) NS_INTERFACE_MAP_END -NS_IMPL_ADDREF(nsBaseContentList) -NS_IMPL_RELEASE(nsBaseContentList) +NS_IMPL_CYCLE_COLLECTING_ADDREF(nsBaseContentList) +NS_IMPL_CYCLE_COLLECTING_RELEASE(nsBaseContentList) NS_IMETHODIMP diff --git a/mozilla/content/base/src/nsContentList.h b/mozilla/content/base/src/nsContentList.h index 57cff9be7a6..cf97823b29f 100644 --- a/mozilla/content/base/src/nsContentList.h +++ b/mozilla/content/base/src/nsContentList.h @@ -52,6 +52,7 @@ #include "nsStubMutationObserver.h" #include "nsIAtom.h" #include "nsINameSpaceManager.h" +#include "nsCycleCollectionParticipant.h" // Magic namespace id that means "match all namespaces". This is // negative so it won't collide with actual namespace constants. @@ -78,10 +79,11 @@ public: nsBaseContentList(); virtual ~nsBaseContentList(); - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS // nsIDOMNodeList NS_DECL_NSIDOMNODELIST + NS_DECL_CYCLE_COLLECTION_CLASS(nsBaseContentList) virtual void AppendElement(nsIContent *aContent); virtual void RemoveElement(nsIContent *aContent); diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 6dbcda17f96..bd3e586618f 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -940,6 +940,76 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS_WITH_DESTROY(nsDocument, LastRelease()) +PR_STATIC_CALLBACK(PLDHashOperator) +SubDocTraverser(PLDHashTable *table, PLDHashEntryHdr *hdr, PRUint32 number, + void *arg) +{ + SubDocMapEntry *entry = NS_STATIC_CAST(SubDocMapEntry*, hdr); + nsCycleCollectionTraversalCallback *cb = + NS_STATIC_CAST(nsCycleCollectionTraversalCallback*, arg); + + cb->NoteXPCOMChild(entry->mKey); + nsISupports *doc = entry->mSubDocument; + if (doc) { + cb->NoteXPCOMChild(doc); + } + + return PL_DHASH_NEXT; +} + +PR_STATIC_CALLBACK(PRIntn) +RadioGroupsTraverser(nsHashKey *aKey, void *aData, void* aClosure) +{ + nsRadioGroupStruct *entry = NS_STATIC_CAST(nsRadioGroupStruct*, aData); + nsCycleCollectionTraversalCallback *cb = + NS_STATIC_CAST(nsCycleCollectionTraversalCallback*, aClosure); + + nsISupports *radioButton = entry->mSelectedRadioButton; + if (radioButton) { + cb->NoteXPCOMChild(radioButton); + } + + nsSmallVoidArray &radioButtons = entry->mRadioButtons; + PRUint32 i, count = radioButtons.Count(); + for (i = 0; i < count; ++i) { + cb->NoteXPCOMChild(NS_STATIC_CAST(nsIFormControl*, radioButtons[i])); + } + + + return kHashEnumerateNext; +} + +PR_STATIC_CALLBACK(PLDHashOperator) +BoxObjectTraverser(nsISupports* key, nsPIBoxObject* boxObject, void* userArg) +{ + nsCycleCollectionTraversalCallback *cb = + NS_STATIC_CAST(nsCycleCollectionTraversalCallback*, userArg); + + cb->NoteXPCOMChild(key); + cb->NoteXPCOMChild(boxObject); + + return PL_DHASH_NEXT; +} + +class LinkMapTraversalVisitor : public nsUint32ToContentHashEntry::Visitor +{ +public: + nsCycleCollectionTraversalCallback *mCb; + virtual void Visit(nsIContent* aContent) + { + mCb->NoteXPCOMChild(aContent); + } +}; + +PLDHashOperator PR_CALLBACK +LinkMapTraverser(nsUint32ToContentHashEntry* aEntry, void* userArg) +{ + LinkMapTraversalVisitor visitor; + visitor.mCb = NS_STATIC_CAST(nsCycleCollectionTraversalCallback*, userArg); + aEntry->VisitContent(&visitor); + return PL_DHASH_NEXT; +} + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDocument) // Traverse the mChildren nsAttrAndChildArray. for (PRInt32 indx = PRInt32(tmp->mChildren.ChildCount()); indx > 0; --indx) { @@ -956,6 +1026,15 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDocument) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mListenerManager) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDOMStyleSheets) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mScriptLoader) + + tmp->mRadioGroups.Enumerate(RadioGroupsTraverser, &cb); + + // The boxobject for an element will only exist as long as it's in the + // document, so we'll traverse the table here instead of from the element. + if (tmp->mBoxObjectTable) { + tmp->mBoxObjectTable->EnumerateRead(BoxObjectTraverser, &cb); + } + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mChannel) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mStyleAttrStyleSheet) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mScriptEventManager) @@ -963,6 +1042,12 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDocument) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLayoutHistoryState) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnloadBlocker) + // An element will only be in the linkmap as long as it's in the + // document, so we'll traverse the table here instead of from the element. + if (tmp->mLinkMap.IsInitialized()) { + tmp->mLinkMap.EnumerateEntries(LinkMapTraverser, &cb); + } + // Traverse all our nsCOMArrays. NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mStyleSheets) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mCatalogSheets) @@ -974,6 +1059,10 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDocument) if (preservedWrapper) cb.NoteXPCOMChild(preservedWrapper); } + + if (tmp->mSubDocuments && tmp->mSubDocuments->ops) { + PL_DHashTableEnumerate(tmp->mSubDocuments, SubDocTraverser, &cb); + } NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END @@ -3580,8 +3669,8 @@ nsDocument::GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult) if (!mBoxObjectTable) { mBoxObjectTable = new nsInterfaceHashtable; - if (mBoxObjectTable) { - mBoxObjectTable->Init(12); + if (mBoxObjectTable && !mBoxObjectTable->Init(12)) { + mBoxObjectTable = nsnull; } } else { // Want to use Get(content, aResult); but it's the wrong type diff --git a/mozilla/content/base/src/nsFrameLoader.cpp b/mozilla/content/base/src/nsFrameLoader.cpp index 88a37419c68..31e8a425e06 100644 --- a/mozilla/content/base/src/nsFrameLoader.cpp +++ b/mozilla/content/base/src/nsFrameLoader.cpp @@ -90,7 +90,16 @@ // we'd need to re-institute a fixed version of bug 98158. #define MAX_DEPTH_CONTENT_FRAMES 10 -NS_IMPL_ISUPPORTS1(nsFrameLoader, nsIFrameLoader) +NS_IMPL_CYCLE_COLLECTION_1(nsFrameLoader, mDocShell) + +NS_IMPL_CYCLE_COLLECTING_ADDREF(nsFrameLoader) +NS_IMPL_CYCLE_COLLECTING_RELEASE(nsFrameLoader) + +NS_INTERFACE_MAP_BEGIN(nsFrameLoader) + NS_INTERFACE_MAP_ENTRY(nsIFrameLoader) + NS_INTERFACE_MAP_ENTRY(nsISupports) + NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsFrameLoader) +NS_INTERFACE_MAP_END NS_IMETHODIMP nsFrameLoader::LoadFrame() diff --git a/mozilla/content/base/src/nsFrameLoader.h b/mozilla/content/base/src/nsFrameLoader.h index d422c046e00..c615f40edd2 100755 --- a/mozilla/content/base/src/nsFrameLoader.h +++ b/mozilla/content/base/src/nsFrameLoader.h @@ -60,7 +60,8 @@ public: mIsTopLevelContent(PR_FALSE) {} - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS(nsFrameLoader) NS_DECL_NSIFRAMELOADER private: diff --git a/mozilla/content/base/src/nsGenericElement.cpp b/mozilla/content/base/src/nsGenericElement.cpp index 4ed216f3ce4..54952d4ae8f 100644 --- a/mozilla/content/base/src/nsGenericElement.cpp +++ b/mozilla/content/base/src/nsGenericElement.cpp @@ -113,6 +113,7 @@ #include "nsEventDispatcher.h" #include "nsContentCreatorFunctions.h" #include "nsIFocusController.h" +#include "nsIControllers.h" #include "nsCycleCollectionParticipant.h" @@ -3003,9 +3004,28 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGenericElement) NS_IMPL_CYCLE_COLLECTION_UNLINK_END NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsGenericElement) + nsIDocument* ownerDoc = tmp->GetOwnerDoc(); + if (ownerDoc) { + ownerDoc->BindingManager()->Traverse(tmp, cb); + } + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_LISTENERMANAGER NS_IMPL_CYCLE_COLLECTION_TRAVERSE_PRESERVED_WRAPPER + if (tmp->HasProperties() && tmp->IsNodeOfType(nsINode::eXUL)) { + nsISupports* property = + NS_STATIC_CAST(nsISupports*, + tmp->GetProperty(nsGkAtoms::contextmenulistener)); + if (property) { + cb.NoteXPCOMChild(property); + } + property = NS_STATIC_CAST(nsISupports*, + tmp->GetProperty(nsGkAtoms::popuplistener)); + if (property) { + cb.NoteXPCOMChild(property); + } + } + // Traverse child content. { PRUint32 i; @@ -3020,9 +3040,11 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsGenericElement) if (slots) { if (slots->mAttributeMap.get()) cb.NoteXPCOMChild(slots->mAttributeMap.get()); + if (slots->mControllers) + cb.NoteXPCOMChild(slots->mControllers); } } -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_INTERFACE_MAP_BEGIN(nsGenericElement) diff --git a/mozilla/content/base/src/nsObjectLoadingContent.cpp b/mozilla/content/base/src/nsObjectLoadingContent.cpp index 252fcc2cafd..804d218330f 100644 --- a/mozilla/content/base/src/nsObjectLoadingContent.cpp +++ b/mozilla/content/base/src/nsObjectLoadingContent.cpp @@ -1028,6 +1028,14 @@ nsObjectLoadingContent::RemovedFromDocument() } } +void +nsObjectLoadingContent::Traverse(nsCycleCollectionTraversalCallback &cb) +{ + if (mFrameLoader) { + cb.NoteXPCOMChild(mFrameLoader); + } +} + // /* static */ PRBool nsObjectLoadingContent::IsSuccessfulRequest(nsIRequest* aRequest) diff --git a/mozilla/content/base/src/nsObjectLoadingContent.h b/mozilla/content/base/src/nsObjectLoadingContent.h index 7df7095f30f..4c47f3b86f3 100644 --- a/mozilla/content/base/src/nsObjectLoadingContent.h +++ b/mozilla/content/base/src/nsObjectLoadingContent.h @@ -215,6 +215,8 @@ class nsObjectLoadingContent : public nsImageLoadingContent */ void RemovedFromDocument(); + void Traverse(nsCycleCollectionTraversalCallback &cb); + private: /** * Check whether the given request represents a successful load. diff --git a/mozilla/content/html/content/src/Makefile.in b/mozilla/content/html/content/src/Makefile.in index 6ffc4ef7c70..1eb775d2173 100644 --- a/mozilla/content/html/content/src/Makefile.in +++ b/mozilla/content/html/content/src/Makefile.in @@ -80,7 +80,6 @@ EXPORTS = \ CPPSRCS = \ nsGenericHTMLElement.cpp \ - nsGenericDOMHTMLCollection.cpp \ nsFormSubmission.cpp \ nsImageMapUtils.cpp \ nsHTMLAnchorElement.cpp \ diff --git a/mozilla/content/html/content/src/nsGenericDOMHTMLCollection.cpp b/mozilla/content/html/content/src/nsGenericDOMHTMLCollection.cpp deleted file mode 100644 index e4d6db86bce..00000000000 --- a/mozilla/content/html/content/src/nsGenericDOMHTMLCollection.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ -#include "nsGenericDOMHTMLCollection.h" -#include "nsIDOMClassInfo.h" -#include "nsContentUtils.h" - - -nsGenericDOMHTMLCollection::nsGenericDOMHTMLCollection() -{ -} - -nsGenericDOMHTMLCollection::~nsGenericDOMHTMLCollection() -{ -} - -NS_IMPL_ADDREF(nsGenericDOMHTMLCollection) -NS_IMPL_RELEASE(nsGenericDOMHTMLCollection) - -NS_INTERFACE_MAP_BEGIN(nsGenericDOMHTMLCollection) - NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLCollection) - NS_INTERFACE_MAP_ENTRY(nsISupports) - NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLGenericCollection) -NS_INTERFACE_MAP_END diff --git a/mozilla/content/html/content/src/nsGenericDOMHTMLCollection.h b/mozilla/content/html/content/src/nsGenericDOMHTMLCollection.h deleted file mode 100644 index b03dc751190..00000000000 --- a/mozilla/content/html/content/src/nsGenericDOMHTMLCollection.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsGenericDOMHTMLCollection_h__ -#define nsGenericDOMHTMLCollection_h__ - -#include "nsISupports.h" -#include "nsIDOMHTMLCollection.h" - -/** - * This is a base class for a generic HTML collection. The base class - * provides implementations for nsISupports, but it is up to the - * subclass to implement the core HTML collection - * - * methods: - * GetLength - * Item - * NamedItem - * */ -class nsGenericDOMHTMLCollection : public nsIDOMHTMLCollection -{ -public: - nsGenericDOMHTMLCollection(); - virtual ~nsGenericDOMHTMLCollection(); - - NS_DECL_ISUPPORTS - - // The following need to be defined in the subclass - // nsIDOMHTMLCollection interface - NS_IMETHOD GetLength(PRUint32* aLength)=0; - NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn)=0; - NS_IMETHOD NamedItem(const nsAString& aName, nsIDOMNode** aReturn)=0; -}; - -#endif // nsGenericDOMHTMLCollection_h__ diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp index 59886989051..dc4dd84ace7 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp @@ -3065,9 +3065,16 @@ nsGenericHTMLFrameElement::~nsGenericHTMLFrameElement() } } +NS_IMPL_CYCLE_COLLECTION_CLASS(nsGenericHTMLFrameElement) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsGenericHTMLFrameElement, + nsGenericHTMLElement) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFrameLoader) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + NS_INTERFACE_MAP_BEGIN(nsGenericHTMLFrameElement) NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLFrameElement) NS_INTERFACE_MAP_ENTRY(nsIFrameLoaderOwner) + NS_INTERFACE_MAP_ENTRY_CYCLE_COLLECTION(nsGenericHTMLFrameElement) NS_INTERFACE_MAP_END_INHERITING(nsGenericHTMLElement) nsresult diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.h b/mozilla/content/html/content/src/nsGenericHTMLElement.h index ba8b0b05f66..8901d301b0e 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.h +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.h @@ -882,6 +882,9 @@ public: NS_IMETHOD GetTabIndex(PRInt32 *aTabIndex); NS_IMETHOD SetTabIndex(PRInt32 aTabIndex); + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsGenericHTMLFrameElement, + nsGenericHTMLElement) + protected: // This doesn't really ensure a frame loade in all cases, only when // it makes sense. @@ -1045,6 +1048,37 @@ NS_NewHTML##_elementName##Element(nsINodeInfo *aNodeInfo, PRBool aFromParser)\ NS_HTML_CONTENT_INTERFACE_MAP_AMBIGOUS_BEGIN(_class, _base, \ nsIDOMHTMLElement) +#define NS_HTML_CONTENT_CC_INTERFACE_MAP_AMBIGUOUS_BEGIN(_class, _base, \ + _base_if) \ + NS_IMETHODIMP _class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \ + { \ + NS_ENSURE_ARG_POINTER(aInstancePtr); \ + \ + if ( aIID.Equals(NS_GET_IID(nsCycleCollectionParticipant)) ) { \ + *aInstancePtr = &NS_CYCLE_COLLECTION_NAME(_class); \ + return NS_OK; \ + } \ + \ + *aInstancePtr = nsnull; \ + \ + nsresult rv; \ + \ + rv = _base::QueryInterface(aIID, aInstancePtr); \ + \ + if (NS_SUCCEEDED(rv)) \ + return rv; \ + \ + rv = DOMQueryInterface(NS_STATIC_CAST(_base_if *, this), aIID, \ + aInstancePtr); \ + \ + if (NS_SUCCEEDED(rv)) \ + return rv; \ + \ + nsISupports *foundInterface = nsnull; + +#define NS_HTML_CONTENT_CC_INTERFACE_MAP_BEGIN(_class, _base) \ + NS_HTML_CONTENT_CC_INTERFACE_MAP_AMBIGUOUS_BEGIN(_class, _base, \ + nsIDOMHTMLElement) #define NS_HTML_CONTENT_INTERFACE_MAP_END \ { \ diff --git a/mozilla/content/html/content/src/nsHTMLFormElement.cpp b/mozilla/content/html/content/src/nsHTMLFormElement.cpp index e3a7b25249e..bbdeac48b4b 100644 --- a/mozilla/content/html/content/src/nsHTMLFormElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLFormElement.cpp @@ -236,6 +236,9 @@ public: virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLFormElement, + nsGenericHTMLElement) + protected: nsresult DoSubmitOrReset(nsEvent* aEvent, PRInt32 aMessage); @@ -389,7 +392,7 @@ public: void DropFormReference(); - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS // nsIDOMHTMLCollection interface NS_DECL_NSIDOMHTMLCOLLECTION @@ -429,6 +432,9 @@ public: nsTArray mNotInElements; // Holds WEAK references + NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsFormControlList, + nsIDOMHTMLCollection) + protected: // Drop all our references to the form elements void Clear(); @@ -553,12 +559,31 @@ nsHTMLFormElement::Init() // nsISupports +PR_STATIC_CALLBACK(PLDHashOperator) +ElementTraverser(const nsAString& key, nsIDOMHTMLInputElement* element, + void* userArg) +{ + nsCycleCollectionTraversalCallback *cb = + NS_STATIC_CAST(nsCycleCollectionTraversalCallback*, userArg); + + cb->NoteXPCOMChild(element); + return PL_DHASH_NEXT; +} + +NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLFormElement) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLFormElement, + nsGenericHTMLElement) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mControls, + nsIDOMHTMLCollection) + tmp->mSelectedRadioButtons.EnumerateRead(ElementTraverser, &cb); +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + NS_IMPL_ADDREF_INHERITED(nsHTMLFormElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLFormElement, nsGenericElement) // QueryInterface implementation for nsHTMLFormElement -NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLFormElement, nsGenericHTMLElement) +NS_HTML_CONTENT_CC_INTERFACE_MAP_BEGIN(nsHTMLFormElement, nsGenericHTMLElement) NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLFormElement) NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLFormElement) @@ -1958,17 +1983,38 @@ nsFormControlList::FlushPendingNotifications() } } +PR_STATIC_CALLBACK(PLDHashOperator) +ControlTraverser(const nsAString& key, nsISupports* control, void* userArg) +{ + nsCycleCollectionTraversalCallback *cb = + NS_STATIC_CAST(nsCycleCollectionTraversalCallback*, userArg); + + cb->NoteXPCOMChild(control); + return PL_DHASH_NEXT; +} + +NS_IMPL_CYCLE_COLLECTION_CLASS(nsFormControlList) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsFormControlList) + tmp->Clear(); +NS_IMPL_CYCLE_COLLECTION_UNLINK_END +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsFormControlList) + tmp->mNameLookupTable.EnumerateRead(ControlTraverser, &cb); +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + // XPConnect interface list for nsFormControlList NS_INTERFACE_MAP_BEGIN(nsFormControlList) NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLFormControlList) NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLCollection) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMHTMLCollection) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLFormControlCollection) + NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsFormControlList) NS_INTERFACE_MAP_END -NS_IMPL_ADDREF(nsFormControlList) -NS_IMPL_RELEASE(nsFormControlList) +NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsFormControlList, + nsIDOMHTMLCollection) +NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsFormControlList, + nsIDOMHTMLCollection) // nsIDOMHTMLCollection interface diff --git a/mozilla/content/html/content/src/nsHTMLInputElement.cpp b/mozilla/content/html/content/src/nsHTMLInputElement.cpp index c77a1d9d214..d56034a2b5c 100644 --- a/mozilla/content/html/content/src/nsHTMLInputElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLInputElement.cpp @@ -238,6 +238,9 @@ public: virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLInputElement, + nsGenericHTMLFormElement) + protected: // Helper method nsresult SetValueInternal(const nsAString& aValue, @@ -371,13 +374,19 @@ nsHTMLInputElement::~nsHTMLInputElement() // nsISupports +NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLInputElement) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLInputElement, + nsGenericHTMLFormElement) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mControllers) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + NS_IMPL_ADDREF_INHERITED(nsHTMLInputElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLInputElement, nsGenericElement) // QueryInterface implementation for nsHTMLInputElement -NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLInputElement, - nsGenericHTMLFormElement) +NS_HTML_CONTENT_CC_INTERFACE_MAP_BEGIN(nsHTMLInputElement, + nsGenericHTMLFormElement) NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLInputElement) NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLInputElement) NS_INTERFACE_MAP_ENTRY(nsITextControlElement) diff --git a/mozilla/content/html/content/src/nsHTMLMapElement.cpp b/mozilla/content/html/content/src/nsHTMLMapElement.cpp index 815eb1e0620..4f434b31dd5 100644 --- a/mozilla/content/html/content/src/nsHTMLMapElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLMapElement.cpp @@ -74,6 +74,9 @@ public: PRBool aNullParent = PR_TRUE); virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLMapElement, + nsGenericHTMLElement) + protected: nsRefPtr mAreas; }; @@ -87,12 +90,19 @@ nsHTMLMapElement::nsHTMLMapElement(nsINodeInfo *aNodeInfo) { } +NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLMapElement) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLMapElement, + nsGenericHTMLElement) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mAreas, + nsBaseContentList) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + NS_IMPL_ADDREF_INHERITED(nsHTMLMapElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLMapElement, nsGenericElement) // QueryInterface implementation for nsHTMLMapElement -NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLMapElement, nsGenericHTMLElement) +NS_HTML_CONTENT_CC_INTERFACE_MAP_BEGIN(nsHTMLMapElement, nsGenericHTMLElement) NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLMapElement) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLMapElement) NS_HTML_CONTENT_INTERFACE_MAP_END diff --git a/mozilla/content/html/content/src/nsHTMLObjectElement.cpp b/mozilla/content/html/content/src/nsHTMLObjectElement.cpp index 668fda88f02..90e29abf8d5 100644 --- a/mozilla/content/html/content/src/nsHTMLObjectElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLObjectElement.cpp @@ -109,6 +109,9 @@ public: virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLObjectElement, + nsGenericHTMLElement) + private: /** * Calls LoadObject with the correct arguments to start the plugin load. @@ -153,11 +156,17 @@ nsHTMLObjectElement::DoneAddingChildren(PRBool aHaveNotified) return NS_OK; } +NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLObjectElement) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLObjectElement, + nsGenericHTMLFormElement) + tmp->Traverse(cb); +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + NS_IMPL_ADDREF_INHERITED(nsHTMLObjectElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLObjectElement, nsGenericElement) -NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLObjectElement, - nsGenericHTMLFormElement) +NS_HTML_CONTENT_CC_INTERFACE_MAP_BEGIN(nsHTMLObjectElement, + nsGenericHTMLFormElement) NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLObjectElement) NS_INTERFACE_MAP_ENTRY(imgIDecoderObserver) NS_INTERFACE_MAP_ENTRY(nsIRequestObserver) diff --git a/mozilla/content/html/content/src/nsHTMLSelectElement.cpp b/mozilla/content/html/content/src/nsHTMLSelectElement.cpp index 9b053b039da..d3f7d63394c 100644 --- a/mozilla/content/html/content/src/nsHTMLSelectElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLSelectElement.cpp @@ -57,7 +57,6 @@ #include "nsIDOMHTMLOptGroupElement.h" #include "nsIOptionElement.h" #include "nsIEventStateManager.h" -#include "nsGenericDOMHTMLCollection.h" #include "nsISelectElement.h" #include "nsISelectControlFrame.h" #include "nsIDOMHTMLOptionsCollection.h" @@ -95,13 +94,13 @@ class nsHTMLSelectElement; */ class nsHTMLOptionCollection: public nsIDOMHTMLOptionsCollection, public nsIDOMNSHTMLOptionCollection, - public nsGenericDOMHTMLCollection + public nsIDOMHTMLCollection { public: nsHTMLOptionCollection(nsHTMLSelectElement* aSelect); virtual ~nsHTMLOptionCollection(); - NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTING_ISUPPORTS // nsIDOMHTMLOptionsCollection interface NS_DECL_NSIDOMHTMLOPTIONSCOLLECTION @@ -112,6 +111,9 @@ public: // nsIDOMHTMLCollection interface, all its methods are defined in // nsIDOMHTMLOptionsCollection + NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsHTMLOptionCollection, + nsIDOMNSHTMLOptionCollection) + // Helpers for nsHTMLSelectElement /** * Insert an option @@ -291,6 +293,9 @@ public: virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLSelectElement, + nsGenericHTMLFormElement) + protected: // Helper Methods /** @@ -517,13 +522,20 @@ nsHTMLSelectElement::~nsHTMLSelectElement() // ISupports +NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLSelectElement) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLSelectElement, + nsGenericHTMLFormElement) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mOptions, + nsIDOMHTMLCollection) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + NS_IMPL_ADDREF_INHERITED(nsHTMLSelectElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLSelectElement, nsGenericElement) // QueryInterface implementation for nsHTMLSelectElement -NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLSelectElement, - nsGenericHTMLFormElement) +NS_HTML_CONTENT_CC_INTERFACE_MAP_BEGIN(nsHTMLSelectElement, + nsGenericHTMLFormElement) NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLSelectElement) NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLSelectElement) NS_INTERFACE_MAP_ENTRY(nsIDOMNSXBLFormControl) @@ -2224,6 +2236,14 @@ nsHTMLOptionCollection::GetOptionIndex(nsIDOMHTMLOptionElement* aOption, } +NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLOptionCollection) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsHTMLOptionCollection) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mElements) +NS_IMPL_CYCLE_COLLECTION_UNLINK_END +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsHTMLOptionCollection) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mElements) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + // nsISupports // QueryInterface implementation for nsHTMLOptionCollection @@ -2233,11 +2253,14 @@ NS_INTERFACE_MAP_BEGIN(nsHTMLOptionCollection) NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLCollection) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNSHTMLOptionCollection) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLOptionsCollection) + NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsHTMLOptionCollection) NS_INTERFACE_MAP_END -NS_IMPL_ADDREF_INHERITED(nsHTMLOptionCollection, nsGenericDOMHTMLCollection) -NS_IMPL_RELEASE_INHERITED(nsHTMLOptionCollection, nsGenericDOMHTMLCollection) +NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsHTMLOptionCollection, + nsIDOMNSHTMLOptionCollection) +NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsHTMLOptionCollection, + nsIDOMNSHTMLOptionCollection) // nsIDOMNSHTMLOptionCollection interface diff --git a/mozilla/content/html/content/src/nsHTMLSharedObjectElement.cpp b/mozilla/content/html/content/src/nsHTMLSharedObjectElement.cpp index 298bff98172..d597d9daa27 100644 --- a/mozilla/content/html/content/src/nsHTMLSharedObjectElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLSharedObjectElement.cpp @@ -128,6 +128,9 @@ public: virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLSharedObjectElement, + nsGenericHTMLElement) + private: /** * Calls LoadObject with the correct arguments to start the plugin load. @@ -197,12 +200,18 @@ nsHTMLSharedObjectElement::DoneAddingChildren(PRBool aHaveNotified) return NS_OK; } +NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLSharedObjectElement) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLSharedObjectElement, + nsGenericHTMLElement) + tmp->Traverse(cb); +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + NS_IMPL_ADDREF_INHERITED(nsHTMLSharedObjectElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLSharedObjectElement, nsGenericElement) -NS_HTML_CONTENT_INTERFACE_MAP_AMBIGOUS_BEGIN(nsHTMLSharedObjectElement, - nsGenericHTMLElement, - nsIDOMHTMLAppletElement) +NS_HTML_CONTENT_CC_INTERFACE_MAP_AMBIGUOUS_BEGIN(nsHTMLSharedObjectElement, + nsGenericHTMLElement, + nsIDOMHTMLAppletElement) NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIDOMHTMLAppletElement, applet) NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIDOMHTMLEmbedElement, embed) #ifdef MOZ_SVG diff --git a/mozilla/content/html/content/src/nsHTMLTableElement.cpp b/mozilla/content/html/content/src/nsHTMLTableElement.cpp index 28f9b3d8160..33c812b804d 100644 --- a/mozilla/content/html/content/src/nsHTMLTableElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTableElement.cpp @@ -41,7 +41,6 @@ #include "nsIDOMEventReceiver.h" #include "nsDOMError.h" #include "nsContentList.h" -#include "nsGenericDOMHTMLCollection.h" #include "nsMappedAttributes.h" #include "nsGenericHTMLElement.h" #include "nsGkAtoms.h" @@ -90,6 +89,9 @@ public: virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLTableElement, + nsGenericHTMLElement) + protected: already_AddRefed GetSection(nsIAtom *aTag); @@ -103,7 +105,7 @@ protected: * This class provides a late-bound collection of rows in a table. * mParent is NOT ref-counted to avoid circular references */ -class TableRowsCollection : public nsGenericDOMHTMLCollection +class TableRowsCollection : public nsIDOMHTMLCollection { public: TableRowsCollection(nsHTMLTableElement *aParent); @@ -111,13 +113,13 @@ public: nsresult Init(); - NS_IMETHOD GetLength(PRUint32* aLength); - NS_IMETHOD Item(PRUint32 aIndex, nsIDOMNode** aReturn); - NS_IMETHOD NamedItem(const nsAString& aName, - nsIDOMNode** aReturn); + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_NSIDOMHTMLCOLLECTION NS_IMETHOD ParentDestroyed(); + NS_DECL_CYCLE_COLLECTION_CLASS(TableRowsCollection) + protected: // Those rows that are not in table sections nsRefPtr mOrphanRows; @@ -126,9 +128,8 @@ protected: TableRowsCollection::TableRowsCollection(nsHTMLTableElement *aParent) - : nsGenericDOMHTMLCollection() + : mParent(aParent) { - mParent = aParent; } TableRowsCollection::~TableRowsCollection() @@ -139,6 +140,23 @@ TableRowsCollection::~TableRowsCollection() // reference for us. } +NS_IMPL_CYCLE_COLLECTION_CLASS(TableRowsCollection) +NS_IMPL_CYCLE_COLLECTION_UNLINK_0(TableRowsCollection) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(TableRowsCollection) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mOrphanRows, + nsBaseContentList) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +NS_IMPL_CYCLE_COLLECTING_ADDREF(TableRowsCollection) +NS_IMPL_CYCLE_COLLECTING_RELEASE(TableRowsCollection) + +NS_INTERFACE_MAP_BEGIN(TableRowsCollection) + NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLCollection) + NS_INTERFACE_MAP_ENTRY(nsISupports) + NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLGenericCollection) + NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(TableRowsCollection) +NS_INTERFACE_MAP_END + nsresult TableRowsCollection::Init() { @@ -333,12 +351,20 @@ nsHTMLTableElement::~nsHTMLTableElement() } +NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLTableElement) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLTableElement, + nsGenericHTMLElement) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mTBodies, + nsBaseContentList) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRows) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + NS_IMPL_ADDREF_INHERITED(nsHTMLTableElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLTableElement, nsGenericElement) // QueryInterface implementation for nsHTMLTableElement -NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLTableElement, nsGenericHTMLElement) +NS_HTML_CONTENT_CC_INTERFACE_MAP_BEGIN(nsHTMLTableElement, nsGenericHTMLElement) NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLTableElement) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLTableElement) NS_HTML_CONTENT_INTERFACE_MAP_END diff --git a/mozilla/content/html/content/src/nsHTMLTableRowElement.cpp b/mozilla/content/html/content/src/nsHTMLTableRowElement.cpp index 96e5eabf711..0aba51efede 100644 --- a/mozilla/content/html/content/src/nsHTMLTableRowElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTableRowElement.cpp @@ -84,6 +84,9 @@ public: virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLTableRowElement, + nsGenericHTMLElement) + protected: nsresult GetSection(nsIDOMHTMLTableSectionElement** aSection); nsresult GetTable(nsIDOMHTMLTableElement** aTable); @@ -124,13 +127,20 @@ nsHTMLTableRowElement::nsHTMLTableRowElement(nsINodeInfo *aNodeInfo) { } +NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLTableRowElement) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLTableRowElement, + nsGenericHTMLElement) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mCells, + nsBaseContentList) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + NS_IMPL_ADDREF_INHERITED(nsHTMLTableRowElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLTableRowElement, nsGenericElement) // QueryInterface implementation for nsHTMLTableRowElement -NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLTableRowElement, - nsGenericHTMLElement) +NS_HTML_CONTENT_CC_INTERFACE_MAP_BEGIN(nsHTMLTableRowElement, + nsGenericHTMLElement) NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLTableRowElement) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLTableRowElement) NS_HTML_CONTENT_INTERFACE_MAP_END diff --git a/mozilla/content/html/content/src/nsHTMLTableSectionElement.cpp b/mozilla/content/html/content/src/nsHTMLTableSectionElement.cpp index 4240367dd77..edbf8c29721 100644 --- a/mozilla/content/html/content/src/nsHTMLTableSectionElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTableSectionElement.cpp @@ -79,6 +79,9 @@ public: virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLTableSectionElement, + nsGenericHTMLElement) + protected: nsRefPtr mRows; }; @@ -92,13 +95,20 @@ nsHTMLTableSectionElement::nsHTMLTableSectionElement(nsINodeInfo *aNodeInfo) { } +NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLTableSectionElement) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLTableSectionElement, + nsGenericHTMLElement) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mRows, + nsBaseContentList) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + NS_IMPL_ADDREF_INHERITED(nsHTMLTableSectionElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLTableSectionElement, nsGenericElement) // QueryInterface implementation for nsHTMLTableSectionElement -NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLTableSectionElement, - nsGenericHTMLElement) +NS_HTML_CONTENT_CC_INTERFACE_MAP_BEGIN(nsHTMLTableSectionElement, + nsGenericHTMLElement) NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLTableSectionElement) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLTableSectionElement) NS_HTML_CONTENT_INTERFACE_MAP_END diff --git a/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp b/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp index d1fc64bd7d9..f3f294c029e 100644 --- a/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTextAreaElement.cpp @@ -165,6 +165,9 @@ public: nsIContent* aChild, PRInt32 aIndexInContainer); + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsHTMLTextAreaElement, + nsGenericHTMLFormElement) + protected: nsCOMPtr mControllers; /** The current value. This is null if the frame owns the value. */ @@ -225,13 +228,23 @@ nsHTMLTextAreaElement::~nsHTMLTextAreaElement() } +NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLTextAreaElement) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsHTMLTextAreaElement, + nsGenericHTMLFormElement) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mControllers) +NS_IMPL_CYCLE_COLLECTION_UNLINK_END +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLTextAreaElement, + nsGenericHTMLFormElement) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mControllers) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + NS_IMPL_ADDREF_INHERITED(nsHTMLTextAreaElement, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsHTMLTextAreaElement, nsGenericElement) // QueryInterface implementation for nsHTMLTextAreaElement -NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLTextAreaElement, - nsGenericHTMLFormElement) +NS_HTML_CONTENT_CC_INTERFACE_MAP_BEGIN(nsHTMLTextAreaElement, + nsGenericHTMLFormElement) NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLTextAreaElement) NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLTextAreaElement) NS_INTERFACE_MAP_ENTRY(nsITextControlElement) diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index e8d1b4efb46..74fdbd6be00 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -343,6 +343,40 @@ nsHTMLDocument::~nsHTMLDocument() } } +NS_IMPL_CYCLE_COLLECTION_CLASS(nsHTMLDocument) + +PR_STATIC_CALLBACK(PLDHashOperator) +IdAndNameMapEntryTraverse(PLDHashTable *table, PLDHashEntryHdr *hdr, + PRUint32 number, void *arg) +{ + nsCycleCollectionTraversalCallback *cb = + NS_STATIC_CAST(nsCycleCollectionTraversalCallback*, arg); + IdAndNameMapEntry *entry = NS_STATIC_CAST(IdAndNameMapEntry*, hdr); + + if (entry->mNameContentList && entry->mNameContentList != NAME_NOT_VALID) + cb->NoteXPCOMChild(entry->mNameContentList); + + return PL_DHASH_NEXT; +} + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsHTMLDocument, nsDocument) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mBodyContent) + if (tmp->mIdAndNameHashTable.ops) { + PL_DHashTableEnumerate(&tmp->mIdAndNameHashTable, + IdAndNameMapEntryTraverse, + &cb); + } + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mImageMaps) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mImages) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mApplets) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mEmbeds) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLinks) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mAnchors) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mForms, nsIDOMNodeList) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mFormControls, + nsIDOMNodeList) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + NS_IMPL_ADDREF_INHERITED(nsHTMLDocument, nsDocument) NS_IMPL_RELEASE_INHERITED(nsHTMLDocument, nsDocument) @@ -353,6 +387,7 @@ NS_INTERFACE_MAP_BEGIN(nsHTMLDocument) NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLDocument) NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLDocument) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLDocument) + NS_INTERFACE_MAP_ENTRY_CYCLE_COLLECTION(nsHTMLDocument) NS_INTERFACE_MAP_END_INHERITING(nsDocument) diff --git a/mozilla/content/html/document/src/nsHTMLDocument.h b/mozilla/content/html/document/src/nsHTMLDocument.h index 80493f82f2e..f77506a6058 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.h +++ b/mozilla/content/html/document/src/nsHTMLDocument.h @@ -207,6 +207,8 @@ public: nsIContent** aResult); #endif + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsHTMLDocument, nsDocument) + protected: nsresult GetPixelDimensions(nsIPresShell* aShell, PRInt32* aWidth, diff --git a/mozilla/content/xbl/src/nsBindingManager.cpp b/mozilla/content/xbl/src/nsBindingManager.cpp index 8aa9a8005a1..beef0482288 100644 --- a/mozilla/content/xbl/src/nsBindingManager.cpp +++ b/mozilla/content/xbl/src/nsBindingManager.cpp @@ -333,30 +333,8 @@ LoadingDocHashtableTraverser(nsIURI* key, return PL_DHASH_NEXT; } -static PLDHashOperator -XBLBindingHashtableTraverser(nsISupports* key, - nsXBLBinding* binding, - void* userArg) -{ - nsCycleCollectionTraversalCallback *cb = - NS_STATIC_CAST(nsCycleCollectionTraversalCallback*, userArg); - - // XBLBindings aren't nsISupports, so we don't tell the cycle collector - // about them explicitly. Instead, we traverse their contents directly - // here. - - while (binding) { - nsISupports *c = binding->GetAnonymousContent(); - if (c) - cb->NoteXPCOMChild(c); - binding = binding->GetBaseBinding(); - } - return PL_DHASH_NEXT; -} - NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsBindingManager) - if (tmp->mBindingTable.IsInitialized()) - tmp->mBindingTable.EnumerateRead(&XBLBindingHashtableTraverser, &cb); + // The hashes keyed on nsIContent are traversed from the nsIContent itself. if (tmp->mDocumentTable.IsInitialized()) tmp->mDocumentTable.EnumerateRead(&DocumentInfoHashtableTraverser, &cb); if (tmp->mLoadingDocTable.IsInitialized()) @@ -1357,3 +1335,36 @@ nsBindingManager::NodeWillBeDestroyed(const nsINode *aNode) { NS_BINDINGMANAGER_NOTIFY_OBSERVERS(NodeWillBeDestroyed, (aNode)); } + +void +nsBindingManager::Traverse(nsIContent *aContent, + nsCycleCollectionTraversalCallback &cb) +{ + nsXBLBinding *binding = GetBinding(aContent); + if (binding) { + // XXX nsXBLBinding isn't nsISupports but it is refcounted, so we can't + // traverse it. + cb.NoteXPCOMChild(aContent); + } + nsISupports *value; + if (mContentListTable.ops && + (value = LookupObject(mContentListTable, aContent))) { + cb.NoteXPCOMChild(aContent); + cb.NoteXPCOMChild(value); + } + if (mAnonymousNodesTable.ops && + (value = LookupObject(mAnonymousNodesTable, aContent))) { + cb.NoteXPCOMChild(aContent); + cb.NoteXPCOMChild(value); + } + if (mInsertionParentTable.ops && + (value = LookupObject(mInsertionParentTable, aContent))) { + cb.NoteXPCOMChild(aContent); + cb.NoteXPCOMChild(value); + } + if (mWrapperTable.ops && + (value = LookupObject(mWrapperTable, aContent))) { + cb.NoteXPCOMChild(aContent); + cb.NoteXPCOMChild(value); + } +} diff --git a/mozilla/content/xbl/src/nsBindingManager.h b/mozilla/content/xbl/src/nsBindingManager.h index 37fb0faaec0..c373ff1cc01 100755 --- a/mozilla/content/xbl/src/nsBindingManager.h +++ b/mozilla/content/xbl/src/nsBindingManager.h @@ -199,6 +199,9 @@ public: RuleProcessorData* aData, PRBool* aCutOffInheritance); + NS_HIDDEN_(void) Traverse(nsIContent *aContent, + nsCycleCollectionTraversalCallback &cb); + NS_DECL_CYCLE_COLLECTION_CLASS(nsBindingManager) protected: diff --git a/mozilla/content/xbl/src/nsXBLDocumentInfo.cpp b/mozilla/content/xbl/src/nsXBLDocumentInfo.cpp index cd721431b0c..19748d3a5fe 100644 --- a/mozilla/content/xbl/src/nsXBLDocumentInfo.cpp +++ b/mozilla/content/xbl/src/nsXBLDocumentInfo.cpp @@ -66,7 +66,7 @@ public: nsXBLDocGlobalObject(); // nsISupports interface - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS // nsIScriptGlobalObject methods virtual nsresult EnsureScriptEnvironment(PRUint32 aLangID); @@ -86,6 +86,9 @@ public: static JSBool doCheckAccess(JSContext *cx, JSObject *obj, jsval id, PRUint32 accessType); + NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXBLDocGlobalObject, + nsIScriptGlobalObject) + protected: virtual ~nsXBLDocGlobalObject(); @@ -203,7 +206,21 @@ nsXBLDocGlobalObject::~nsXBLDocGlobalObject() {} -NS_IMPL_ISUPPORTS2(nsXBLDocGlobalObject, nsIScriptGlobalObject, nsIScriptObjectPrincipal) +NS_IMPL_CYCLE_COLLECTION_CLASS(nsXBLDocGlobalObject) +NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsXBLDocGlobalObject) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXBLDocGlobalObject) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mScriptContext) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +NS_INTERFACE_MAP_BEGIN(nsXBLDocGlobalObject) + NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObject) + NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptGlobalObject) + NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsXBLDocGlobalObject) +NS_INTERFACE_MAP_END + +NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsXBLDocGlobalObject, nsIScriptGlobalObject) +NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsXBLDocGlobalObject, nsIScriptGlobalObject) void JS_DLL_CALLBACK XBL_ProtoErrorReporter(JSContext *cx, @@ -426,7 +443,28 @@ static PRBool IsChromeURI(nsIURI* aURI) /* Implementation file */ -NS_IMPL_CYCLE_COLLECTION_2(nsXBLDocumentInfo, mDocument, mGlobalObject) +static PRIntn PR_CALLBACK +TraverseProtos(nsHashKey *aKey, void *aData, void* aClosure) +{ + nsCycleCollectionTraversalCallback *cb = + NS_STATIC_CAST(nsCycleCollectionTraversalCallback*, aClosure); + nsXBLPrototypeBinding *proto = NS_STATIC_CAST(nsXBLPrototypeBinding*, aData); + proto->Traverse(*cb); + return kHashEnumerateNext; +} + +NS_IMPL_CYCLE_COLLECTION_CLASS(nsXBLDocumentInfo) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXBLDocumentInfo) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDocument) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mGlobalObject) +NS_IMPL_CYCLE_COLLECTION_UNLINK_END +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXBLDocumentInfo) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocument) + if (tmp->mBindingTable) { + tmp->mBindingTable->Enumerate(TraverseProtos, &cb); + } + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mGlobalObject) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_INTERFACE_MAP_BEGIN(nsXBLDocumentInfo) NS_INTERFACE_MAP_ENTRY(nsIXBLDocumentInfo) diff --git a/mozilla/content/xbl/src/nsXBLPrototypeBinding.cpp b/mozilla/content/xbl/src/nsXBLPrototypeBinding.cpp index 705a48ddade..aef60f7a4b6 100644 --- a/mozilla/content/xbl/src/nsXBLPrototypeBinding.cpp +++ b/mozilla/content/xbl/src/nsXBLPrototypeBinding.cpp @@ -76,6 +76,7 @@ #include "nsICSSLoader.h" #include "nsIStyleRuleProcessor.h" +#include "nsXBLResourceLoader.h" // Helper Classes ===================================================================== @@ -278,6 +279,15 @@ nsXBLPrototypeBinding::Init(const nsACString& aID, return NS_OK; } +void +nsXBLPrototypeBinding::Traverse(nsCycleCollectionTraversalCallback &cb) const +{ + cb.NoteXPCOMChild(mBinding); + // XXX mInsertionPointTable! + if (mResources && mResources->mLoader) + cb.NoteXPCOMChild(mResources->mLoader); +} + void nsXBLPrototypeBinding::Initialize() { diff --git a/mozilla/content/xbl/src/nsXBLPrototypeBinding.h b/mozilla/content/xbl/src/nsXBLPrototypeBinding.h index 30b9791f718..0ba5951308c 100644 --- a/mozilla/content/xbl/src/nsXBLPrototypeBinding.h +++ b/mozilla/content/xbl/src/nsXBLPrototypeBinding.h @@ -172,7 +172,9 @@ public: nsresult Init(const nsACString& aRef, nsIXBLDocumentInfo* aInfo, nsIContent* aElement); - + + void Traverse(nsCycleCollectionTraversalCallback &cb) const; + // Static members static PRUint32 gRefCnt; diff --git a/mozilla/content/xbl/src/nsXBLResourceLoader.cpp b/mozilla/content/xbl/src/nsXBLResourceLoader.cpp index 33812e5e27d..de53a4ed8a5 100644 --- a/mozilla/content/xbl/src/nsXBLResourceLoader.cpp +++ b/mozilla/content/xbl/src/nsXBLResourceLoader.cpp @@ -59,7 +59,26 @@ #include "nsCSSRuleProcessor.h" #include "nsContentUtils.h" -NS_IMPL_ISUPPORTS1(nsXBLResourceLoader, nsICSSLoaderObserver) +NS_IMPL_CYCLE_COLLECTION_CLASS(nsXBLResourceLoader) +NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsXBLResourceLoader) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXBLResourceLoader) + if (tmp->mBoundElements) { + PRUint32 i, count; + tmp->mBoundElements->Count(&count); + for (i = 0; i < count; ++i) { + cb.NoteXPCOMChild(tmp->mBoundElements->ElementAt(i)); + } + } +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +NS_INTERFACE_MAP_BEGIN(nsXBLResourceLoader) + NS_INTERFACE_MAP_ENTRY(nsICSSLoaderObserver) + NS_INTERFACE_MAP_ENTRY(nsISupports) + NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsXBLResourceLoader) +NS_INTERFACE_MAP_END + +NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXBLResourceLoader) +NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXBLResourceLoader) nsXBLResourceLoader::nsXBLResourceLoader(nsXBLPrototypeBinding* aBinding, nsXBLPrototypeResources* aResources) diff --git a/mozilla/content/xbl/src/nsXBLResourceLoader.h b/mozilla/content/xbl/src/nsXBLResourceLoader.h index f90bb2800ab..f14e668161c 100644 --- a/mozilla/content/xbl/src/nsXBLResourceLoader.h +++ b/mozilla/content/xbl/src/nsXBLResourceLoader.h @@ -39,6 +39,7 @@ #include "nsCOMPtr.h" #include "nsICSSLoaderObserver.h" #include "nsISupportsArray.h" +#include "nsCycleCollectionParticipant.h" class nsIContent; class nsIAtom; @@ -72,7 +73,8 @@ struct nsXBLResource { class nsXBLResourceLoader : public nsICSSLoaderObserver { public: - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS(nsXBLResourceLoader) // nsICSSLoaderObserver NS_IMETHOD StyleSheetLoaded(nsICSSStyleSheet* aSheet, PRBool aWasAlternate, diff --git a/mozilla/content/xml/document/src/nsXMLDocument.cpp b/mozilla/content/xml/document/src/nsXMLDocument.cpp index 9b457c7b8c4..3dc9bbf7873 100644 --- a/mozilla/content/xml/document/src/nsXMLDocument.cpp +++ b/mozilla/content/xml/document/src/nsXMLDocument.cpp @@ -191,6 +191,11 @@ nsXMLDocument::~nsXMLDocument() mLoopingForSyncLoad = PR_FALSE; } +NS_IMPL_CYCLE_COLLECTION_CLASS(nsXMLDocument) + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXMLDocument, nsDocument) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mScriptContext) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END // QueryInterface implementation for nsXMLDocument NS_INTERFACE_MAP_BEGIN(nsXMLDocument) @@ -198,6 +203,7 @@ NS_INTERFACE_MAP_BEGIN(nsXMLDocument) NS_INTERFACE_MAP_ENTRY(nsIChannelEventSink) NS_INTERFACE_MAP_ENTRY(nsIDOMXMLDocument) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(XMLDocument) + NS_INTERFACE_MAP_ENTRY_CYCLE_COLLECTION(nsXMLDocument) NS_INTERFACE_MAP_END_INHERITING(nsDocument) diff --git a/mozilla/content/xml/document/src/nsXMLDocument.h b/mozilla/content/xml/document/src/nsXMLDocument.h index 53010626d76..66544689351 100644 --- a/mozilla/content/xml/document/src/nsXMLDocument.h +++ b/mozilla/content/xml/document/src/nsXMLDocument.h @@ -97,6 +97,8 @@ public: virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsXMLDocument, nsDocument) + protected: virtual nsresult GetLoadGroup(nsILoadGroup **aLoadGroup); diff --git a/mozilla/content/xul/document/src/nsXULControllers.cpp b/mozilla/content/xul/document/src/nsXULControllers.cpp index d3a8c2f65e5..56ea10739c6 100644 --- a/mozilla/content/xul/document/src/nsXULControllers.cpp +++ b/mozilla/content/xul/document/src/nsXULControllers.cpp @@ -97,18 +97,33 @@ NS_NewXULControllers(nsISupports* aOuter, REFNSIID aIID, void** aResult) return rv; } -// QueryInterface implementation for nsXULControllers +NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULControllers) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXULControllers) + tmp->DeleteControllers(); +NS_IMPL_CYCLE_COLLECTION_UNLINK_END +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULControllers) + { + PRUint32 i, count = tmp->mControllers.Count(); + for (i = 0; i < count; ++i) { + nsXULControllerData* controllerData = + NS_STATIC_CAST(nsXULControllerData*, tmp->mControllers[i]); + if (controllerData) { + cb.NoteXPCOMChild(controllerData->mController); + } + } + } +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + NS_INTERFACE_MAP_BEGIN(nsXULControllers) NS_INTERFACE_MAP_ENTRY(nsIControllers) NS_INTERFACE_MAP_ENTRY(nsISecurityCheckedComponent) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIControllers) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(XULControllers) + NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsXULControllers) NS_INTERFACE_MAP_END - -NS_IMPL_ADDREF(nsXULControllers) -NS_IMPL_RELEASE(nsXULControllers) - +NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsXULControllers, nsIControllers) +NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsXULControllers, nsIControllers) NS_IMETHODIMP nsXULControllers::GetControllerForCommand(const char *aCommand, nsIController** _retval) diff --git a/mozilla/content/xul/document/src/nsXULControllers.h b/mozilla/content/xul/document/src/nsXULControllers.h index 3ad6a7049aa..e06b3a9aa61 100644 --- a/mozilla/content/xul/document/src/nsXULControllers.h +++ b/mozilla/content/xul/document/src/nsXULControllers.h @@ -51,6 +51,7 @@ #include "nsIControllers.h" #include "nsISupportsArray.h" #include "nsISecurityCheckedComponent.h" +#include "nsCycleCollectionParticipant.h" /* non-XPCOM class for holding controllers and their IDs */ class nsXULControllerData @@ -72,8 +73,6 @@ public: return NS_OK; } -protected: - PRUint32 mControllerID; nsCOMPtr mController; }; @@ -88,7 +87,8 @@ public: friend NS_IMETHODIMP NS_NewXULControllers(nsISupports* aOuter, REFNSIID aIID, void** aResult); - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXULControllers, nsIControllers) NS_DECL_NSICONTROLLERS NS_DECL_NSISECURITYCHECKEDCOMPONENT diff --git a/mozilla/content/xul/document/src/nsXULDocument.cpp b/mozilla/content/xul/document/src/nsXULDocument.cpp index 95d6b5ccf25..55afe96f985 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULDocument.cpp @@ -296,6 +296,72 @@ NS_NewXULDocument(nsIXULDocument** result) // nsISupports interface // +NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULDocument) + +static PRIntn +TraverseElement(const PRUnichar* aID, nsIContent* aElement, void* aContext) +{ + nsCycleCollectionTraversalCallback *cb = + NS_STATIC_CAST(nsCycleCollectionTraversalCallback*, aContext); + + cb->NoteXPCOMChild(aElement); + + return HT_ENUMERATE_NEXT; +} + +static PLDHashOperator PR_CALLBACK +TraverseTemplateBuilders(nsISupports* aKey, nsIXULTemplateBuilder* aData, + void* aContext) +{ + nsCycleCollectionTraversalCallback *cb = + NS_STATIC_CAST(nsCycleCollectionTraversalCallback*, aContext); + + cb->NoteXPCOMChild(aKey); + cb->NoteXPCOMChild(aData); + + return PL_DHASH_NEXT; +} + +static PLDHashOperator PR_CALLBACK +TraverseObservers(nsIURI* aKey, nsIObserver* aData, void* aContext) +{ + nsCycleCollectionTraversalCallback *cb = + NS_STATIC_CAST(nsCycleCollectionTraversalCallback*, aContext); + + cb->NoteXPCOMChild(aData); + + return PL_DHASH_NEXT; +} + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsXULDocument, nsXMLDocument) + // XXX tmp->mForwardReferences? + // XXX tmp->mContextStack? + + tmp->mElementMap.Enumerate(TraverseElement, &cb); + + // An element will only have a template builder as long as it's in the + // document, so we'll traverse the table here instead of from the element. + if (tmp->mTemplateBuilderTable) + tmp->mTemplateBuilderTable->EnumerateRead(TraverseTemplateBuilders, &cb); + + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mCurrentPrototype, + nsIScriptGlobalObjectOwner) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mMasterPrototype, + nsIScriptGlobalObjectOwner) + PRUint32 i, count = tmp->mPrototypes.Length(); + for (i = 0; i < count; ++i) { + cb.NoteXPCOMChild(NS_STATIC_CAST(nsIScriptGlobalObjectOwner*, + tmp->mPrototypes[i])); + } + + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTooltipNode) + + if (tmp->mOverlayLoadObservers.IsInitialized()) + tmp->mOverlayLoadObservers.EnumerateRead(TraverseObservers, &cb); + if (tmp->mPendingOverlayLoadNotifications.IsInitialized()) + tmp->mPendingOverlayLoadNotifications.EnumerateRead(TraverseObservers, &cb); +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + NS_IMPL_ADDREF_INHERITED(nsXULDocument, nsXMLDocument) NS_IMPL_RELEASE_INHERITED(nsXULDocument, nsXMLDocument) @@ -307,6 +373,7 @@ NS_INTERFACE_MAP_BEGIN(nsXULDocument) NS_INTERFACE_MAP_ENTRY(nsIStreamLoaderObserver) NS_INTERFACE_MAP_ENTRY(nsICSSLoaderObserver) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(XULDocument) + NS_INTERFACE_MAP_ENTRY_CYCLE_COLLECTION(nsXULDocument) NS_INTERFACE_MAP_END_INHERITING(nsXMLDocument) @@ -1754,18 +1821,18 @@ nsXULDocument::SetTemplateBuilderFor(nsIContent* aContent, nsIXULTemplateBuilder* aBuilder) { if (! mTemplateBuilderTable) { - mTemplateBuilderTable = new nsSupportsHashtable(); - if (! mTemplateBuilderTable) + mTemplateBuilderTable = new BuilderTable; + if (! mTemplateBuilderTable || !mTemplateBuilderTable->Init()) { + mTemplateBuilderTable = nsnull; return NS_ERROR_OUT_OF_MEMORY; + } } - nsISupportsKey key(aContent); - if (aBuilder) { - mTemplateBuilderTable->Put(&key, aBuilder); + mTemplateBuilderTable->Put(aContent, aBuilder); } else { - mTemplateBuilderTable->Remove(&key); + mTemplateBuilderTable->Remove(aContent); } return NS_OK; @@ -1776,9 +1843,7 @@ nsXULDocument::GetTemplateBuilderFor(nsIContent* aContent, nsIXULTemplateBuilder** aResult) { if (mTemplateBuilderTable) { - nsISupportsKey key(aContent); - *aResult = NS_STATIC_CAST(nsIXULTemplateBuilder*, - mTemplateBuilderTable->Get(&key)); + mTemplateBuilderTable->Get(aContent, aResult); } else *aResult = nsnull; diff --git a/mozilla/content/xul/document/src/nsXULDocument.h b/mozilla/content/xul/document/src/nsXULDocument.h index 10dc5cf9613..8b6ba634649 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.h +++ b/mozilla/content/xul/document/src/nsXULDocument.h @@ -172,6 +172,9 @@ public: nsIAtom* aAttrName, void* aData); + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsXULDocument, + nsXMLDocument) + protected: // Implementation methods friend nsresult @@ -290,7 +293,9 @@ protected: // Maintains the template builders that have been attached to // content elements - nsSupportsHashtable* mTemplateBuilderTable; + typedef nsInterfaceHashtable + BuilderTable; + BuilderTable* mTemplateBuilderTable; nsVoidArray mForwardReferences; nsForwardReference::Phase mResolutionPhase; diff --git a/mozilla/content/xul/document/src/nsXULPrototypeDocument.cpp b/mozilla/content/xul/document/src/nsXULPrototypeDocument.cpp index c62251e039d..749787e62ba 100644 --- a/mozilla/content/xul/document/src/nsXULPrototypeDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULPrototypeDocument.cpp @@ -76,7 +76,7 @@ public: nsXULPDGlobalObject(nsXULPrototypeDocument* owner); // nsISupports interface - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS // nsIScriptGlobalObject methods virtual void SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner); @@ -94,6 +94,9 @@ public: // nsIScriptObjectPrincipal methods virtual nsIPrincipal* GetPrincipal(); + NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXULPDGlobalObject, + nsIScriptGlobalObject) + protected: virtual ~nsXULPDGlobalObject(); @@ -190,9 +193,24 @@ nsXULPrototypeDocument::~nsXULPrototypeDocument() } } -NS_IMPL_ISUPPORTS2(nsXULPrototypeDocument, - nsIScriptGlobalObjectOwner, - nsISerializable) +NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULPrototypeDocument) +NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsXULPrototypeDocument) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULPrototypeDocument) + // XXX Can't traverse tmp->mRoot, non-XPCOM refcounted object + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mGlobalObject) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +NS_INTERFACE_MAP_BEGIN(nsXULPrototypeDocument) + NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObjectOwner) + NS_INTERFACE_MAP_ENTRY(nsISerializable) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptGlobalObjectOwner) + NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsXULPrototypeDocument) +NS_INTERFACE_MAP_END + +NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsXULPrototypeDocument, + nsIScriptGlobalObjectOwner) +NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsXULPrototypeDocument, + nsIScriptGlobalObjectOwner) NS_IMETHODIMP NS_NewXULPrototypeDocument(nsXULPrototypeDocument** aResult) @@ -601,15 +619,32 @@ nsXULPDGlobalObject::~nsXULPDGlobalObject() { } -NS_IMPL_ADDREF(nsXULPDGlobalObject) -NS_IMPL_RELEASE(nsXULPDGlobalObject) +NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULPDGlobalObject) +NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsXULPDGlobalObject) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULPDGlobalObject) + { + PRUint32 lang_id; + NS_STID_FOR_ID(lang_id) { + nsISupports *context = tmp->mScriptContexts[NS_STID_INDEX(lang_id)]; + if (context) { + cb.NoteXPCOMChild(context); + } + } + } +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_INTERFACE_MAP_BEGIN(nsXULPDGlobalObject) - NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObject) - NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptGlobalObject) + NS_INTERFACE_MAP_ENTRY(nsIScriptGlobalObject) + NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptGlobalObject) + NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsXULPDGlobalObject) NS_INTERFACE_MAP_END +NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsXULPDGlobalObject, + nsIScriptGlobalObject) +NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsXULPDGlobalObject, + nsIScriptGlobalObject) + //---------------------------------------------------------------------- // // nsIScriptGlobalObject methods diff --git a/mozilla/content/xul/document/src/nsXULPrototypeDocument.h b/mozilla/content/xul/document/src/nsXULPrototypeDocument.h index e3bbaeb580f..fef0e22f93a 100644 --- a/mozilla/content/xul/document/src/nsXULPrototypeDocument.h +++ b/mozilla/content/xul/document/src/nsXULPrototypeDocument.h @@ -48,6 +48,7 @@ #include "nsTArray.h" #include "nsIScriptGlobalObjectOwner.h" #include "nsISerializable.h" +#include "nsCycleCollectionParticipant.h" class nsIAtom; class nsIPrincipal; @@ -73,7 +74,7 @@ public: Create(nsIURI* aURI, nsXULPrototypeDocument** aResult); // nsISupports interface - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS // nsISerializable interface NS_DECL_NSISERIALIZABLE @@ -145,6 +146,9 @@ public: // nsIScriptGlobalObjectOwner methods virtual nsIScriptGlobalObject* GetScriptGlobalObject(); + NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXULPrototypeDocument, + nsIScriptGlobalObjectOwner) + protected: nsCOMPtr mURI; nsXULPrototypeElement* mRoot; diff --git a/mozilla/content/xul/templates/src/nsRDFQuery.cpp b/mozilla/content/xul/templates/src/nsRDFQuery.cpp index 83e3411123e..d3c726561a3 100755 --- a/mozilla/content/xul/templates/src/nsRDFQuery.cpp +++ b/mozilla/content/xul/templates/src/nsRDFQuery.cpp @@ -40,7 +40,16 @@ #include "nsXULTemplateQueryProcessorRDF.h" #include "nsRDFQuery.h" -NS_IMPL_ISUPPORTS1(nsRDFQuery, nsITemplateRDFQuery) +NS_IMPL_CYCLE_COLLECTION_1(nsRDFQuery, mQueryNode) + +NS_INTERFACE_MAP_BEGIN(nsRDFQuery) + NS_INTERFACE_MAP_ENTRY(nsITemplateRDFQuery) + NS_INTERFACE_MAP_ENTRY(nsISupports) + NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsRDFQuery) +NS_INTERFACE_MAP_END + +NS_IMPL_CYCLE_COLLECTING_ADDREF(nsRDFQuery) +NS_IMPL_CYCLE_COLLECTING_RELEASE(nsRDFQuery) void nsRDFQuery::Finish() diff --git a/mozilla/content/xul/templates/src/nsRDFQuery.h b/mozilla/content/xul/templates/src/nsRDFQuery.h index 9f49de38e87..dd66b9c5d4e 100755 --- a/mozilla/content/xul/templates/src/nsRDFQuery.h +++ b/mozilla/content/xul/templates/src/nsRDFQuery.h @@ -39,6 +39,7 @@ #include "nsAutoPtr.h" #include "nsISimpleEnumerator.h" +#include "nsCycleCollectionParticipant.h" #define NS_ITEMPLATERDFQUERY_IID \ {0x8929ff60, 0x1c9c, 0x4d87, \ @@ -79,7 +80,8 @@ public: ~nsRDFQuery() { Finish(); } - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS(nsRDFQuery) /** * Retrieve the root node in the rule network diff --git a/mozilla/content/xul/templates/src/nsTemplateRule.h b/mozilla/content/xul/templates/src/nsTemplateRule.h index 7e54e4e7e6c..06f97a945c9 100644 --- a/mozilla/content/xul/templates/src/nsTemplateRule.h +++ b/mozilla/content/xul/templates/src/nsTemplateRule.h @@ -48,6 +48,7 @@ #include "nsVoidArray.h" #include "nsString.h" #include "nsIXULTemplateRuleFilter.h" +#include "nsCycleCollectionParticipant.h" class nsIXULTemplateQueryProcessor; class nsTemplateQuerySet; @@ -224,6 +225,16 @@ public: nsresult AddBindingsToQueryProcessor(nsIXULTemplateQueryProcessor* aProcessor); + void Traverse(nsCycleCollectionTraversalCallback &cb) const + { + if (mRuleNode) { + cb.NoteXPCOMChild(mRuleNode); + } + if (mAction) { + cb.NoteXPCOMChild(mAction); + } + } + protected: struct Binding { diff --git a/mozilla/content/xul/templates/src/nsXULContentBuilder.cpp b/mozilla/content/xul/templates/src/nsXULContentBuilder.cpp index 971e6ab00fd..1e8f6cbfcdf 100644 --- a/mozilla/content/xul/templates/src/nsXULContentBuilder.cpp +++ b/mozilla/content/xul/templates/src/nsXULContentBuilder.cpp @@ -152,6 +152,11 @@ protected: nsXULContentBuilder(); + void Traverse(nsCycleCollectionTraversalCallback &cb) const + { + mSortState.Traverse(cb); + } + virtual void Uninit(PRBool aIsFinal); // Implementation methods diff --git a/mozilla/content/xul/templates/src/nsXULSortService.h b/mozilla/content/xul/templates/src/nsXULSortService.h index 4bfd63343f6..c820198bf3f 100644 --- a/mozilla/content/xul/templates/src/nsXULSortService.h +++ b/mozilla/content/xul/templates/src/nsXULSortService.h @@ -63,6 +63,7 @@ #include "nsIXULTemplateResult.h" #include "nsIXULTemplateQueryProcessor.h" #include "nsIXULSortService.h" +#include "nsCycleCollectionParticipant.h" enum nsSortState_direction { nsSortState_descending, @@ -91,6 +92,15 @@ struct nsSortState : initialized(PR_FALSE) { } + void Traverse(nsCycleCollectionTraversalCallback &cb) const + { + if (processor) { + cb.NoteXPCOMChild(processor); + } + if (lastContainer) { + cb.NoteXPCOMChild(lastContainer); + } + } }; // information about a particular item to be sorted diff --git a/mozilla/content/xul/templates/src/nsXULTemplateBuilder.cpp b/mozilla/content/xul/templates/src/nsXULTemplateBuilder.cpp index c5e83111fa8..7acff49a90e 100644 --- a/mozilla/content/xul/templates/src/nsXULTemplateBuilder.cpp +++ b/mozilla/content/xul/templates/src/nsXULTemplateBuilder.cpp @@ -230,9 +230,57 @@ nsXULTemplateBuilder::Uninit(PRBool aIsFinal) mQueriesCompiled = PR_FALSE; } +static PLDHashOperator +TraverseMatchList(nsISupports* aKey, nsTemplateMatch* aMatch, void* aContext) +{ + nsCycleCollectionTraversalCallback *cb = + NS_STATIC_CAST(nsCycleCollectionTraversalCallback*, aContext); -NS_IMPL_ADDREF(nsXULTemplateBuilder) -NS_IMPL_RELEASE(nsXULTemplateBuilder) + cb->NoteXPCOMChild(aKey); + nsTemplateMatch* match = aMatch; + while (match) { + nsISupports *container = match->GetContainer(); + if (container) + cb->NoteXPCOMChild(container); + nsISupports *result = match->mResult; + if (result) + cb->NoteXPCOMChild(result); + match = match->mNext; + } + + return PL_DHASH_NEXT; +} + +NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULTemplateBuilder) +NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsXULTemplateBuilder) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULTemplateBuilder) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRoot) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRootResult) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mListeners) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mQueryProcessor) + if (tmp->mMatchMap.IsInitialized()) + tmp->mMatchMap.EnumerateRead(TraverseMatchList, &cb); + { + PRUint32 i, count = tmp->mQuerySets.Length(); + for (i = 0; i < count; ++i) { + nsTemplateQuerySet *set = tmp->mQuerySets[i]; + cb.NoteXPCOMChild(set->mQueryNode); + if (set->mCompiledQuery) { + cb.NoteXPCOMChild(set->mCompiledQuery); + } + PRUint16 j, rulesCount = set->RuleCount(); + for (j = 0; j < rulesCount; ++j) { + set->GetRuleAt(j)->Traverse(cb); + } + } + } + tmp->Traverse(cb); +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsXULTemplateBuilder, + nsIXULTemplateBuilder) +NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsXULTemplateBuilder, + nsIXULTemplateBuilder) NS_INTERFACE_MAP_BEGIN(nsXULTemplateBuilder) NS_INTERFACE_MAP_ENTRY(nsIXULTemplateBuilder) @@ -240,6 +288,7 @@ NS_INTERFACE_MAP_BEGIN(nsXULTemplateBuilder) NS_INTERFACE_MAP_ENTRY(nsIMutationObserver) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXULTemplateBuilder) NS_INTERFACE_MAP_ENTRY_DOM_CLASSINFO(XULTemplateBuilder) + NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsXULTemplateBuilder) NS_INTERFACE_MAP_END //---------------------------------------------------------------------- diff --git a/mozilla/content/xul/templates/src/nsXULTemplateBuilder.h b/mozilla/content/xul/templates/src/nsXULTemplateBuilder.h index f32e8a7eb4f..9fbdb9cd7a4 100644 --- a/mozilla/content/xul/templates/src/nsXULTemplateBuilder.h +++ b/mozilla/content/xul/templates/src/nsXULTemplateBuilder.h @@ -62,6 +62,7 @@ #include "nsTemplateRule.h" #include "nsTemplateMatch.h" #include "nsIXULTemplateQueryProcessor.h" +#include "nsCycleCollectionParticipant.h" #include "prlog.h" #ifdef PR_LOGGING @@ -91,7 +92,9 @@ public: virtual void Uninit(PRBool aIsFinal); // nsISupports interface - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXULTemplateBuilder, + nsIXULTemplateBuilder) // nsIXULTemplateBuilder interface NS_DECL_NSIXULTEMPLATEBUILDER @@ -463,6 +466,10 @@ protected: */ virtual nsresult SynchronizeResult(nsIXULTemplateResult* aResult) = 0; + + virtual void Traverse(nsCycleCollectionTraversalCallback &cb) const + { + } }; #endif // nsXULTemplateBuilder_h__ diff --git a/mozilla/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.cpp b/mozilla/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.cpp index c2ccc878a9a..db3e545c14a 100755 --- a/mozilla/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.cpp +++ b/mozilla/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.cpp @@ -82,9 +82,78 @@ nsIRDFContainerUtils* nsXULTemplateQueryProcessorRDF::gRDFContainerUtils; nsIRDFResource* nsXULTemplateQueryProcessorRDF::kNC_BookmarkSeparator; nsIRDFResource* nsXULTemplateQueryProcessorRDF::kRDF_type; -NS_IMPL_ISUPPORTS2(nsXULTemplateQueryProcessorRDF, - nsIXULTemplateQueryProcessor, - nsIRDFObserver) +NS_IMPL_CYCLE_COLLECTION_CLASS(nsXULTemplateQueryProcessorRDF) +NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsXULTemplateQueryProcessorRDF) + +PR_STATIC_CALLBACK(PLDHashOperator) +BindingDependenciesTraverser(nsISupports* key, + nsCOMArray* array, + void* userArg) +{ + nsCycleCollectionTraversalCallback *cb = + NS_STATIC_CAST(nsCycleCollectionTraversalCallback*, userArg); + + PRInt32 i, count = array->Count(); + for (i = 0; i < count; ++i) { + cb->NoteXPCOMChild(array->ObjectAt(i)); + } + + return PL_DHASH_NEXT; +} + +PR_STATIC_CALLBACK(PLDHashOperator) +MemoryElementTraverser(const PRUint32& key, + nsCOMArray* array, + void* userArg) +{ + nsCycleCollectionTraversalCallback *cb = + NS_STATIC_CAST(nsCycleCollectionTraversalCallback*, userArg); + + PRInt32 i, count = array->Count(); + for (i = 0; i < count; ++i) { + cb->NoteXPCOMChild(array->ObjectAt(i)); + } + + return PL_DHASH_NEXT; +} + +PR_STATIC_CALLBACK(PLDHashOperator) +RuleToBindingTraverser(nsISupports* key, RDFBindingSet* binding, void* userArg) +{ + nsCycleCollectionTraversalCallback *cb = + NS_STATIC_CAST(nsCycleCollectionTraversalCallback*, userArg); + + cb->NoteXPCOMChild(key); + + return PL_DHASH_NEXT; +} + +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULTemplateQueryProcessorRDF) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLastRef) + if (tmp->mBindingDependencies.IsInitialized()) { + tmp->mBindingDependencies.EnumerateRead(BindingDependenciesTraverser, + &cb); + } + if (tmp->mMemoryElementToResultMap.IsInitialized()) { + tmp->mMemoryElementToResultMap.EnumerateRead(MemoryElementTraverser, + &cb); + } + if (tmp->mRuleToBindingsMap.IsInitialized()) { + tmp->mRuleToBindingsMap.EnumerateRead(RuleToBindingTraverser, &cb); + } + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mQueries) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsXULTemplateQueryProcessorRDF, + nsIXULTemplateQueryProcessor) +NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsXULTemplateQueryProcessorRDF, + nsIXULTemplateQueryProcessor) +NS_INTERFACE_MAP_BEGIN(nsXULTemplateQueryProcessorRDF) + NS_INTERFACE_MAP_ENTRY(nsIXULTemplateQueryProcessor) + NS_INTERFACE_MAP_ENTRY(nsIRDFObserver) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXULTemplateQueryProcessor) + NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsXULTemplateQueryProcessorRDF) +NS_INTERFACE_MAP_END nsXULTemplateQueryProcessorRDF::nsXULTemplateQueryProcessorRDF(void) : mDB(nsnull), diff --git a/mozilla/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.h b/mozilla/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.h index 66b883a86be..2b95998e5b2 100755 --- a/mozilla/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.h +++ b/mozilla/content/xul/templates/src/nsXULTemplateQueryProcessorRDF.h @@ -67,6 +67,7 @@ #include "nsString.h" #include "nsClassHashtable.h" #include "nsRefPtrHashtable.h" +#include "nsCycleCollectionParticipant.h" #include "prlog.h" #ifdef PR_LOGGING @@ -91,7 +92,9 @@ public: nsresult InitGlobals(); // nsISupports interface - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXULTemplateQueryProcessorRDF, + nsIXULTemplateQueryProcessor) // nsIXULTemplateQueryProcessor interface NS_DECL_NSIXULTEMPLATEQUERYPROCESSOR diff --git a/mozilla/content/xul/templates/src/nsXULTemplateResultRDF.cpp b/mozilla/content/xul/templates/src/nsXULTemplateResultRDF.cpp index 5fab8268921..bd928ad591b 100755 --- a/mozilla/content/xul/templates/src/nsXULTemplateResultRDF.cpp +++ b/mozilla/content/xul/templates/src/nsXULTemplateResultRDF.cpp @@ -40,7 +40,16 @@ // XXXndeakin for some reason, making this class have classinfo breaks trees. //#include "nsIDOMClassInfo.h" -NS_IMPL_ISUPPORTS1(nsXULTemplateResultRDF, nsIXULTemplateResult) +NS_IMPL_CYCLE_COLLECTION_1(nsXULTemplateResultRDF, mQuery) + +NS_INTERFACE_MAP_BEGIN(nsXULTemplateResultRDF) + NS_INTERFACE_MAP_ENTRY(nsIXULTemplateResult) + NS_INTERFACE_MAP_ENTRY(nsISupports) + NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsXULTemplateResultRDF) +NS_INTERFACE_MAP_END + +NS_IMPL_CYCLE_COLLECTING_ADDREF(nsXULTemplateResultRDF) +NS_IMPL_CYCLE_COLLECTING_RELEASE(nsXULTemplateResultRDF) nsXULTemplateResultRDF::nsXULTemplateResultRDF(nsIRDFResource* aNode) : mQuery(nsnull), diff --git a/mozilla/content/xul/templates/src/nsXULTemplateResultRDF.h b/mozilla/content/xul/templates/src/nsXULTemplateResultRDF.h index fb971a2bead..6a3342aaa05 100755 --- a/mozilla/content/xul/templates/src/nsXULTemplateResultRDF.h +++ b/mozilla/content/xul/templates/src/nsXULTemplateResultRDF.h @@ -51,7 +51,8 @@ class nsXULTemplateResultRDF : public nsIXULTemplateResult { public: - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS(nsXULTemplateResultRDF) NS_DECL_NSIXULTEMPLATERESULT diff --git a/mozilla/content/xul/templates/src/nsXULTreeBuilder.cpp b/mozilla/content/xul/templates/src/nsXULTreeBuilder.cpp index d212cc5eaea..b41f2a976a2 100644 --- a/mozilla/content/xul/templates/src/nsXULTreeBuilder.cpp +++ b/mozilla/content/xul/templates/src/nsXULTreeBuilder.cpp @@ -295,13 +295,12 @@ NS_NewXULTreeBuilder(nsISupports* aOuter, REFNSIID aIID, void** aResult) return rv; } -NS_IMPL_ADDREF(nsXULTreeBuilder) -NS_IMPL_RELEASE(nsXULTreeBuilder) +NS_IMPL_ADDREF_INHERITED(nsXULTreeBuilder, nsXULTemplateBuilder) +NS_IMPL_RELEASE_INHERITED(nsXULTreeBuilder, nsXULTemplateBuilder) NS_INTERFACE_MAP_BEGIN(nsXULTreeBuilder) NS_INTERFACE_MAP_ENTRY(nsIXULTreeBuilder) NS_INTERFACE_MAP_ENTRY(nsITreeView) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIXULTreeBuilder) NS_INTERFACE_MAP_ENTRY_DOM_CLASSINFO(XULTreeBuilder) NS_INTERFACE_MAP_END_INHERITING(nsXULTemplateBuilder) diff --git a/mozilla/dom/src/base/nsFocusController.cpp b/mozilla/dom/src/base/nsFocusController.cpp index 91887acedae..1445a152ac5 100644 --- a/mozilla/dom/src/base/nsFocusController.cpp +++ b/mozilla/dom/src/base/nsFocusController.cpp @@ -85,8 +85,28 @@ nsFocusController::~nsFocusController(void) { } -NS_IMPL_ISUPPORTS4(nsFocusController, nsIFocusController, nsIDOMFocusListener, - nsIDOMEventListener, nsSupportsWeakReference) +NS_IMPL_CYCLE_COLLECTION_CLASS(nsFocusController) + +NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsFocusController, nsIFocusController) +NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsFocusController, + nsIFocusController) + +NS_INTERFACE_MAP_BEGIN(nsFocusController) + NS_INTERFACE_MAP_ENTRY(nsIFocusController) + NS_INTERFACE_MAP_ENTRY(nsIDOMFocusListener) + NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener) + NS_INTERFACE_MAP_ENTRY(nsSupportsWeakReference) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIFocusController) + NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsFocusController) +NS_INTERFACE_MAP_END + +NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsFocusController) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsFocusController) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCurrentElement) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCurrentWindow) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mPopupNode) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mPopupEvent) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMETHODIMP nsFocusController::Create(nsIFocusController** aResult) diff --git a/mozilla/dom/src/base/nsFocusController.h b/mozilla/dom/src/base/nsFocusController.h index ba8ef2e683e..dce57361fe3 100644 --- a/mozilla/dom/src/base/nsFocusController.h +++ b/mozilla/dom/src/base/nsFocusController.h @@ -47,6 +47,7 @@ #include "nsIDOMElement.h" #include "nsIDOMWindow.h" #include "nsWeakReference.h" +#include "nsCycleCollectionParticipant.h" class nsIDOMElement; class nsIDOMWindow; @@ -66,7 +67,7 @@ protected: virtual ~nsFocusController(void); public: - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_IMETHOD GetFocusedElement(nsIDOMElement** aResult); NS_IMETHOD SetFocusedElement(nsIDOMElement* aElement); @@ -103,6 +104,9 @@ public: // nsIDOMEventListener NS_IMETHOD HandleEvent(nsIDOMEvent* anEvent) { return NS_OK; }; + NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsFocusController, + nsIFocusController) + protected: void UpdateCommands(); void UpdateWWActiveWindow(); diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index 4050aff57ce..691fe8c68f6 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -703,12 +703,7 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsGlobalWindow, NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsGlobalWindow) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mContext) - // Strange bug: If you uncomment this line you will find that - // the cycle collector crashes when working with multiple open - // top-level windows. It is as though the windows somehow - // race with one another. How can this be? Curious. - // - // NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOpener) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOpener) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mControllers) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mArguments) @@ -740,20 +735,9 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsGlobalWindow) } } - // Traverse our possibly-inner window. - if (tmp->IsOuterWindow() - && tmp->GetCurrentInnerWindowInternal()) { - cb.NoteXPCOMChild(NS_STATIC_CAST(nsIScriptGlobalObject*, - tmp->GetCurrentInnerWindowInternal())); - } - - // FIXME: somewhere in these commented lines lies a bug that causes - // a segfault. So we have disabled them, even though it seems wrong - // to do so. Other matters are more pressing at the moment. - // Traverse stuff from nsPIDOMWindow - // NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mChromeEventHandler) - // NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocument) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mChromeEventHandler) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mDocument) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindow) @@ -7564,10 +7548,17 @@ nsGlobalWindow::SetScriptTypeID(PRUint32 aScriptType) return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMPL_CYCLE_COLLECTION_CLASS(nsGlobalChromeWindow) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsGlobalChromeWindow, + nsGlobalWindow) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mBrowserDOMWindow) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + // QueryInterface implementation for nsGlobalChromeWindow NS_INTERFACE_MAP_BEGIN(nsGlobalChromeWindow) NS_INTERFACE_MAP_ENTRY(nsIDOMChromeWindow) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(ChromeWindow) + NS_INTERFACE_MAP_ENTRY_CYCLE_COLLECTION(nsGlobalChromeWindow) NS_INTERFACE_MAP_END_INHERITING(nsGlobalWindow) NS_IMPL_ADDREF_INHERITED(nsGlobalChromeWindow, nsGlobalWindow) diff --git a/mozilla/dom/src/base/nsGlobalWindow.h b/mozilla/dom/src/base/nsGlobalWindow.h index 79cbb5635b3..a121e1f07fd 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.h +++ b/mozilla/dom/src/base/nsGlobalWindow.h @@ -713,6 +713,9 @@ public: { } + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(nsGlobalChromeWindow, + nsGlobalWindow) + protected: nsCOMPtr mBrowserDOMWindow; }; diff --git a/mozilla/dom/src/base/nsJSEnvironment.cpp b/mozilla/dom/src/base/nsJSEnvironment.cpp index 487339c5174..e15ba13a7be 100644 --- a/mozilla/dom/src/base/nsJSEnvironment.cpp +++ b/mozilla/dom/src/base/nsJSEnvironment.cpp @@ -1018,16 +1018,28 @@ nsJSContext::~nsJSContext() } // QueryInterface implementation for nsJSContext +NS_IMPL_CYCLE_COLLECTION_CLASS(nsJSContext) +// XXX Should we call ClearScope here? +NS_IMPL_CYCLE_COLLECTION_UNLINK_0(nsJSContext) +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsJSContext) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mGlobalWrapperRef) + JSObject *globalObject = ::JS_GetGlobalObject(tmp->mContext); + if (globalObject) { + cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, globalObject); + } +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + NS_INTERFACE_MAP_BEGIN(nsJSContext) NS_INTERFACE_MAP_ENTRY(nsIScriptContext) NS_INTERFACE_MAP_ENTRY(nsIXPCScriptNotify) NS_INTERFACE_MAP_ENTRY(nsITimerCallback) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIScriptContext) + NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsJSContext) NS_INTERFACE_MAP_END -NS_IMPL_ADDREF(nsJSContext) -NS_IMPL_RELEASE(nsJSContext) +NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsJSContext, nsIScriptContext) +NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsJSContext, nsIScriptContext) nsresult nsJSContext::EvaluateStringWithValue(const nsAString& aScript, @@ -3556,13 +3568,17 @@ public: nsJSArgArray(JSContext *aContext, PRUint32 argc, jsval *argv, nsresult *prv); ~nsJSArgArray(); // nsISupports - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsJSArgArray, nsIJSArgArray) // nsIArray NS_DECL_NSIARRAY // nsIJSArgArray nsresult GetArgs(PRUint32 *argc, void **argv); + + void ReleaseJSObjects(); + protected: JSContext *mContext; jsval *mArgv; @@ -3594,6 +3610,12 @@ nsJSArgArray::nsJSArgArray(JSContext *aContext, PRUint32 argc, jsval *argv, } nsJSArgArray::~nsJSArgArray() +{ + ReleaseJSObjects(); +} + +void +nsJSArgArray::ReleaseJSObjects() { if (mArgv) { NS_ASSERTION(nsJSRuntime::sRuntime, "Where's the runtime gone?"); @@ -3604,17 +3626,37 @@ nsJSArgArray::~nsJSArgArray() } PR_DELETE(mArgv); } + mArgc = 0; } // QueryInterface implementation for nsJSArgArray +NS_IMPL_CYCLE_COLLECTION_CLASS(nsJSArgArray) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsJSArgArray) + tmp->ReleaseJSObjects(); +NS_IMPL_CYCLE_COLLECTION_UNLINK_END +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsJSArgArray) + { + jsval *argv = tmp->mArgv; + if (argv) { + jsval *end; + for (end = argv + tmp->mArgc; argv < end; ++argv) { + if (JSVAL_IS_OBJECT(*argv)) + cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, + JSVAL_TO_OBJECT(*argv)); + } + } + } +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + NS_INTERFACE_MAP_BEGIN(nsJSArgArray) NS_INTERFACE_MAP_ENTRY(nsIArray) NS_INTERFACE_MAP_ENTRY(nsIJSArgArray) NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIJSArgArray) + NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsJSArgArray) NS_INTERFACE_MAP_END -NS_IMPL_ADDREF(nsJSArgArray) -NS_IMPL_RELEASE(nsJSArgArray) +NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsJSArgArray, nsIJSArgArray) +NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsJSArgArray, nsIJSArgArray) nsresult nsJSArgArray::GetArgs(PRUint32 *argc, void **argv) diff --git a/mozilla/dom/src/base/nsJSEnvironment.h b/mozilla/dom/src/base/nsJSEnvironment.h index a3b4c1a180d..01d0187f8da 100644 --- a/mozilla/dom/src/base/nsJSEnvironment.h +++ b/mozilla/dom/src/base/nsJSEnvironment.h @@ -45,6 +45,7 @@ #include "nsIXPCScriptNotify.h" #include "nsITimer.h" #include "prtime.h" +#include "nsCycleCollectionParticipant.h" class nsIXPConnectJSObjectHolder; @@ -56,7 +57,8 @@ public: nsJSContext(JSRuntime *aRuntime); virtual ~nsJSContext(); - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsJSContext, nsIScriptContext) virtual PRUint32 GetScriptTypeID() { return nsIProgrammingLanguage::JAVASCRIPT; } diff --git a/mozilla/dom/src/base/nsJSTimeoutHandler.cpp b/mozilla/dom/src/base/nsJSTimeoutHandler.cpp index 1ff8fc82593..9991daa5e37 100644 --- a/mozilla/dom/src/base/nsJSTimeoutHandler.cpp +++ b/mozilla/dom/src/base/nsJSTimeoutHandler.cpp @@ -58,7 +58,8 @@ class nsJSScriptTimeoutHandler: public nsIScriptTimeoutHandler { public: // nsISupports - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS(nsJSScriptTimeoutHandler) nsJSScriptTimeoutHandler(); ~nsJSScriptTimeoutHandler(); @@ -88,6 +89,9 @@ public: nsresult Init(nsIScriptContext *aContext, PRBool aIsInterval, PRInt32 *aInterval); + + void ReleaseJSObjects(); + private: nsCOMPtr mContext; @@ -107,13 +111,25 @@ private: // nsJSScriptTimeoutHandler // QueryInterface implementation for nsJSScriptTimeoutHandler +NS_IMPL_CYCLE_COLLECTION_CLASS(nsJSScriptTimeoutHandler) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsJSScriptTimeoutHandler) + tmp->ReleaseJSObjects(); +NS_IMPL_CYCLE_COLLECTION_UNLINK_END +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsJSScriptTimeoutHandler) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mContext) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mArgv) + if (tmp->mFunObj) + cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, tmp->mFunObj); +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + NS_INTERFACE_MAP_BEGIN(nsJSScriptTimeoutHandler) NS_INTERFACE_MAP_ENTRY(nsIScriptTimeoutHandler) NS_INTERFACE_MAP_ENTRY(nsISupports) + NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsJSScriptTimeoutHandler) NS_INTERFACE_MAP_END -NS_IMPL_ADDREF(nsJSScriptTimeoutHandler) -NS_IMPL_RELEASE(nsJSScriptTimeoutHandler) +NS_IMPL_CYCLE_COLLECTING_ADDREF(nsJSScriptTimeoutHandler) +NS_IMPL_CYCLE_COLLECTING_RELEASE(nsJSScriptTimeoutHandler) nsJSScriptTimeoutHandler::nsJSScriptTimeoutHandler() : mLineNo(0), @@ -124,15 +140,22 @@ nsJSScriptTimeoutHandler::nsJSScriptTimeoutHandler() : } nsJSScriptTimeoutHandler::~nsJSScriptTimeoutHandler() +{ + ReleaseJSObjects(); +} + +void +nsJSScriptTimeoutHandler::ReleaseJSObjects() { if (mExpr || mFunObj) { - nsIScriptContext *scx = mContext; + nsCOMPtr scx = mContext; JSRuntime *rt = nsnull; if (scx) { JSContext *cx; cx = (JSContext *)scx->GetNativeContext(); rt = ::JS_GetRuntime(cx); + mContext = nsnull; } else { // XXX The timeout *must* be unrooted, even if !scx. This can be // done without a JS context using the JSRuntime. This is safe @@ -152,7 +175,7 @@ nsJSScriptTimeoutHandler::~nsJSScriptTimeoutHandler() if (rtsvc) { rtsvc->GetRuntime(&rt); - } + } } if (!rt) { @@ -165,8 +188,10 @@ nsJSScriptTimeoutHandler::~nsJSScriptTimeoutHandler() if (mExpr) { ::JS_RemoveRootRT(rt, &mExpr); + mExpr = nsnull; } else if (mFunObj) { ::JS_RemoveRootRT(rt, &mFunObj); + mFunObj = nsnull; } else { NS_WARNING("No func and no expr - roots may not have been removed"); } diff --git a/mozilla/dom/src/events/nsJSEventListener.cpp b/mozilla/dom/src/events/nsJSEventListener.cpp index 8c61995f58b..e9556f5e9af 100644 --- a/mozilla/dom/src/events/nsJSEventListener.cpp +++ b/mozilla/dom/src/events/nsJSEventListener.cpp @@ -87,7 +87,15 @@ nsJSEventListener::~nsJSEventListener() mContext->DropScriptObject(mScopeObject); } -NS_IMPL_CYCLE_COLLECTION_1(nsJSEventListener, mTarget) +NS_IMPL_CYCLE_COLLECTION_CLASS(nsJSEventListener) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsJSEventListener) + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTarget) +NS_IMPL_CYCLE_COLLECTION_UNLINK_END +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsJSEventListener) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTarget) + NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mContext) + cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, tmp->mScopeObject); +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_INTERFACE_MAP_BEGIN(nsJSEventListener) NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener) diff --git a/mozilla/embedding/components/commandhandler/src/nsCommandManager.cpp b/mozilla/embedding/components/commandhandler/src/nsCommandManager.cpp index 8d2da9fed59..5856aa2daa8 100644 --- a/mozilla/embedding/components/commandhandler/src/nsCommandManager.cpp +++ b/mozilla/embedding/components/commandhandler/src/nsCommandManager.cpp @@ -70,7 +70,42 @@ nsCommandManager::~nsCommandManager() } -NS_IMPL_ISUPPORTS3(nsCommandManager, nsICommandManager, nsPICommandUpdater, nsISupportsWeakReference) +PR_STATIC_CALLBACK(PRBool) +TraverseCommandObservers(nsHashKey *aKey, void *aData, void* aClosure) +{ + nsISupportsArray *observers = NS_STATIC_CAST(nsISupportsArray*, aData); + nsCycleCollectionTraversalCallback *cb = + NS_STATIC_CAST(nsCycleCollectionTraversalCallback*, aClosure); + + PRUint32 i, numItems; + nsresult rv = observers->Count(&numItems); + NS_ENSURE_SUCCESS(rv, kHashEnumerateStop); + + for (i = 0; i < numItems; ++i) { + cb->NoteXPCOMChild(observers->ElementAt(i)); + } + + return kHashEnumerateNext; +} + +NS_IMPL_CYCLE_COLLECTION_CLASS(nsCommandManager) +NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsCommandManager) + tmp->mCommandObserversTable.Reset(); +NS_IMPL_CYCLE_COLLECTION_UNLINK_END +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsCommandManager) + tmp->mCommandObserversTable.Enumerate(TraverseCommandObservers, &cb); +NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END + +NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsCommandManager, nsICommandManager) +NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsCommandManager, nsICommandManager) + +NS_INTERFACE_MAP_BEGIN(nsCommandManager) + NS_INTERFACE_MAP_ENTRY(nsICommandManager) + NS_INTERFACE_MAP_ENTRY(nsPICommandUpdater) + NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICommandManager) + NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsCommandManager) +NS_INTERFACE_MAP_END #if 0 #pragma mark - diff --git a/mozilla/embedding/components/commandhandler/src/nsCommandManager.h b/mozilla/embedding/components/commandhandler/src/nsCommandManager.h index c13bc5bb71d..b7fe6e6dec7 100644 --- a/mozilla/embedding/components/commandhandler/src/nsCommandManager.h +++ b/mozilla/embedding/components/commandhandler/src/nsCommandManager.h @@ -46,6 +46,7 @@ #include "nsICommandManager.h" #include "nsPICommandUpdater.h" +#include "nsCycleCollectionParticipant.h" class nsIController; @@ -62,7 +63,8 @@ public: virtual ~nsCommandManager(); // nsISupports - NS_DECL_ISUPPORTS + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsCommandManager, nsICommandManager) // nsICommandManager NS_DECL_NSICOMMANDMANAGER diff --git a/mozilla/xpcom/base/nsCycleCollectionParticipant.cpp b/mozilla/xpcom/base/nsCycleCollectionParticipant.cpp index 6ded15b94e4..ab622638e08 100644 --- a/mozilla/xpcom/base/nsCycleCollectionParticipant.cpp +++ b/mozilla/xpcom/base/nsCycleCollectionParticipant.cpp @@ -54,18 +54,6 @@ NS_IMETHODIMP_(nsrefcnt) nsCycleCollectionParticipant::Release(void) return 1; } -NS_IMETHODIMP nsCycleCollectionParticipant::Unlink(nsISupports *n) -{ - return NS_OK; -} - -NS_IMETHODIMP -nsCycleCollectionParticipant::Traverse(nsISupports *n, - nsCycleCollectionTraversalCallback &cb) -{ - return NS_OK; -} - #ifdef DEBUG PRBool nsCycleCollectionParticipant::CheckForRightISupports(nsISupports *s) diff --git a/mozilla/xpcom/base/nsCycleCollectionParticipant.h b/mozilla/xpcom/base/nsCycleCollectionParticipant.h index 83adb49987f..3e8566dc05b 100644 --- a/mozilla/xpcom/base/nsCycleCollectionParticipant.h +++ b/mozilla/xpcom/base/nsCycleCollectionParticipant.h @@ -97,9 +97,9 @@ public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_CYCLECOLLECTIONPARTICIPANT_IID) NS_DECL_ISUPPORTS - NS_IMETHOD Unlink(nsISupports *p); + NS_IMETHOD Unlink(nsISupports *p) = 0; NS_IMETHOD Traverse(nsISupports *p, - nsCycleCollectionTraversalCallback &cb); + nsCycleCollectionTraversalCallback &cb) = 0; #ifdef DEBUG NS_EXTERNAL_VIS_(PRBool) CheckForRightISupports(nsISupports *s); @@ -159,6 +159,15 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsCycleCollectionParticipant, "not the nsISupports pointer we expect"); \ _class *tmp = Downcast(s); +#define NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(_class, _base_class) \ + NS_IMETHODIMP \ + NS_CYCLE_COLLECTION_CLASSNAME(_class)::Unlink(nsISupports *s) \ + { \ + NS_ASSERTION(CheckForRightISupports(s), \ + "not the nsISupports pointer we expect"); \ + _class *tmp = NS_STATIC_CAST(_class*, Downcast(s)); \ + NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::Unlink(s); + #define NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(_field) \ tmp->_field = NULL; @@ -197,12 +206,29 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsCycleCollectionParticipant, _class *tmp = Downcast(s); \ NS_IMPL_CYCLE_COLLECTION_DESCRIBE(_class) +#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(_class, _base_class) \ + NS_IMETHODIMP \ + NS_CYCLE_COLLECTION_CLASSNAME(_class)::Traverse \ + (nsISupports *s, \ + nsCycleCollectionTraversalCallback &cb) \ + { \ + NS_ASSERTION(CheckForRightISupports(s), \ + "not the nsISupports pointer we expect"); \ + _class *tmp = NS_STATIC_CAST(_class*, Downcast(s)); \ + NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::Traverse(s, cb); + #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(_field) \ if (tmp->_field) { cb.NoteXPCOMChild(tmp->_field); } #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(_field) \ if (tmp->_field) { cb.NoteXPCOMChild(tmp->_field.get()); } +#define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(_field, _base) \ + { \ + nsISupports *f = NS_ISUPPORTS_CAST(_base*, tmp->_field); \ + if (f) { cb.NoteXPCOMChild(f); } \ + } + #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(_field) \ { \ PRInt32 i; \ @@ -240,14 +266,40 @@ public: \ #define NS_DECL_CYCLE_COLLECTION_CLASS(_class) \ NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(_class, _class) +#define NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(_class, _base_class) \ +class NS_CYCLE_COLLECTION_INNERCLASS \ + : public NS_CYCLE_COLLECTION_CLASSNAME(_base_class) \ +{ \ +public: \ + NS_IMETHOD Unlink(nsISupports *n); \ + NS_IMETHOD Traverse(nsISupports *n, \ + nsCycleCollectionTraversalCallback &cb); \ + static _class* Downcast(nsISupports* s) \ + { \ + return NS_STATIC_CAST(_class*, NS_STATIC_CAST(_base_class*, \ + NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::Downcast(s))); \ + } \ +}; + +#define NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED_NO_UNLINK(_class, \ + _base_class) \ +class NS_CYCLE_COLLECTION_INNERCLASS \ + : public NS_CYCLE_COLLECTION_CLASSNAME(_base_class) \ +{ \ +public: \ + NS_IMETHOD Traverse(nsISupports *n, \ + nsCycleCollectionTraversalCallback &cb); \ + static _class* Downcast(nsISupports* s) \ + { \ + return NS_STATIC_CAST(_class*, NS_STATIC_CAST(_base_class*, \ + NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::Downcast(s))); \ + } \ +}; + #define NS_IMPL_CYCLE_COLLECTION_CLASS(_class) \ static NS_CYCLE_COLLECTION_CLASSNAME(_class) \ NS_CYCLE_COLLECTION_NAME(_class); -// The *_AMBIGUOUS macros are needed when a cast from _class* to -// nsISupports* is ambiguous. The _base parameter must match the base -// class used to implement QueryInterface to nsISupports. - #define NS_IMPL_CYCLE_COLLECTION_0(_class) \ NS_IMPL_CYCLE_COLLECTION_CLASS(_class) \ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(_class) \