Bug 1165052 - Part 9: Use ArraySpeciesCreate in Array.prototype.filter. r=efaust
☠☠ backed out by 8e3a42336a37 ☠ ☠
authorTooru Fujisawa <arai_a@mac.com>
Fri, 07 Aug 2015 08:02:14 +0900
changeset 290614 e49d0dfcaa5c7415c94b830e11dda40700522011
parent 290613 0c725d3463f112ca08e0c0a05537a6077a915723
child 290615 5d13efb13fec2a7843d65c27c9862bd5e51c457d
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersefaust
bugs1165052
milestone48.0a1
Bug 1165052 - Part 9: Use ArraySpeciesCreate in Array.prototype.filter. r=efaust
js/src/builtin/Array.js
--- a/js/src/builtin/Array.js
+++ b/js/src/builtin/Array.js
@@ -304,52 +304,52 @@ function ArrayStaticMap(list, callbackfn
     if (arguments.length < 2)
         ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'Array.map');
     if (!IsCallable(callbackfn))
         ThrowTypeError(JSMSG_NOT_FUNCTION, DecompileArg(1, callbackfn));
     var T = arguments.length > 2 ? arguments[2] : void 0;
     return callFunction(ArrayMap, list, callbackfn, T);
 }
 
-/* ES2015 22.1.3.7 Array.prototype.filter. */
+/* ES 2016 draft Mar 25, 2016 22.1.3.7 Array.prototype.filter. */
 function ArrayFilter(callbackfn/*, thisArg*/) {
-    /* Steps 1-2. */
+    /* Step 1. */
     var O = ToObject(this);
 
-    /* Steps 3-4. */
+    /* Step 2. */
     var len = ToInteger(O.length);
 
-    /* Step 5. */
+    /* Step 3. */
     if (arguments.length === 0)
         ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'Array.prototype.filter');
     if (!IsCallable(callbackfn))
         ThrowTypeError(JSMSG_NOT_FUNCTION, DecompileArg(0, callbackfn));
 
-    /* Step 6. */
+    /* Step 4. */
     var T = arguments.length > 1 ? arguments[1] : void 0;
 
-    /* Step 7. */
-    var A = [];
+    /* Step 5. */
+    var A = ArraySpeciesCreate(O, 0);
 
-    /* Steps 8-11. */
-    /* Steps 11.a (implicit), and 11.e. */
+    /* Steps 6-8. */
+    /* Steps 8.a (implicit), and 8.d. */
     for (var k = 0, to = 0; k < len; k++) {
-        /* Steps 11.b-c. */
+        /* Steps 8.b-c. */
         if (k in O) {
-            /* Steps 11.c.i-ii. */
+            /* Step 8.c.i. */
             var kValue = O[k];
-            /* Steps 11.c.iii-iv. */
+            /* Step 8.c.ii. */
             var selected = callContentFunction(callbackfn, T, kValue, k, O);
-            /* Step 11.c.v. */
+            /* Step 8.c.iii. */
             if (selected)
                 _DefineDataProperty(A, to++, kValue);
         }
     }
 
-    /* Step 12. */
+    /* Step 9. */
     return A;
 }
 
 function ArrayStaticFilter(list, callbackfn/*, thisArg*/) {
     if (arguments.length < 2)
         ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'Array.filter');
     if (!IsCallable(callbackfn))
         ThrowTypeError(JSMSG_NOT_FUNCTION, DecompileArg(1, callbackfn));