Bug 797821 - Stop storing mScriptObjectPrincipal. r=mrbkap

This commit is contained in:
Bobby Holley 2012-10-25 17:01:08 +02:00
Родитель 6e408995a1
Коммит 467b5d350e
2 изменённых файлов: 8 добавлений и 42 удалений

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

@ -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<nsISupports*>(xpc_GetJSPrivate(aGlobal));
nsCOMPtr<nsIXPConnectWrappedNative> wn = do_QueryInterface(priv);
if (wn)
native = static_cast<XPCWrappedNative*>(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<nsIScriptObjectPrincipal> 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.

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

@ -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<nsDepCharHashKey, JSObject*> mCachedDOMPrototypes;
JSBool mExperimentalBindingsEnabled;