Bug 947448 - Define and use nsXPCWrappedJS::IsRootWrapper. r=bholley

This commit is contained in:
Andrew McCreight 2013-12-10 08:07:20 -08:00
parent 64bc62ec96
commit 0aeb884580
3 changed files with 14 additions and 19 deletions

View File

@ -674,7 +674,7 @@ CanSkipWrappedJS(nsXPCWrappedJS *wrappedJS)
// If traversing wrappedJS wouldn't release it, nor
// cause any other objects to be added to the graph, no
// need to add it to the graph at all.
bool isRootWrappedJS = wrappedJS->GetRootWrapper() == wrappedJS;
bool isRootWrappedJS = wrappedJS->IsRootWrapper();
if (nsCCUncollectableMarker::sGeneration &&
(!obj || !xpc_IsGrayGCThing(obj)) &&
!wrappedJS->IsSubjectToFinalization() &&

View File

@ -51,15 +51,12 @@ NS_CYCLE_COLLECTION_CLASSNAME(nsXPCWrappedJS)::Traverse
cb.NoteJSChild(tmp->GetJSObjectPreserveColor());
}
nsXPCWrappedJS* root = tmp->GetRootWrapper();
if (root == tmp) {
// The root wrapper keeps the aggregated native object alive.
if (tmp->IsRootWrapper()) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "aggregated native");
cb.NoteXPCOMChild(tmp->GetAggregatedNativeObject());
} else {
// Non-root wrappers keep their root alive.
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "root");
cb.NoteXPCOMChild(static_cast<nsIXPConnectWrappedJS*>(root));
cb.NoteXPCOMChild(static_cast<nsIXPConnectWrappedJS*>(tmp->GetRootWrapper()));
}
return NS_OK;
@ -219,7 +216,7 @@ nsXPCWrappedJS::GetTraceName(JSTracer* trc, char *buf, size_t bufsize)
NS_IMETHODIMP
nsXPCWrappedJS::GetWeakReference(nsIWeakReference** aInstancePtr)
{
if (mRoot != this)
if (!IsRootWrapper())
return mRoot->GetWeakReference(aInstancePtr);
return nsSupportsWeakReference::GetWeakReference(aInstancePtr);
@ -356,7 +353,7 @@ nsXPCWrappedJS::nsXPCWrappedJS(JSContext* cx,
NS_ADDREF(aClass);
NS_IF_ADDREF(mOuter);
if (mRoot != this)
if (!IsRootWrapper())
NS_ADDREF(mRoot);
}
@ -365,8 +362,7 @@ nsXPCWrappedJS::~nsXPCWrappedJS()
{
NS_PRECONDITION(0 == mRefCnt, "refcounting error");
if (mRoot == this) {
// Remove this root wrapper from the map
if (IsRootWrapper()) {
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
JSObject2WrappedJSMap* map = rt->GetWrappedJSMap();
if (map)
@ -381,8 +377,7 @@ nsXPCWrappedJS::Unlink()
if (IsValid()) {
XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance();
if (rt) {
if (mRoot == this) {
// remove this root wrapper from the map
if (IsRootWrapper()) {
JSObject2WrappedJSMap* map = rt->GetWrappedJSMap();
if (map)
map->Remove(this);
@ -395,7 +390,7 @@ nsXPCWrappedJS::Unlink()
mJSObj = nullptr;
}
if (mRoot == this) {
if (IsRootWrapper()) {
ClearWeakReferences();
} else if (mRoot) {
// unlink this wrapper
@ -551,9 +546,8 @@ nsXPCWrappedJS::DebugDump(int16_t depth)
XPC_LOG_ALWAYS(("nsXPCWrappedJS @ %x with mRefCnt = %d", this, mRefCnt.get()));
XPC_LOG_INDENT();
bool isRoot = mRoot == this;
XPC_LOG_ALWAYS(("%s wrapper around JSObject @ %x", \
isRoot ? "ROOT":"non-root", mJSObj.get()));
IsRootWrapper() ? "ROOT":"non-root", mJSObj.get()));
char* name;
GetClass()->GetInterfaceInfo()->GetName(&name);
XPC_LOG_ALWAYS(("interface name is %s", name));
@ -565,18 +559,18 @@ nsXPCWrappedJS::DebugDump(int16_t depth)
NS_Free(iid);
XPC_LOG_ALWAYS(("nsXPCWrappedJSClass @ %x", mClass));
if (!isRoot)
if (!IsRootWrapper())
XPC_LOG_OUTDENT();
if (mNext) {
if (isRoot) {
if (IsRootWrapper()) {
XPC_LOG_ALWAYS(("Additional wrappers for this object..."));
XPC_LOG_INDENT();
}
mNext->DebugDump(depth);
if (isRoot)
if (IsRootWrapper())
XPC_LOG_OUTDENT();
}
if (isRoot)
if (IsRootWrapper())
XPC_LOG_OUTDENT();
#endif
return NS_OK;

View File

@ -2502,6 +2502,7 @@ public:
nsXPCWrappedJS* Find(REFNSIID aIID);
nsXPCWrappedJS* FindInherited(REFNSIID aIID);
bool IsRootWrapper() const {return mRoot == this;}
bool IsValid() const {return mJSObj != nullptr;}
void SystemIsBeingShutDown();