Bug 946813 - Part 1: Expose invisibleToDebugger as a sandbox flag. r=bholley, a=lsblakk
authorJ. Ryan Stinnett <jryans@gmail.com>
Thu, 19 Dec 2013 17:31:05 -0600
changeset 175764 7044a11396975d6ba1220603e6b9efbfb8f260c3
parent 175763 3f0b920677460be8b4432729bda84691e793df92
child 175765 1dd80f8faa2f2af1dbb82065650ec11a07857ab6
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley, lsblakk
bugs946813
milestone28.0a2
Bug 946813 - Part 1: Expose invisibleToDebugger as a sandbox flag. r=bholley, a=lsblakk
js/xpconnect/src/Sandbox.cpp
js/xpconnect/src/xpcprivate.h
js/xpconnect/tests/chrome/test_evalInSandbox.xul
--- a/js/xpconnect/src/Sandbox.cpp
+++ b/js/xpconnect/src/Sandbox.cpp
@@ -1034,16 +1034,19 @@ xpc::CreateSandboxObject(JSContext *cx, 
         MOZ_ASSERT(principal);
     }
 
     JS::CompartmentOptions compartmentOptions;
     if (options.sameZoneAs)
         compartmentOptions.setSameZoneAs(js::UncheckedUnwrap(options.sameZoneAs));
     else
         compartmentOptions.setZone(JS::SystemZone);
+
+    compartmentOptions.setInvisibleToDebugger(options.invisibleToDebugger);
+
     RootedObject sandbox(cx, xpc::CreateGlobalObject(cx, &SandboxClass,
                                                      principal, compartmentOptions));
     if (!sandbox)
         return NS_ERROR_FAILURE;
 
     // Set up the wantXrays flag, which indicates whether xrays are desired even
     // for same-origin access.
     //
@@ -1467,16 +1470,17 @@ bool
 SandboxOptions::Parse()
 {
     return ParseObject("sandboxPrototype", &proto) &&
            ParseBoolean("wantXrays", &wantXrays) &&
            ParseBoolean("wantComponents", &wantComponents) &&
            ParseBoolean("wantExportHelpers", &wantExportHelpers) &&
            ParseString("sandboxName", sandboxName) &&
            ParseObject("sameZoneAs", &sameZoneAs) &&
+           ParseBoolean("invisibleToDebugger", &invisibleToDebugger) &&
            ParseGlobalProperties() &&
            ParseValue("metadata", &metadata);
 }
 
 static nsresult
 AssembleSandboxMemoryReporterName(JSContext *cx, nsCString &sandboxName)
 {
     // Use a default name when the caller did not provide a sandboxName.
--- a/js/xpconnect/src/xpcprivate.h
+++ b/js/xpconnect/src/xpcprivate.h
@@ -3432,27 +3432,29 @@ public:
     SandboxOptions(JSContext *cx = xpc_GetSafeJSContext(),
                    JSObject *options = nullptr)
         : OptionsBase(cx, options)
         , wantXrays(true)
         , wantComponents(true)
         , wantExportHelpers(false)
         , proto(cx)
         , sameZoneAs(cx)
+        , invisibleToDebugger(false)
         , metadata(cx)
     { }
 
     virtual bool Parse();
 
     bool wantXrays;
     bool wantComponents;
     bool wantExportHelpers;
     JS::RootedObject proto;
     nsCString sandboxName;
     JS::RootedObject sameZoneAs;
+    bool invisibleToDebugger;
     GlobalProperties globalProperties;
     JS::RootedValue metadata;
 
 protected:
     bool ParseGlobalProperties();
 };
 
 class MOZ_STACK_CLASS CreateObjectInOptions : public OptionsBase {
--- a/js/xpconnect/tests/chrome/test_evalInSandbox.xul
+++ b/js/xpconnect/tests/chrome/test_evalInSandbox.xul
@@ -145,10 +145,31 @@ https://bugzilla.mozilla.org/show_bug.cg
 
       try {
         var sandbox = new Cu.Sandbox(this, { sameZoneAs: this } );
         ok(true, "sameZoneAs works");
       }
       catch (e) {
         ok(false, "sameZoneAs works");
       }
+
+      Cu.import("resource://gre/modules/jsdebugger.jsm");
+      addDebuggerToGlobal(this);
+
+      try {
+        let dbg = new Debugger();
+        let sandbox = new Cu.Sandbox(this, { invisibleToDebugger: false });
+        dbg.addDebuggee(sandbox);
+        ok(true, "debugger added visible value");
+      } catch(e) {
+        ok(false, "debugger could not add visible value");
+      }
+
+      try {
+        let dbg = new Debugger();
+        let sandbox = new Cu.Sandbox(this, { invisibleToDebugger: true });
+        dbg.addDebuggee(sandbox);
+        ok(false, "debugger added invisible value");
+      } catch(e) {
+        ok(true, "debugger did not add invisible value");
+      }
   ]]></script>
 </window>