[gnome-shell] modalDialog: Don't use a for...in loop for iterating over arrays.



commit 4352cc231eb6b85f2edad24c09622094137fca2e
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Sun Sep 18 20:40:21 2011 -0400

    modalDialog: Don't use a for...in loop for iterating over arrays.
    
    for...in loops do not guarantee that the indexes iterate in order. As a
    consequence, buttons may appear in an undesired order.

 js/ui/modalDialog.js |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
---
diff --git a/js/ui/modalDialog.js b/js/ui/modalDialog.js
index 49f086b..8061587 100644
--- a/js/ui/modalDialog.js
+++ b/js/ui/modalDialog.js
@@ -110,9 +110,8 @@ ModalDialog.prototype = {
         this._buttonLayout.destroy_children();
         this._actionKeys = {};
 
-        let i = 0;
-        for (let index in buttons) {
-            let buttonInfo = buttons[index];
+        for (let i = 0; i < buttons.length; i ++) {
+            let buttonInfo = buttons[i];
             let label = buttonInfo['label'];
             let action = buttonInfo['action'];
             let key = buttonInfo['key'];
@@ -144,11 +143,10 @@ ModalDialog.prototype = {
 
             if (key)
                 this._actionKeys[key] = action;
-            i++;
         }
 
         // Fade in buttons if there weren't any before
-        if (!hadChildren && i > 0) {
+        if (!hadChildren && buttons.length > 0) {
             this._buttonLayout.opacity = 0;
             Tweener.addTween(this._buttonLayout,
                              { opacity: 255,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]