Bug 1248717 - Don't initialize variables in a for head with var, then use them later. r=jorendorff
authorMorgan Phillips <winter2718@gmail.com>
Tue, 16 Feb 2016 14:25:24 -0600
changeset 331403 b725dddce40eb603d9801a59cb9736ad5a2db751
parent 331402 37a288bd14768f6b960874b61322224b3f926e02
child 331404 58b7b92c3ad92a3bb9a59df7d944eb43a7ee0f9a
push id10977
push usercykesiopka.bmo@gmail.com
push dateWed, 17 Feb 2016 01:27:23 +0000
reviewersjorendorff
bugs1248717
milestone47.0a1
Bug 1248717 - Don't initialize variables in a for head with var, then use them later. r=jorendorff
js/src/builtin/Sorting.js
--- a/js/src/builtin/Sorting.js
+++ b/js/src/builtin/Sorting.js
@@ -40,20 +40,20 @@ function CountingSort(array, len, signed
             }
         }
     }
     return array;
 }
 
 // For sorting small arrays.
 function InsertionSort(array, from, to, comparefn) {
-    var item, swap;
-    for (var i = from + 1; i <= to; i++) {
+    let item, swap, i, j;
+    for (i = from + 1; i <= to; i++) {
         item = array[i];
-        for (var j = i - 1; j >= from; j--) {
+        for (j = i - 1; j >= from; j--) {
             swap = array[j];
             if (comparefn(swap, item) <= 0)
                 break;
             array[j + 1] = swap;
         }
         array[j + 1] = item;
     }
 }