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

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: Tests for toString/valueOf throwing user exception 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
« no previous file with comments | « 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..d39998d07f6b4b615eabdfef78ddc2c9d1c1f98b 100644
--- a/test/mjsunit/harmony/array-concat.js
+++ b/test/mjsunit/harmony/array-concat.js
@@ -40,6 +40,110 @@
})();
+(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},
+ "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 testConcatArrayLikePrimitiveNonNumberLength() {
+ "use strict";
+ var obj = {
+ "1": "A",
+ "3": "B",
+ "5": "C"
+ };
+ obj[Symbol.isConcatSpreadable] = true;
+ obj.length = {toString: function() { return "SIX"; }, valueOf: null };
+ assertEquals([], [].concat(obj));
+ obj.length = {toString: null, valueOf: function() { return "SIX"; } };
+ assertEquals([], [].concat(obj));
+})();
+
+
+(function testConcatArrayLikeLengthToStringThrows() {
+ "use strict";
+ function MyError() {}
+ var obj = {
+ "length": { toString: function() {
+ throw new MyError();
+ }, valueOf: null
+ },
+ "1": "A",
+ "3": "B",
+ "5": "C"
+ };
+ obj[Symbol.isConcatSpreadable] = true;
+ assertThrows(function() {
+ [].concat(obj);
+ }, MyError);
+})();
+
+
+(function testConcatArrayLikeLengthValueOfThrows() {
+ "use strict";
+ function MyError() {}
+ var obj = {
+ "length": { valueOf: function() {
+ throw new MyError();
+ }, toString: null
+ },
+ "1": "A",
+ "3": "B",
+ "5": "C"
+};
+obj[Symbol.isConcatSpreadable] = true;
+assertThrows(function() {
+ [].concat(obj);
+}, MyError);
+})();
+
+
(function testConcatHoleyArray() {
"use strict";
var arr = [];
« no previous file with comments | « src/runtime/runtime-array.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698