Bug 1051224 - Use the opt-out for the webconsole helpers. r=ochameau
authorBobby Holley <bobbyholley@gmail.com>
Wed, 03 Sep 2014 13:02:36 -0700
changeset 203459 7fc38635dd4ed0505c01979041ad347888d284c8
parent 203458 1048b554fdf800947f09d5852f733a55044424c2
child 203460 d13a843f2163ea58c91ff995d927b4b9ad361eb0
push id27428
push usercbook@mozilla.com
push dateThu, 04 Sep 2014 13:00:04 +0000
treeherdermozilla-central@7bfd030e8fc8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1051224
milestone35.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 1051224 - Use the opt-out for the webconsole helpers. r=ochameau
toolkit/devtools/server/actors/webconsole.js
toolkit/devtools/webconsole/utils.js
--- a/toolkit/devtools/server/actors/webconsole.js
+++ b/toolkit/devtools/server/actors/webconsole.js
@@ -928,23 +928,41 @@ WebConsoleActor.prototype =
       makeDebuggeeValue: aDebuggerGlobal.makeDebuggeeValue.bind(aDebuggerGlobal),
       createValueGrip: this.createValueGrip.bind(this),
       sandbox: Object.create(null),
       helperResult: null,
       consoleActor: this,
     };
     JSTermHelpers(helpers);
 
-    // Make sure the helpers can be used during eval.
+    let evalWindow = this.evalWindow;
+    function maybeExport(obj, name) {
+      if (typeof obj[name] != "function") {
+        return;
+      }
+
+      // By default, chrome-implemented functions that are exposed to content
+      // refuse to accept arguments that are cross-origin for the caller. This
+      // is generally the safe thing, but causes problems for certain console
+      // helpers like cd(), where we users sometimes want to pass a cross-origin
+      // window. To circumvent this restriction, we use exportFunction along
+      // with a special option designed for this purpose. See bug 1051224.
+      obj[name] =
+        Cu.exportFunction(obj[name], evalWindow, { allowCrossOriginArguments: true });
+    }
     for (let name in helpers.sandbox) {
       let desc = Object.getOwnPropertyDescriptor(helpers.sandbox, name);
-      if (desc.get || desc.set) {
-        continue;
+      maybeExport(desc, 'get');
+      maybeExport(desc, 'set');
+      maybeExport(desc, 'value');
+      if (desc.value) {
+        // Make sure the helpers can be used during eval.
+        desc.value = aDebuggerGlobal.makeDebuggeeValue(desc.value);
       }
-      helpers.sandbox[name] = aDebuggerGlobal.makeDebuggeeValue(desc.value);
+      Object.defineProperty(helpers.sandbox, name, desc);
     }
     return helpers;
   },
 
   /**
    * Evaluates a string using the debugger API.
    *
    * To allow the variables view to update properties from the Web Console we
--- a/toolkit/devtools/webconsole/utils.js
+++ b/toolkit/devtools/webconsole/utils.js
@@ -1578,17 +1578,17 @@ function JSTermHelpers(aOwner)
    * @return Object representing the current selection in the
    *         Inspector, or null if no selection exists.
    */
   Object.defineProperty(aOwner.sandbox, "$0", {
     get: function() {
       return aOwner.makeDebuggeeValue(aOwner.selectedNode)
     },
     enumerable: true,
-    configurable: false
+    configurable: true
   });
 
   /**
    * Clears the output of the JSTerm.
    */
   aOwner.sandbox.clear = function JSTH_clear()
   {
     aOwner.helperResult = {