Bug 1062490 - Array indexes in console.table() are sorted lexicographically. r=harth, a=lmandel
authorGabriel Luong <gabriel.luong@gmail.com>
Thu, 04 Sep 2014 09:45:00 +0200
changeset 224842 41e56fdebf65461747a18511899bbfe371d1da76
parent 224841 99043f498353e2b8c92aa458c46a9fc036829e6c
child 224843 b339d53f95f289b2d0a9197c95d3535e218a233f
push id3979
push userraliiev@mozilla.com
push dateMon, 13 Oct 2014 16:35:44 +0000
treeherdermozilla-beta@30f2cc610691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersharth, lmandel
bugs1062490
milestone34.0a2
Bug 1062490 - Array indexes in console.table() are sorted lexicographically. r=harth, a=lmandel
browser/devtools/shared/widgets/TableWidget.js
browser/devtools/webconsole/console-output.js
browser/devtools/webconsole/test/browser_webconsole_output_table.js
--- a/browser/devtools/shared/widgets/TableWidget.js
+++ b/browser/devtools/shared/widgets/TableWidget.js
@@ -588,17 +588,17 @@ Column.prototype = {
     this.items = null;
     this.selectedRow = null;
   },
 
   /**
    * Selects the row at the `index` index
    */
   selectRowAt: function(index) {
-    if (this.selectedRow) {
+    if (this.selectedRow != null) {
       this.cells[this.items[this.selectedRow]].toggleClass("theme-selected");
     }
     if (index < 0) {
       this.selectedRow = null;
       return;
     }
     let cell = this.cells[index];
     cell.toggleClass("theme-selected");
@@ -925,17 +925,17 @@ Cell.prototype = {
   },
 
   get id() {
     return this._id;
   },
 
   set value(value) {
     this._value = value;
-    if (!value) {
+    if (value == null) {
       this.label.setAttribute("value", "");
       return;
     }
 
     if (!(value instanceof Ci.nsIDOMNode) &&
         value.length > MAX_VISIBLE_STRING_SIZE) {
       value = value .substr(0, MAX_VISIBLE_STRING_SIZE) + "\u2026"; // …
     }
--- a/browser/devtools/webconsole/console-output.js
+++ b/browser/devtools/webconsole/console-output.js
@@ -1780,16 +1780,22 @@ Messages.ConsoleTable.prototype = Herita
           if (data.class == "Array" && index == "length") {
             continue;
           }
 
           if (!hasColumnsArg) {
             this._columns["_index"] = l10n.getStr("table.index");
           }
 
+          if (data.class == "Array") {
+            if (index == parseInt(index)) {
+              index = parseInt(index);
+            }
+          }
+
           let property = ownProperties[index].value;
           let item = { _index: index };
 
           if (property.class == "Object" || property.class == "Array") {
             let {preview} = property;
             let entries = property.class == "Object" ?
                 preview.ownProperties : preview.items;
 
@@ -1827,20 +1833,19 @@ Messages.ConsoleTable.prototype = Herita
 
       if (!hasColumnsArg) {
         this._columns["_index"] = l10n.getStr("table.iterationIndex");
         this._columns["_key"] = l10n.getStr("table.key");
         this._columns["_value"] = l10n.getStr("table.value");
       }
 
       let rowCount = 0;
-      for (let index of Object.keys(entries || {})) {
-        let [key, value] = entries[index];
+      for (let [key, value] of entries) {
         let item = {
-          _index: index,
+          _index: rowCount,
           _key: this._renderValueGrip(key, { concise: true }),
           _value: this._renderValueGrip(value, { concise: true })
         };
 
         this._data.push(item);
 
         if (++rowCount == TABLE_ROW_MAX_ITEMS) {
           break;
@@ -1852,21 +1857,20 @@ Messages.ConsoleTable.prototype = Herita
       let entries = data.preview.items;
 
       if (!hasColumnsArg) {
         this._columns["_index"] = l10n.getStr("table.iterationIndex");
         this._columns["_value"] = l10n.getStr("table.value");
       }
 
       let rowCount = 0;
-      for (let index of Object.keys(entries || {})) {
-        let value = entries[index];
+      for (let entry of entries) {
         let item = {
-          _index : index,
-          _value: this._renderValueGrip(value, { concise: true })
+          _index : rowCount,
+          _value: this._renderValueGrip(entry, { concise: true })
         };
 
         this._data.push(item);
 
         if (++rowCount == TABLE_ROW_MAX_ITEMS) {
           break;
         }
       }
--- a/browser/devtools/webconsole/test/browser_webconsole_output_table.js
+++ b/browser/devtools/webconsole/test/browser_webconsole_output_table.js
@@ -7,53 +7,53 @@
  "use strict";
 
 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console-table.html";
 
 const TEST_DATA = [
   {
     command: "console.table(languages1)",
     data: [
-        { _index: "0", name: "\"JavaScript\"", fileExtension: "Array[1]" },
-        { _index: "1", name: "Object", fileExtension: "\".ts\"" },
-        { _index: "2", name: "\"CoffeeScript\"", fileExtension: "\".coffee\"" }
+        { _index: 0, name: "\"JavaScript\"", fileExtension: "Array[1]" },
+        { _index: 1, name: "Object", fileExtension: "\".ts\"" },
+        { _index: 2, name: "\"CoffeeScript\"", fileExtension: "\".coffee\"" }
     ],
     columns: { _index: "(index)", name: "name", fileExtension: "fileExtension" }
   },
   {
     command: "console.table(languages1, 'name')",
     data: [
-        { _index: "0", name: "\"JavaScript\"", fileExtension: "Array[1]" },
-        { _index: "1", name: "Object", fileExtension: "\".ts\"" },
-        { _index: "2", name: "\"CoffeeScript\"", fileExtension: "\".coffee\"" }
+        { _index: 0, name: "\"JavaScript\"", fileExtension: "Array[1]" },
+        { _index: 1, name: "Object", fileExtension: "\".ts\"" },
+        { _index: 2, name: "\"CoffeeScript\"", fileExtension: "\".coffee\"" }
     ],
     columns: { _index: "(index)", name: "name" }
   },
   {
     command: "console.table(languages1, ['name'])",
     data: [
-        { _index: "0", name: "\"JavaScript\"", fileExtension: "Array[1]" },
-        { _index: "1", name: "Object", fileExtension: "\".ts\"" },
-        { _index: "2", name: "\"CoffeeScript\"", fileExtension: "\".coffee\"" }
+        { _index: 0, name: "\"JavaScript\"", fileExtension: "Array[1]" },
+        { _index: 1, name: "Object", fileExtension: "\".ts\"" },
+        { _index: 2, name: "\"CoffeeScript\"", fileExtension: "\".coffee\"" }
     ],
     columns: { _index: "(index)", name: "name" }
   },
   {
     command: "console.table(languages2)",
     data: [
       { _index: "csharp", name: "\"C#\"", paradigm: "\"object-oriented\"" },
       { _index: "fsharp", name: "\"F#\"", paradigm: "\"functional\"" }
     ],
     columns: { _index: "(index)", name: "name", paradigm: "paradigm" }
   },
   {
     command: "console.table([[1, 2], [3, 4]])",
     data: [
-      { _index: "0", 0: "1", 1: "2" },
-      { _index: "1", 0: "3", 1: "4" }
+      { _index: 0, 0: "1", 1: "2" },
+      { _index: 1, 0: "3", 1: "4" }
     ],
     columns: { _index: "(index)", 0: "0", 1: "1" }
   },
   {
     command: "console.table({a: [1, 2], b: [3, 4]})",
     data: [
       { _index: "a", 0: "1", 1: "2" },
       { _index: "b", 0: "3", 1: "4" }
@@ -88,29 +88,29 @@ const TEST_DATA = [
       { _index: "daughter", firstName: "\"Lily\"", lastName: "\"Doyle\"", age: "5" },
       { _index: "son", firstName: "\"Mike\"", lastName: "\"Doyle\"", age: "8" },
     ],
     columns: { _index: "(index)", firstName: "firstName", lastName: "lastName" }
   },
   {
     command: "console.table(mySet)",
     data: [
-      { _index: "0", _value: "1" },
-      { _index: "1", _value: "5" },
-      { _index: "2", _value: "\"some text\"" },
-      { _index: "3", _value: "null" },
-      { _index: "4", _value: "undefined" }
+      { _index: 0, _value: "1" },
+      { _index: 1, _value: "5" },
+      { _index: 2, _value: "\"some text\"" },
+      { _index: 3, _value: "null" },
+      { _index: 4, _value: "undefined" }
     ],
     columns: { _index: "(iteration index)", _value: "Values" }
   },
   {
     command: "console.table(myMap)",
     data: [
-      { _index: "0", _key: "\"a string\"", _value: "\"value associated with 'a string'\"" },
-      { _index: "1", _key: "5", _value: "\"value associated with 5\"" },
+      { _index: 0, _key: "\"a string\"", _value: "\"value associated with 'a string'\"" },
+      { _index: 1, _key: "5", _value: "\"value associated with 5\"" },
     ],
     columns: { _index: "(iteration index)", _key: "Key", _value: "Values" }
   }
 ];
 
 let test = asyncTest(function*() {
   const {tab} = yield loadTab(TEST_URI);
   let hud = yield openConsole(tab);