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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/runtime/runtime-array.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Flags: --harmony-arrays --harmony-classes 5 // Flags: --harmony-arrays --harmony-classes
6 6
7 (function testArrayConcatArity() { 7 (function testArrayConcatArity() {
8 "use strict"; 8 "use strict";
9 assertEquals(1, Array.prototype.concat.length); 9 assertEquals(1, Array.prototype.concat.length);
10 })(); 10 })();
(...skipping 22 matching lines...) Expand all
33 }; 33 };
34 obj[Symbol.isConcatSpreadable] = true; 34 obj[Symbol.isConcatSpreadable] = true;
35 var obj2 = { length: 3, "0": "0", "1": "1", "2": "2" }; 35 var obj2 = { length: 3, "0": "0", "1": "1", "2": "2" };
36 var arr = ["X", "Y", "Z"]; 36 var arr = ["X", "Y", "Z"];
37 assertEquals([void 0, "A", void 0, "B", void 0, "C", 37 assertEquals([void 0, "A", void 0, "B", void 0, "C",
38 { "length": 3, "0": "0", "1": "1", "2": "2" }, 38 { "length": 3, "0": "0", "1": "1", "2": "2" },
39 "X", "Y", "Z"], Array.prototype.concat.call(obj, obj2, arr)); 39 "X", "Y", "Z"], Array.prototype.concat.call(obj, obj2, arr));
40 })(); 40 })();
41 41
42 42
43 (function testConcatArrayLikeStringLength() {
44 "use strict";
45 var obj = {
46 "length": "6",
47 "1": "A",
48 "3": "B",
49 "5": "C"
50 };
51 obj[Symbol.isConcatSpreadable] = true;
52 var obj2 = { length: 3, "0": "0", "1": "1", "2": "2" };
53 var arr = ["X", "Y", "Z"];
54 assertEquals([void 0, "A", void 0, "B", void 0, "C",
55 { "length": 3, "0": "0", "1": "1", "2": "2" },
56 "X", "Y", "Z"], Array.prototype.concat.call(obj, obj2, arr));
57 })();
58
59
60 (function testConcatArrayLikeNegativeLength() {
61 "use strict";
62 var obj = {
63 "length": -6,
64 "1": "A",
65 "3": "B",
66 "5": "C"
67 };
68 obj[Symbol.isConcatSpreadable] = true;
69 assertEquals([], [].concat(obj));
70 obj.length = -6.7;
71 assertEquals([], [].concat(obj));
72 obj.length = "-6";
73 assertEquals([], [].concat(obj));
74 })();
75
76
77 (function testConcatArrayLikeToLengthThrows() {
78 "use strict";
79 var obj = {
80 "length": {valueOf: null, toString: null},
81 "1": "A",
82 "3": "B",
83 "5": "C"
84 };
85 obj[Symbol.isConcatSpreadable] = true;
86 var obj2 = { length: 3, "0": "0", "1": "1", "2": "2" };
87 var arr = ["X", "Y", "Z"];
88 assertThrows(function() {
89 Array.prototype.concat.call(obj, obj2, arr);
90 }, TypeError);
91 })();
92
93
94 (function testConcatArrayLikePrimitiveNonNumberLength() {
95 "use strict";
96 var obj = {
97 "1": "A",
98 "3": "B",
99 "5": "C"
100 };
101 obj[Symbol.isConcatSpreadable] = true;
102 obj.length = {toString: function() { return "SIX"; }, valueOf: null };
103 assertEquals([], [].concat(obj));
104 obj.length = {toString: null, valueOf: function() { return "SIX"; } };
105 assertEquals([], [].concat(obj));
106 })();
107
108
109 (function testConcatArrayLikeLengthToStringThrows() {
110 "use strict";
111 function MyError() {}
112 var obj = {
113 "length": { toString: function() {
114 throw new MyError();
115 }, valueOf: null
116 },
117 "1": "A",
118 "3": "B",
119 "5": "C"
120 };
121 obj[Symbol.isConcatSpreadable] = true;
122 assertThrows(function() {
123 [].concat(obj);
124 }, MyError);
125 })();
126
127
128 (function testConcatArrayLikeLengthValueOfThrows() {
129 "use strict";
130 function MyError() {}
131 var obj = {
132 "length": { valueOf: function() {
133 throw new MyError();
134 }, toString: null
135 },
136 "1": "A",
137 "3": "B",
138 "5": "C"
139 };
140 obj[Symbol.isConcatSpreadable] = true;
141 assertThrows(function() {
142 [].concat(obj);
143 }, MyError);
144 })();
145
146
43 (function testConcatHoleyArray() { 147 (function testConcatHoleyArray() {
44 "use strict"; 148 "use strict";
45 var arr = []; 149 var arr = [];
46 arr[4] = "Item 4"; 150 arr[4] = "Item 4";
47 arr[8] = "Item 8"; 151 arr[8] = "Item 8";
48 var arr2 = [".", "!", "?"]; 152 var arr2 = [".", "!", "?"];
49 assertEquals([void 0, void 0, void 0, void 0, "Item 4", void 0, void 0, 153 assertEquals([void 0, void 0, void 0, void 0, "Item 4", void 0, void 0,
50 void 0, "Item 8", ".", "!", "?"], arr.concat(arr2)); 154 void 0, "Item 8", ".", "!", "?"], arr.concat(arr2));
51 })(); 155 })();
52 156
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 arr3.length = 10000; 508 arr3.length = 10000;
405 for (var i = 0; i < 100; i++) { 509 for (var i = 0; i < 100; i++) {
406 Object.defineProperty(arr3, i * i, {get: mkGetter(i)}); 510 Object.defineProperty(arr3, i * i, {get: mkGetter(i)});
407 expectedTrace[i] = i; 511 expectedTrace[i] = i;
408 expectedTrace[100 + i] = i; 512 expectedTrace[100 + i] = i;
409 } 513 }
410 var r4 = [0].concat(arr3, arr3); 514 var r4 = [0].concat(arr3, arr3);
411 assertEquals(1 + arr3.length * 2, r4.length); 515 assertEquals(1 + arr3.length * 2, r4.length);
412 assertEquals(expectedTrace, trace); 516 assertEquals(expectedTrace, trace);
413 })(); 517 })();
OLDNEW
« 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