bug 576963 - executed string is written to the console output after executing it, r=dietrich
authorJulian Viereck <jviereck@mozilla.com>
Fri, 16 Jul 2010 12:10:36 -0300
changeset 47818 d018b4a493a38a4a2c210a93d75ddefffcc7a90a
parent 47817 f120e7e60a16aba1f6209e3260415388c32e2b1c
child 47819 70aa61505c8f5958527905bf8467a35e026b02f9
push id14428
push userrcampbell@mozilla.com
push dateFri, 16 Jul 2010 15:58:31 +0000
treeherderautoland@1c7a77f65f9b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdietrich
bugs576963
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 576963 - executed string is written to the console output after executing it, r=dietrich
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
@@ -2187,28 +2187,30 @@ JSTerm.prototype = {
     this.sandbox.__proto__ = this._window.wrappedJSObject;
   },
 
   get _window()
   {
     return this.context.get().QueryInterface(Ci.nsIDOMWindowInternal);
   },
 
-  execute: function JST_execute()
+  execute: function JST_execute(aExecuteString)
   {
     // attempt to execute the content of the inputNode
-    var str = this.inputNode.value;
+    var str = aExecuteString || this.inputNode.value;
     if (!str) {
       this.console.log("no value to execute");
       return;
     }
+
+    this.writeOutput(str);
+
     try {
       var result =
       Cu.evalInSandbox(str, this.sandbox, "default", "HUD Console", 1);
-      this.writeOutput(str);
 
       if (result !== undefined) {
         this.writeOutput(result);
       }
     }
     catch (ex) {
       if (ex) {
         this.console.error(ex);
@@ -2231,16 +2233,25 @@ JSTerm.prototype = {
       node.setAttribute("class", "jsterm-output-line");
     }
     var textNode = this.textFactory(aOutputMessage);
     node.appendChild(textNode);
     this.outputNode.appendChild(node);
     node.scrollIntoView(false);
   },
 
+  clearOutput: function JST_clearOutput()
+  {
+    let outputNode = this.outputNode;
+
+    while (outputNode.firstChild) {
+      outputNode.removeChild(outputNode.firstChild);
+    }
+  },
+
   keyDown: function JSTF_keyDown(aEvent)
   {
     var self = this;
     function handleKeyDown(aEvent) {
       // ctrl-a
       var setTimeout = aEvent.target.ownerDocument.defaultView.setTimeout;
       var target = aEvent.target;
       var tmp;
--- a/toolkit/components/console/hudservice/tests/browser/browser_HUDServiceTestsAll.js
+++ b/toolkit/components/console/hudservice/tests/browser/browser_HUDServiceTestsAll.js
@@ -268,16 +268,37 @@ function testNet()
       "Found the loggged network message referencing a js file";
     var errMsg = "Could not get logged network message for js file";
     testLogEntry(outputNode,
                  "Network:", { success: successMsg, err: errMsg });
                  content.location.href = noCacheUriSpec(TEST_NETWORK_URI);
   });
 }
 
+function testOutputOrder()
+{
+  let HUD = HUDService.hudWeakReferences[hudId].get();
+  let jsterm = HUD.jsterm;
+  let outputNode = jsterm.outputNode;
+
+  jsterm.clearOutput();
+  jsterm.execute("console.log('foo', 'bar');");
+
+  is(outputNode.childNodes.length, 2, "Two children in output");
+  let outputChildren = outputNode.childNodes;
+
+  let executedStringFirst =
+    /console\.log\('foo', 'bar'\);/.test(outputChildren[0].childNodes[0].nodeValue);
+
+  let outputSecond =
+    /foo bar/.test(outputChildren[1].childNodes[0].nodeValue);
+
+  ok(executedStringFirst && outputSecond, "executed string comes first");
+}
+
 function testCreateDisplay() {
   ok(typeof cs.consoleDisplays == "object",
      "consoledisplays exist");
   ok(typeof cs.displayIndexes == "object",
      "console indexes exist");
   cs.createDisplay("foo");
   ok(typeof cs.consoleDisplays["foo"] == "object",
      "foo display exists");
@@ -447,16 +468,17 @@ function test() {
       testNet();
 
       // ConsoleStorageTests
       testCreateDisplay();
       testRecordEntry();
       testRecordManyEntries();
       testIteration();
       testConsoleHistory();
+      testOutputOrder();
 
       // testUnregister();
       executeSoon(function () {
         HUDService.deactivateHUDForContext(tab);
         HUDService.shutdown();
       });
       finish();
     });