From 9ed76255264f43a065b3b5750ef0eda15afad891 Mon Sep 17 00:00:00 2001 From: "peterv%propagandism.org" Date: Fri, 9 Mar 2007 13:14:06 +0000 Subject: [PATCH] Fix for bug 373219 (ASSERTION: Fault in cycle collector: null XPCOM pointer returned (ptr: 0)). r/sr=dbaron. --- browser/components/sidebar/src/nsSidebar.js | 389 ------------------ content/base/public/nsIContent.h | 3 +- content/base/src/nsDOMAttributeMap.cpp | 3 +- content/base/src/nsDocument.cpp | 16 +- content/base/src/nsGenericElement.cpp | 14 +- content/base/src/nsObjectLoadingContent.cpp | 4 +- content/events/src/nsEventListenerManager.cpp | 2 +- content/html/document/src/nsHTMLDocument.cpp | 2 +- content/xbl/src/nsXBLPrototypeBinding.cpp | 2 +- .../document/src/nsXULPrototypeDocument.cpp | 9 +- content/xul/templates/src/nsTemplateRule.h | 8 +- content/xul/templates/src/nsXULSortService.h | 8 +- .../templates/src/nsXULTemplateBuilder.cpp | 12 +- dom/src/base/nsGlobalWindow.cpp | 5 +- dom/src/base/nsJSEnvironment.cpp | 5 +- dom/src/base/nsJSTimeoutHandler.cpp | 3 +- js/src/xpconnect/src/nsXPConnect.cpp | 28 +- js/src/xpconnect/src/xpccomponents.cpp | 3 +- js/src/xpconnect/src/xpcthreadcontext.cpp | 2 +- js/src/xpconnect/src/xpcwrappedjs.cpp | 8 +- js/src/xpconnect/src/xpcwrappednative.cpp | 12 +- .../xpconnect/src/xpcwrappednativescope.cpp | 9 +- xpcom/base/nsCycleCollectionParticipant.h | 16 +- xpcom/base/nsCycleCollector.cpp | 9 +- xpcom/ds/nsVariant.cpp | 7 +- 25 files changed, 57 insertions(+), 522 deletions(-) diff --git a/browser/components/sidebar/src/nsSidebar.js b/browser/components/sidebar/src/nsSidebar.js index 0f4ed69eacc..e69de29bb2d 100644 --- a/browser/components/sidebar/src/nsSidebar.js +++ b/browser/components/sidebar/src/nsSidebar.js @@ -1,389 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * ***** 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.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1999 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Stephen Lamm - * Robert John Churchill - * David Hyatt - * Christopher A. Aillon - * Myk Melez - * Pamela Greene - * - * Alternatively, the contents of this file may be used under the terms of - * either 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 ***** */ - -/* - * No magic constructor behaviour, as is de rigeur for XPCOM. - * If you must perform some initialization, and it could possibly fail (even - * due to an out-of-memory condition), you should use an Init method, which - * can convey failure appropriately (thrown exception in JS, - * NS_FAILED(nsresult) return in C++). - * - * In JS, you can actually cheat, because a thrown exception will cause the - * CreateInstance call to fail in turn, but not all languages are so lucky. - * (Though ANSI C++ provides exceptions, they are verboten in Mozilla code - * for portability reasons -- and even when you're building completely - * platform-specific code, you can't throw across an XPCOM method boundary.) - */ - -const DEBUG = false; /* set to false to suppress debug messages */ - -const SIDEBAR_CONTRACTID = "@mozilla.org/sidebar;1"; -const SIDEBAR_CID = Components.ID("{22117140-9c6e-11d3-aaf1-00805f8a4905}"); -const nsISupports = Components.interfaces.nsISupports; -const nsIFactory = Components.interfaces.nsIFactory; -const nsISidebar = Components.interfaces.nsISidebar; -const nsISidebarExternal = Components.interfaces.nsISidebarExternal; -const nsIClassInfo = Components.interfaces.nsIClassInfo; - -// File extension for Sherlock search plugin description files -const SHERLOCK_FILE_EXT_REGEXP = /\.src$/i; - -function nsSidebar() -{ - const PROMPTSERVICE_CONTRACTID = "@mozilla.org/embedcomp/prompt-service;1"; - const nsIPromptService = Components.interfaces.nsIPromptService; - this.promptService = - Components.classes[PROMPTSERVICE_CONTRACTID].getService(nsIPromptService); - - const SEARCHSERVICE_CONTRACTID = "@mozilla.org/browser/search-service;1"; - const nsIBrowserSearchService = Components.interfaces.nsIBrowserSearchService; - this.searchService = - Components.classes[SEARCHSERVICE_CONTRACTID].getService(nsIBrowserSearchService); -} - -nsSidebar.prototype.nc = "http://home.netscape.com/NC-rdf#"; - -function sidebarURLSecurityCheck(url) -{ - if (!/^(https?:|ftp:)/i.test(url)) { - Components.utils.reportError("Invalid argument passed to window.sidebar.addPanel: Unsupported panel URL." ); - return false; - } - return true; -} - -/* decorate prototype to provide ``class'' methods and property accessors */ -nsSidebar.prototype.addPanel = -function (aTitle, aContentURL, aCustomizeURL) -{ - debug("addPanel(" + aTitle + ", " + aContentURL + ", " + - aCustomizeURL + ")"); - - return this.addPanelInternal(aTitle, aContentURL, aCustomizeURL, false); -} - -nsSidebar.prototype.addPersistentPanel = -function(aTitle, aContentURL, aCustomizeURL) -{ - debug("addPersistentPanel(" + aTitle + ", " + aContentURL + ", " + - aCustomizeURL + ")\n"); - - return this.addPanelInternal(aTitle, aContentURL, aCustomizeURL, true); -} - -nsSidebar.prototype.addPanelInternal = -function (aTitle, aContentURL, aCustomizeURL, aPersist) -{ - var WINMEDSVC = Components.classes['@mozilla.org/appshell/window-mediator;1'] - .getService(Components.interfaces.nsIWindowMediator); - var win = WINMEDSVC.getMostRecentWindow( "navigator:browser" ); - - if (!sidebarURLSecurityCheck(aContentURL)) - return; - -#ifdef MOZ_PLACES_BOOKMARKS - var uri = null; - var ioService = Components.classes["@mozilla.org/network/io-service;1"] - .getService(Components.interfaces.nsIIOService); - try { - uri = ioService.newURI(aContentURL, null, null); - } - catch(ex) { return; } - - win.PlacesUtils.showAddBookmarkUI(uri, aTitle, null, true, true); -#else - var dialogArgs = { - name: aTitle, - url: aContentURL, - bWebPanel: true - } -#ifdef XP_MACOSX - var features = "chrome,dialog,resizable,modal"; -#else - var features = "centerscreen,chrome,dialog,resizable,dependent"; -#endif - win.openDialog("chrome://browser/content/bookmarks/addBookmark2.xul", "", - features, dialogArgs); -#endif -} - -nsSidebar.prototype.validateSearchEngine = -function (engineURL, iconURL) -{ - try - { - // Make sure we're using HTTP, HTTPS, or FTP. - if (! /^(https?|ftp):\/\//i.test(engineURL)) - throw "Unsupported search engine URL"; - - // Make sure we're using HTTP, HTTPS, or FTP and refering to a - // .gif/.jpg/.jpeg/.png/.ico file for the icon. - if (iconURL && - ! /^(https?|ftp):\/\/.+\.(gif|jpg|jpeg|png|ico)$/i.test(iconURL)) - throw "Unsupported search icon URL."; - } - catch(ex) - { - debug(ex); - Components.utils.reportError("Invalid argument passed to window.sidebar.addSearchEngine: " + ex); - - var searchBundle = srGetStrBundle("chrome://browser/locale/search.properties"); - var brandBundle = srGetStrBundle("chrome://branding/locale/brand.properties"); - var brandName = brandBundle.GetStringFromName("brandShortName"); - var title = searchBundle.GetStringFromName("error_invalid_engine_title"); - var msg = searchBundle.formatStringFromName("error_invalid_engine_msg", - [brandName], 1); - var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]. - getService(Components.interfaces.nsIWindowWatcher); - ww.getNewPrompter(null).alert(title, msg); - return false; - } - - return true; -} - -// The suggestedTitle and suggestedCategory parameters are ignored, but remain -// for backward compatibility. -nsSidebar.prototype.addSearchEngine = -function (engineURL, iconURL, suggestedTitle, suggestedCategory) -{ - debug("addSearchEngine(" + engineURL + ", " + iconURL + ", " + - suggestedCategory + ", " + suggestedTitle + ")"); - - if (!this.validateSearchEngine(engineURL, iconURL)) - return; - - // OpenSearch files will likely be far more common than Sherlock files, and - // have less consistent suffixes, so we assume that ".src" is a Sherlock - // (text) file, and anything else is OpenSearch (XML). - var dataType; - if (SHERLOCK_FILE_EXT_REGEXP.test(engineURL)) - dataType = Components.interfaces.nsISearchEngine.DATA_TEXT; - else - dataType = Components.interfaces.nsISearchEngine.DATA_XML; - - this.searchService.addEngine(engineURL, dataType, iconURL, true); -} - -// This function exists largely to implement window.external.AddSearchProvider(), -// to match other browsers' APIs. The capitalization, although nonstandard here, -// is therefore important. -nsSidebar.prototype.AddSearchProvider = -function (aDescriptionURL) -{ - // Get the favicon URL for the current page, or our best guess at the current - // page since we don't have easy access to the active document. Most search - // engines will override this with an icon specified in the OpenSearch - // description anyway. - var WINMEDSVC = Components.classes['@mozilla.org/appshell/window-mediator;1'] - .getService(Components.interfaces.nsIWindowMediator); - var win = WINMEDSVC.getMostRecentWindow("navigator:browser"); - var browser = win.document.getElementById("content"); - var iconURL = ""; - if (browser.shouldLoadFavIcon(browser.selectedBrowser.currentURI)) - iconURL = win.gProxyFavIcon.getAttribute("src"); - - if (!this.validateSearchEngine(aDescriptionURL, iconURL)) - return; - - const typeXML = Components.interfaces.nsISearchEngine.DATA_XML; - this.searchService.addEngine(aDescriptionURL, typeXML, iconURL, true); -} - -// This function exists to implement window.external.IsSearchProviderInstalled(), -// for compatibility with other browsers. It will return an integer value -// indicating whether the given engine is installed for the current user. -// However, it is currently stubbed out due to security/privacy concerns -// stemming from difficulties in determining what domain issued the request. -// See bug 340604 and -// http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/issearchproviderinstalled.asp . -// XXX Implement this! -nsSidebar.prototype.IsSearchProviderInstalled = -function (aSearchURL) -{ - return 0; -} - -nsSidebar.prototype.addMicrosummaryGenerator = -function (generatorURL) -{ - debug("addMicrosummaryGenerator(" + generatorURL + ")"); - - var stringBundle = srGetStrBundle("chrome://browser/locale/sidebar/sidebar.properties"); - var titleMessage = stringBundle.GetStringFromName("addMicsumGenConfirmTitle"); - var dialogMessage = stringBundle.formatStringFromName("addMicsumGenConfirmText", [generatorURL], 1); - - if (!this.promptService.confirm(null, titleMessage, dialogMessage)) - return; - - var ioService = Components.classes["@mozilla.org/network/io-service;1"]. - getService(Components.interfaces.nsIIOService); - var generatorURI = ioService.newURI(generatorURL, null, null); - - var microsummaryService = Components.classes["@mozilla.org/microsummary/service;1"]. - getService(Components.interfaces.nsIMicrosummaryService); - if (microsummaryService) - microsummaryService.addGenerator(generatorURI); -} - -// property of nsIClassInfo -nsSidebar.prototype.flags = nsIClassInfo.DOM_OBJECT; - -// property of nsIClassInfo -nsSidebar.prototype.classDescription = "Sidebar"; - -// method of nsIClassInfo -nsSidebar.prototype.getInterfaces = function(count) { - var interfaceList = [nsISidebar, nsISidebarExternal, nsIClassInfo]; - count.value = interfaceList.length; - return interfaceList; -} - -// method of nsIClassInfo -nsSidebar.prototype.getHelperForLanguage = function(count) {return null;} - -nsSidebar.prototype.QueryInterface = -function (iid) { - if (!iid.equals(nsISidebar) && - !iid.equals(nsISidebarExternal) && - !iid.equals(nsIClassInfo) && - !iid.equals(nsISupports)) - throw Components.results.NS_ERROR_NO_INTERFACE; - return this; -} - -var sidebarModule = new Object(); - -sidebarModule.registerSelf = -function (compMgr, fileSpec, location, type) -{ - debug("registering (all right -- a JavaScript module!)"); - compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); - - compMgr.registerFactoryLocation(SIDEBAR_CID, - "Sidebar JS Component", - SIDEBAR_CONTRACTID, - fileSpec, - location, - type); - const CATMAN_CONTRACTID = "@mozilla.org/categorymanager;1"; - const nsICategoryManager = Components.interfaces.nsICategoryManager; - var catman = Components.classes[CATMAN_CONTRACTID]. - getService(nsICategoryManager); - - const JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY = "JavaScript global property"; - catman.addCategoryEntry(JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY, - "sidebar", - SIDEBAR_CONTRACTID, - true, - true); - - catman.addCategoryEntry(JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY, - "external", - SIDEBAR_CONTRACTID, - true, - true); -} - -sidebarModule.getClassObject = -function (compMgr, cid, iid) { - if (!cid.equals(SIDEBAR_CID)) - throw Components.results.NS_ERROR_NO_INTERFACE; - - if (!iid.equals(Components.interfaces.nsIFactory)) - throw Components.results.NS_ERROR_NOT_IMPLEMENTED; - - return sidebarFactory; -} - -sidebarModule.canUnload = -function(compMgr) -{ - debug("Unloading component."); - return true; -} - -/* factory object */ -var sidebarFactory = new Object(); - -sidebarFactory.createInstance = -function (outer, iid) { - debug("CI: " + iid); - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - - return (new nsSidebar()).QueryInterface(iid); -} - -/* entrypoint */ -function NSGetModule(compMgr, fileSpec) { - return sidebarModule; -} - -/* static functions */ -if (DEBUG) - debug = function (s) { dump("-*- sidebar component: " + s + "\n"); } -else - debug = function (s) {} - -var strBundleService = null; -function srGetStrBundle(path) -{ - var strBundle = null; - if (!strBundleService) { - try { - strBundleService = - Components.classes["@mozilla.org/intl/stringbundle;1"].getService(); - strBundleService = - strBundleService.QueryInterface(Components.interfaces.nsIStringBundleService); - } catch (ex) { - dump("\n--** strBundleService failed: " + ex + "\n"); - return null; - } - } - strBundle = strBundleService.createBundle(path); - if (!strBundle) { - dump("\n--** strBundle createInstance failed **--\n"); - } - return strBundle; -} diff --git a/content/base/public/nsIContent.h b/content/base/public/nsIContent.h index 092409f0987..8f1bb56c90a 100644 --- a/content/base/public/nsIContent.h +++ b/content/base/public/nsIContent.h @@ -831,8 +831,7 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIContent, NS_ICONTENT_IID) nsISupports *preservedWrapper = nsnull; \ if (tmp->GetOwnerDoc()) \ preservedWrapper = tmp->GetOwnerDoc()->GetReference(tmp); \ - if (preservedWrapper) \ - cb.NoteXPCOMChild(preservedWrapper); \ + cb.NoteXPCOMChild(preservedWrapper); \ } #define NS_IMPL_CYCLE_COLLECTION_UNLINK_LISTENERMANAGER \ diff --git a/content/base/src/nsDOMAttributeMap.cpp b/content/base/src/nsDOMAttributeMap.cpp index 62d70c58326..b41d82284f2 100644 --- a/content/base/src/nsDOMAttributeMap.cpp +++ b/content/base/src/nsDOMAttributeMap.cpp @@ -103,8 +103,7 @@ TraverseMapEntry(nsAttrHashKey::KeyType aKey, nsCOMPtr& aData, void* nsCycleCollectionTraversalCallback *cb = NS_STATIC_CAST(nsCycleCollectionTraversalCallback*, aUserArg); - if (aData.get()) - cb->NoteXPCOMChild(aData.get()); + cb->NoteXPCOMChild(aData.get()); return PL_DHASH_NEXT; } diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index bd3e586618f..e933d8e5523 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -949,10 +949,7 @@ SubDocTraverser(PLDHashTable *table, PLDHashEntryHdr *hdr, PRUint32 number, NS_STATIC_CAST(nsCycleCollectionTraversalCallback*, arg); cb->NoteXPCOMChild(entry->mKey); - nsISupports *doc = entry->mSubDocument; - if (doc) { - cb->NoteXPCOMChild(doc); - } + cb->NoteXPCOMChild(entry->mSubDocument); return PL_DHASH_NEXT; } @@ -964,10 +961,7 @@ RadioGroupsTraverser(nsHashKey *aKey, void *aData, void* aClosure) nsCycleCollectionTraversalCallback *cb = NS_STATIC_CAST(nsCycleCollectionTraversalCallback*, aClosure); - nsISupports *radioButton = entry->mSelectedRadioButton; - if (radioButton) { - cb->NoteXPCOMChild(radioButton); - } + cb->NoteXPCOMChild(entry->mSelectedRadioButton); nsSmallVoidArray &radioButtons = entry->mRadioButtons; PRUint32 i, count = radioButtons.Count(); @@ -1054,11 +1048,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsDocument) NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mVisitednessChangedURIs) // Traverse any associated preserved wrapper. - { - nsISupports *preservedWrapper = tmp->GetReference(tmp); - if (preservedWrapper) - cb.NoteXPCOMChild(preservedWrapper); - } + cb.NoteXPCOMChild(tmp->GetReference(tmp)); if (tmp->mSubDocuments && tmp->mSubDocuments->ops) { PL_DHashTableEnumerate(tmp->mSubDocuments, SubDocTraverser, &cb); diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index 54952d4ae8f..0c01ed57007 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -3016,14 +3016,10 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsGenericElement) nsISupports* property = NS_STATIC_CAST(nsISupports*, tmp->GetProperty(nsGkAtoms::contextmenulistener)); - if (property) { - cb.NoteXPCOMChild(property); - } + cb.NoteXPCOMChild(property); property = NS_STATIC_CAST(nsISupports*, tmp->GetProperty(nsGkAtoms::popuplistener)); - if (property) { - cb.NoteXPCOMChild(property); - } + cb.NoteXPCOMChild(property); } // Traverse child content. @@ -3038,10 +3034,8 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsGenericElement) { nsDOMSlots *slots = tmp->GetExistingDOMSlots(); if (slots) { - if (slots->mAttributeMap.get()) - cb.NoteXPCOMChild(slots->mAttributeMap.get()); - if (slots->mControllers) - cb.NoteXPCOMChild(slots->mControllers); + cb.NoteXPCOMChild(slots->mAttributeMap.get()); + cb.NoteXPCOMChild(slots->mControllers); } } NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END diff --git a/content/base/src/nsObjectLoadingContent.cpp b/content/base/src/nsObjectLoadingContent.cpp index 804d218330f..a1b2e5a6bc5 100644 --- a/content/base/src/nsObjectLoadingContent.cpp +++ b/content/base/src/nsObjectLoadingContent.cpp @@ -1031,9 +1031,7 @@ nsObjectLoadingContent::RemovedFromDocument() void nsObjectLoadingContent::Traverse(nsCycleCollectionTraversalCallback &cb) { - if (mFrameLoader) { - cb.NoteXPCOMChild(mFrameLoader); - } + cb.NoteXPCOMChild(mFrameLoader); } // diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp index abfdfbc2740..f7e384961e2 100644 --- a/content/events/src/nsEventListenerManager.cpp +++ b/content/events/src/nsEventListenerManager.cpp @@ -400,7 +400,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsEventListenerManager) nsListenerStruct *ls; for (i = 0; i < count; i++) { ls = NS_STATIC_CAST(nsListenerStruct*, tmp->mListeners.ElementAt(i)); - if (ls && ls->mListener.get()) { + if (ls) { cb.NoteXPCOMChild(ls->mListener.get()); } } diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 74fdbd6be00..ba78e692219 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -353,7 +353,7 @@ IdAndNameMapEntryTraverse(PLDHashTable *table, PLDHashEntryHdr *hdr, NS_STATIC_CAST(nsCycleCollectionTraversalCallback*, arg); IdAndNameMapEntry *entry = NS_STATIC_CAST(IdAndNameMapEntry*, hdr); - if (entry->mNameContentList && entry->mNameContentList != NAME_NOT_VALID) + if (entry->mNameContentList != NAME_NOT_VALID) cb->NoteXPCOMChild(entry->mNameContentList); return PL_DHASH_NEXT; diff --git a/content/xbl/src/nsXBLPrototypeBinding.cpp b/content/xbl/src/nsXBLPrototypeBinding.cpp index aef60f7a4b6..843429cc504 100644 --- a/content/xbl/src/nsXBLPrototypeBinding.cpp +++ b/content/xbl/src/nsXBLPrototypeBinding.cpp @@ -284,7 +284,7 @@ nsXBLPrototypeBinding::Traverse(nsCycleCollectionTraversalCallback &cb) const { cb.NoteXPCOMChild(mBinding); // XXX mInsertionPointTable! - if (mResources && mResources->mLoader) + if (mResources) cb.NoteXPCOMChild(mResources->mLoader); } diff --git a/content/xul/document/src/nsXULPrototypeDocument.cpp b/content/xul/document/src/nsXULPrototypeDocument.cpp index 749787e62ba..b3abb09265f 100644 --- a/content/xul/document/src/nsXULPrototypeDocument.cpp +++ b/content/xul/document/src/nsXULPrototypeDocument.cpp @@ -623,12 +623,9 @@ 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); - } + PRUint32 lang_index; + NS_STID_FOR_INDEX(lang_index) { + cb.NoteXPCOMChild(tmp->mScriptContexts[lang_index]); } } NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END diff --git a/content/xul/templates/src/nsTemplateRule.h b/content/xul/templates/src/nsTemplateRule.h index 06f97a945c9..5b023644123 100644 --- a/content/xul/templates/src/nsTemplateRule.h +++ b/content/xul/templates/src/nsTemplateRule.h @@ -227,12 +227,8 @@ public: void Traverse(nsCycleCollectionTraversalCallback &cb) const { - if (mRuleNode) { - cb.NoteXPCOMChild(mRuleNode); - } - if (mAction) { - cb.NoteXPCOMChild(mAction); - } + cb.NoteXPCOMChild(mRuleNode); + cb.NoteXPCOMChild(mAction); } protected: diff --git a/content/xul/templates/src/nsXULSortService.h b/content/xul/templates/src/nsXULSortService.h index c820198bf3f..f06804da3df 100644 --- a/content/xul/templates/src/nsXULSortService.h +++ b/content/xul/templates/src/nsXULSortService.h @@ -94,12 +94,8 @@ struct nsSortState } void Traverse(nsCycleCollectionTraversalCallback &cb) const { - if (processor) { - cb.NoteXPCOMChild(processor); - } - if (lastContainer) { - cb.NoteXPCOMChild(lastContainer); - } + cb.NoteXPCOMChild(processor); + cb.NoteXPCOMChild(lastContainer); } }; diff --git a/content/xul/templates/src/nsXULTemplateBuilder.cpp b/content/xul/templates/src/nsXULTemplateBuilder.cpp index 7acff49a90e..0c4a907e99c 100644 --- a/content/xul/templates/src/nsXULTemplateBuilder.cpp +++ b/content/xul/templates/src/nsXULTemplateBuilder.cpp @@ -239,12 +239,8 @@ TraverseMatchList(nsISupports* aKey, nsTemplateMatch* aMatch, void* aContext) 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); + cb->NoteXPCOMChild(match->GetContainer()); + cb->NoteXPCOMChild(match->mResult); match = match->mNext; } @@ -265,9 +261,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXULTemplateBuilder) for (i = 0; i < count; ++i) { nsTemplateQuerySet *set = tmp->mQuerySets[i]; cb.NoteXPCOMChild(set->mQueryNode); - if (set->mCompiledQuery) { - cb.NoteXPCOMChild(set->mCompiledQuery); - } + cb.NoteXPCOMChild(set->mCompiledQuery); PRUint16 j, rulesCount = set->RuleCount(); for (j = 0; j < rulesCount; ++j) { set->GetRuleAt(j)->Traverse(cb); diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index 691fe8c68f6..2dcf7026e75 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -727,11 +727,8 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsGlobalWindow) // Traverse any associated preserved wrappers. { - nsISupports *preservedWrapper = nsnull; if (tmp->mDoc) { - preservedWrapper = tmp->mDoc->GetReference(tmp); - if (preservedWrapper) - cb.NoteXPCOMChild(preservedWrapper); + cb.NoteXPCOMChild(tmp->mDoc->GetReference(tmp)); } } diff --git a/dom/src/base/nsJSEnvironment.cpp b/dom/src/base/nsJSEnvironment.cpp index 8dcf4b571e8..26ba67f41d1 100644 --- a/dom/src/base/nsJSEnvironment.cpp +++ b/dom/src/base/nsJSEnvironment.cpp @@ -1023,10 +1023,7 @@ NS_IMPL_CYCLE_COLLECTION_CLASS(nsJSContext) 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(JAVASCRIPT, globalObject); - } + cb.NoteScriptChild(JAVASCRIPT, ::JS_GetGlobalObject(tmp->mContext)); NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_INTERFACE_MAP_BEGIN(nsJSContext) diff --git a/dom/src/base/nsJSTimeoutHandler.cpp b/dom/src/base/nsJSTimeoutHandler.cpp index 9991daa5e37..3028b2c7efe 100644 --- a/dom/src/base/nsJSTimeoutHandler.cpp +++ b/dom/src/base/nsJSTimeoutHandler.cpp @@ -118,8 +118,7 @@ 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); + cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, tmp->mFunObj); NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END NS_INTERFACE_MAP_BEGIN(nsJSScriptTimeoutHandler) diff --git a/js/src/xpconnect/src/nsXPConnect.cpp b/js/src/xpconnect/src/nsXPConnect.cpp index a48072ee3c9..26dbcb9fd23 100644 --- a/js/src/xpconnect/src/nsXPConnect.cpp +++ b/js/src/xpconnect/src/nsXPConnect.cpp @@ -656,29 +656,20 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb) else if(clazz->flags & JSCLASS_HAS_PRIVATE && clazz->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS) { - void *v = JS_GetPrivate(cx, obj); - if (v) - cb.NoteXPCOMChild(NS_STATIC_CAST(nsISupports*, v)); + cb.NoteXPCOMChild(NS_STATIC_CAST(nsISupports*, JS_GetPrivate(cx, obj))); } - JSObject *parent = OBJ_GET_PARENT(cx, obj); - if(parent) - cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, parent); - - JSObject *proto = OBJ_GET_PROTO(cx, obj); - if(proto) - cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, proto); + cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, + OBJ_GET_PARENT(cx, obj)); + cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, + OBJ_GET_PROTO(cx, obj)); for(uint32 i = JSSLOT_START(clazz); i < STOBJ_NSLOTS(obj); ++i) { jsval val = STOBJ_GET_SLOT(obj, i); - if (!JSVAL_IS_NULL(val) - && JSVAL_IS_OBJECT(val)) - { - JSObject *child = JSVAL_TO_OBJECT(val); - if (child) - cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, child); - } + if (JSVAL_IS_OBJECT(val)) + cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, + JSVAL_TO_OBJECT(val)); } #ifndef XPCONNECT_STANDALONE @@ -686,8 +677,7 @@ nsXPConnect::Traverse(void *p, nsCycleCollectionTraversalCallback &cb) { nsISupports *principal = nsnull; mObjRefcounts->mScopes.Get(obj, &principal); - if(principal) - cb.NoteXPCOMChild(principal); + cb.NoteXPCOMChild(principal); } #endif diff --git a/js/src/xpconnect/src/xpccomponents.cpp b/js/src/xpconnect/src/xpccomponents.cpp index 68a02607de1..57482c79e93 100644 --- a/js/src/xpconnect/src/xpccomponents.cpp +++ b/js/src/xpconnect/src/xpccomponents.cpp @@ -3101,7 +3101,8 @@ sandbox_finalize(JSContext *cx, JSObject *obj) } static JSClass SandboxClass = { - "Sandbox", JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS, + "Sandbox", + JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS | JSCLASS_GLOBAL_FLAGS, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, sandbox_enumerate, sandbox_resolve, JS_ConvertStub, sandbox_finalize, JSCLASS_NO_OPTIONAL_MEMBERS diff --git a/js/src/xpconnect/src/xpcthreadcontext.cpp b/js/src/xpconnect/src/xpcthreadcontext.cpp index 7dbe263f750..3d7422a6699 100644 --- a/js/src/xpconnect/src/xpcthreadcontext.cpp +++ b/js/src/xpconnect/src/xpcthreadcontext.cpp @@ -140,7 +140,7 @@ SafeFinalize(JSContext* cx, JSObject* obj) static JSClass global_class = { "global_for_XPCJSContextStack_SafeJSContext", #ifndef XPCONNECT_STANDALONE - JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS, + JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS | JSCLASS_GLOBAL_FLAGS, #else 0, #endif diff --git a/js/src/xpconnect/src/xpcwrappedjs.cpp b/js/src/xpconnect/src/xpcwrappedjs.cpp index fee0b5faf77..b933d61017e 100644 --- a/js/src/xpconnect/src/xpcwrappedjs.cpp +++ b/js/src/xpconnect/src/xpcwrappedjs.cpp @@ -102,17 +102,11 @@ NS_CYCLE_COLLECTION_CLASSNAME(nsXPCWrappedJS)::Traverse nsXPCWrappedJS* root = tmp->GetRootWrapper(); if(root == tmp) - { // The root wrapper keeps the aggregated native object alive. - nsISupports* outer = tmp->GetAggregatedNativeObject(); - if (outer) - cb.NoteXPCOMChild(outer); - } + cb.NoteXPCOMChild(tmp->GetAggregatedNativeObject()); else - { // Non-root wrappers keep their root alive. cb.NoteXPCOMChild(NS_STATIC_CAST(nsIXPConnectWrappedJS*, root)); - } return NS_OK; } diff --git a/js/src/xpconnect/src/xpcwrappednative.cpp b/js/src/xpconnect/src/xpcwrappednative.cpp index bc48097c1fa..c0b141f279f 100644 --- a/js/src/xpconnect/src/xpcwrappednative.cpp +++ b/js/src/xpconnect/src/xpcwrappednative.cpp @@ -85,9 +85,8 @@ NS_CYCLE_COLLECTION_CLASSNAME(XPCWrappedNative)::Traverse(nsISupports *s, JSObject *obj = nsnull; nsresult rv = tmp->GetJSObject(&obj); - if (NS_SUCCEEDED(rv) && obj) { + if (NS_SUCCEEDED(rv)) cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, obj); - } } // XXX If there is a scriptable helper we will not be able to find out what @@ -103,17 +102,14 @@ NS_CYCLE_COLLECTION_CLASSNAME(XPCWrappedNative)::Traverse(nsISupports *s, tmp->GetProto()->GetJSProtoObject()); // XPCWrappedNative marks its mNativeWrapper (see MarkBeforeJSFinalize). - if(tmp->mNativeWrapper) - cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, - tmp->mNativeWrapper); + cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, tmp->mNativeWrapper); // XPCWrappedNative marks its scope. tmp->GetScope()->Traverse(cb); // XPCWrappedNative keeps its native object alive. - if (tmp->GetIdentityObject()) { - cb.NoteXPCOMChild(tmp->GetIdentityObject()); - } + cb.NoteXPCOMChild(tmp->GetIdentityObject()); + return NS_OK; } diff --git a/js/src/xpconnect/src/xpcwrappednativescope.cpp b/js/src/xpconnect/src/xpcwrappednativescope.cpp index 425cd6d5b45..2fb085cc9c7 100644 --- a/js/src/xpconnect/src/xpcwrappednativescope.cpp +++ b/js/src/xpconnect/src/xpcwrappednativescope.cpp @@ -798,12 +798,9 @@ XPCWrappedNativeScope::Traverse(nsCycleCollectionTraversalCallback &cb) { // See MarkScopeJSObjects. cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, mGlobalJSObject); - JSObject *obj = mPrototypeJSObject; - if(obj) - cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, obj); - obj = mPrototypeJSFunction; - if(obj) - cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, obj); + cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, mPrototypeJSObject); + cb.NoteScriptChild(nsIProgrammingLanguage::JAVASCRIPT, + mPrototypeJSFunction); } #ifndef XPCONNECT_STANDALONE diff --git a/xpcom/base/nsCycleCollectionParticipant.h b/xpcom/base/nsCycleCollectionParticipant.h index 256c0d83997..ebf8b05ed9e 100644 --- a/xpcom/base/nsCycleCollectionParticipant.h +++ b/xpcom/base/nsCycleCollectionParticipant.h @@ -218,23 +218,19 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsCycleCollectionParticipant, NS_CYCLE_COLLECTION_CLASSNAME(_base_class)::Traverse(s, cb); #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_RAWPTR(_field) \ - if (tmp->_field) { cb.NoteXPCOMChild(tmp->_field); } + cb.NoteXPCOMChild(tmp->_field); #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(_field) \ - if (tmp->_field) { cb.NoteXPCOMChild(tmp->_field.get()); } + 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); } \ - } + cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(_base*, tmp->_field)); #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(_field) \ { \ - PRInt32 i; \ - for (i = 0; i < tmp->_field.Count(); ++i) \ - if (tmp->_field[i]) \ - cb.NoteXPCOMChild(tmp->_field[i]); \ + PRInt32 i; \ + for (i = 0; i < tmp->_field.Count(); ++i) \ + cb.NoteXPCOMChild(tmp->_field[i]); \ } #define NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END \ diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp index 5d2638f0bc4..fb39487e86e 100644 --- a/xpcom/base/nsCycleCollector.cpp +++ b/xpcom/base/nsCycleCollector.cpp @@ -636,7 +636,7 @@ void GraphWalker::NoteXPCOMChild(nsISupports *child) { if (!child) - Fault("null XPCOM pointer returned"); + return; child = canonicalize(child); @@ -655,7 +655,7 @@ void GraphWalker::NoteScriptChild(PRUint32 langID, void *child) { if (!child) - Fault("null script language pointer returned"); + return; if (!mRuntimes[langID]) Fault("traversing pointer for unregistered language", child); @@ -1532,7 +1532,7 @@ nsCycleCollector::Suspect(nsISupports *n) if (!NS_IsMainThread()) Fault("trying to suspect from non-main thread"); - if (!nsCycleCollector_isScanSafe(n)) + if (!n || !nsCycleCollector_isScanSafe(n)) Fault("suspected a non-scansafe pointer", n); if (nsCycleCollector_shouldSuppress(n)) @@ -1764,9 +1764,6 @@ nsCycleCollector_isScanSafe(nsISupports *s) { nsresult rv; - if (!s) - return PR_FALSE; - nsCOMPtr cp = do_QueryInterface(s, &rv); if (NS_FAILED(rv)) { sCollector.mStats.mFailedQI++; diff --git a/xpcom/ds/nsVariant.cpp b/xpcom/ds/nsVariant.cpp index c1e240395fe..c33621b977b 100644 --- a/xpcom/ds/nsVariant.cpp +++ b/xpcom/ds/nsVariant.cpp @@ -1666,9 +1666,7 @@ nsVariant::Traverse(const nsDiscriminatedUnion& data, { case nsIDataType::VTYPE_INTERFACE: case nsIDataType::VTYPE_INTERFACE_IS: - if (data.u.iface.mInterfaceValue) { - cb.NoteXPCOMChild(data.u.iface.mInterfaceValue); - } + cb.NoteXPCOMChild(data.u.iface.mInterfaceValue); break; case nsIDataType::VTYPE_ARRAY: switch(data.u.array.mArrayType) { @@ -1677,8 +1675,7 @@ nsVariant::Traverse(const nsDiscriminatedUnion& data, { nsISupports** p = (nsISupports**) data.u.array.mArrayValue; for(PRUint32 i = data.u.array.mArrayCount; i > 0; p++, i--) - if(*p) - cb.NoteXPCOMChild(*p); + cb.NoteXPCOMChild(*p); } default: break;