Bug 911578 - Backout of invalid packed array optimizations for array extras that can turn packed arrays into non-packed ones. r=me
authorTill Schneidereit <till@tillschneidereit.net>
Sat, 30 Nov 2013 14:16:13 +0100
changeset 158157 9439760a61966ef34abab7c0709b3e547a636683
parent 158156 fe97252f9c2032d387802d69918642414049e623
child 158158 0b5a8fd704adbdd763c191e713a54d5a38e239fa
push id25737
push usercbook@mozilla.com
push dateMon, 02 Dec 2013 11:42:38 +0000
treeherdermozilla-central@5b9a4d273114 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs911578
milestone28.0a1
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 911578 - Backout of invalid packed array optimizations for array extras that can turn packed arrays into non-packed ones. r=me
js/src/builtin/Array.js
--- a/js/src/builtin/Array.js
+++ b/js/src/builtin/Array.js
@@ -127,32 +127,23 @@ function ArrayEvery(callbackfn/*, thisAr
     if (!IsCallable(callbackfn))
         ThrowError(JSMSG_NOT_FUNCTION, DecompileArg(0, callbackfn));
 
     /* Step 5. */
     var T = arguments.length > 1 ? arguments[1] : void 0;
 
     /* Steps 6-7. */
     /* Steps a (implicit), and d. */
-    if (IsPackedArray(O)) {
-        for (var k = 0; k < len; k++) {
-            /* Step b (omitted). */
+    for (var k = 0; k < len; k++) {
+        /* Step b */
+        if (k in O) {
             /* Step c. */
             if (!callFunction(callbackfn, T, O[k], k, O))
                 return false;
         }
-    } else {
-        for (var k = 0; k < len; k++) {
-            /* Step b. */
-            if (k in O) {
-                /* Step c. */
-                if (!callFunction(callbackfn, T, O[k], k, O))
-                    return false;
-            }
-        }
     }
 
     /* Step 8. */
     return true;
 }
 
 function ArrayStaticEvery(list, callbackfn/*, thisArg*/) {
     if (arguments.length < 2)
@@ -177,32 +168,23 @@ function ArraySome(callbackfn/*, thisArg
     if (!IsCallable(callbackfn))
         ThrowError(JSMSG_NOT_FUNCTION, DecompileArg(0, callbackfn));
 
     /* Step 5. */
     var T = arguments.length > 1 ? arguments[1] : void 0;
 
     /* Steps 6-7. */
     /* Steps a (implicit), and d. */
-    if (IsPackedArray(O)) {
-        for (var k = 0; k < len; k++) {
-            /* Step b (omitted). */
+    for (var k = 0; k < len; k++) {
+        /* Step b */
+        if (k in O) {
             /* Step c. */
             if (callFunction(callbackfn, T, O[k], k, O))
                 return true;
         }
-    } else {
-        for (var k = 0; k < len; k++) {
-            /* Step b */
-            if (k in O) {
-                /* Step c. */
-                if (callFunction(callbackfn, T, O[k], k, O))
-                    return true;
-            }
-        }
     }
 
     /* Step 8. */
     return false;
 }
 
 function ArrayStaticSome(list, callbackfn/*, thisArg*/) {
     if (arguments.length < 2)
@@ -227,30 +209,22 @@ function ArrayForEach(callbackfn/*, this
     if (!IsCallable(callbackfn))
         ThrowError(JSMSG_NOT_FUNCTION, DecompileArg(0, callbackfn));
 
     /* Step 5. */
     var T = arguments.length > 1 ? arguments[1] : void 0;
 
     /* Steps 6-7. */
     /* Steps a (implicit), and d. */
-    if (IsPackedArray(O)) {
-        for (var k = 0; k < len; k++) {
-            /* Step b (omitted). */
+    for (var k = 0; k < len; k++) {
+        /* Step b */
+        if (k in O) {
             /* Step c. */
             callFunction(callbackfn, T, O[k], k, O);
         }
-    } else {
-        for (var k = 0; k < len; k++) {
-            /* Step b. */
-            if (k in O) {
-                /* Step c. */
-                callFunction(callbackfn, T, O[k], k, O);
-            }
-        }
     }
 
     /* Step 8. */
     return void 0;
 }
 
 /* ES5 15.4.4.19. */
 function ArrayMap(callbackfn/*, thisArg*/) {
@@ -269,34 +243,24 @@ function ArrayMap(callbackfn/*, thisArg*
     /* Step 5. */
     var T = arguments.length > 1 ? arguments[1] : void 0;
 
     /* Step 6. */
     var A = NewDenseArray(len);
 
     /* Step 7-8. */
     /* Step a (implicit), and d. */
-    if (IsPackedArray(O)) {
-        for (var k = 0; k < len; k++) {
-            /* Step b (omitted). */
+    for (var k = 0; k < len; k++) {
+        /* Step b */
+        if (k in O) {
             /* Step c.i-iii. */
             var mappedValue = callFunction(callbackfn, T, O[k], k, O);
             // UnsafePutElements doesn't invoke setters, so we can use it here.
             UnsafePutElements(A, k, mappedValue);
         }
-    } else {
-        for (var k = 0; k < len; k++) {
-            /* Step b. */
-            if (k in O) {
-                /* Step c.i-iii. */
-                var mappedValue = callFunction(callbackfn, T, O[k], k, O);
-                // UnsafePutElements doesn't invoke setters, so we can use it here.
-                UnsafePutElements(A, k, mappedValue);
-            }
-        }
     }
 
     /* Step 9. */
     return A;
 }
 
 function ArrayStaticMap(list, callbackfn/*, thisArg*/) {
     if (arguments.length < 2)
@@ -328,27 +292,25 @@ function ArrayReduce(callbackfn/*, initi
     if (arguments.length === 0)
         ThrowError(JSMSG_MISSING_FUN_ARG, 0, 'Array.prototype.reduce');
     if (!IsCallable(callbackfn))
         ThrowError(JSMSG_NOT_FUNCTION, DecompileArg(0, callbackfn));
 
     /* Step 6. */
     var k = 0;
 
-    var isPacked = IsPackedArray(O);
-
     /* Steps 5, 7-8. */
     var accumulator;
     if (arguments.length > 1) {
         accumulator = arguments[1];
     } else {
         /* Step 5. */
         if (len === 0)
             ThrowError(JSMSG_EMPTY_ARRAY_REDUCE);
-        if (isPacked) {
+        if (IsPackedArray(O)) {
             accumulator = O[k++];
         } else {
             var kPresent = false;
             for (; k < len; k++) {
                 if (k in O) {
                     accumulator = O[k];
                     kPresent = true;
                     k++;
@@ -357,30 +319,22 @@ function ArrayReduce(callbackfn/*, initi
             }
             if (!kPresent)
               ThrowError(JSMSG_EMPTY_ARRAY_REDUCE);
         }
     }
 
     /* Step 9. */
     /* Steps a (implicit), and d. */
-    if (isPacked) {
-        for (; k < len; k++) {
-            /* Step b (omitted). */
+    for (; k < len; k++) {
+        /* Step b */
+        if (k in O) {
             /* Step c. */
             accumulator = callbackfn(accumulator, O[k], k, O);
         }
-    } else {
-        for (; k < len; k++) {
-            /* Step b. */
-            if (k in O) {
-                /* Step c. */
-                accumulator = callbackfn(accumulator, O[k], k, O);
-            }
-        }
     }
 
     /* Step 10. */
     return accumulator;
 }
 
 function ArrayStaticReduce(list, callbackfn) {
     if (arguments.length < 2)
@@ -405,27 +359,25 @@ function ArrayReduceRight(callbackfn/*, 
     if (arguments.length === 0)
         ThrowError(JSMSG_MISSING_FUN_ARG, 0, 'Array.prototype.reduce');
     if (!IsCallable(callbackfn))
         ThrowError(JSMSG_NOT_FUNCTION, DecompileArg(0, callbackfn));
 
     /* Step 6. */
     var k = len - 1;
 
-    var isPacked = IsPackedArray(O);
-
     /* Steps 5, 7-8. */
     var accumulator;
     if (arguments.length > 1) {
         accumulator = arguments[1];
     } else {
         /* Step 5. */
         if (len === 0)
             ThrowError(JSMSG_EMPTY_ARRAY_REDUCE);
-        if (isPacked) {
+        if (IsPackedArray(O)) {
             accumulator = O[k--];
         } else {
             var kPresent = false;
             for (; k >= 0; k--) {
                 if (k in O) {
                     accumulator = O[k];
                     kPresent = true;
                     k--;
@@ -434,30 +386,22 @@ function ArrayReduceRight(callbackfn/*, 
             }
             if (!kPresent)
                 ThrowError(JSMSG_EMPTY_ARRAY_REDUCE);
         }
     }
 
     /* Step 9. */
     /* Steps a (implicit), and d. */
-    if (isPacked) {
-        for (; k >= 0; k--) {
-            /* Step b (omitted). */
+    for (; k >= 0; k--) {
+        /* Step b */
+        if (k in O) {
             /* Step c. */
             accumulator = callbackfn(accumulator, O[k], k, O);
         }
-    } else {
-        for (; k >= 0; k--) {
-            /* Step b. */
-            if (k in O) {
-                /* Step c. */
-                accumulator = callbackfn(accumulator, O[k], k, O);
-            }
-        }
     }
 
     /* Step 10. */
     return accumulator;
 }
 
 function ArrayStaticReduceRight(list, callbackfn) {
     if (arguments.length < 2)
@@ -489,35 +433,24 @@ function ArrayFind(predicate/*, thisArg*
 
     /* Steps 8-9. */
     /* Steps a (implicit), and e. */
     /* Note: this will hang in some corner-case situations, because of IEEE-754 numbers'
      * imprecision for large values. Example:
      * var obj = { 18014398509481984: true, length: 18014398509481988 };
      * Array.prototype.find.call(obj, () => true);
      */
-    var k;
-    if (IsPackedArray(O)) {
-        for (k = 0; k < len; k++) {
-            /* Steps b (omitted) and c (implicit). */
+    for (var k = 0; k < len; k++) {
+        /* Steps b and c (implicit) */
+        if (k in O) {
             /* Step d. */
             var kValue = O[k];
             if (callFunction(predicate, T, kValue, k, O))
                 return kValue;
         }
-    } else {
-        for (k = 0; k < len; k++) {
-            /* Steps b and c (implicit). */
-            if (k in O) {
-                /* Step d. */
-                var kValue = O[k];
-                if (callFunction(predicate, T, kValue, k, O))
-                    return kValue;
-            }
-        }
     }
 
     /* Step 10. */
     return undefined;
 }
 
 /* ES6 draft 2013-05-14 15.4.3.23. */
 function ArrayFindIndex(predicate/*, thisArg*/) {
@@ -538,33 +471,23 @@ function ArrayFindIndex(predicate/*, thi
 
     /* Steps 8-9. */
     /* Steps a (implicit), and e. */
     /* Note: this will hang in some corner-case situations, because of IEEE-754 numbers'
      * imprecision for large values. Example:
      * var obj = { 18014398509481984: true, length: 18014398509481988 };
      * Array.prototype.find.call(obj, () => true);
      */
-    var k;
-    if (IsPackedArray(O)) {
-        for (k = 0; k < len; k++) {
-            /* Steps b (omitted) and c (implicit). */
+    for (var k = 0; k < len; k++) {
+        /* Steps b and c (implicit) */
+        if (k in O) {
             /* Step d. */
             if (callFunction(predicate, T, O[k], k, O))
                 return k;
         }
-    } else {
-        for (k = 0; k < len; k++) {
-            /* Steps b and c (implicit). */
-            if (k in O) {
-                /* Step d. */
-                if (callFunction(predicate, T, O[k], k, O))
-                    return k;
-            }
-        }
     }
 
     /* Step 10. */
     return -1;
 }
 
 #define ARRAY_ITERATOR_SLOT_ITERATED_OBJECT 0
 #define ARRAY_ITERATOR_SLOT_NEXT_INDEX 1