Bug 797821 - Allow compartment privates to be lazily created when using them just for storing about:memory URIs. r=mrbkap

This will allow us to stop making nsXULPrototypeDocument and nsXBLDocumentInfo
globals XPConnect globals.
This commit is contained in:
Bobby Holley 2012-10-25 17:01:07 +02:00
parent 826ce1e16b
commit d6ecaf26fe
3 changed files with 23 additions and 12 deletions

View File

@ -213,11 +213,27 @@ ContextCallback(JSContext *cx, unsigned operation)
return true;
}
xpc::CompartmentPrivate::~CompartmentPrivate()
namespace xpc {
CompartmentPrivate::~CompartmentPrivate()
{
MOZ_COUNT_DTOR(xpc::CompartmentPrivate);
}
CompartmentPrivate*
EnsureCompartmentPrivate(JSObject *obj)
{
JSCompartment *c = js::GetObjectCompartment(obj);
CompartmentPrivate *priv = GetCompartmentPrivate(c);
if (priv)
return priv;
priv = new CompartmentPrivate();
JS_SetCompartmentPrivate(c, priv);
return priv;
}
}
static void
CompartmentDestroyedCallback(JSFreeOp *fop, JSCompartment *compartment)
{

View File

@ -1087,8 +1087,8 @@ CreateGlobalObject(JSContext *cx, JSClass *clasp, nsIPrincipal *principal)
JSObject *global = JS_NewGlobalObject(cx, clasp, nsJSPrincipals::get(principal));
if (!global)
return nullptr;
EnsureCompartmentPrivate(global);
JSCompartment *compartment = js::GetObjectCompartment(global);
JS_SetCompartmentPrivate(compartment, new xpc::CompartmentPrivate());
XPCCompartmentSet& set = nsXPConnect::GetRuntimeInstance()->GetCompartmentSet();
if (!set.put(compartment))
@ -2403,22 +2403,14 @@ void
SetLocationForGlobal(JSObject *global, const nsACString& location)
{
MOZ_ASSERT(global);
CompartmentPrivate *priv = GetCompartmentPrivate(global);
MOZ_ASSERT(priv, "No compartment private");
priv->SetLocation(location);
EnsureCompartmentPrivate(global)->SetLocation(location);
}
void
SetLocationForGlobal(JSObject *global, nsIURI *locationURI)
{
MOZ_ASSERT(global);
CompartmentPrivate *priv = GetCompartmentPrivate(global);
MOZ_ASSERT(priv, "No compartment private");
priv->SetLocation(locationURI);
EnsureCompartmentPrivate(global)->SetLocation(locationURI);
}
} // namespace xpc

View File

@ -4382,6 +4382,9 @@ private:
nsCOMPtr<nsIURI> locationURI;
};
CompartmentPrivate*
EnsureCompartmentPrivate(JSObject *obj);
inline CompartmentPrivate*
GetCompartmentPrivate(JSCompartment *compartment)
{