From 467b5d350e9034239f217ae1334f495db1a0f12e Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Thu, 25 Oct 2012 17:01:08 +0200 Subject: [PATCH] Bug 797821 - Stop storing mScriptObjectPrincipal. r=mrbkap --- js/xpconnect/src/XPCWrappedNativeScope.cpp | 31 ---------------------- js/xpconnect/src/xpcprivate.h | 19 ++++++------- 2 files changed, 8 insertions(+), 42 deletions(-) diff --git a/js/xpconnect/src/XPCWrappedNativeScope.cpp b/js/xpconnect/src/XPCWrappedNativeScope.cpp index 32ea9397add9..97b2ed298f46 100644 --- a/js/xpconnect/src/XPCWrappedNativeScope.cpp +++ b/js/xpconnect/src/XPCWrappedNativeScope.cpp @@ -113,7 +113,6 @@ XPCWrappedNativeScope::XPCWrappedNativeScope(JSContext *cx, mGlobalJSObject(nullptr), mPrototypeJSObject(nullptr), mPrototypeNoHelper(nullptr), - mScriptObjectPrincipal(nullptr), mExperimentalBindingsEnabled(XPCJSRuntime::Get()->ExperimentalBindingsEnabled()) { // add ourselves to the scopes list @@ -218,36 +217,7 @@ XPCWrappedNativeScope::SetGlobal(JSContext *cx, JSObject* aGlobal, { // We allow for calling this more than once. This feature is used by // nsXPConnect::InitClassesWithNewWrappedGlobal. - mGlobalJSObject = aGlobal; - mScriptObjectPrincipal = nullptr; - - // Try to find the native global object. If we didn't receive it explicitly, - // we might be able to find it in the private slot. - nsISupports *native; - if (aNative) { - native = aNative; - } else { - const JSClass *jsClass = js::GetObjectJSClass(aGlobal); - if (!(~jsClass->flags & (JSCLASS_HAS_PRIVATE | - JSCLASS_PRIVATE_IS_NSISUPPORTS))) { - // Our global has an nsISupports native pointer. Let's - // see whether it's what we want. - nsISupports *priv = - static_cast(xpc_GetJSPrivate(aGlobal)); - nsCOMPtr wn = do_QueryInterface(priv); - if (wn) - native = static_cast(wn.get())->GetIdentityObject(); - else - native = nullptr; - } else if (!mozilla::dom::UnwrapDOMObjectToISupports(aGlobal, native)) { - native = nullptr; - } - } - - // Now init our script object principal, if the new global has one. - nsCOMPtr sop = do_QueryInterface(native); - mScriptObjectPrincipal = sop; // Lookup 'globalObject.Object.prototype' for our wrapper's proto JSObject *objectPrototype = @@ -398,7 +368,6 @@ XPCWrappedNativeScope::StartFinalizationPhaseOfGC(JSFreeOp *fop, XPCJSRuntime* r if (cur->mGlobalJSObject && JS_IsAboutToBeFinalized(cur->mGlobalJSObject)) { cur->mGlobalJSObject.finalize(fop->runtime()); - cur->mScriptObjectPrincipal = nullptr; if (cur->GetCachedDOMPrototypes().IsInitialized()) cur->GetCachedDOMPrototypes().Clear(); // Move this scope from the live list to the dying list. diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index d6447ecd133d..1e636e905074 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -170,8 +170,9 @@ #include "nsIXPCScriptNotify.h" // used to notify: ScriptEvaluated -#include "nsIScriptObjectPrincipal.h" #include "nsIPrincipal.h" +#include "nsJSPrincipals.h" +#include "nsIScriptObjectPrincipal.h" #include "nsISecurityCheckedComponent.h" #include "xpcObjectHelper.h" #include "nsIThreadInternal.h" @@ -1643,9 +1644,12 @@ public: GetPrototypeNoHelper(XPCCallContext& ccx); nsIPrincipal* - GetPrincipal() const - {return mScriptObjectPrincipal ? - mScriptObjectPrincipal->GetPrincipal() : nullptr;} + GetPrincipal() const { + if (!mGlobalJSObject) + return nullptr; + JSCompartment *c = js::GetObjectCompartment(mGlobalJSObject); + return nsJSPrincipals::get(JS_GetCompartmentPrincipals(c)); + } void RemoveWrappedNativeProtos(); @@ -1779,13 +1783,6 @@ private: XPCContext* mContext; - // The script object principal instance corresponding to our current global - // JS object. - // XXXbz what happens if someone calls JS_SetPrivate on mGlobalJSObject. - // How do we deal? Do we need to? I suspect this isn't worth worrying - // about, since all of our scope objects are verified as not doing that. - nsIScriptObjectPrincipal* mScriptObjectPrincipal; - nsDataHashtable mCachedDOMPrototypes; JSBool mExperimentalBindingsEnabled;