Bug 758143 - Add xpc::GetCompartmentPrivate; r=bholley

This commit is contained in:
Ms2ger 2012-05-25 09:18:31 +02:00
parent 61eec5d79c
commit a552eafda2
8 changed files with 37 additions and 35 deletions

View File

@ -31,6 +31,7 @@
using namespace mozilla;
using namespace js;
using namespace xpc;
using mozilla::dom::DestroyProtoOrIfaceCache;
@ -3734,9 +3735,7 @@ xpc_EvalInSandbox(JSContext *cx, JSObject *sandbox, const nsAString& source,
v = STRING_TO_JSVAL(str);
}
xpc::CompartmentPrivate *sandboxdata =
static_cast<xpc::CompartmentPrivate *>
(JS_GetCompartmentPrivate(js::GetObjectCompartment(sandbox)));
CompartmentPrivate *sandboxdata = GetCompartmentPrivate(sandbox);
if (!ac.enter(cx, callingScope) ||
!WrapForSandbox(cx, sandboxdata->wantXrays, &v)) {
rv = NS_ERROR_FAILURE;

View File

@ -33,6 +33,7 @@
#endif
using namespace mozilla;
using namespace xpc;
/***************************************************************************/
@ -225,8 +226,7 @@ CompartmentDestroyedCallback(JSFreeOp *fop, JSCompartment *compartment)
// Get the current compartment private into an AutoPtr (which will do the
// cleanup for us), and null out the private (which may already be null).
nsAutoPtr<xpc::CompartmentPrivate>
priv(static_cast<xpc::CompartmentPrivate*>(JS_GetCompartmentPrivate(compartment)));
nsAutoPtr<CompartmentPrivate> priv(GetCompartmentPrivate(compartment));
JS_SetCompartmentPrivate(compartment, nsnull);
// JSD creates compartments in our runtime without going through our creation
@ -387,8 +387,7 @@ void XPCJSRuntime::TraceXPConnectRoots(JSTracer *trc)
// Trace compartments.
XPCCompartmentSet &set = GetCompartmentSet();
for (XPCCompartmentRange r = set.all(); !r.empty(); r.popFront()) {
xpc::CompartmentPrivate *priv = (xpc::CompartmentPrivate *)
JS_GetCompartmentPrivate(r.front());
CompartmentPrivate *priv = GetCompartmentPrivate(r.front());
if (priv->expandoMap)
priv->expandoMap->Enumerate(TraceExpandos, trc);
if (priv->domExpandoMap)
@ -538,8 +537,7 @@ XPCJSRuntime::AddXPConnectRoots(nsCycleCollectionTraversalCallback &cb)
// Suspect wrapped natives with expando objects.
XPCCompartmentSet &set = GetCompartmentSet();
for (XPCCompartmentRange r = set.all(); !r.empty(); r.popFront()) {
xpc::CompartmentPrivate *priv = (xpc::CompartmentPrivate *)
JS_GetCompartmentPrivate(r.front());
CompartmentPrivate *priv = GetCompartmentPrivate(r.front());
if (priv->expandoMap)
priv->expandoMap->EnumerateRead(SuspectExpandos, &closure);
if (priv->domExpandoMap)
@ -675,8 +673,7 @@ XPCJSRuntime::FinalizeCallback(JSFreeOp *fop, JSFinalizeStatus status)
// Sweep compartments.
XPCCompartmentSet &set = self->GetCompartmentSet();
for (XPCCompartmentRange r = set.all(); !r.empty(); r.popFront()) {
xpc::CompartmentPrivate *priv = (xpc::CompartmentPrivate *)
JS_GetCompartmentPrivate(r.front());
CompartmentPrivate *priv = GetCompartmentPrivate(r.front());
if (priv->waiverWrapperMap)
priv->waiverWrapperMap->Sweep();
if (priv->expandoMap)
@ -1173,8 +1170,7 @@ GetCompartmentName(JSCompartment *c, nsCString &name)
// script location, append the compartment's location to allow
// differentiation of multiple compartments owned by the same principal
// (e.g. components owned by the system or null principal).
xpc::CompartmentPrivate *compartmentPrivate =
static_cast<xpc::CompartmentPrivate*>(JS_GetCompartmentPrivate(c));
CompartmentPrivate *compartmentPrivate = GetCompartmentPrivate(c);
if (compartmentPrivate) {
const nsACString& location = compartmentPrivate->GetLocation();
if (!location.IsEmpty() && !location.Equals(name)) {

View File

@ -24,6 +24,8 @@
#include "mozilla/StandardInteger.h"
#include "mozilla/Util.h"
using namespace xpc;
bool
xpc_OkToHandOutWrapper(nsWrapperCache *cache)
{
@ -92,8 +94,7 @@ NS_CYCLE_COLLECTION_CLASSNAME(XPCWrappedNative)::Traverse(void *p,
XPCJSRuntime *rt = tmp->GetRuntime();
XPCCompartmentSet &set = rt->GetCompartmentSet();
for (XPCCompartmentRange r = set.all(); !r.empty(); r.popFront()) {
xpc::CompartmentPrivate *priv = (xpc::CompartmentPrivate *)
JS_GetCompartmentPrivate(r.front());
CompartmentPrivate *priv = GetCompartmentPrivate(r.front());
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "XPCWrappedNative expando object");
cb.NoteJSChild(priv->LookupExpandoObjectPreserveColor(tmp));
}

View File

@ -668,8 +668,7 @@ ListBase<LC>::ensureExpandoObject(JSContext *cx, JSObject *obj)
return NULL;
JSCompartment *compartment = js::GetObjectCompartment(obj);
xpc::CompartmentPrivate *priv =
static_cast<xpc::CompartmentPrivate *>(JS_GetCompartmentPrivate(compartment));
xpc::CompartmentPrivate *priv = xpc::GetCompartmentPrivate(compartment);
if (!priv->RegisterDOMExpandoObject(obj))
return NULL;

View File

@ -40,6 +40,7 @@
#include "nsDOMMutationObserver.h"
using namespace mozilla::dom;
using namespace xpc;
NS_IMPL_THREADSAFE_ISUPPORTS7(nsXPConnect,
nsIXPConnect,
@ -2615,11 +2616,7 @@ SetLocationForGlobal(JSObject *global, const nsACString& location)
{
MOZ_ASSERT(global);
JSCompartment *compartment = js::GetObjectCompartment(global);
MOZ_ASSERT(compartment, "No compartment for global");
xpc::CompartmentPrivate *priv =
static_cast<xpc::CompartmentPrivate *>(JS_GetCompartmentPrivate(compartment));
CompartmentPrivate *priv = GetCompartmentPrivate(global);
MOZ_ASSERT(priv, "No compartment private");
priv->SetLocation(location);
@ -2630,11 +2627,7 @@ SetLocationForGlobal(JSObject *global, nsIURI *locationURI)
{
MOZ_ASSERT(global);
JSCompartment *compartment = js::GetObjectCompartment(global);
MOZ_ASSERT(compartment, "No compartment for global");
xpc::CompartmentPrivate *priv =
static_cast<xpc::CompartmentPrivate *>(JS_GetCompartmentPrivate(compartment));
CompartmentPrivate *priv = GetCompartmentPrivate(global);
MOZ_ASSERT(priv, "No compartment private");
priv->SetLocation(locationURI);

View File

@ -4432,6 +4432,24 @@ private:
nsCOMPtr<nsIURI> locationURI;
};
inline CompartmentPrivate*
GetCompartmentPrivate(JSCompartment *compartment)
{
MOZ_ASSERT(compartment);
void *priv = JS_GetCompartmentPrivate(compartment);
return static_cast<CompartmentPrivate*>(priv);
}
inline CompartmentPrivate*
GetCompartmentPrivate(JSObject *object)
{
MOZ_ASSERT(object);
JSCompartment *compartment = js::GetObjectCompartment(object);
MOZ_ASSERT(compartment);
return GetCompartmentPrivate(compartment);
}
}
/***************************************************************************/

View File

@ -70,8 +70,7 @@ WrapperFactory::WaiveXray(JSContext *cx, JSObject *obj)
{
// See if we already have a waiver wrapper for this object.
CompartmentPrivate *priv =
(CompartmentPrivate *)JS_GetCompartmentPrivate(js::GetObjectCompartment(obj));
CompartmentPrivate *priv = GetCompartmentPrivate(obj);
JSObject *wobj = nsnull;
if (priv && priv->waiverWrapperMap) {
wobj = priv->waiverWrapperMap->Find(obj);
@ -273,8 +272,7 @@ WrapperFactory::Rewrap(JSContext *cx, JSObject *obj, JSObject *wrappedProto, JSO
bool usingXray = false;
Wrapper *wrapper;
CompartmentPrivate *targetdata =
static_cast<CompartmentPrivate *>(JS_GetCompartmentPrivate(target));
CompartmentPrivate *targetdata = GetCompartmentPrivate(target);
if (AccessCheck::isChrome(target)) {
if (AccessCheck::isChrome(origin)) {
wrapper = &CrossCompartmentWrapper::singleton;

View File

@ -49,8 +49,7 @@ createHolder(JSContext *cx, JSObject *wrappedNative, JSObject *parent)
if (!holder)
return nsnull;
CompartmentPrivate *priv =
(CompartmentPrivate *)JS_GetCompartmentPrivate(js::GetObjectCompartment(holder));
CompartmentPrivate *priv = GetCompartmentPrivate(holder);
JSObject *inner = JS_ObjectToInnerObject(cx, wrappedNative);
XPCWrappedNative *wn = GetWrappedNative(inner);
Value expando = ObjectOrNullValue(priv->LookupExpandoObject(wn));
@ -258,8 +257,7 @@ EnsureExpandoObject(JSContext *cx, JSObject *holder)
JSObject *expando = GetExpandoObject(holder);
if (expando)
return expando;
CompartmentPrivate *priv =
(CompartmentPrivate *)JS_GetCompartmentPrivate(js::GetObjectCompartment(holder));
CompartmentPrivate *priv = GetCompartmentPrivate(holder);
XPCWrappedNative *wn = GetWrappedNativeFromHolder(holder);
expando = priv->LookupExpandoObject(wn);
if (!expando) {