Bug 1283855 part 19 - Make security callbacks take JSContext instead of JSRuntime. r=jorendorff
authorJan de Mooij <jdemooij@mozilla.com>
Tue, 05 Jul 2016 16:49:44 +0200
changeset 328775 a2d7ff2d4bd87297766a8c95cf47f8d1db7117c0
parent 328774 ae90cded54077ae5a7c845970ec874d9c6d1af1a
child 328776 bdc9d813908682539916c32134673f30fbcf3fa1
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1283855
milestone50.0a1
Bug 1283855 part 19 - Make security callbacks take JSContext instead of JSRuntime. r=jorendorff
caps/nsScriptSecurityManager.cpp
dom/workers/RuntimeService.cpp
js/public/Principals.h
js/src/jsapi-tests/testStructuredClone.cpp
js/src/jsapi.cpp
js/src/shell/js.cpp
js/xpconnect/src/XPCShellImpl.cpp
--- a/caps/nsScriptSecurityManager.cpp
+++ b/caps/nsScriptSecurityManager.cpp
@@ -1381,18 +1381,18 @@ nsresult nsScriptSecurityManager::Init()
     //   Currently this is used to control access to function.caller
     sRuntime = xpc::GetJSRuntime();
 
     static const JSSecurityCallbacks securityCallbacks = {
         ContentSecurityPolicyPermitsJSAction,
         JSPrincipalsSubsume,
     };
 
-    MOZ_ASSERT(!JS_GetSecurityCallbacks(sRuntime));
-    JS_SetSecurityCallbacks(sRuntime, &securityCallbacks);
+    MOZ_ASSERT(!JS_GetSecurityCallbacks(JS_GetContext(sRuntime)));
+    JS_SetSecurityCallbacks(JS_GetContext(sRuntime), &securityCallbacks);
     JS_InitDestroyPrincipalsCallback(sRuntime, nsJSPrincipals::Destroy);
 
     JS_SetTrustedPrincipals(sRuntime, system);
 
     return NS_OK;
 }
 
 static StaticRefPtr<nsScriptSecurityManager> gScriptSecMan;
@@ -1409,17 +1409,17 @@ nsScriptSecurityManager::~nsScriptSecuri
     MOZ_ASSERT_IF(XRE_IsParentProcess(),
                   !mDomainPolicy);
 }
 
 void
 nsScriptSecurityManager::Shutdown()
 {
     if (sRuntime) {
-        JS_SetSecurityCallbacks(sRuntime, nullptr);
+        JS_SetSecurityCallbacks(JS_GetContext(sRuntime), nullptr);
         JS_SetTrustedPrincipals(sRuntime, nullptr);
         sRuntime = nullptr;
     }
 
     NS_IF_RELEASE(sIOService);
     NS_IF_RELEASE(sStrBundle);
 }
 
--- a/dom/workers/RuntimeService.cpp
+++ b/dom/workers/RuntimeService.cpp
@@ -772,17 +772,17 @@ InitJSContextForWorker(WorkerPrivate* aW
   }
 
   JS_SetNativeStackQuota(workerCx, WORKER_CONTEXT_NATIVE_STACK_LIMIT);
 
   // Security policy:
   static const JSSecurityCallbacks securityCallbacks = {
     ContentSecurityPolicyAllows
   };
-  JS_SetSecurityCallbacks(aRuntime, &securityCallbacks);
+  JS_SetSecurityCallbacks(workerCx, &securityCallbacks);
 
   // Set up the asm.js cache callbacks
   static const JS::AsmJSCacheOps asmJSCacheOps = {
     AsmJSCacheOpenEntryForRead,
     asmjscache::CloseEntryForRead,
     AsmJSCacheOpenEntryForWrite,
     asmjscache::CloseEntryForWrite
   };
--- a/js/public/Principals.h
+++ b/js/public/Principals.h
@@ -71,20 +71,20 @@ typedef bool
 (* JSCSPEvalChecker)(JSContext* cx);
 
 struct JSSecurityCallbacks {
     JSCSPEvalChecker           contentSecurityPolicyAllows;
     JSSubsumesOp               subsumes;
 };
 
 extern JS_PUBLIC_API(void)
-JS_SetSecurityCallbacks(JSRuntime* rt, const JSSecurityCallbacks* callbacks);
+JS_SetSecurityCallbacks(JSContext* cx, const JSSecurityCallbacks* callbacks);
 
 extern JS_PUBLIC_API(const JSSecurityCallbacks*)
-JS_GetSecurityCallbacks(JSRuntime* rt);
+JS_GetSecurityCallbacks(JSContext* cx);
 
 /*
  * Code running with "trusted" principals will be given a deeper stack
  * allocation than ordinary scripts. This allows trusted script to run after
  * untrusted script has exhausted the stack. This function sets the
  * runtime-wide trusted principal.
  *
  * This principals is not held (via JS_HoldPrincipals/JS_DropPrincipals) since
--- a/js/src/jsapi-tests/testStructuredClone.cpp
+++ b/js/src/jsapi-tests/testStructuredClone.cpp
@@ -125,17 +125,17 @@ struct StructuredCloneTestPrincipals fin
 
 JSSecurityCallbacks StructuredCloneTestPrincipals::securityCallbacks = {
     nullptr, // contentSecurityPolicyAllows
     subsumes
 };
 
 BEGIN_TEST(testStructuredClone_SavedFrame)
 {
-    JS_SetSecurityCallbacks(rt, &StructuredCloneTestPrincipals::securityCallbacks);
+    JS_SetSecurityCallbacks(cx, &StructuredCloneTestPrincipals::securityCallbacks);
     JS_InitDestroyPrincipalsCallback(rt, StructuredCloneTestPrincipals::destroy);
     JS_InitReadPrincipalsCallback(rt, StructuredCloneTestPrincipals::read);
 
     auto testPrincipals = new StructuredCloneTestPrincipals(42, 0);
     CHECK(testPrincipals);
 
     auto DONE = (JSPrincipals*) 0xDEADBEEF;
 
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -3271,26 +3271,26 @@ JS_PUBLIC_API(void)
 JS_DropPrincipals(JSContext* cx, JSPrincipals* principals)
 {
     int rc = --principals->refcount;
     if (rc == 0)
         cx->destroyPrincipals(principals);
 }
 
 JS_PUBLIC_API(void)
-JS_SetSecurityCallbacks(JSRuntime* rt, const JSSecurityCallbacks* scb)
+JS_SetSecurityCallbacks(JSContext* cx, const JSSecurityCallbacks* scb)
 {
     MOZ_ASSERT(scb != &NullSecurityCallbacks);
-    rt->securityCallbacks = scb ? scb : &NullSecurityCallbacks;
+    cx->securityCallbacks = scb ? scb : &NullSecurityCallbacks;
 }
 
 JS_PUBLIC_API(const JSSecurityCallbacks*)
-JS_GetSecurityCallbacks(JSRuntime* rt)
-{
-    return (rt->securityCallbacks != &NullSecurityCallbacks) ? rt->securityCallbacks : nullptr;
+JS_GetSecurityCallbacks(JSContext* cx)
+{
+    return (cx->securityCallbacks != &NullSecurityCallbacks) ? cx->securityCallbacks : nullptr;
 }
 
 JS_PUBLIC_API(void)
 JS_SetTrustedPrincipals(JSRuntime* rt, JSPrincipals* prin)
 {
     rt->setTrustedPrincipals(prin);
 }
 
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -7392,17 +7392,17 @@ main(int argc, char** argv, char** envp)
 
     JS_SetGCParameter(cx, JSGC_MAX_BYTES, 0xffffffff);
 
     size_t availMem = op.getIntOption("available-memory");
     if (availMem > 0)
         JS_SetGCParametersBasedOnAvailableMemory(cx, availMem);
 
     JS_SetTrustedPrincipals(rt, &ShellPrincipals::fullyTrusted);
-    JS_SetSecurityCallbacks(rt, &ShellPrincipals::securityCallbacks);
+    JS_SetSecurityCallbacks(cx, &ShellPrincipals::securityCallbacks);
     JS_InitDestroyPrincipalsCallback(rt, ShellPrincipals::destroy);
 
     JS_SetInterruptCallback(rt, ShellInterruptCallback);
     JS::SetBuildIdOp(cx, ShellBuildId);
     JS::SetAsmJSCacheOps(cx, &asmJSCacheOps);
 
     JS_SetNativeStackQuota(cx, gMaxStackSize);
 
--- a/js/xpconnect/src/XPCShellImpl.cpp
+++ b/js/xpconnect/src/XPCShellImpl.cpp
@@ -1458,20 +1458,20 @@ XRE_XPCShellMain(int argc, char** argv, 
                     gJSPrincipals = nsJSPrincipals::get(systemprincipal);
                     JS_HoldPrincipals(gJSPrincipals);
                 }
             } else {
                 fprintf(gErrFile, "+++ Failed to get ScriptSecurityManager service, running without principals");
             }
         }
 
-        const JSSecurityCallbacks* scb = JS_GetSecurityCallbacks(rt);
+        const JSSecurityCallbacks* scb = JS_GetSecurityCallbacks(cx);
         MOZ_ASSERT(scb, "We are assuming that nsScriptSecurityManager::Init() has been run");
         shellSecurityCallbacks = *scb;
-        JS_SetSecurityCallbacks(rt, &shellSecurityCallbacks);
+        JS_SetSecurityCallbacks(cx, &shellSecurityCallbacks);
 
 #ifdef TEST_TranslateThis
         nsCOMPtr<nsIXPCFunctionThisTranslator>
             translator(new nsXPCFunctionThisTranslator);
         xpc->SetFunctionThisTranslator(NS_GET_IID(nsITestXPCFunctionCallback), translator);
 #endif
 
         RefPtr<BackstagePass> backstagePass;