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

Side by Side Diff: test/mjsunit/array-concat.js

Issue 8888006: Make more JS files beter match the coding standard. Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comments Created 9 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 | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/arguments-read-and-assignment.js ('k') | test/mjsunit/array-constructor.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 176
177 } 177 }
178 178
179 a = []; 179 a = [];
180 c = a.concat('Hello'); 180 c = a.concat('Hello');
181 assertEquals(1, c.length); 181 assertEquals(1, c.length);
182 assertEquals("Hello", c[0]); 182 assertEquals("Hello", c[0]);
183 assertEquals("Hello", c.toString()); 183 assertEquals("Hello", c.toString());
184 184
185 // Check that concat preserves holes. 185 // Check that concat preserves holes.
186 var holey = [void 0,'a',,'c'].concat(['d',,'f',[0,,2],void 0]) 186 var holey = [void 0,'a',,'c'].concat(['d',,'f',[0,,2],void 0]);
187 assertEquals(9, holey.length); // hole in embedded array is ignored 187 assertEquals(9, holey.length); // hole in embedded array is ignored
188 for (var i = 0; i < holey.length; i++) { 188 for (var i = 0; i < holey.length; i++) {
189 if (i == 2 || i == 5) { 189 if (i == 2 || i == 5) {
190 assertFalse(i in holey); 190 assertFalse(i in holey);
191 } else { 191 } else {
192 assertTrue(i in holey); 192 assertTrue(i in holey);
193 } 193 }
194 } 194 }
195 195
196 // Polluted prototype from prior tests. 196 // Polluted prototype from prior tests.
197 delete Array.prototype[123]; 197 delete Array.prototype[123];
198 198
199 // Check that concat reads getters in the correct order. 199 // Check that concat reads getters in the correct order.
200 var arr1 = [,2]; 200 var arr1 = [,2];
201 var arr2 = [1,3]; 201 var arr2 = [1,3];
202 var r1 = [].concat(arr1, arr2); // [,2,1,3] 202 var r1 = [].concat(arr1, arr2); // [,2,1,3]
203 assertEquals([,2,1,3], r1); 203 assertEquals([,2,1,3], r1);
204 204
205 // Make first array change length of second array. 205 // Make first array change length of second array.
206 Object.defineProperty(arr1, 0, {get: function() { 206 Object.defineProperty(arr1, 0, {get: function() {
207 arr2.push("X"); 207 arr2.push("X");
208 return undefined; 208 return undefined;
209 }, configurable: true}) 209 },
210 configurable: true});
210 var r2 = [].concat(arr1, arr2); // [undefined,2,1,3,"X"] 211 var r2 = [].concat(arr1, arr2); // [undefined,2,1,3,"X"]
211 assertEquals([undefined,2,1,3,"X"], r2); 212 assertEquals([undefined,2,1,3,"X"], r2);
212 213
213 // Make first array change length of second array massively. 214 // Make first array change length of second array massively.
214 arr2.length = 2; 215 arr2.length = 2;
215 Object.defineProperty(arr1, 0, {get: function() { 216 Object.defineProperty(arr1, 0, {get: function() {
216 arr2[500000] = "X"; 217 arr2[500000] = "X";
217 return undefined; 218 return undefined;
218 }, configurable: true}) 219 },
220 configurable: true});
219 var r3 = [].concat(arr1, arr2); // [undefined,2,1,3,"X"] 221 var r3 = [].concat(arr1, arr2); // [undefined,2,1,3,"X"]
220 var expected = [undefined,2,1,3]; 222 var expected = [undefined,2,1,3];
221 expected[500000 + 2] = "X"; 223 expected[500000 + 2] = "X";
222 224
223 assertEquals(expected, r3); 225 assertEquals(expected, r3);
224 226
225 var arr3 = []; 227 var arr3 = [];
226 var trace = []; 228 var trace = [];
227 var expectedTrace = [] 229 var expectedTrace = [];
228 function mkGetter(i) { return function() { trace.push(i); }; } 230 function mkGetter(i) { return function() { trace.push(i); }; }
229 arr3.length = 10000; 231 arr3.length = 10000;
230 for (var i = 0; i < 100; i++) { 232 for (var i = 0; i < 100; i++) {
231 Object.defineProperty(arr3, i * i, {get: mkGetter(i)}); 233 Object.defineProperty(arr3, i * i, {get: mkGetter(i)});
232 expectedTrace[i] = i; 234 expectedTrace[i] = i;
233 expectedTrace[100 + i] = i; 235 expectedTrace[100 + i] = i;
234 } 236 }
235 var r4 = [0].concat(arr3, arr3); 237 var r4 = [0].concat(arr3, arr3);
236 assertEquals(1 + arr3.length * 2, r4.length); 238 assertEquals(1 + arr3.length * 2, r4.length);
237 assertEquals(expectedTrace, trace); 239 assertEquals(expectedTrace, trace);
OLDNEW
« no previous file with comments | « test/mjsunit/arguments-read-and-assignment.js ('k') | test/mjsunit/array-constructor.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698