Bug 973780 - Implement an expando WeakMap on XPCWrappedNativeScope. r=mccr8

This commit is contained in:
Bobby Holley 2014-02-21 11:35:48 -08:00
Родитель f0b23970a3
Коммит 7535769229
2 изменённых файлов: 35 добавлений и 0 удалений

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

@ -302,6 +302,9 @@ XPCWrappedNativeScope::~XPCWrappedNativeScope()
// XXX might not want to do this at xpconnect shutdown time???
mComponents = nullptr;
if (mXrayExpandos.initialized())
mXrayExpandos.destroy();
JSRuntime *rt = XPCJSRuntime::Get()->Runtime();
mXBLScope.finalize(rt);
mGlobalJSObject.finalize(rt);
@ -599,6 +602,27 @@ XPCWrappedNativeScope::RemoveWrappedNativeProtos()
GetRuntime()->GetDetachedWrappedNativeProtoMap());
}
JSObject *
XPCWrappedNativeScope::GetExpandoChain(JSObject *target)
{
MOZ_ASSERT(GetObjectScope(target) == this);
if (!mXrayExpandos.initialized())
return nullptr;
return mXrayExpandos.lookup(target);
}
bool
XPCWrappedNativeScope::SetExpandoChain(JSContext *cx, HandleObject target,
HandleObject chain)
{
MOZ_ASSERT(GetObjectScope(target) == this);
MOZ_ASSERT(js::IsObjectInContextCompartment(target, cx));
MOZ_ASSERT_IF(chain, GetObjectScope(chain) == this);
if (!mXrayExpandos.initialized() && !mXrayExpandos.init(cx))
return false;
return mXrayExpandos.put(target, chain);
}
/***************************************************************************/
// static

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

@ -90,6 +90,7 @@
#include "xpcpublic.h"
#include "js/Tracer.h"
#include "js/WeakMapPtr.h"
#include "pldhash.h"
#include "nscore.h"
#include "nsXPCOM.h"
@ -1037,6 +1038,12 @@ public:
return nsJSPrincipals::get(JS_GetCompartmentPrincipals(c));
}
JSObject*
GetExpandoChain(JSObject *target);
bool
SetExpandoChain(JSContext *cx, JS::HandleObject target, JS::HandleObject chain);
void RemoveWrappedNativeProtos();
static void
@ -1050,6 +1057,8 @@ public:
mGlobalJSObject.trace(trc, "XPCWrappedNativeScope::mGlobalJSObject");
if (mXBLScope)
mXBLScope.trace(trc, "XPCWrappedNativeScope::mXBLScope");
if (mXrayExpandos.initialized())
mXrayExpandos.trace(trc);
}
static void
@ -1169,6 +1178,8 @@ private:
nsAutoPtr<DOMExpandoSet> mDOMExpandoSet;
JS::WeakMapPtr<JSObject*, JSObject*> mXrayExpandos;
bool mIsXBLScope;
// For remote XUL domains, we run all XBL in the content scope for compat