Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Unified Diff: test/mjsunit/harmony/array-concat.js

Issue 799853003: Use proper ToLength() operation in %ArrayConcat() (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Try ToUint32 before calling JS ToLength() Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/runtime/runtime-array.cc ('K') | « src/runtime/runtime-array.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/array-concat.js
diff --git a/test/mjsunit/harmony/array-concat.js b/test/mjsunit/harmony/array-concat.js
index 738c81a45753d44653f0e0e6aabf6c4fbde4e4d0..57ae048e2d81c030b61fae423a1765df08420305 100644
--- a/test/mjsunit/harmony/array-concat.js
+++ b/test/mjsunit/harmony/array-concat.js
@@ -40,6 +40,57 @@
})();
+(function testConcatArrayLikeStringLength() {
+ "use strict";
+ var obj = {
+ "length": "6",
+ "1": "A",
+ "3": "B",
+ "5": "C"
+ };
+ obj[Symbol.isConcatSpreadable] = true;
+ var obj2 = { length: 3, "0": "0", "1": "1", "2": "2" };
+ var arr = ["X", "Y", "Z"];
+ assertEquals([void 0, "A", void 0, "B", void 0, "C",
+ { "length": 3, "0": "0", "1": "1", "2": "2" },
+ "X", "Y", "Z"], Array.prototype.concat.call(obj, obj2, arr));
+})();
+
+
+(function testConcatArrayLikeNegativeLength() {
+ "use strict";
+ var obj = {
+ "length": -6,
+ "1": "A",
+ "3": "B",
+ "5": "C"
+ };
+ obj[Symbol.isConcatSpreadable] = true;
+ assertEquals([], [].concat(obj));
+ obj.length = -6.7;
+ assertEquals([], [].concat(obj));
+ obj.length = "-6";
+ assertEquals([], [].concat(obj));
+})();
+
+
+(function testConcatArrayLikeToLengthThrows() {
+ "use strict";
+ var obj = {
+ "length": {valueOf: null, toString: null},
Dmitry Lomov (no reviews) 2014/12/15 07:23:51 Add a test where `toString` and `valueOf` throw an
caitp (gmail) 2014/12/15 18:15:29 Done
+ "1": "A",
+ "3": "B",
+ "5": "C"
+ };
+ obj[Symbol.isConcatSpreadable] = true;
+ var obj2 = { length: 3, "0": "0", "1": "1", "2": "2" };
+ var arr = ["X", "Y", "Z"];
+ assertThrows(function() {
+ Array.prototype.concat.call(obj, obj2, arr);
+ }, TypeError);
+})();
+
+
(function testConcatHoleyArray() {
"use strict";
var arr = [];
« src/runtime/runtime-array.cc ('K') | « src/runtime/runtime-array.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698