зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1533302 part 3 - Use UniquePtr for CompartmentPrivate's XPCWrappedNativeScope. r=mccr8
`CompartmentPrivate::GetScope()` was added so callers don't have to do `scope.get()` manually. The `scope` field is now private and was renamed to `mScope`. Also replaces some `CompartmentPrivate::Get(obj)->scope` instances with `ObjectScope(obj)`. It's equivalent but shorter. Differential Revision: https://phabricator.services.mozilla.com/D22664 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
38270c952c
Коммит
d105968a3d
|
@ -184,12 +184,10 @@ class AsyncFreeSnowWhite : public Runnable {
|
|||
|
||||
namespace xpc {
|
||||
|
||||
CompartmentPrivate::CompartmentPrivate(JS::Compartment* c,
|
||||
XPCWrappedNativeScope* scope,
|
||||
mozilla::BasePrincipal* origin,
|
||||
const SiteIdentifier& site)
|
||||
CompartmentPrivate::CompartmentPrivate(
|
||||
JS::Compartment* c, mozilla::UniquePtr<XPCWrappedNativeScope> scope,
|
||||
mozilla::BasePrincipal* origin, const SiteIdentifier& site)
|
||||
: originInfo(origin, site),
|
||||
scope(scope),
|
||||
wantXrays(false),
|
||||
allowWaivers(true),
|
||||
isWebExtensionContentScript(false),
|
||||
|
@ -199,14 +197,14 @@ CompartmentPrivate::CompartmentPrivate(JS::Compartment* c,
|
|||
hasExclusiveExpandos(false),
|
||||
universalXPConnectEnabled(false),
|
||||
wasShutdown(false),
|
||||
mWrappedJSMap(JSObject2WrappedJSMap::newMap(XPC_JS_MAP_LENGTH)) {
|
||||
mWrappedJSMap(JSObject2WrappedJSMap::newMap(XPC_JS_MAP_LENGTH)),
|
||||
mScope(std::move(scope)) {
|
||||
MOZ_COUNT_CTOR(xpc::CompartmentPrivate);
|
||||
}
|
||||
|
||||
CompartmentPrivate::~CompartmentPrivate() {
|
||||
MOZ_COUNT_DTOR(xpc::CompartmentPrivate);
|
||||
delete mWrappedJSMap;
|
||||
delete scope;
|
||||
}
|
||||
|
||||
void CompartmentPrivate::SystemIsBeingShutDown() {
|
||||
|
@ -244,9 +242,9 @@ void RealmPrivate::Init(HandleObject aGlobal, const SiteIdentifier& aSite) {
|
|||
if (CompartmentPrivate* priv = CompartmentPrivate::Get(c)) {
|
||||
MOZ_ASSERT(priv->originInfo.IsSameOrigin(principal));
|
||||
} else {
|
||||
auto* scope = new XPCWrappedNativeScope(c, aGlobal);
|
||||
priv =
|
||||
new CompartmentPrivate(c, scope, BasePrincipal::Cast(principal), aSite);
|
||||
auto scope = mozilla::MakeUnique<XPCWrappedNativeScope>(c, aGlobal);
|
||||
priv = new CompartmentPrivate(c, std::move(scope),
|
||||
BasePrincipal::Cast(principal), aSite);
|
||||
JS_SetCompartmentPrivate(c, priv);
|
||||
}
|
||||
}
|
||||
|
@ -593,10 +591,8 @@ bool EnableUniversalXPConnect(JSContext* cx) {
|
|||
// but we define it when UniversalXPConnect is enabled to support legacy
|
||||
// tests.
|
||||
Compartment* comp = js::GetContextCompartment(cx);
|
||||
XPCWrappedNativeScope* scope = CompartmentPrivate::Get(comp)->scope;
|
||||
if (!scope) {
|
||||
return true;
|
||||
}
|
||||
XPCWrappedNativeScope* scope = CompartmentPrivate::Get(comp)->GetScope();
|
||||
MOZ_ASSERT(scope);
|
||||
scope->ForcePrivilegedComponents();
|
||||
return scope->AttachComponentsObject(cx);
|
||||
}
|
||||
|
@ -986,7 +982,7 @@ void XPCJSRuntime::WeakPointerCompartmentCallback(JSContext* cx,
|
|||
void CompartmentPrivate::UpdateWeakPointersAfterGC() {
|
||||
mRemoteProxies.sweep();
|
||||
mWrappedJSMap->UpdateWeakPointersAfterGC();
|
||||
scope->UpdateWeakPointersAfterGC();
|
||||
mScope->UpdateWeakPointersAfterGC();
|
||||
}
|
||||
|
||||
void XPCJSRuntime::CustomOutOfMemoryCallback() {
|
||||
|
|
|
@ -505,8 +505,7 @@ class JSObject2JSObjectMap {
|
|||
if (!mTable.add(p, key, value)) {
|
||||
return nullptr;
|
||||
}
|
||||
MOZ_ASSERT(xpc::CompartmentPrivate::Get(key)->scope->mWaiverWrapperMap ==
|
||||
this);
|
||||
MOZ_ASSERT(xpc::ObjectScope(key)->mWaiverWrapperMap == this);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
|
|
@ -183,7 +183,7 @@ nsresult XPCWrappedNative::WrapNewGlobal(xpcObjectHelper& nativeHelper,
|
|||
if (!global) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
XPCWrappedNativeScope* scope = CompartmentPrivate::Get(global)->scope;
|
||||
XPCWrappedNativeScope* scope = ObjectScope(global);
|
||||
|
||||
// Immediately enter the global's realm, so that everything else we
|
||||
// create ends up there.
|
||||
|
|
|
@ -217,8 +217,7 @@ namespace xpc {
|
|||
JSObject* GetXBLScope(JSContext* cx, JSObject* contentScopeArg) {
|
||||
JS::RootedObject contentScope(cx, contentScopeArg);
|
||||
JSAutoRealm ar(cx, contentScope);
|
||||
XPCWrappedNativeScope* nativeScope =
|
||||
CompartmentPrivate::Get(contentScope)->scope;
|
||||
XPCWrappedNativeScope* nativeScope = ObjectScope(contentScope);
|
||||
|
||||
RootedObject scope(cx, nativeScope->EnsureContentXBLScope(cx));
|
||||
NS_ENSURE_TRUE(scope, nullptr); // See bug 858642.
|
||||
|
@ -251,7 +250,7 @@ JSObject* GetUAWidgetScope(JSContext* cx, nsIPrincipal* principal) {
|
|||
|
||||
bool AllowContentXBLScope(JS::Realm* realm) {
|
||||
JS::Compartment* comp = GetCompartmentForRealm(realm);
|
||||
XPCWrappedNativeScope* scope = CompartmentPrivate::Get(comp)->scope;
|
||||
XPCWrappedNativeScope* scope = CompartmentPrivate::Get(comp)->GetScope();
|
||||
MOZ_ASSERT(scope);
|
||||
return scope->AllowContentXBLScope(realm);
|
||||
}
|
||||
|
|
|
@ -419,8 +419,8 @@ void xpc::TraceXPCGlobal(JSTracer* trc, JSObject* obj) {
|
|||
// We might be called from a GC during the creation of a global, before we've
|
||||
// been able to set up the compartment private.
|
||||
if (xpc::CompartmentPrivate* priv = xpc::CompartmentPrivate::Get(obj)) {
|
||||
MOZ_ASSERT(priv->scope);
|
||||
priv->scope->TraceInside(trc);
|
||||
MOZ_ASSERT(priv->GetScope());
|
||||
priv->GetScope()->TraceInside(trc);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -514,8 +514,7 @@ bool InitGlobalObject(JSContext* aJSContext, JS::Handle<JSObject*> aGlobal,
|
|||
|
||||
if (!(aFlags & xpc::OMIT_COMPONENTS_OBJECT)) {
|
||||
// XPCCallContext gives us an active request needed to save/restore.
|
||||
if (!CompartmentPrivate::Get(aGlobal)->scope->AttachComponentsObject(
|
||||
aJSContext) ||
|
||||
if (!ObjectScope(aGlobal)->AttachComponentsObject(aJSContext) ||
|
||||
!XPCNativeWrapper::AttachNewConstructorObject(aJSContext, aGlobal)) {
|
||||
return UnexpectedFailure(false);
|
||||
}
|
||||
|
|
|
@ -2668,7 +2668,8 @@ class CompartmentPrivate {
|
|||
CompartmentPrivate(const CompartmentPrivate&) = delete;
|
||||
|
||||
public:
|
||||
CompartmentPrivate(JS::Compartment* c, XPCWrappedNativeScope* scope,
|
||||
CompartmentPrivate(JS::Compartment* c,
|
||||
mozilla::UniquePtr<XPCWrappedNativeScope> scope,
|
||||
mozilla::BasePrincipal* origin,
|
||||
const mozilla::SiteIdentifier& site);
|
||||
|
||||
|
@ -2700,14 +2701,12 @@ class CompartmentPrivate {
|
|||
// Don't share if we have any weird state set.
|
||||
return !wantXrays && !isWebExtensionContentScript &&
|
||||
!isContentXBLCompartment && !isUAWidgetCompartment &&
|
||||
!universalXPConnectEnabled && scope->XBLScopeStateMatches(principal);
|
||||
!universalXPConnectEnabled &&
|
||||
mScope->XBLScopeStateMatches(principal);
|
||||
}
|
||||
|
||||
CompartmentOriginInfo originInfo;
|
||||
|
||||
// Our XPCWrappedNativeScope.
|
||||
XPCWrappedNativeScope* scope;
|
||||
|
||||
// Controls whether this compartment gets Xrays to same-origin. This behavior
|
||||
// is deprecated, but is still the default for sandboxes for compatibity
|
||||
// reasons.
|
||||
|
@ -2771,12 +2770,17 @@ class CompartmentPrivate {
|
|||
RemoteProxyMap;
|
||||
RemoteProxyMap& GetRemoteProxyMap() { return mRemoteProxies; }
|
||||
|
||||
XPCWrappedNativeScope* GetScope() { return mScope.get(); }
|
||||
|
||||
private:
|
||||
JSObject2WrappedJSMap* mWrappedJSMap;
|
||||
|
||||
// Cache holding proxy objects for Window objects (and their Location oject)
|
||||
// that are loaded in a different process.
|
||||
RemoteProxyMap mRemoteProxies;
|
||||
|
||||
// Our XPCWrappedNativeScope.
|
||||
mozilla::UniquePtr<XPCWrappedNativeScope> mScope;
|
||||
};
|
||||
|
||||
bool IsUniversalXPConnectEnabled(JS::Compartment* compartment);
|
||||
|
@ -2896,7 +2900,7 @@ class RealmPrivate {
|
|||
};
|
||||
|
||||
inline XPCWrappedNativeScope* ObjectScope(JSObject* obj) {
|
||||
return CompartmentPrivate::Get(obj)->scope;
|
||||
return CompartmentPrivate::Get(obj)->GetScope();
|
||||
}
|
||||
|
||||
JSObject* NewOutObject(JSContext* cx);
|
||||
|
|
Загрузка…
Ссылка в новой задаче