Bug 889714 - Stop manually holding onto system JSPrincipals. r=mrbkap
authorBobby Holley <bobbyholley@gmail.com>
Wed, 31 Jul 2013 10:59:26 -0700
changeset 148169 2e0d0144923c7480f0100feb4fbed2dbc1ee99b7
parent 148168 fb2a3ba7080d871ced3eaebe88b85b33e469ccdd
child 148170 90ad8d976c7cc91a7551d2510fb9b48f3d94ce09
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs889714
milestone24.0a2
Bug 889714 - Stop manually holding onto system JSPrincipals. r=mrbkap
ipc/testshell/XPCShellEnvironment.cpp
ipc/testshell/XPCShellEnvironment.h
--- a/ipc/testshell/XPCShellEnvironment.cpp
+++ b/ipc/testshell/XPCShellEnvironment.cpp
@@ -652,17 +652,16 @@ XPCShellEnvironment::CreateEnvironment()
         delete env;
         env = nullptr;
     }
     return env;
 }
 
 XPCShellEnvironment::XPCShellEnvironment()
 :   mCx(NULL),
-    mJSPrincipals(NULL),
     mQuitting(JS_FALSE)
 {
 }
 
 XPCShellEnvironment::~XPCShellEnvironment()
 {
     if (mCx) {
         JS_BeginRequest(mCx);
@@ -671,20 +670,16 @@ XPCShellEnvironment::~XPCShellEnvironmen
         if (global) {
             JS_SetAllNonReservedSlotsToUndefined(mCx, global);
         }
         mGlobalHolder.Release();
 
         JSRuntime *rt = JS_GetRuntime(mCx);
         JS_GC(rt);
 
-        if (mJSPrincipals) {
-            JS_DropPrincipals(rt, mJSPrincipals);
-        }
-
         JS_EndRequest(mCx);
         JS_DestroyContext(mCx);
 
         if (gOldContextCallback) {
             NS_ASSERTION(rt, "Should never be null!");
             JS_SetContextCallback(rt, gOldContextCallback);
             gOldContextCallback = NULL;
         }
@@ -744,20 +739,16 @@ XPCShellEnvironment::Init()
 
     nsCOMPtr<nsIPrincipal> principal;
     nsCOMPtr<nsIScriptSecurityManager> securityManager =
         do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
     if (NS_SUCCEEDED(rv) && securityManager) {
         rv = securityManager->GetSystemPrincipal(getter_AddRefs(principal));
         if (NS_FAILED(rv)) {
             fprintf(stderr, "+++ Failed to obtain SystemPrincipal from ScriptSecurityManager service.\n");
-        } else {
-            // fetch the JS principals and stick in a global
-            mJSPrincipals = nsJSPrincipals::get(principal);
-            JS_HoldPrincipals(mJSPrincipals);
         }
     } else {
         fprintf(stderr, "+++ Failed to get ScriptSecurityManager service, running without principals");
     }
 
     nsCxPusher pusher;
     pusher.Push(mCx);
 
--- a/ipc/testshell/XPCShellEnvironment.h
+++ b/ipc/testshell/XPCShellEnvironment.h
@@ -9,16 +9,18 @@
 
 #include <string>
 #include <stdio.h>
 
 #include "nsAutoJSValHolder.h"
 #include "nsCOMPtr.h"
 #include "nsDebug.h"
 #include "nsStringGlue.h"
+#include "nsJSPrincipals.h"
+#include "nsContentUtils.h"
 
 struct JSContext;
 class JSObject;
 struct JSPrincipals;
 
 namespace mozilla {
 namespace ipc {
 
@@ -29,17 +31,17 @@ public:
     ~XPCShellEnvironment();
 
     void ProcessFile(JSContext *cx, JS::Handle<JSObject*> obj,
                      const char *filename, FILE *file, JSBool forceTTY);
     bool EvaluateString(const nsString& aString,
                         nsString* aResult = nullptr);
 
     JSPrincipals* GetPrincipal() {
-        return mJSPrincipals;
+        return nsJSPrincipals::get(nsContentUtils::GetSystemPrincipal());
     }
 
     JSObject* GetGlobalObject() {
         return mGlobalHolder.ToJSObject();
     }
 
     JSContext* GetContext() {
         return mCx;
@@ -54,17 +56,16 @@ public:
 
 protected:
     XPCShellEnvironment();
     bool Init();
 
 private:
     JSContext* mCx;
     nsAutoJSValHolder mGlobalHolder;
-    JSPrincipals* mJSPrincipals;
 
     JSBool mQuitting;
 };
 
 } /* namespace ipc */
 } /* namespace mozilla */
 
 #endif /* _IPC_TESTSHELL_XPCSHELLENVIRONMENT_H_ */