Bug 892214 - Rename DOMConstructors to GlobalProperties in SandboxOptions. r=bholley, r=mossop
authorGabor Krizsanits <gkrizsanits@mozilla.com>
Sat, 21 Sep 2013 15:25:46 +0200
changeset 162071 044237be11e20d0de0f3053d89f37b63f07f80ab
parent 162070 7f8feafb0a443e2954503f1e2b90f6ed81ccd3fb
child 162072 2d42170cc6cce200e8c05a4a68ce00c956b5b257
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley, mossop
bugs892214
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 892214 - Rename DOMConstructors to GlobalProperties in SandboxOptions. r=bholley, r=mossop
addon-sdk/source/lib/sdk/content/worker.js
dom/tests/mochitest/chrome/test_sandbox_eventhandler.xul
js/xpconnect/src/Sandbox.cpp
js/xpconnect/src/xpcprivate.h
js/xpconnect/tests/unit/test_allowedDomainsXHR.js
js/xpconnect/tests/unit/test_bug868675.js
js/xpconnect/tests/unit/test_bug872772.js
js/xpconnect/tests/unit/test_exportFunction.js
js/xpconnect/tests/unit/test_textDecoder.js
--- a/addon-sdk/source/lib/sdk/content/worker.js
+++ b/addon-sdk/source/lib/sdk/content/worker.js
@@ -125,36 +125,36 @@ const WorkerSandbox = EventEmitter.compo
     // 1/ It is useless to use multiple domains as the worker is only used
     // to communicate with the addon,
     // 2/ By using it it would prevent the document to have access to any JS
     // value of the worker. As JS values coming from multiple domain principals
     // can't be accessed by "mono-principals" (principal with only one domain).
     // Even if this principal is for a domain that is specified in the multiple
     // domain principal.
     let principals  = window;
-    let wantDOMConstructors = []
+    let wantGlobalProperties = []
     if (EXPANDED_PRINCIPALS.length > 0 && !worker._injectInDocument) {
       principals = EXPANDED_PRINCIPALS.concat(window);
       // We have to replace XHR constructor of the content document
       // with a custom cross origin one, automagically added by platform code:
       delete proto.XMLHttpRequest;
-      wantDOMConstructors.push("XMLHttpRequest");
+      wantGlobalProperties.push("XMLHttpRequest");
     }
 
     // Instantiate trusted code in another Sandbox in order to prevent content
     // script from messing with standard classes used by proxy and API code.
     let apiSandbox = sandbox(principals, { wantXrays: true, sameZoneAs: window });
     apiSandbox.console = console;
 
     // Create the sandbox and bind it to window in order for content scripts to
     // have access to all standard globals (window, document, ...)
     let content = this._sandbox = sandbox(principals, {
       sandboxPrototype: proto,
       wantXrays: true,
-      wantDOMConstructors: wantDOMConstructors,
+      wantGlobalProperties: wantGlobalProperties,
       sameZoneAs: window
     });
     // We have to ensure that window.top and window.parent are the exact same
     // object than window object, i.e. the sandbox global object. But not
     // always, in case of iframes, top and parent are another window object.
     let top = window.top === window ? content : content.top;
     let parent = window.parent === window ? content : content.parent;
     merge(content, {
--- a/dom/tests/mochitest/chrome/test_sandbox_eventhandler.xul
+++ b/dom/tests/mochitest/chrome/test_sandbox_eventhandler.xul
@@ -15,17 +15,17 @@ https://bugzilla.mozilla.org/show_bug.cg
   </body>
 
   <!-- test code goes here -->
   <script type="application/javascript">
   <![CDATA[
 
   /** Test for Bug 817284 **/
   var cu = Components.utils;
-  var sb = cu.Sandbox("http://example.com", { wantDOMConstructors: ["XMLHttpRequest"] });
+  var sb = cu.Sandbox("http://example.com", { wantGlobalProperties: ["XMLHttpRequest"] });
 
   // Test event handler calls
   var xhr = cu.evalInSandbox(
       'var xhr = new XMLHttpRequest();\
        var called = false;\
        xhr.onload = function() { called = true; };\
        xhr', sb);
 
--- a/js/xpconnect/src/Sandbox.cpp
+++ b/js/xpconnect/src/Sandbox.cpp
@@ -866,17 +866,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::DOMConstructors::Parse(JSContext* cx, JS::HandleObject obj)
+xpc::SandboxOptions::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);
@@ -887,25 +887,25 @@ xpc::SandboxOptions::DOMConstructors::Pa
         NS_ENSURE_TRUE(name, false);
         if (!strcmp(name, "XMLHttpRequest")) {
             XMLHttpRequest = true;
         } else if (!strcmp(name, "TextEncoder")) {
             TextEncoder = true;
         } else if (!strcmp(name, "TextDecoder")) {
             TextDecoder = true;
         } else {
-            // Reporting error, if one of the DOM constructor names is unknown.
+            // Reporting error, if one of the global property names is unknown.
             return false;
         }
     }
     return true;
 }
 
 bool
-xpc::SandboxOptions::DOMConstructors::Define(JSContext* cx, JS::HandleObject obj)
+xpc::SandboxOptions::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;
@@ -1020,17 +1020,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.DOMConstructors.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);
@@ -1286,31 +1286,31 @@ GetStringPropFromOptions(JSContext *cx, 
 
     char *tmp = JS_EncodeString(cx, value.toString());
     NS_ENSURE_TRUE(tmp, NS_ERROR_INVALID_ARG);
     prop.Adopt(tmp, strlen(tmp));
     return NS_OK;
 }
 
 /*
- * Helper that tries to get a list of DOM constructors from the options object.
+ * Helper that tries to get a list of DOM constructors and other helpers from the options object.
  */
 static nsresult
-GetDOMConstructorsFromOptions(JSContext *cx, HandleObject from, SandboxOptions& options)
+GetGlobalPropertiesFromOptions(JSContext *cx, HandleObject from, SandboxOptions& options)
 {
     RootedValue value(cx);
     bool found;
-    nsresult rv = GetPropFromOptions(cx, from, "wantDOMConstructors", &value, &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.DOMConstructors.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
@@ -1337,17 +1337,17 @@ ParseOptionsObject(JSContext *cx, jsval 
     rv = GetStringPropFromOptions(cx, optionsObject,
                                   "sandboxName", options.sandboxName);
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = GetObjPropFromOptions(cx, optionsObject,
                                "sameZoneAs", options.sameZoneAs.address());
     NS_ENSURE_SUCCESS(rv, rv);
 
-    rv = GetDOMConstructorsFromOptions(cx, optionsObject, options);
+    rv = GetGlobalPropertiesFromOptions(cx, optionsObject, options);
 
     bool found;
     rv = GetPropFromOptions(cx, optionsObject,
                             "metadata", &options.metadata, &found);
     NS_ENSURE_SUCCESS(rv, rv);
 
     return NS_OK;
 }
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -3581,18 +3581,18 @@ ThrowAndFail(nsresult errNum, JSContext 
 already_AddRefed<nsIXPCComponents_utils_Sandbox>
 NewSandboxConstructor();
 
 // Returns true if class of 'obj' is SandboxClass.
 bool
 IsSandbox(JSObject *obj);
 
 struct SandboxOptions {
-    struct DOMConstructors {
-        DOMConstructors() { mozilla::PodZero(this); }
+    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;
     };
 
     SandboxOptions(JSContext *cx)
@@ -3605,17 +3605,17 @@ struct SandboxOptions {
     { }
 
     bool wantXrays;
     bool wantComponents;
     bool wantExportHelpers;
     JS::RootedObject proto;
     nsCString sandboxName;
     JS::RootedObject sameZoneAs;
-    DOMConstructors DOMConstructors;
+    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
--- a/js/xpconnect/tests/unit/test_allowedDomainsXHR.js
+++ b/js/xpconnect/tests/unit/test_allowedDomainsXHR.js
@@ -5,17 +5,17 @@ cu.import("resource://testing-common/htt
 var httpserver = new HttpServer();
 var httpserver2 = new HttpServer();
 var testpath = "/simple";
 var negativetestpath = "/negative";
 var httpbody = "<?xml version='1.0' ?><root>0123456789</root>";
 
 var sb = cu.Sandbox(["http://www.example.com",
                      "http://localhost:4444/simple"],
-                     { wantDOMConstructors: ["XMLHttpRequest"] });
+                     { wantGlobalProperties: ["XMLHttpRequest"] });
 
 function createXHR(loc, async)
 {
   var xhr = new XMLHttpRequest();
   xhr.open("GET", "http://localhost:" + loc, async);
   return xhr;
 }
 
--- a/js/xpconnect/tests/unit/test_bug868675.js
+++ b/js/xpconnect/tests/unit/test_bug868675.js
@@ -6,17 +6,17 @@ function run_test() {
   try { result = XPCNativeWrapper.unwrap(2); } catch (e) {}
   do_check_eq(result, 2);
   result = "threw";
   try { result = XPCNativeWrapper(2); } catch (e) {}
   do_check_eq(result, 2);
 
   // Make sure that we can waive on a non-Xrayable object, and that we preserve
   // transitive waiving behavior.
-  var sb = new Cu.Sandbox('http://www.example.com', { wantDOMConstructors: ["XMLHttpRequest"] });
+  var sb = new Cu.Sandbox('http://www.example.com', { wantGlobalProperties: ["XMLHttpRequest"] });
   Cu.evalInSandbox('this.xhr = new XMLHttpRequest();', sb);
   Cu.evalInSandbox('this.jsobj = {mynative: xhr};', sb);
   do_check_true(!Cu.isXrayWrapper(XPCNativeWrapper.unwrap(sb.xhr)));
   do_check_true(Cu.isXrayWrapper(sb.jsobj.mynative));
   do_check_true(!Cu.isXrayWrapper(XPCNativeWrapper.unwrap(sb.jsobj).mynative));
 
   // Test the new Cu API.
   var waived = Cu.waiveXrays(sb.xhr);
--- a/js/xpconnect/tests/unit/test_bug872772.js
+++ b/js/xpconnect/tests/unit/test_bug872772.js
@@ -1,16 +1,16 @@
 const Cu = Components.utils;
 function run_test() {
 
   // Make a content sandbox with an Xrayable object.
   // NB: We use an nsEP here so that we can have access to Components, but still
   // have Xray behavior from this scope.
   var contentSB = new Cu.Sandbox(['http://www.google.com'],
-                                 { wantDOMConstructors: ["XMLHttpRequest"], wantComponents: true });
+                                 { wantGlobalProperties: ["XMLHttpRequest"], wantComponents: true });
 
   // Make an XHR in the content sandbox.
   Cu.evalInSandbox('xhr = new XMLHttpRequest();', contentSB);
 
   // Make sure that waivers can be set as Xray expandos.
   var xhr = contentSB.xhr;
   do_check_true(Cu.isXrayWrapper(xhr));
   xhr.unwaivedExpando = xhr;
--- a/js/xpconnect/tests/unit/test_exportFunction.js
+++ b/js/xpconnect/tests/unit/test_exportFunction.js
@@ -1,13 +1,13 @@
 function run_test() {
   var Cu = Components.utils;
   var epsb = new Cu.Sandbox(["http://example.com", "http://example.org"], { wantExportHelpers: true });
-  subsb = new Cu.Sandbox("http://example.com", { wantDOMConstructors: ["XMLHttpRequest"] });
-  subsb2 = new Cu.Sandbox("http://example.com", { wantDOMConstructors: ["XMLHttpRequest"] });
+  subsb = new Cu.Sandbox("http://example.com", { wantGlobalProperties: ["XMLHttpRequest"] });
+  subsb2 = new Cu.Sandbox("http://example.com", { wantGlobalProperties: ["XMLHttpRequest"] });
   xorigsb = new Cu.Sandbox("http://test.com");
 
   epsb.subsb = subsb;
   epsb.xorigsb = xorigsb;
   epsb.do_check_true = do_check_true;
   epsb.do_check_eq = do_check_eq;
   epsb.do_check_neq = do_check_neq;
 
--- a/js/xpconnect/tests/unit/test_textDecoder.js
+++ b/js/xpconnect/tests/unit/test_textDecoder.js
@@ -1,9 +1,9 @@
 function run_test() {
   var Cu = Components.utils;
   sb = new Cu.Sandbox('http://www.example.com',
-                      { wantDOMConstructors: ["TextDecoder", "TextEncoder"] });
+                      { wantGlobalProperties: ["TextDecoder", "TextEncoder"] });
   sb.do_check_eq = do_check_eq;
   Cu.evalInSandbox('do_check_eq(new TextDecoder().encoding, "utf-8");' +
                    'do_check_eq(new TextEncoder().encoding, "utf-8");',
                    sb);
 }