Bug 730208 - XPConnect changes to UnmarkGray some more objects and return them for convenience. r=mccr8

--HG--
extra : rebase_source : ddbfd05ec43868d39c26b1c37cac7e81522df29f
This commit is contained in:
Steve Fink 2012-03-20 21:22:40 -07:00
parent ce400592c2
commit 80175b16ed
5 changed files with 45 additions and 23 deletions

View File

@ -652,11 +652,11 @@ TraceScopeJSObjects(JSTracer *trc, XPCWrappedNativeScope* scope)
JSObject* obj;
obj = scope->GetGlobalJSObject();
obj = scope->GetGlobalJSObjectPreserveColor();
NS_ASSERTION(obj, "bad scope JSObject");
JS_CALL_OBJECT_TRACER(trc, obj, "XPCWrappedNativeScope::mGlobalJSObject");
obj = scope->GetPrototypeJSObject();
obj = scope->GetPrototypeJSObjectPreserveColor();
if (obj) {
JS_CALL_OBJECT_TRACER(trc, obj,
"XPCWrappedNativeScope::mPrototypeJSObject");

View File

@ -158,7 +158,7 @@ XPCWrappedNativeScope::XPCWrappedNativeScope(XPCCallContext& ccx,
#ifdef DEBUG
for (XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext)
NS_ASSERTION(aGlobal != cur->GetGlobalJSObject(), "dup object");
MOZ_ASSERT(aGlobal != cur->GetGlobalJSObjectPreserveColor(), "dup object");
#endif
mNext = gScopes;
@ -773,7 +773,7 @@ XPCWrappedNativeScope::FindInJSObjectScope(JSContext* cx, JSObject* obj,
DEBUG_TrackScopeTraversal();
for (XPCWrappedNativeScope* cur = gScopes; cur; cur = cur->mNext) {
if (obj == cur->GetGlobalJSObject()) {
if (obj == cur->GetGlobalJSObjectPreserveColor()) {
found = cur;
break;
}

View File

@ -686,17 +686,19 @@ UnmarkGrayChildren(JSTracer *trc, void **thingp, JSGCTraceKind kind)
}
void
xpc_UnmarkGrayObjectRecursive(JSObject *obj)
xpc_UnmarkGrayGCThingRecursive(void *thing, JSGCTraceKind kind)
{
NS_ASSERTION(obj, "Don't pass me null!");
MOZ_ASSERT(thing, "Don't pass me null!");
MOZ_ASSERT(kind != JSTRACE_SHAPE, "UnmarkGrayGCThingRecursive not intended for Shapes");
// Unmark.
js::gc::AsCell(obj)->unmark(js::gc::GRAY);
static_cast<js::gc::Cell *>(thing)->unmark(js::gc::GRAY);
// Trace children.
UnmarkGrayTracer trc;
JS_TracerInit(&trc, JS_GetObjectRuntime(obj), UnmarkGrayChildren);
JS_TraceChildren(&trc, obj, JSTRACE_OBJECT);
JSRuntime *rt = nsXPConnect::GetRuntimeInstance()->GetJSRuntime();
JS_TracerInit(&trc, rt, UnmarkGrayChildren);
JS_TraceChildren(&trc, thing, kind);
}
struct TraversalTracer : public JSTracer

View File

@ -1219,7 +1219,7 @@ public:
if (mCcx)
return mCcx->GetScopeForNewJSObjects();
return mObj;
return xpc_UnmarkGrayObject(mObj);
}
void SetScopeForNewJSObjects(JSObject *obj)
{
@ -1235,7 +1235,7 @@ public:
if (mCcx)
return mCcx->GetFlattenedJSObject();
return mFlattenedJSObject;
return xpc_UnmarkGrayObject(mFlattenedJSObject);
}
XPCCallContext &GetXPCCallContext()
{
@ -1244,8 +1244,9 @@ public:
mCcxToDestroy = mCcx =
new (data) XPCCallContext(mCallerLanguage, mCx,
mCallBeginRequest == CALL_BEGINREQUEST,
mObj,
mFlattenedJSObject, mWrapper,
xpc_UnmarkGrayObject(mObj),
xpc_UnmarkGrayObject(mFlattenedJSObject),
mWrapper,
mTearOff);
if (!mCcx->IsValid()) {
NS_ERROR("This is not supposed to fail!");
@ -1452,10 +1453,18 @@ public:
GetComponents() const {return mComponents;}
JSObject*
GetGlobalJSObject() const {return mGlobalJSObject;}
GetGlobalJSObject() const
{return xpc_UnmarkGrayObject(mGlobalJSObject);}
JSObject*
GetPrototypeJSObject() const {return mPrototypeJSObject;}
GetGlobalJSObjectPreserveColor() const {return mGlobalJSObject;}
JSObject*
GetPrototypeJSObject() const
{return xpc_UnmarkGrayObject(mPrototypeJSObject);}
JSObject*
GetPrototypeJSObjectPreserveColor() const {return mPrototypeJSObject;}
// Getter for the prototype that we use for wrappers that have no
// helper.
@ -2168,7 +2177,7 @@ public:
GetRuntime() const {return mScope->GetRuntime();}
JSObject*
GetJSProtoObject() const {return mJSProtoObject;}
GetJSProtoObject() const {return xpc_UnmarkGrayObject(mJSProtoObject);}
nsIClassInfo*
GetClassInfo() const {return mClassInfo;}
@ -2956,8 +2965,7 @@ public:
* This getter clears the gray bit before handing out the JSObject which
* means that the object is guaranteed to be kept alive past the next CC.
*/
JSObject* GetJSObject() const {xpc_UnmarkGrayObject(mJSObj);
return mJSObj;}
JSObject* GetJSObject() const {return xpc_UnmarkGrayObject(mJSObj);}
/**
* This getter does not change the color of the JSObject meaning that the
@ -4417,8 +4425,7 @@ struct CompartmentPrivate
*/
JSObject *LookupExpandoObject(XPCWrappedNative *wn) {
JSObject *obj = LookupExpandoObjectPreserveColor(wn);
xpc_UnmarkGrayObject(obj);
return obj;
return xpc_UnmarkGrayObject(obj);
}
bool RegisterDOMExpandoObject(JSObject *expando) {

View File

@ -170,19 +170,32 @@ xpc_GCThingIsGrayCCThing(void *thing);
// Implemented in nsXPConnect.cpp.
extern void
xpc_UnmarkGrayObjectRecursive(JSObject* obj);
xpc_UnmarkGrayGCThingRecursive(void *thing, JSGCTraceKind kind);
// Remove the gray color from the given JSObject and any other objects that can
// be reached through it.
inline void
inline JSObject *
xpc_UnmarkGrayObject(JSObject *obj)
{
if (obj) {
if (xpc_IsGrayGCThing(obj))
xpc_UnmarkGrayObjectRecursive(obj);
xpc_UnmarkGrayGCThingRecursive(obj, JSTRACE_OBJECT);
else if (js::IsIncrementalBarrierNeededOnObject(obj))
js::IncrementalReferenceBarrier(obj);
}
return obj;
}
inline JSScript *
xpc_UnmarkGrayScript(JSScript *script)
{
if (script) {
if (xpc_IsGrayGCThing(script))
xpc_UnmarkGrayGCThingRecursive(script, JSTRACE_SCRIPT);
else if (js::IsIncrementalBarrierNeededOnScript(script))
js::IncrementalReferenceBarrier(script);
}
return script;
}
// If aVariant is an XPCVariant, this marks the object to be in aGeneration.