bug 574033 - HUD Console should evaluate commands in window scope
authorJulian Viereck <jviereck@mozilla.com>
Mon, 19 Jul 2010 10:51:51 -0300
changeset 47920 8f6215091539e1563c7eccae2faa45b2943c4374
parent 47919 4989f8c0fdc3000a97f3640858d7c04bf2091155
child 47921 eeeb549a37cd0c400ed1b8b6dc446741b3bf7a40
push id14477
push userrcampbell@mozilla.com
push dateMon, 19 Jul 2010 13:52:27 +0000
treeherdermozilla-central@8f6215091539 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs574033
milestone2.0b2pre
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 574033 - HUD Console should evaluate commands in window scope
toolkit/components/console/hudservice/HUDService.jsm
toolkit/components/console/hudservice/tests/browser/browser_HUDServiceTestsAll.js
--- a/toolkit/components/console/hudservice/HUDService.jsm
+++ b/toolkit/components/console/hudservice/HUDService.jsm
@@ -2193,18 +2193,19 @@ JSTerm.prototype = {
     if (!str) {
       this.console.log("no value to execute");
       return;
     }
 
     this.writeOutput(str);
 
     try {
+      var execStr = "with(window) {" + str + "}";
       var result =
-      Cu.evalInSandbox(str, this.sandbox, "default", "HUD Console", 1);
+        Cu.evalInSandbox(execStr,  this.sandbox, "default", "HUD Console", 1);
 
       if (result || result === false || result === " ") {
         this.writeOutput(result);
       }
       else if (result === undefined) {
         this.writeOutput("undefined");
       }
       else if (result === null) {
--- a/toolkit/components/console/hudservice/tests/browser/browser_HUDServiceTestsAll.js
+++ b/toolkit/components/console/hudservice/tests/browser/browser_HUDServiceTestsAll.js
@@ -425,16 +425,37 @@ function testConsoleHistory()
 
   is (input.value, "", "check input is still empty");
 
   let idxLast = executeList.length - 1;
   jsterm.historyPeruse(true);
   is (input.value, executeList[idxLast], "check history next idx:" + idxLast);
 }
 
+function testExecutionScope()
+{
+  content.location.href = TEST_URI;
+
+  let HUD = HUDService.hudWeakReferences[hudId].get();
+  let jsterm = HUD.jsterm;
+  let outputNode = jsterm.outputNode;
+
+  jsterm.clearOutput();
+  jsterm.execute("location;");
+
+  is(outputNode.childNodes.length, 2, "Two children in output");
+  let outputChildren = outputNode.childNodes;
+
+  is(/location;/.test(outputChildren[0].childNodes[0].nodeValue), true,
+    "'location;' written to output");
+
+  isnot(outputChildren[1].childNodes[0].nodeValue.indexOf(TEST_URI), -1,
+    "command was executed in the window scope");
+}
+
 function testIteration() {
   var id = "foo";
   var it = cs.displayStore(id);
   var entry = it.next();
   var entry2 = it.next();
 
   let entries = [];
   for (var i = 0; i < 100; i++) {
@@ -506,16 +527,17 @@ function test() {
       // ConsoleStorageTests
       testCreateDisplay();
       testRecordEntry();
       testRecordManyEntries();
       testIteration();
       testConsoleHistory();
       testOutputOrder();
       testNullUndefinedOutput();
+      testExecutionScope();
 
       // testUnregister();
       executeSoon(function () {
         HUDService.deactivateHUDForContext(tab);
         HUDService.shutdown();
       });
       finish();
     });