Bug 843231 - Remove SetGlobal. r=bz
authorBobby Holley <bobbyholley@gmail.com>
Wed, 27 Mar 2013 11:40:43 -0700
changeset 128700 add20e9fce39967ebbeb60dc684112e87a7076bf
parent 128699 eecd27a6668906eed9a1ed52c4bb49e5a596242a
child 128701 dedc70b52eaa50a7b14828de3da0e1f1ebd0e4f1
push id3562
push userbobbyholley@gmail.com
push dateWed, 27 Mar 2013 18:41:22 +0000
treeherdermozilla-aurora@c5add7fbc027 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs843231
milestone21.0a2
Bug 843231 - Remove SetGlobal. r=bz This stuff has all been simplified significantly with CPG, and this is no longer necessary. We always have a global when we construct a scope, and it never changes.
js/xpconnect/src/XPCWrappedNativeScope.cpp
js/xpconnect/src/xpcprivate.h
--- a/js/xpconnect/src/XPCWrappedNativeScope.cpp
+++ b/js/xpconnect/src/XPCWrappedNativeScope.cpp
@@ -84,34 +84,28 @@ XPCWrappedNativeScope* XPCWrappedNativeS
 
 // static
 XPCWrappedNativeScope*
 XPCWrappedNativeScope::GetNewOrUsed(JSContext *cx, JSObject* aGlobal)
 {
     XPCWrappedNativeScope* scope = GetObjectScope(aGlobal);
     if (!scope) {
         scope = new XPCWrappedNativeScope(cx, aGlobal);
-    } else {
-        // We need to call SetGlobal in order to clear mPrototypeNoHelper (so we
-        // get a new new one if requested in the new scope) in the case where
-        // the global object is being reused (JS_SetAllNonReservedSlotsToUndefined
-        // has been called). NOTE: We are only called by nsXPConnect::InitClasses.
-        scope->SetGlobal(cx, aGlobal);
     }
     return scope;
 }
 
 XPCWrappedNativeScope::XPCWrappedNativeScope(JSContext *cx,
                                              JSObject* aGlobal)
       : mWrappedNativeMap(Native2WrappedNativeMap::newMap(XPC_NATIVE_MAP_SIZE)),
         mWrappedNativeProtoMap(ClassInfo2WrappedNativeProtoMap::newMap(XPC_NATIVE_PROTO_MAP_SIZE)),
         mMainThreadWrappedNativeProtoMap(ClassInfo2WrappedNativeProtoMap::newMap(XPC_NATIVE_PROTO_MAP_SIZE)),
         mComponents(nullptr),
         mNext(nullptr),
-        mGlobalJSObject(nullptr),
+        mGlobalJSObject(aGlobal),
         mPrototypeNoHelper(nullptr),
         mExperimentalBindingsEnabled(XPCJSRuntime::Get()->ExperimentalBindingsEnabled()),
         mIsXBLScope(false)
 {
     // add ourselves to the scopes list
     {   // scoped lock
         XPCAutoLock lock(XPCJSRuntime::Get()->GetMapLock());
 
@@ -123,19 +117,16 @@ XPCWrappedNativeScope::XPCWrappedNativeS
         mNext = gScopes;
         gScopes = this;
 
         // Grab the XPCContext associated with our context.
         mContext = XPCContext::GetXPCContext(cx);
         mContext->AddScope(this);
     }
 
-    if (aGlobal)
-        SetGlobal(cx, aGlobal);
-
     DEBUG_TrackNewScope(this);
     MOZ_COUNT_CTOR(XPCWrappedNativeScope);
 
     // Attach ourselves to the compartment private.
     CompartmentPrivate *priv = EnsureCompartmentPrivate(aGlobal);
     priv->scope = this;
 }
 
@@ -281,26 +272,16 @@ js::Class XPC_WN_NoHelper_Proto_JSClass 
     nullptr,                         // construct;
     nullptr,                         // hasInstance;
     nullptr,                         // trace;
 
     JS_NULL_CLASS_EXT,
     XPC_WN_NoCall_ObjectOps
 };
 
-
-void
-XPCWrappedNativeScope::SetGlobal(JSContext *cx, JSObject* aGlobal)
-{
-    // We allow for calling this more than once. This feature is used by
-    // nsXPConnect::InitClassesWithNewWrappedGlobal.
-    mGlobalJSObject = aGlobal;
-
-}
-
 XPCWrappedNativeScope::~XPCWrappedNativeScope()
 {
     MOZ_COUNT_DTOR(XPCWrappedNativeScope);
     DEBUG_TrackDeleteScope(this);
 
     // We can do additional cleanup assertions here...
 
     if (mWrappedNativeMap) {
@@ -333,17 +314,17 @@ XPCWrappedNativeScope::~XPCWrappedNative
     JSRuntime *rt = XPCJSRuntime::Get()->GetJSRuntime();
     mXBLScope.finalize(rt);
     mGlobalJSObject.finalize(rt);
 }
 
 JSObject *
 XPCWrappedNativeScope::GetPrototypeNoHelper(XPCCallContext& ccx)
 {
-    // We could create this prototype in SetGlobal(), but all scopes
+    // We could create this prototype in our constructor, but all scopes
     // don't need one, so we save ourselves a bit of space if we
     // create these when they're needed.
     if (!mPrototypeNoHelper) {
         mPrototypeNoHelper = JS_NewObject(ccx, js::Jsvalify(&XPC_WN_NoHelper_Proto_JSClass),
                                           JS_GetObjectPrototype(ccx, mGlobalJSObject),
                                           mGlobalJSObject);
 
         NS_ASSERTION(mPrototypeNoHelper,
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -1622,18 +1622,16 @@ public:
 
     // Getter for the prototype that we use for wrappers that have no
     // helper.
     JSObject*
     GetPrototypeNoHelper(XPCCallContext& ccx);
 
     nsIPrincipal*
     GetPrincipal() const {
-        if (!mGlobalJSObject)
-            return nullptr;
         JSCompartment *c = js::GetObjectCompartment(mGlobalJSObject);
         return nsJSPrincipals::get(JS_GetCompartmentPrincipals(c));
     }
 
     void RemoveWrappedNativeProtos();
 
     static void
     SystemIsBeingShutDown();
@@ -1685,18 +1683,16 @@ public:
     SizeOfIncludingThis(nsMallocSizeOfFun mallocSizeOf);
 
     JSBool
     IsValid() const {return mRuntime != nullptr;}
 
     static JSBool
     IsDyingScope(XPCWrappedNativeScope *scope);
 
-    void SetGlobal(JSContext *cx, JSObject* aGlobal);
-
     static void InitStatics() { gScopes = nullptr; gDyingScopes = nullptr; }
 
     XPCContext *GetContext() { return mContext; }
     void ClearContext() { mContext = nullptr; }
 
     JSBool ExperimentalBindingsEnabled()
     {
         return mExperimentalBindingsEnabled;