Bug 986107: Make new sandboxes inherit the metadata of the creating sandbox by default. r=bholley
authorDave Townsend <dtownsend@oxymoronical.com>
Fri, 21 Mar 2014 19:57:42 -0700
changeset 174933 099f98a960a97ae4ccfaefeb80d8a37bdb6eb7e4
parent 174932 884a711d95479b1553162c5f5cb8c96ccb51bc00
child 174934 473cb1d6c18f34f5ca211ca390a9c5636ab24533
push id26470
push userphilringnalda@gmail.com
push dateSun, 23 Mar 2014 15:27:28 +0000
treeherdermozilla-central@88bd925b04a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs986107
milestone31.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 986107: Make new sandboxes inherit the metadata of the creating sandbox by default. r=bholley
js/xpconnect/src/Sandbox.cpp
js/xpconnect/tests/unit/test_sandbox_metadata.js
--- a/js/xpconnect/src/Sandbox.cpp
+++ b/js/xpconnect/src/Sandbox.cpp
@@ -1569,16 +1569,26 @@ nsXPCComponents_utils_Sandbox::CallOrCon
 
     SandboxOptions options(cx, optionsObject);
     if (calledWithOptions && !options.Parse())
         return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
 
     if (NS_FAILED(AssembleSandboxMemoryReporterName(cx, options.sandboxName)))
         return ThrowAndFail(NS_ERROR_INVALID_ARG, cx, _retval);
 
+    if (options.metadata.isNullOrUndefined()) {
+        // If the caller is running in a sandbox, inherit.
+        RootedObject callerGlobal(cx, CurrentGlobalOrNull(cx));
+        if (IsSandbox(callerGlobal)) {
+            rv = GetSandboxMetadata(cx, callerGlobal, &options.metadata);
+            if (NS_WARN_IF(NS_FAILED(rv)))
+                return rv;
+        }
+    }
+
     rv = CreateSandboxObject(cx, args.rval(), prinOrSop, options);
 
     if (NS_FAILED(rv))
         return ThrowAndFail(rv, cx, _retval);
 
     *_retval = true;
     return NS_OK;
 }
--- a/js/xpconnect/tests/unit/test_sandbox_metadata.js
+++ b/js/xpconnect/tests/unit/test_sandbox_metadata.js
@@ -36,10 +36,21 @@ function run_test()
 
   try {
     Components.utils.setSandboxMetadata(sandbox, { foo: reflector });
   } catch(e) {
     thrown = true;
   }
 
   do_check_eq(thrown, true);
+
+  sandbox = Components.utils.Sandbox(this, {
+    metadata: { foopy: { bar: 2 }, baz: "hi" }
+  });
+
+  let inner = Components.utils.evalInSandbox("Components.utils.Sandbox('http://www.blah.com')", sandbox);
+
+  metadata = Components.utils.getSandboxMetadata(inner);
+  do_check_eq(metadata.baz, "hi");
+  do_check_eq(metadata.foopy.bar, 2);
+  metadata.baz = "foo";
 }