Bug 1184400, part 1 - Make XPCJSRuntime::SuspectWrappedNative into a method on XPCWrappedNative. r=bholley

This commit is contained in:
Andrew McCreight 2015-07-16 17:50:43 -07:00
Родитель f3d75a224c
Коммит e7070f39fe
4 изменённых файлов: 19 добавлений и 22 удалений

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

@ -571,24 +571,6 @@ void XPCJSRuntime::TraceAdditionalNativeGrayRoots(JSTracer* trc)
static_cast<nsXPCWrappedJS*>(e)->TraceJS(trc);
}
// static
void
XPCJSRuntime::SuspectWrappedNative(XPCWrappedNative* wrapper,
nsCycleCollectionNoteRootCallback& cb)
{
if (!wrapper->IsValid() || wrapper->IsWrapperExpired())
return;
MOZ_ASSERT(NS_IsMainThread(),
"Suspecting wrapped natives from non-main thread");
// Only record objects that might be part of a cycle as roots, unless
// the callback wants all traces (a debug feature).
JSObject* obj = wrapper->GetFlatJSObjectPreserveColor();
if (JS::ObjectIsMarkedGray(obj) || cb.WantAllTraces())
cb.NoteJSRoot(obj);
}
void
XPCJSRuntime::TraverseAdditionalNativeRoots(nsCycleCollectionNoteRootCallback& cb)
{

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

@ -17,6 +17,7 @@
#include "XrayWrapper.h"
#include "nsContentUtils.h"
#include "nsCycleCollectionNoteRootCallback.h"
#include <stdint.h>
#include "mozilla/DeferredFinalize.h"
@ -93,6 +94,22 @@ NS_CYCLE_COLLECTION_CLASSNAME(XPCWrappedNative)::Traverse
return NS_OK;
}
void
XPCWrappedNative::Suspect(nsCycleCollectionNoteRootCallback& cb)
{
if (!IsValid() || IsWrapperExpired())
return;
MOZ_ASSERT(NS_IsMainThread(),
"Suspecting wrapped natives from non-main thread");
// Only record objects that might be part of a cycle as roots, unless
// the callback wants all traces (a debug feature).
JSObject* obj = GetFlatJSObjectPreserveColor();
if (JS::ObjectIsMarkedGray(obj) || cb.WantAllTraces())
cb.NoteJSRoot(obj);
}
void
XPCWrappedNative::NoteTearoffs(nsCycleCollectionTraversalCallback& cb)
{

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

@ -500,7 +500,7 @@ XPCWrappedNativeScope::SuspectAllWrappers(XPCJSRuntime* rt,
auto entry = static_cast<Native2WrappedNativeMap::Entry*>(i.Get());
XPCWrappedNative* wrapper = entry->value;
if (wrapper->HasExternalReference())
XPCJSRuntime::SuspectWrappedNative(wrapper, cb);
wrapper->Suspect(cb);
}
if (cur->mDOMExpandoSet) {

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

@ -580,9 +580,6 @@ public:
inline void AddWrappedJSRoot(nsXPCWrappedJS* wrappedJS);
inline void AddObjectHolderRoot(XPCJSObjectHolder* holder);
static void SuspectWrappedNative(XPCWrappedNative* wrapper,
nsCycleCollectionNoteRootCallback& cb);
void DebugDump(int16_t depth);
void SystemIsBeingShutDown();
@ -2247,6 +2244,7 @@ public:
bool HasExternalReference() const {return mRefCnt > 1;}
void Suspect(nsCycleCollectionNoteRootCallback& cb);
void NoteTearoffs(nsCycleCollectionTraversalCallback& cb);
// Make ctor and dtor protected (rather than private) to placate nsCOMPtr.