Bug 1165052 - Part 6: Implement self-hosted ArraySpeciesCreate. r=efaust
☠☠ backed out by 70de0d01ec44 ☠ ☠
authorTooru Fujisawa <arai_a@mac.com>
Wed, 23 Dec 2015 13:28:38 +0900
changeset 290611 0344adae92f3c3fe026a7c365689343cde287fe1
parent 290610 cb171b15a882723b189e2fefa2a06f27e8f907c5
child 290612 aa59399ae8e09a153b63210b966c6364376c1e0c
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 6: Implement self-hosted ArraySpeciesCreate. r=efaust
js/src/builtin/Array.js
--- a/js/src/builtin/Array.js
+++ b/js/src/builtin/Array.js
@@ -871,16 +871,63 @@ function ArrayToString() {
 }
 
 // ES 2016 draft Mar 25, 2016 22.1.2.5.
 function ArraySpecies() {
     // Step 1.
     return this;
 }
 
+// ES 2016 draft Mar 25, 2016 9.4.2.3.
+function ArraySpeciesCreate(originalArray, length) {
+    // Step 1.
+    assert(typeof length == "number", "length should be a number");
+    assert(length >= 0, "length should be a non-negative number");
+
+    // Step 2.
+    if (length === -0)
+        length = 0;
+
+    // Step 4, 6.
+    if (!IsArray(originalArray))
+        return std_Array(length);
+
+    // Step 5.a.
+    var C = originalArray.constructor;
+
+    // Step 5.b.
+    if (IsConstructor(C) && IsWrappedArrayConstructor(C))
+        return std_Array(length);
+
+    // Step 5.c.
+    if (IsObject(C)) {
+        // Step 5.c.i.
+        C = C[std_species];
+
+        // Optimized path for an ordinary Array.
+        if (C === GetBuiltinConstructor("Array"))
+            return std_Array(length);
+
+        // Step 5.c.ii.
+        if (C === null)
+            return std_Array(length);
+    }
+
+    // Step 6.
+    if (C === undefined)
+        return std_Array(length);
+
+    // Step 7.
+    if (!IsConstructor(C))
+        ThrowTypeError(JSMSG_NOT_CONSTRUCTOR, "constructor property");
+
+    // Step 8.
+    return new C(length);
+}
+
 // ES 2016 draft Mar 25, 2016 22.1.3.1.
 // Note: Array.prototype.concat.length is 1.
 function ArrayConcat(arg1) {
     // Step 1.
     var O = ToObject(this);
 
     // Step 2.
     var A = std_Array(0);