Bug 1582039 - Make JSContext::runningWithTrustedPrincipals() return false if trustedPrincipals() is nullptr. r=luke
authorJan de Mooij <jdemooij@mozilla.com>
Fri, 20 Sep 2019 13:02:53 +0000
changeset 494284 6fb6e6cf5d94964f8532d578ac6a53583988d113
parent 494283 ca69b14d6dbf3cc71ee12c0f3457de35ddf82998
child 494285 5ecd5f4f59ae00cab5d0bb16a434a28e0d73ec27
push id114114
push userdluca@mozilla.com
push dateFri, 20 Sep 2019 22:00:08 +0000
treeherdermozilla-inbound@56e11fddf939 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1582039
milestone71.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 1582039 - Make JSContext::runningWithTrustedPrincipals() return false if trustedPrincipals() is nullptr. r=luke Differential Revision: https://phabricator.services.mozilla.com/D46258
js/src/vm/JSContext-inl.h
js/src/vm/JSContext.h
--- a/js/src/vm/JSContext-inl.h
+++ b/js/src/vm/JSContext-inl.h
@@ -299,17 +299,23 @@ inline js::LifoAlloc& JSContext::typeLif
 
 inline js::Nursery& JSContext::nursery() { return runtime()->gc.nursery(); }
 
 inline void JSContext::minorGC(JS::GCReason reason) {
   runtime()->gc.minorGC(reason);
 }
 
 inline bool JSContext::runningWithTrustedPrincipals() {
-  return !realm() || realm()->principals() == runtime()->trustedPrincipals();
+  if (!realm()) {
+    return true;
+  }
+  if (!runtime()->trustedPrincipals()) {
+    return false;
+  }
+  return realm()->principals() == runtime()->trustedPrincipals();
 }
 
 inline void JSContext::enterRealm(JS::Realm* realm) {
   // We should never enter a realm while in the atoms zone.
   MOZ_ASSERT_IF(zone(), !zone()->isAtomsZone());
 
   realm->enter();
   setRealm(realm);
--- a/js/src/vm/JSContext.h
+++ b/js/src/vm/JSContext.h
@@ -799,17 +799,17 @@ struct JSContext : public JS::RootingCon
 
   bool isThrowingOverRecursed() const { return throwing && overRecursed_; }
   bool isPropagatingForcedReturn() const { return propagatingForcedReturn_; }
   void setPropagatingForcedReturn() { propagatingForcedReturn_ = true; }
   void clearPropagatingForcedReturn() { propagatingForcedReturn_ = false; }
 
   /*
    * See JS_SetTrustedPrincipals in jsapi.h.
-   * Note: !cx->compartment is treated as trusted.
+   * Note: !cx->realm() is treated as trusted.
    */
   inline bool runningWithTrustedPrincipals();
 
   JS_FRIEND_API size_t
   sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) const;
 
   void trace(JSTracer* trc);