Bug 1301301, part 1 - Unify NoteJSObject and NoteJSScript into NoteJSChild. r=smaug

This will let my next patch pass in other GC things.

This should not change behavior in any important way.

MozReview-Commit-ID: FykviKKvQzI
This commit is contained in:
Andrew McCreight 2016-09-23 15:42:13 -07:00
parent 47c77f7e97
commit 5b9c57b7a2
8 changed files with 17 additions and 50 deletions

View File

@ -69,7 +69,7 @@ class DebugWrapperTraversalCallback : public nsCycleCollectionTraversalCallback
public:
explicit DebugWrapperTraversalCallback(JSObject* aWrapper)
: mFound(false)
, mWrapper(aWrapper)
, mWrapper(JS::GCCellPtr(aWrapper))
{
mFlags = WANT_ALL_TRACES;
}
@ -84,15 +84,12 @@ public:
{
}
NS_IMETHOD_(void) NoteJSObject(JSObject* aChild)
NS_IMETHOD_(void) NoteJSChild(const JS::GCCellPtr& aChild)
{
if (aChild == mWrapper) {
mFound = true;
}
}
NS_IMETHOD_(void) NoteJSScript(JSScript* aChild)
{
}
NS_IMETHOD_(void) NoteXPCOMChild(nsISupports* aChild)
{
}
@ -108,7 +105,7 @@ public:
bool mFound;
private:
JSObject* mWrapper;
JS::GCCellPtr mWrapper;
};
static void
@ -117,7 +114,7 @@ DebugWrapperTraceCallback(JS::GCCellPtr aPtr, const char* aName, void* aClosure)
DebugWrapperTraversalCallback* callback =
static_cast<DebugWrapperTraversalCallback*>(aClosure);
if (aPtr.is<JSObject>()) {
callback->NoteJSObject(&aPtr.as<JSObject>());
callback->NoteJSChild(aPtr);
}
}

View File

@ -75,7 +75,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(XPCVariant)
JS::Value val = tmp->GetJSValPreserveColor();
if (val.isObject()) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mJSVal");
cb.NoteJSObject(&val.toObject());
cb.NoteJSChild(JS::GCCellPtr(val));
}
tmp->mData.Traverse(cb);

View File

@ -123,7 +123,7 @@ NS_CYCLE_COLLECTION_CLASSNAME(nsXPCWrappedJS)::Traverse
if (tmp->IsValid()) {
MOZ_ASSERT(refcnt > 1);
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mJSObj");
cb.NoteJSObject(tmp->GetJSObjectPreserveColor());
cb.NoteJSChild(JS::GCCellPtr(tmp->GetJSObjectPreserveColor()));
}
if (tmp->IsRootWrapper()) {

View File

@ -74,7 +74,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INTERNAL(XPCWrappedNative)
JSObject* obj = tmp->GetFlatJSObjectPreserveColor();
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mFlatJSObject");
cb.NoteJSObject(obj);
cb.NoteJSChild(JS::GCCellPtr(obj));
}
// XPCWrappedNative keeps its native object alive.

View File

@ -355,11 +355,7 @@ TraversalTracer::onChild(const JS::GCCellPtr& aThing)
getTracingEdgeName(buffer, sizeof(buffer));
mCb.NoteNextEdgeName(buffer);
}
if (aThing.is<JSObject>()) {
mCb.NoteJSObject(&aThing.as<JSObject>());
} else {
mCb.NoteJSScript(&aThing.as<JSScript>());
}
mCb.NoteJSChild(aThing);
} else if (aThing.is<js::Shape>()) {
// The maximum depth of traversal when tracing a Shape is unbounded, due to
// the parent pointers on the shape.

View File

@ -2122,8 +2122,7 @@ public:
uint64_t aCompartmentAddress);
NS_IMETHOD_(void) NoteXPCOMChild(nsISupports* aChild);
NS_IMETHOD_(void) NoteJSObject(JSObject* aChild);
NS_IMETHOD_(void) NoteJSScript(JSScript* aChild);
NS_IMETHOD_(void) NoteJSChild(const JS::GCCellPtr& aThing);
NS_IMETHOD_(void) NoteNativeChild(void* aChild,
nsCycleCollectionParticipant* aParticipant);
NS_IMETHOD_(void) NoteNextEdgeName(const char* aName);
@ -2401,19 +2400,7 @@ CCGraphBuilder::NoteNativeChild(void* aChild,
}
NS_IMETHODIMP_(void)
CCGraphBuilder::NoteJSObject(JSObject* aChild)
{
return NoteJSChild(JS::GCCellPtr(aChild));
}
NS_IMETHODIMP_(void)
CCGraphBuilder::NoteJSScript(JSScript* aChild)
{
return NoteJSChild(JS::GCCellPtr(aChild));
}
void
CCGraphBuilder::NoteJSChild(JS::GCCellPtr aChild)
CCGraphBuilder::NoteJSChild(const JS::GCCellPtr& aChild)
{
if (!aChild) {
return;
@ -2503,8 +2490,7 @@ public:
NS_IMETHOD_(void) NoteXPCOMChild(nsISupports* aChild);
NS_IMETHOD_(void) NoteNativeChild(void* aChild,
nsCycleCollectionParticipant* aHelper);
NS_IMETHOD_(void) NoteJSObject(JSObject* aChild);
NS_IMETHOD_(void) NoteJSScript(JSScript* aChild);
NS_IMETHOD_(void) NoteJSChild(const JS::GCCellPtr& aThing);
NS_IMETHOD_(void) DescribeRefCountedNode(nsrefcnt aRefcount,
const char* aObjname)
@ -2553,17 +2539,9 @@ ChildFinder::NoteNativeChild(void* aChild,
}
NS_IMETHODIMP_(void)
ChildFinder::NoteJSObject(JSObject* aChild)
ChildFinder::NoteJSChild(const JS::GCCellPtr& aChild)
{
if (aChild && JS::ObjectIsMarkedGray(aChild)) {
mMayHaveChild = true;
}
}
NS_IMETHODIMP_(void)
ChildFinder::NoteJSScript(JSScript* aChild)
{
if (aChild && JS::ScriptIsMarkedGray(aChild)) {
if (aChild && JS::GCThingIsMarkedGray(aChild)) {
mMayHaveChild = true;
}
}

View File

@ -27,12 +27,8 @@ nsScriptObjectTracer::NoteJSChild(JS::GCCellPtr aGCThing, const char* aName,
nsCycleCollectionTraversalCallback* cb =
static_cast<nsCycleCollectionTraversalCallback*>(aClosure);
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, aName);
if (aGCThing.is<JSObject>()) {
cb->NoteJSObject(&aGCThing.as<JSObject>());
} else if (aGCThing.is<JSScript>()) {
cb->NoteJSScript(&aGCThing.as<JSScript>());
} else {
MOZ_ASSERT(!mozilla::AddToCCKind(aGCThing.kind()));
if (mozilla::AddToCCKind(aGCThing.kind())) {
cb->NoteJSChild(aGCThing);
}
}

View File

@ -8,6 +8,7 @@
#define nsCycleCollectionTraversalCallback_h__
#include "jspubtd.h"
#include "js/HeapAPI.h"
#include "nsISupports.h"
class nsCycleCollectionParticipant;
@ -27,8 +28,7 @@ public:
uint64_t aCompartmentAddress = 0) = 0;
NS_IMETHOD_(void) NoteXPCOMChild(nsISupports* aChild) = 0;
NS_IMETHOD_(void) NoteJSObject(JSObject* aChild) = 0;
NS_IMETHOD_(void) NoteJSScript(JSScript* aChild) = 0;
NS_IMETHOD_(void) NoteJSChild(const JS::GCCellPtr& aThing) = 0;
NS_IMETHOD_(void) NoteNativeChild(void* aChild,
nsCycleCollectionParticipant* aHelper) = 0;