summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/array-concat-spreadable.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/jit-test/tests/basic/array-concat-spreadable.js')
-rw-r--r--js/src/jit-test/tests/basic/array-concat-spreadable.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/basic/array-concat-spreadable.js b/js/src/jit-test/tests/basic/array-concat-spreadable.js
new file mode 100644
index 0000000000..5a8bd496d5
--- /dev/null
+++ b/js/src/jit-test/tests/basic/array-concat-spreadable.js
@@ -0,0 +1,33 @@
+function testConcat(o1, o2, len, json) {
+ let res = Array.prototype.concat.call(o1, o2);
+ assertEq(res.length, len);
+ assertEq(JSON.stringify(res), json);
+}
+
+const o1 = {[Symbol.isConcatSpreadable]: true, length: 2, 0: 4, 1: 5, 2: 6};
+const o2 = {[Symbol.isConcatSpreadable]: true, length: 2, 0: 4, 2: 6};
+
+testConcat([1, 2, 3], o1, 5, "[1,2,3,4,5]");
+testConcat([1, 2, 3], o2, 5, "[1,2,3,4,null]");
+
+testConcat(o1, [1, 2, 3], 5, "[4,5,1,2,3]");
+testConcat(o2, [1, 2, 3], 5, "[4,null,1,2,3]");
+
+testConcat(o1, o1, 4, "[4,5,4,5]");
+testConcat(o2, o2, 4, "[4,null,4,null]");
+
+testConcat(o1, o2, 4, "[4,5,4,null]");
+testConcat(o2, o1, 4, "[4,null,4,5]");
+
+o1[Symbol.isConcatSpreadable] = false;
+
+testConcat(o1, o2, 3, '[{"0":4,"1":5,"2":6,"length":2},4,null]');
+testConcat(o2, o1, 3, '[4,null,{"0":4,"1":5,"2":6,"length":2}]');
+
+const ta = new Int32Array([4, 5, 6]);
+testConcat([1, 2, 3], ta, 4, '[1,2,3,{"0":4,"1":5,"2":6}]');
+testConcat(ta, ta, 2, '[{"0":4,"1":5,"2":6},{"0":4,"1":5,"2":6}]');
+
+ta[Symbol.isConcatSpreadable] = true;
+testConcat([1, 2, 3], ta, 6, "[1,2,3,4,5,6]");
+testConcat(ta, ta, 6, "[4,5,6,4,5,6]");