From b0da382c6caf99d976a51c931e4444cf89be1970 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 28 Jan 2016 14:08:19 -0800 Subject: [PATCH] Bug 1187151 (part 15) - Replace nsBaseHashtable::Enumerate() calls in dom/ with iterators. r=baku. --HG-- extra : rebase_source : ecaa04bef4088c23213fe470549336c1a7420f1c --- dom/base/nsCCUncollectableMarker.cpp | 52 ++++++++++------------------ dom/base/nsFrameMessageManager.cpp | 14 +++----- 2 files changed, 22 insertions(+), 44 deletions(-) diff --git a/dom/base/nsCCUncollectableMarker.cpp b/dom/base/nsCCUncollectableMarker.cpp index eb5b76afbc04..b8b010402d94 100644 --- a/dom/base/nsCCUncollectableMarker.cpp +++ b/dom/base/nsCCUncollectableMarker.cpp @@ -464,37 +464,6 @@ nsCCUncollectableMarker::Observe(nsISupports* aSubject, const char* aTopic, return NS_OK; } -struct TraceClosure -{ - TraceClosure(JSTracer* aTrc, uint32_t aGCNumber) - : mTrc(aTrc), mGCNumber(aGCNumber) - {} - JSTracer* mTrc; - uint32_t mGCNumber; -}; - -static PLDHashOperator -TraceActiveWindowGlobal(const uint64_t& aId, nsGlobalWindow*& aWindow, void* aClosure) -{ - if (aWindow->GetDocShell() && aWindow->IsOuterWindow()) { - TraceClosure* closure = static_cast(aClosure); - aWindow->TraceGlobalJSObject(closure->mTrc); - EventListenerManager* elm = aWindow->GetExistingListenerManager(); - if (elm) { - elm->TraceListeners(closure->mTrc); - } - -#ifdef MOZ_XUL - nsIDocument* doc = aWindow->GetExtantDoc(); - if (doc && doc->IsXULDocument()) { - XULDocument* xulDoc = static_cast(doc); - xulDoc->TraceProtos(closure->mTrc, closure->mGCNumber); - } -#endif - } - return PL_DHASH_NEXT; -} - void mozilla::dom::TraceBlackJS(JSTracer* aTrc, uint32_t aGCNumber, bool aIsShutdownGC) { @@ -515,12 +484,27 @@ mozilla::dom::TraceBlackJS(JSTracer* aTrc, uint32_t aGCNumber, bool aIsShutdownG return; } - TraceClosure closure(aTrc, aGCNumber); - // Mark globals of active windows black. nsGlobalWindow::WindowByIdTable* windowsById = nsGlobalWindow::GetWindowsTable(); if (windowsById) { - windowsById->Enumerate(TraceActiveWindowGlobal, &closure); + for (auto iter = windowsById->Iter(); !iter.Done(); iter.Next()) { + nsGlobalWindow* window = iter.Data(); + if (window->GetDocShell() && window->IsOuterWindow()) { + window->TraceGlobalJSObject(aTrc); + EventListenerManager* elm = window->GetExistingListenerManager(); + if (elm) { + elm->TraceListeners(aTrc); + } + +#ifdef MOZ_XUL + nsIDocument* doc = window->GetExtantDoc(); + if (doc && doc->IsXULDocument()) { + XULDocument* xulDoc = static_cast(doc); + xulDoc->TraceProtos(aTrc, aGCNumber); + } +#endif + } + } } } diff --git a/dom/base/nsFrameMessageManager.cpp b/dom/base/nsFrameMessageManager.cpp index 5453095a953e..caab48780ba5 100644 --- a/dom/base/nsFrameMessageManager.cpp +++ b/dom/base/nsFrameMessageManager.cpp @@ -1624,15 +1624,6 @@ nsMessageManagerScriptExecutor::DidCreateGlobal() } } -static PLDHashOperator -RemoveCachedScriptEntry(const nsAString& aKey, - nsMessageManagerScriptHolder*& aData, - void* aUserArg) -{ - delete aData; - return PL_DHASH_REMOVE; -} - // static void nsMessageManagerScriptExecutor::Shutdown() @@ -1640,7 +1631,10 @@ nsMessageManagerScriptExecutor::Shutdown() if (sCachedScripts) { AutoSafeJSContext cx; NS_ASSERTION(sCachedScripts != nullptr, "Need cached scripts"); - sCachedScripts->Enumerate(RemoveCachedScriptEntry, nullptr); + for (auto iter = sCachedScripts->Iter(); !iter.Done(); iter.Next()) { + delete iter.Data(); + iter.Remove(); + } delete sCachedScripts; sCachedScripts = nullptr;