Bug 1041586 - Tests. r=arai
☠☠ backed out by 533daf1ab8c9 ☠ ☠
authorTom Schuster <evilpies@gmail.com>
Sat, 16 Apr 2016 12:22:18 +0200
changeset 317306 35b1a010cb9fe88ee4975e7c7e6291096bd4a748
parent 317305 2021fd52a8c9e4c19282b8dfd92f60974c9fd52e
child 317307 037893f93079315cf4dfaac7e6ae6691876abcc6
push id9480
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 17:12:58 +0000
treeherdermozilla-aurora@0d6a91c76a9e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarai
bugs1041586
milestone48.0a1
Bug 1041586 - Tests. r=arai
js/src/tests/ecma_6/Array/concat-spreadable-basic.js
js/src/tests/ecma_6/Array/concat-spreadable-primitive.js
js/src/tests/ecma_6/Array/species.js
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/Array/concat-spreadable-basic.js
@@ -0,0 +1,37 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/ */
+"use strict";
+
+const x = Object.freeze([1, 2, 3]);
+
+let fakeArray = {
+    [Symbol.isConcatSpreadable]: true,
+    length: 2,
+    0: "hello",
+    1: "world"
+}
+assertDeepEq(x.concat(fakeArray), [1, 2, 3, "hello", "world"]);
+assertDeepEq(x.concat(fakeArray, fakeArray), [1, 2, 3, "hello", "world", "hello", "world"]);
+
+for (let truthy of [true, 3.41, "abc", Symbol(), {}]) {
+    let obj = {[Symbol.isConcatSpreadable]: truthy, length: 1, 0: "hey"}
+    assertDeepEq(x.concat(obj), [1, 2, 3, "hey"]);
+}
+
+for (let notTruthy of [null, undefined, false, 0, NaN, ""]) {
+    let obj = {[Symbol.isConcatSpreadable]: notTruthy, length: 1, 0: "hey"}
+    assertDeepEq(x.concat(obj), [1, 2, 3, obj]);
+}
+
+let array = [5, 4];
+assertDeepEq(x.concat(array), [1, 2, 3, 5, 4]);
+
+// Can make arrays non-spreadable
+array[Symbol.isConcatSpreadable] = false;
+assertDeepEq(x.concat(array), [1, 2, 3, [5, 4]]);
+
+// Explicitly spreadable
+array[Symbol.isConcatSpreadable] = true;
+assertDeepEq(x.concat(array), [1, 2, 3, 5, 4]);
+
+reportCompare(true, true);
new file mode 100644
--- /dev/null
+++ b/js/src/tests/ecma_6/Array/concat-spreadable-primitive.js
@@ -0,0 +1,34 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/ */
+"use strict";
+
+// Primitive values should never be tried to spread
+let primitives = [
+    10,
+    false,
+    Symbol()
+    // Can't change String.prototype.length
+];
+
+for (let value of primitives) {
+    let prototype = Object.getPrototypeOf(value);
+    prototype[Symbol.isConcatSpreadable] = true;
+
+    Object.defineProperty(prototype, "length", {
+        configurable: true,
+        get() {
+            // Should never invoke length getter
+            assertEq(true, false);
+        },
+    });
+
+    let x = [1, 2].concat(value);
+    assertDeepEq(x, [1, 2, value]);
+
+    delete prototype[Symbol.isConcatSpreadable];
+    delete prototype.length;
+
+    prototype.length;
+}
+
+reportCompare(true, true);
--- a/js/src/tests/ecma_6/Array/species.js
+++ b/js/src/tests/ecma_6/Array/species.js
@@ -167,16 +167,16 @@ class ${funcName}Class2 extends Array {
   }
 }
 a = new ${funcName}Class2(1, 2, 3, 4, 5);
 b = a[funcName](...args);
 assertEq(b.constructor, Date);
 `);
 }
 
-test("concat", [], 0, "get:concat,get:constructor,c-get:Symbol(Symbol.species),get:length,get:0,define:0:1:true:true:true,get:1,define:1:2:true:true:true,get:2,define:2:3:true:true:true,get:3,define:3:4:true:true:true,get:4,define:4:5:true:true:true,set:length:5,");
+test("concat", [], 0, "get:concat,get:constructor,c-get:Symbol(Symbol.species),get:Symbol(Symbol.isConcatSpreadable),get:length,get:0,define:0:1:true:true:true,get:1,define:1:2:true:true:true,get:2,define:2:3:true:true:true,get:3,define:3:4:true:true:true,get:4,define:4:5:true:true:true,set:length:5,");
 test("filter", [x => x % 2], 0, "get:filter,get:length,get:constructor,c-get:Symbol(Symbol.species),get:0,define:0:1:true:true:true,get:1,get:2,define:1:3:true:true:true,get:3,get:4,define:2:5:true:true:true,");
 test("map", [x => x * 2], 5, "get:map,get:length,get:constructor,c-get:Symbol(Symbol.species),get:0,define:0:2:true:true:true,get:1,define:1:4:true:true:true,get:2,define:2:6:true:true:true,get:3,define:3:8:true:true:true,get:4,define:4:10:true:true:true,");
 test("slice", [], 5, "get:slice,get:length,get:constructor,c-get:Symbol(Symbol.species),get:0,define:0:1:true:true:true,get:1,define:1:2:true:true:true,get:2,define:2:3:true:true:true,get:3,define:3:4:true:true:true,get:4,define:4:5:true:true:true,set:length:5,");
 test("splice", [0, 5], 5, "get:splice,get:length,get:constructor,c-get:Symbol(Symbol.species),get:0,define:0:1:true:true:true,get:1,define:1:2:true:true:true,get:2,define:2:3:true:true:true,get:3,define:3:4:true:true:true,get:4,define:4:5:true:true:true,set:length:5,");
 
 if (typeof reportCompare === "function")
   reportCompare(true, true);