Bug 920553 - Hoist GlobalProperties out of SandboxOptions. r=gabor
authorBobby Holley <bobbyholley@gmail.com>
Fri, 27 Sep 2013 18:34:25 +0200
changeset 149013 f0fad858e878f144ddc875515ea8f0b025d94af2
parent 149012 6b8e91bf52b637c04d37f92fd7fae0e01924640c
child 149014 05f41a913bee8286084a32c8dbd986f2d103a52d
push id25366
push userkwierso@gmail.com
push dateSat, 28 Sep 2013 02:13:38 +0000
treeherdermozilla-central@e1914e294152 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgabor
bugs920553
milestone27.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 920553 - Hoist GlobalProperties out of SandboxOptions. r=gabor
js/xpconnect/src/Sandbox.cpp
js/xpconnect/src/xpcprivate.h
--- a/js/xpconnect/src/Sandbox.cpp
+++ b/js/xpconnect/src/Sandbox.cpp
@@ -867,17 +867,17 @@ xpc::SandboxProxyHandler::keys(JSContext
 bool
 xpc::SandboxProxyHandler::iterate(JSContext *cx, JS::Handle<JSObject*> proxy,
                                   unsigned flags, JS::MutableHandle<Value> vp)
 {
     return BaseProxyHandler::iterate(cx, proxy, flags, vp);
 }
 
 bool
-xpc::SandboxOptions::GlobalProperties::Parse(JSContext* cx, JS::HandleObject obj)
+xpc::GlobalProperties::Parse(JSContext *cx, JS::HandleObject obj)
 {
     NS_ENSURE_TRUE(JS_IsArrayObject(cx, obj), false);
 
     uint32_t length;
     bool ok = JS_GetArrayLength(cx, obj, &length);
     NS_ENSURE_TRUE(ok, false);
     for (uint32_t i = 0; i < length; i++) {
         RootedValue nameValue(cx);
@@ -900,17 +900,17 @@ xpc::SandboxOptions::GlobalProperties::P
             // Reporting error, if one of the global property names is unknown.
             return false;
         }
     }
     return true;
 }
 
 bool
-xpc::SandboxOptions::GlobalProperties::Define(JSContext* cx, JS::HandleObject obj)
+xpc::GlobalProperties::Define(JSContext *cx, JS::HandleObject obj)
 {
     if (XMLHttpRequest &&
         !JS_DefineFunction(cx, obj, "XMLHttpRequest", CreateXMLHttpRequest, 0, JSFUN_CONSTRUCTOR))
         return false;
 
     if (TextEncoder &&
         !dom::TextEncoderBinding::GetConstructorObject(cx, obj))
         return false;
@@ -1033,17 +1033,17 @@ xpc::CreateSandboxObject(JSContext *cx, 
         if (!JS_DefineFunctions(cx, sandbox, SandboxFunctions))
             return NS_ERROR_XPC_UNEXPECTED;
 
         if (options.wantExportHelpers &&
             (!JS_DefineFunction(cx, sandbox, "exportFunction", ExportFunction, 3, 0) ||
              !JS_DefineFunction(cx, sandbox, "evalInWindow", EvalInWindow, 2, 0)))
             return NS_ERROR_XPC_UNEXPECTED;
 
-        if (!options.GlobalProperties.Define(cx, sandbox))
+        if (!options.globalProperties.Define(cx, sandbox))
             return NS_ERROR_XPC_UNEXPECTED;
     }
 
     if (vp) {
         // We have this crazy behavior where wantXrays=false also implies that the
         // returned sandbox is implicitly waived. We've stopped advertising it, but
         // keep supporting it for now.
         *vp = OBJECT_TO_JSVAL(sandbox);
@@ -1313,17 +1313,17 @@ GetGlobalPropertiesFromOptions(JSContext
     bool found;
     nsresult rv = GetPropFromOptions(cx, from, "wantGlobalProperties", &value, &found);
     NS_ENSURE_SUCCESS(rv, rv);
     if (!found)
         return NS_OK;
 
     NS_ENSURE_TRUE(value.isObject(), NS_ERROR_INVALID_ARG);
     RootedObject ctors(cx, &value.toObject());
-    bool ok = options.GlobalProperties.Parse(cx, ctors);
+    bool ok = options.globalProperties.Parse(cx, ctors);
     NS_ENSURE_TRUE(ok, NS_ERROR_INVALID_ARG);
     return NS_OK;
 }
 
 /*
  * Helper that parsing the sandbox options object (from) and sets the fields of the incoming options struct (options).
  */
 static nsresult
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -3581,52 +3581,52 @@ Btoa(JSContext *cx, unsigned argc, jsval
 bool
 NewFunctionForwarder(JSContext *cx, JS::HandleId id, JS::HandleObject callable,
                      bool doclone, JS::MutableHandleValue vp);
 
 // Old fashioned xpc error reporter. Try to use JS_ReportError instead.
 nsresult
 ThrowAndFail(nsresult errNum, JSContext *cx, bool *retval);
 
+struct GlobalProperties {
+    GlobalProperties() { mozilla::PodZero(this); }
+    bool Parse(JSContext *cx, JS::HandleObject obj);
+    bool Define(JSContext *cx, JS::HandleObject obj);
+    bool XMLHttpRequest;
+    bool TextDecoder;
+    bool TextEncoder;
+    bool atob;
+    bool btoa;
+};
+
 // Infallible.
 already_AddRefed<nsIXPCComponents_utils_Sandbox>
 NewSandboxConstructor();
 
 // Returns true if class of 'obj' is SandboxClass.
 bool
 IsSandbox(JSObject *obj);
 
 struct SandboxOptions {
-    struct GlobalProperties {
-        GlobalProperties() { mozilla::PodZero(this); }
-        bool Parse(JSContext* cx, JS::HandleObject obj);
-        bool Define(JSContext* cx, JS::HandleObject obj);
-        bool XMLHttpRequest;
-        bool TextDecoder;
-        bool TextEncoder;
-        bool atob;
-        bool btoa;
-    };
-
     SandboxOptions(JSContext *cx)
         : wantXrays(true)
         , wantComponents(true)
         , wantExportHelpers(false)
         , proto(xpc_GetSafeJSContext())
         , sameZoneAs(xpc_GetSafeJSContext())
         , metadata(xpc_GetSafeJSContext())
     { }
 
     bool wantXrays;
     bool wantComponents;
     bool wantExportHelpers;
     JS::RootedObject proto;
     nsCString sandboxName;
     JS::RootedObject sameZoneAs;
-    GlobalProperties GlobalProperties;
+    GlobalProperties globalProperties;
     JS::RootedValue metadata;
 };
 
 JSObject *
 CreateGlobalObject(JSContext *cx, const JSClass *clasp, nsIPrincipal *principal,
                    JS::CompartmentOptions& aOptions);
 
 // Helper for creating a sandbox object to use for evaluating