Bug 1110546 - Allow null as the principal argument for the sandbox constructor. r=gabor
authorBobby Holley <bobbyholley@gmail.com>
Thu, 18 Dec 2014 12:44:42 -0800
changeset 220380 36f9d31965036534c74757e73c3ce0b8bdd71f20
parent 220379 9fa4c542936b5addb460bed38c9071f0508f70fa
child 220381 ce51003483e4df7dd5afa6abb5fe4800f5795a8c
push id53085
push userbobbyholley@gmail.com
push dateThu, 18 Dec 2014 20:45:16 +0000
treeherdermozilla-inbound@36f9d3196503 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgabor
bugs1110546
milestone37.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 1110546 - Allow null as the principal argument for the sandbox constructor. r=gabor
js/xpconnect/src/Sandbox.cpp
js/xpconnect/tests/unit/test_bug1110546.js
js/xpconnect/tests/unit/xpcshell.ini
--- a/js/xpconnect/src/Sandbox.cpp
+++ b/js/xpconnect/src/Sandbox.cpp
@@ -1410,16 +1410,20 @@ nsXPCComponents_utils_Sandbox::CallOrCon
     } else if (args[0].isObject()) {
         RootedObject obj(cx, &args[0].toObject());
         if (JS_IsArrayObject(cx, obj)) {
             ok = GetExpandedPrincipal(cx, obj, getter_AddRefs(expanded));
             prinOrSop = expanded;
         } else {
             ok = GetPrincipalOrSOP(cx, obj, getter_AddRefs(prinOrSop));
         }
+    } else if (args[0].isNull()) {
+        // Null means that we just pass prinOrSop = nullptr, and get an
+        // nsNullPrincipal.
+        ok = true;
     }
 
     if (!ok)
         return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
 
     bool calledWithOptions = args.length() > 1;
     if (calledWithOptions && !args[1].isObject())
         return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
new file mode 100644
--- /dev/null
+++ b/js/xpconnect/tests/unit/test_bug1110546.js
@@ -0,0 +1,5 @@
+const Cu = Components.utils;
+function run_test() {
+  var sb = new Cu.Sandbox(null);
+  do_check_true(Cu.getObjectPrincipal(sb).isNullPrincipal);
+}
--- a/js/xpconnect/tests/unit/xpcshell.ini
+++ b/js/xpconnect/tests/unit/xpcshell.ini
@@ -48,16 +48,17 @@ support-files =
 [test_bug1001094.js]
 [test_bug1021312.js]
 [test_bug1033253.js]
 [test_bug1033920.js]
 [test_bug1033927.js]
 [test_bug1034262.js]
 [test_bug1082450.js]
 [test_bug1081990.js]
+[test_bug1110546.js]
 [test_bug_442086.js]
 [test_file.js]
 [test_blob.js]
 [test_blob2.js]
 [test_file2.js]
 [test_import.js]
 [test_import_fail.js]
 [test_interposition.js]