Bug 794158, Remove over-complicated AutoWrapperChanger, r=peterv

This commit is contained in:
Olli Pettay 2012-11-20 23:01:28 +02:00
Родитель 1f959a566c
Коммит 6531f58d50
1 изменённых файлов: 5 добавлений и 44 удалений

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

@ -1396,43 +1396,6 @@ XPCWrappedNative::SystemIsBeingShutDown()
/***************************************************************************/
// If we have to transplant an object across compartments, we need to be
// careful if the underlying object implements nsWrapperCache and is preserving
// the wrapper.
//
// The class brackets a pair of Unpreserve/Preserve calls in the given scope.
//
// This class _must_ live on the stack, in part so that mPreservedWrapper is
// visible to the stack scanner. The caller wants the wrapper to be preserved,
// so we don't want it to get accidentally GCed.
class AutoWrapperChanger NS_STACK_CLASS {
public:
AutoWrapperChanger() : mCache(nullptr)
, mCOMObj(nullptr)
, mPreservedWrapper(nullptr)
{}
void init(nsISupports* aCOMObj, nsWrapperCache* aWrapperCache) {
mCOMObj = aCOMObj;
mCache = aWrapperCache;
if (mCache->PreservingWrapper()) {
mPreservedWrapper = mCache->GetWrapper();
MOZ_ASSERT(mPreservedWrapper);
nsContentUtils::ReleaseWrapper(mCOMObj, mCache);
}
}
~AutoWrapperChanger() {
if (mPreservedWrapper)
nsContentUtils::PreserveWrapper(mCOMObj, mCache);
}
private:
nsWrapperCache* mCache;
nsISupports* mCOMObj;
JSObject* mPreservedWrapper;
};
// Dynamically ensure that two objects don't end up with the same private.
class AutoClonePrivateGuard NS_STACK_CLASS {
public:
@ -1472,16 +1435,10 @@ XPCWrappedNative::ReparentWrapperIfFound(XPCCallContext& ccx,
nsresult rv;
nsRefPtr<XPCWrappedNative> wrapper;
AutoWrapperChanger wrapperChanger;
JSObject *flat = nullptr;
nsWrapperCache* cache = nullptr;
CallQueryInterface(aCOMObj, &cache);
if (cache) {
// There's a wrapper cache. Make sure we keep it sane no matter what
// happens.
wrapperChanger.init(aCOMObj, cache);
flat = cache->GetWrapper();
if (flat && !IS_SLIM_WRAPPER_OBJECT(flat)) {
wrapper = static_cast<XPCWrappedNative*>(xpc_GetJSPrivate(flat));
@ -1666,8 +1623,12 @@ XPCWrappedNative::ReparentWrapperIfFound(XPCCallContext& ccx,
}
wrapper->mFlatJSObject = flat;
if (cache)
if (cache) {
bool preserving = cache->PreservingWrapper();
cache->SetPreservingWrapper(false);
cache->SetWrapper(flat);
cache->SetPreservingWrapper(preserving);
}
if (!JS_CopyPropertiesFrom(ccx, flat, propertyHolder))
MOZ_CRASH();
} else {