Bug 580814 - Avoid accessing rows that don't exist in treeviews for Places. r=mak
authorOHZEKI Tetsuharu <saneyuki.s.snyk@gmail.com>
Sun, 04 Mar 2012 12:36:14 -0500
changeset 88424 058ac6b6930be019d8605512b387ac907d56f82a
parent 88423 ab7ed8a7a885178298f104969c35d30967f519c1
child 88425 433cfbd2a0da3f9cc7c1391f95a28404966c6466
child 88431 a108aee4f00d7a6bbc427f3bd3f317cb53ac121e
push id157
push userMs2ger@gmail.com
push dateWed, 07 Mar 2012 19:27:10 +0000
reviewersmak
bugs580814
milestone13.0a1
Bug 580814 - Avoid accessing rows that don't exist in treeviews for Places. r=mak
browser/components/places/content/treeView.js
--- a/browser/components/places/content/treeView.js
+++ b/browser/components/places/content/treeView.js
@@ -193,30 +193,35 @@ PlacesTreeView.prototype = {
   /**
    * Given a row, finds and returns the parent details of the associated node.
    *
    * @param aChildRow
    *        Row number.
    * @return [parentNode, parentRow]
    */
   _getParentByChildRow: function PTV__getParentByChildRow(aChildRow) {
-    let parent = this._getNodeForRow(aChildRow).parent;
+    let node = this._getNodeForRow(aChildRow);
+    let parent = (node === null) ? this._rootNode : node.parent;
 
     // The root node is never visible
     if (parent == this._rootNode)
       return [this._rootNode, -1];
 
     let parentRow = this._rows.lastIndexOf(parent, aChildRow - 1);
     return [parent, parentRow];
   },
 
   /**
    * Gets the node at a given row.
    */
   _getNodeForRow: function PTV__getNodeForRow(aRow) {
+    if (aRow < 0) {
+      return null;
+    }
+  
     let node = this._rows[aRow];
     if (node !== undefined)
       return node;
 
     // Find the nearest node.
     let rowNode, row;
     for (let i = aRow - 1; i >= 0 && rowNode === undefined; i--) {
       rowNode = this._rows[i];