Bug 1342244, try to avoid extra CompartmentPrivate::Get calls during Rewrap, r=bholley
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Fri, 24 Feb 2017 15:03:38 +0200
changeset 373807 41d90dc1a067f2fe6469e467cde7c81d71cd7ecf
parent 373806 c8e97754bd0f23cbd271c114a5333a8944844b33
child 373808 3f70707e9a98b032ed8d5f2769611579de214b72
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1342244
milestone54.0a1
Bug 1342244, try to avoid extra CompartmentPrivate::Get calls during Rewrap, r=bholley
js/xpconnect/wrappers/WrapperFactory.cpp
--- a/js/xpconnect/wrappers/WrapperFactory.cpp
+++ b/js/xpconnect/wrappers/WrapperFactory.cpp
@@ -468,29 +468,34 @@ WrapperFactory::Rewrap(JSContext* cx, Ha
                                   AccessCheck::subsumesConsideringDomainIgnoringFPD(origin, target);
     bool targetSubsumesOrigin = OriginAttributes::IsRestrictOpenerAccessForFPI() ?
                                   AccessCheck::subsumesConsideringDomain(target, origin) :
                                   AccessCheck::subsumesConsideringDomainIgnoringFPD(target, origin);
     bool sameOrigin = targetSubsumesOrigin && originSubsumesTarget;
 
     const Wrapper* wrapper;
 
+    CompartmentPrivate* originCompartmentPrivate =
+      CompartmentPrivate::Get(origin);
+    CompartmentPrivate* targetCompartmentPrivate =
+      CompartmentPrivate::Get(target);
+
     //
     // First, handle the special cases.
     //
 
     // If UniversalXPConnect is enabled, this is just some dumb mochitest. Use
     // a vanilla CCW.
-    if (xpc::IsUniversalXPConnectEnabled(target)) {
+    if (targetCompartmentPrivate->universalXPConnectEnabled) {
         CrashIfNotInAutomation();
         wrapper = &CrossCompartmentWrapper::singleton;
     }
 
     // Let the SpecialPowers scope make its stuff easily accessible to content.
-    else if (CompartmentPrivate::Get(origin)->forcePermissiveCOWs) {
+    else if (originCompartmentPrivate->forcePermissiveCOWs) {
         CrashIfNotInAutomation();
         wrapper = &CrossCompartmentWrapper::singleton;
     }
 
     // Special handling for chrome objects being exposed to content.
     else if (originIsChrome && !targetIsChrome) {
         // If this is a chrome function being exposed to content, we need to allow
         // call (but nothing else). We allow CPOWs that purport to be function's
@@ -528,33 +533,33 @@ WrapperFactory::Rewrap(JSContext* cx, Ha
         bool securityWrapper = !targetSubsumesOrigin;
 
         // Xrays are warranted if either the target or the origin don't trust
         // each other. This is generally the case, unless the two are same-origin
         // and the caller has not requested same-origin Xrays.
         //
         // Xrays are a bidirectional protection, since it affords clarity to the
         // caller and privacy to the callee.
-        bool sameOriginXrays = CompartmentPrivate::Get(origin)->wantXrays ||
-                               CompartmentPrivate::Get(target)->wantXrays;
+        bool sameOriginXrays = originCompartmentPrivate->wantXrays ||
+                               targetCompartmentPrivate->wantXrays;
         bool wantXrays = !sameOrigin || sameOriginXrays;
 
         XrayType xrayType = wantXrays ? GetXrayType(obj) : NotXray;
 
         // If Xrays are warranted, the caller may waive them for non-security
         // wrappers (unless explicitly forbidden from doing so).
         bool waiveXrays = wantXrays && !securityWrapper &&
-                          CompartmentPrivate::Get(target)->allowWaivers &&
+                          targetCompartmentPrivate->allowWaivers &&
                           HasWaiveXrayFlag(obj);
 
         wrapper = SelectWrapper(securityWrapper, xrayType, waiveXrays, obj);
 
         // If we want to apply add-on interposition in the target compartment,
         // then we try to "upgrade" the wrapper to an interposing one.
-        if (CompartmentPrivate::Get(target)->scope->HasInterposition())
+        if (targetCompartmentPrivate->scope->HasInterposition())
             wrapper = SelectAddonWrapper(cx, obj, wrapper);
     }
 
     if (!targetSubsumesOrigin) {
         // Do a belt-and-suspenders check against exposing eval()/Function() to
         // non-subsuming content.
         if (JSFunction* fun = JS_GetObjectFunction(obj)) {
             if (JS_IsBuiltinEvalFunction(fun) || JS_IsBuiltinFunctionConstructor(fun)) {