Bug 1380397 - Use PersistentRooted to implement XPCJSObjectHolder r=mccr8

This commit is contained in:
Jon Coppeard 2017-07-13 09:51:58 +01:00
Родитель e899441ccb
Коммит 350ab58390
5 изменённых файлов: 11 добавлений и 42 удалений

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

@ -729,13 +729,13 @@ XPCConvert::JSData2Native(void* d, HandleValue s,
}
static inline bool
CreateHolderIfNeeded(HandleObject obj, MutableHandleValue d,
CreateHolderIfNeeded(JSContext* cx, HandleObject obj, MutableHandleValue d,
nsIXPConnectJSObjectHolder** dest)
{
if (dest) {
if (!obj)
return false;
RefPtr<XPCJSObjectHolder> objHolder = new XPCJSObjectHolder(obj);
RefPtr<XPCJSObjectHolder> objHolder = new XPCJSObjectHolder(cx, obj);
objHolder.forget(dest);
}
@ -796,7 +796,7 @@ XPCConvert::NativeInterface2JSObject(MutableHandleValue d,
if (flat) {
if (allowNativeWrapper && !JS_WrapObject(cx, &flat))
return false;
return CreateHolderIfNeeded(flat, d, dest);
return CreateHolderIfNeeded(cx, flat, d, dest);
}
if (iid->Equals(NS_GET_IID(nsISupports))) {
@ -808,7 +808,7 @@ XPCConvert::NativeInterface2JSObject(MutableHandleValue d,
flat = promise->PromiseObj();
if (!JS_WrapObject(cx, &flat))
return false;
return CreateHolderIfNeeded(flat, d, dest);
return CreateHolderIfNeeded(cx, flat, d, dest);
}
}
@ -867,7 +867,7 @@ XPCConvert::NativeInterface2JSObject(MutableHandleValue d,
} else {
if (!flat)
return false;
RefPtr<XPCJSObjectHolder> objHolder = new XPCJSObjectHolder(flat);
RefPtr<XPCJSObjectHolder> objHolder = new XPCJSObjectHolder(cx, flat);
objHolder.forget(dest);
}
}

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

@ -25,12 +25,6 @@ XPCJSRuntime::AddWrappedJSRoot(nsXPCWrappedJS* wrappedJS)
wrappedJS->AddToRootSet(&mWrappedJSRoots);
}
inline void
XPCJSRuntime::AddObjectHolderRoot(XPCJSObjectHolder* holder)
{
holder->AddToRootSet(&mObjectHolderRoots);
}
/***************************************************************************/
inline bool

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

@ -629,12 +629,6 @@ void XPCJSRuntime::TraceNativeBlackRoots(JSTracer* trc)
roots->TraceJSAll(trc);
}
// XPCJSObjectHolders don't participate in cycle collection, so always
// trace them here.
XPCRootSetElem* e;
for (e = mObjectHolderRoots; e; e = e->GetNextRoot())
static_cast<XPCJSObjectHolder*>(e)->TraceJS(trc);
JSContext* cx = XPCJSContext::Get()->Context();
dom::TraceBlackJS(trc, JS_GetGCParameter(cx, JSGC_NUMBER),
nsXPConnect::XPConnect()->IsShuttingDown());
@ -2807,7 +2801,6 @@ XPCJSRuntime::XPCJSRuntime(JSContext* aCx)
mDoingFinalization(false),
mVariantRoots(nullptr),
mWrappedJSRoots(nullptr),
mObjectHolderRoots(nullptr),
mAsyncSnowWhiteFreer(new AsyncFreeSnowWhite())
{
MOZ_COUNT_CTOR_INHERITED(XPCJSRuntime, CycleCollectedJSRuntime);

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

@ -2238,20 +2238,8 @@ XPCJSObjectHolder::GetJSObject()
return mJSObj;
}
XPCJSObjectHolder::XPCJSObjectHolder(JSObject* obj)
: mJSObj(obj)
XPCJSObjectHolder::XPCJSObjectHolder(JSContext* cx, JSObject* obj)
: mJSObj(cx, obj)
{
MOZ_ASSERT(obj);
XPCJSRuntime::Get()->AddObjectHolderRoot(this);
}
XPCJSObjectHolder::~XPCJSObjectHolder()
{
RemoveFromRootSet();
}
void
XPCJSObjectHolder::TraceJS(JSTracer* trc)
{
JS::TraceEdge(trc, &mJSObj, "XPCJSObjectHolder::mJSObj");
}

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

@ -619,7 +619,6 @@ public:
inline void AddVariantRoot(XPCTraceableVariant* variant);
inline void AddWrappedJSRoot(nsXPCWrappedJS* wrappedJS);
inline void AddObjectHolderRoot(XPCJSObjectHolder* holder);
void DebugDump(int16_t depth);
@ -664,7 +663,6 @@ private:
bool mDoingFinalization;
XPCRootSetElem* mVariantRoots;
XPCRootSetElem* mWrappedJSRoots;
XPCRootSetElem* mObjectHolderRoots;
nsTArray<xpcGCCallback> extraGCCallbacks;
JS::GCSliceCallback mPrevGCSliceCallback;
JS::DoCycleCollectionCallback mPrevDoCycleCollectionCallback;
@ -2049,8 +2047,7 @@ private:
/***************************************************************************/
class XPCJSObjectHolder final : public nsIXPConnectJSObjectHolder,
public XPCRootSetElem
class XPCJSObjectHolder final : public nsIXPConnectJSObjectHolder
{
public:
// all the interface method declarations...
@ -2060,16 +2057,13 @@ public:
// non-interface implementation
public:
void TraceJS(JSTracer* trc);
explicit XPCJSObjectHolder(JSObject* obj);
XPCJSObjectHolder(JSContext* cx, JSObject* obj);
private:
virtual ~XPCJSObjectHolder();
virtual ~XPCJSObjectHolder() {}
XPCJSObjectHolder() = delete;
JS::Heap<JSObject*> mJSObj;
JS::PersistentRooted<JSObject*> mJSObj;
};
/***************************************************************************