Skip to content

Commit

Permalink
Bug 1187151 (part 15) - Replace nsBaseHashtable::Enumerate() calls in…
Browse files Browse the repository at this point in the history
… dom/ with iterators. r=baku.
  • Loading branch information
nnethercote committed Jan 28, 2016
1 parent 78661dc commit 1459b65
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 44 deletions.
52 changes: 18 additions & 34 deletions dom/base/nsCCUncollectableMarker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TraceClosure*>(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<XULDocument*>(doc);
xulDoc->TraceProtos(closure->mTrc, closure->mGCNumber);
}
#endif
}
return PL_DHASH_NEXT;
}

void
mozilla::dom::TraceBlackJS(JSTracer* aTrc, uint32_t aGCNumber, bool aIsShutdownGC)
{
Expand All @@ -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<XULDocument*>(doc);
xulDoc->TraceProtos(aTrc, aGCNumber);
}
#endif
}
}
}
}
14 changes: 4 additions & 10 deletions dom/base/nsFrameMessageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1624,23 +1624,17 @@ nsMessageManagerScriptExecutor::DidCreateGlobal()
}
}

static PLDHashOperator
RemoveCachedScriptEntry(const nsAString& aKey,
nsMessageManagerScriptHolder*& aData,
void* aUserArg)
{
delete aData;
return PL_DHASH_REMOVE;
}

// static
void
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;
Expand Down

0 comments on commit 1459b65

Please sign in to comment.