Bug 1283855 part 18 - Make JS_DropPrincipals take JSContext instead of JSRuntime. r=luke
authorJan de Mooij <jdemooij@mozilla.com>
Tue, 05 Jul 2016 16:49:41 +0200
changeset 303703 ae90cded54077ae5a7c845970ec874d9c6d1af1a
parent 303702 2e94e4eb877c523d790f64cb23c662249a1bf500
child 303704 a2d7ff2d4bd87297766a8c95cf47f8d1db7117c0
push id79145
push userjandemooij@gmail.com
push dateTue, 05 Jul 2016 14:54:28 +0000
treeherdermozilla-inbound@eee13ff3e4d8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1283855
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1283855 part 18 - Make JS_DropPrincipals take JSContext instead of JSRuntime. r=luke
js/public/Principals.h
js/src/jsapi-tests/testCloneScript.cpp
js/src/jsapi.cpp
js/src/jscompartment.h
js/src/jsfriendapi.cpp
js/src/jsgc.cpp
js/src/shell/js.cpp
js/src/vm/SavedStacks.cpp
js/xpconnect/src/XPCShellImpl.cpp
--- a/js/public/Principals.h
+++ b/js/public/Principals.h
@@ -50,17 +50,17 @@ struct JSPrincipals {
      */
     JS_PUBLIC_API(void) dump();
 };
 
 extern JS_PUBLIC_API(void)
 JS_HoldPrincipals(JSPrincipals* principals);
 
 extern JS_PUBLIC_API(void)
-JS_DropPrincipals(JSRuntime* rt, JSPrincipals* principals);
+JS_DropPrincipals(JSContext* cx, JSPrincipals* principals);
 
 // Return whether the first principal subsumes the second. The exact meaning of
 // 'subsumes' is left up to the browser. Subsumption is checked inside the JS
 // engine when determining, e.g., which stack frames to display in a backtrace.
 typedef bool
 (* JSSubsumesOp)(JSPrincipals* first, JSPrincipals* second);
 
 /*
--- a/js/src/jsapi-tests/testCloneScript.cpp
+++ b/js/src/jsapi-tests/testCloneScript.cpp
@@ -74,17 +74,17 @@ class AutoDropPrincipals
     AutoDropPrincipals(JSRuntime* rt, JSPrincipals* principals)
       : rt(rt), principals(principals)
     {
         JS_HoldPrincipals(principals);
     }
 
     ~AutoDropPrincipals()
     {
-        JS_DropPrincipals(rt, principals);
+        JS_DropPrincipals(JS_GetContext(rt), principals);
     }
 };
 
 static void
 DestroyPrincipals(JSPrincipals* principals)
 {
     auto p = static_cast<Principals*>(principals);
     delete p;
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -3263,21 +3263,21 @@ JS_SetArrayLength(JSContext* cx, HandleO
 
 JS_PUBLIC_API(void)
 JS_HoldPrincipals(JSPrincipals* principals)
 {
     ++principals->refcount;
 }
 
 JS_PUBLIC_API(void)
-JS_DropPrincipals(JSRuntime* rt, JSPrincipals* principals)
+JS_DropPrincipals(JSContext* cx, JSPrincipals* principals)
 {
     int rc = --principals->refcount;
     if (rc == 0)
-        rt->destroyPrincipals(principals);
+        cx->destroyPrincipals(principals);
 }
 
 JS_PUBLIC_API(void)
 JS_SetSecurityCallbacks(JSRuntime* rt, const JSSecurityCallbacks* scb)
 {
     MOZ_ASSERT(scb != &NullSecurityCallbacks);
     rt->securityCallbacks = scb ? scb : &NullSecurityCallbacks;
 }
--- a/js/src/jscompartment.h
+++ b/js/src/jscompartment.h
@@ -380,16 +380,20 @@ struct JSCompartment
     }
 
     // Note: Unrestricted access to the zone's runtime from an arbitrary
     // thread can easily lead to races. Use this method very carefully.
     JSRuntime* runtimeFromAnyThread() const {
         return runtime_;
     }
 
+    JSContext* contextFromMainThread() const {
+        return runtime_->contextFromMainThread();
+    }
+
     /*
      * Nb: global_ might be nullptr, if (a) it's the atoms compartment, or
      * (b) the compartment's global has been collected.  The latter can happen
      * if e.g. a string in a compartment is rooted but no object is, and thus
      * the global isn't rooted, and thus the global can be finalized while the
      * compartment lives on.
      *
      * In contrast, JSObject::global() is infallible because marking a JSObject
--- a/js/src/jsfriendapi.cpp
+++ b/js/src/jsfriendapi.cpp
@@ -164,17 +164,17 @@ JS_SetCompartmentPrincipals(JSCompartmen
 
     // Any compartment with the trusted principals -- and there can be
     // multiple -- is a system compartment.
     const JSPrincipals* trusted = compartment->runtimeFromMainThread()->trustedPrincipals();
     bool isSystem = principals && principals == trusted;
 
     // Clear out the old principals, if any.
     if (compartment->principals()) {
-        JS_DropPrincipals(compartment->runtimeFromMainThread(), compartment->principals());
+        JS_DropPrincipals(compartment->contextFromMainThread(), compartment->principals());
         compartment->setPrincipals(nullptr);
         // We'd like to assert that our new principals is always same-origin
         // with the old one, but JSPrincipals doesn't give us a way to do that.
         // But we can at least assert that we're not switching between system
         // and non-system.
         MOZ_ASSERT(compartment->isSystem() == isSystem);
     }
 
--- a/js/src/jsgc.cpp
+++ b/js/src/jsgc.cpp
@@ -3505,17 +3505,17 @@ Zone::sweepCompartments(FreeOp* fop, boo
          * Don't delete the last compartment if all the ones before it were
          * deleted and keepAtleastOne is true.
          */
         bool dontDelete = read == end && !foundOne && keepAtleastOne;
         if ((!comp->marked && !dontDelete) || destroyingRuntime) {
             if (callback)
                 callback(fop, comp);
             if (comp->principals())
-                JS_DropPrincipals(rt, comp->principals());
+                JS_DropPrincipals(rt->contextFromMainThread(), comp->principals());
             js_delete(comp);
         } else {
             *write++ = comp;
             foundOne = true;
         }
     }
     compartments.shrinkTo(write - compartments.begin());
     MOZ_ASSERT_IF(keepAtleastOne, !compartments.empty());
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -4347,17 +4347,17 @@ NewGlobal(JSContext* cx, unsigned argc, 
             if (!principals)
                 return false;
             JS_HoldPrincipals(principals);
         }
     }
 
     RootedObject global(cx, NewGlobalObject(cx, options, principals));
     if (principals)
-        JS_DropPrincipals(cx->runtime(), principals);
+        JS_DropPrincipals(cx, principals);
     if (!global)
         return false;
 
     if (!JS_WrapObject(cx, &global))
         return false;
 
     args.rval().setObject(*global);
     return true;
--- a/js/src/vm/SavedStacks.cpp
+++ b/js/src/vm/SavedStacks.cpp
@@ -352,17 +352,17 @@ SavedFrame::protoAccessors[] = {
 };
 
 /* static */ void
 SavedFrame::finalize(FreeOp* fop, JSObject* obj)
 {
     JSPrincipals* p = obj->as<SavedFrame>().getPrincipals();
     if (p) {
         JSRuntime* rt = obj->runtimeFromMainThread();
-        JS_DropPrincipals(rt, p);
+        JS_DropPrincipals(rt->contextFromMainThread(), p);
     }
 }
 
 JSAtom*
 SavedFrame::getSource()
 {
     const Value& v = getReservedSlot(JSSLOT_SOURCE);
     JSString* s = v.toString();
--- a/js/xpconnect/src/XPCShellImpl.cpp
+++ b/js/xpconnect/src/XPCShellImpl.cpp
@@ -1574,17 +1574,17 @@ XRE_XPCShellMain(int argc, char** argv, 
                     } else if (gQuitting) {
                         result = 0;
                     } else {
                         result = EXITCODE_RUNTIME_ERROR;
                     }
                 }
             }
 
-            JS_DropPrincipals(rt, gJSPrincipals);
+            JS_DropPrincipals(cx, gJSPrincipals);
             JS_SetAllNonReservedSlotsToUndefined(cx, glob);
             JS_SetAllNonReservedSlotsToUndefined(cx, JS_GlobalLexicalScope(glob));
             JS_GC(rt);
         }
         JS_GC(rt);
     } // this scopes the nsCOMPtrs
 
     if (!XRE_ShutdownTestShell())