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

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

Issue 669160: Better diagnostic of tests. (Closed)
Patch Set: Created 10 years, 9 months 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 | « no previous file | 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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 13 matching lines...) Expand all
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Check that splicing array of holes keeps it as array of holes 28 // Check that splicing array of holes keeps it as array of holes
29 (function() { 29 (function() {
30 for (var i = 0; i < 7; i++) { 30 for (var i = 0; i < 7; i++) {
31 var array = new Array(10); 31 var array = new Array(10);
32 var spliced = array.splice(1, 1, 'one', 'two'); 32 var spliced = array.splice(1, 1, 'one', 'two');
33 assertEquals(1, spliced.length); 33 assertEquals(1, spliced.length);
34 assertFalse(0 in spliced); 34 assertFalse(0 in spliced, "0 in spliced");
35 35
36 assertEquals(11, array.length); 36 assertEquals(11, array.length);
37 assertFalse(0 in array); 37 assertFalse(0 in array, "0 in array");
38 assertTrue(1 in array); 38 assertTrue(1 in array);
39 assertTrue(2 in array); 39 assertTrue(2 in array);
40 assertFalse(3 in array); 40 assertFalse(3 in array, "3 in array");
41 } 41 }
42 })(); 42 })();
43 43
44 44
45 // Check various variants of empty array's splicing. 45 // Check various variants of empty array's splicing.
46 (function() { 46 (function() {
47 for (var i = 0; i < 7; i++) { 47 for (var i = 0; i < 7; i++) {
48 assertEquals([], [].splice(0, 0)); 48 assertEquals([], [].splice(0, 0));
49 assertEquals([], [].splice(1, 0)); 49 assertEquals([], [].splice(1, 0));
50 assertEquals([], [].splice(0, 1)); 50 assertEquals([], [].splice(0, 1));
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 // Second hole (at index 3) of array turns into 263 // Second hole (at index 3) of array turns into
264 // value of Array.prototype[3] while copying. 264 // value of Array.prototype[3] while copying.
265 assertEquals([, at3], spliced); 265 assertEquals([, at3], spliced);
266 assertEquals([, , 'one', undefined, 'two', , , at7, at7, ,], array); 266 assertEquals([, , 'one', undefined, 'two', , , at7, at7, ,], array);
267 267
268 // ... but array[7] is actually a hole: 268 // ... but array[7] is actually a hole:
269 assertTrue(delete Array.prototype[7]); 269 assertTrue(delete Array.prototype[7]);
270 assertEquals(undefined, array[7]); 270 assertEquals(undefined, array[7]);
271 271
272 // and now check hasOwnProperty 272 // and now check hasOwnProperty
273 assertFalse(array.hasOwnProperty(0)); 273 assertFalse(array.hasOwnProperty(0), "array.hasOwnProperty(0)");
274 assertFalse(array.hasOwnProperty(1)); 274 assertFalse(array.hasOwnProperty(1), "array.hasOwnProperty(1)");
275 assertTrue(array.hasOwnProperty(2)); 275 assertTrue(array.hasOwnProperty(2));
276 assertTrue(array.hasOwnProperty(3)); 276 assertTrue(array.hasOwnProperty(3));
277 assertTrue(array.hasOwnProperty(4)); 277 assertTrue(array.hasOwnProperty(4));
278 assertFalse(array.hasOwnProperty(5)); 278 assertFalse(array.hasOwnProperty(5), "array.hasOwnProperty(5)");
279 assertFalse(array.hasOwnProperty(6)); 279 assertFalse(array.hasOwnProperty(6), "array.hasOwnProperty(6)");
280 assertFalse(array.hasOwnProperty(7)); 280 assertFalse(array.hasOwnProperty(7), "array.hasOwnProperty(7)");
281 assertTrue(array.hasOwnProperty(8)); 281 assertTrue(array.hasOwnProperty(8));
282 assertFalse(array.hasOwnProperty(9)); 282 assertFalse(array.hasOwnProperty(9), "array.hasOwnProperty(9)");
283 283
284 // and now check couple of indices above length. 284 // and now check couple of indices above length.
285 assertFalse(array.hasOwnProperty(10)); 285 assertFalse(array.hasOwnProperty(10), "array.hasOwnProperty(10)");
286 assertFalse(array.hasOwnProperty(15)); 286 assertFalse(array.hasOwnProperty(15), "array.hasOwnProperty(15)");
287 assertFalse(array.hasOwnProperty(31)); 287 assertFalse(array.hasOwnProperty(31), "array.hasOwnProperty(31)");
288 assertFalse(array.hasOwnProperty(63)); 288 assertFalse(array.hasOwnProperty(63), "array.hasOwnProperty(63)");
289 assertFalse(array.hasOwnProperty(2 << 32 - 1)); 289 assertFalse(array.hasOwnProperty(2 << 32 - 1), "array.hasOwnProperty(2 << 31 - 1)");
290 } 290 }
291 })(); 291 })();
292 292
293 293
294 // Check the behaviour when approaching maximal values for length. 294 // Check the behaviour when approaching maximal values for length.
295 (function() { 295 (function() {
296 for (var i = 0; i < 7; i++) { 296 for (var i = 0; i < 7; i++) {
297 try { 297 try {
298 new Array((1 << 32) - 3).splice(-1, 0, 1, 2, 3, 4, 5); 298 new Array((1 << 32) - 3).splice(-1, 0, 1, 2, 3, 4, 5);
299 throw 'Should have thrown RangeError'; 299 throw 'Should have thrown RangeError';
300 } catch (e) { 300 } catch (e) {
301 assertTrue(e instanceof RangeError); 301 assertTrue(e instanceof RangeError);
302 } 302 }
303 303
304 // Check smi boundary 304 // Check smi boundary
305 var bigNum = (1 << 30) - 3; 305 var bigNum = (1 << 30) - 3;
306 var array = new Array(bigNum); 306 var array = new Array(bigNum);
307 array.splice(-1, 0, 1, 2, 3, 4, 5, 6, 7); 307 array.splice(-1, 0, 1, 2, 3, 4, 5, 6, 7);
308 assertEquals(bigNum + 7, array.length); 308 assertEquals(bigNum + 7, array.length);
309 } 309 }
310 })(); 310 })();
311 311
312 (function() { 312 (function() {
313 for (var i = 0; i < 7; i++) { 313 for (var i = 0; i < 7; i++) {
314 var a = [7, 8, 9]; 314 var a = [7, 8, 9];
315 a.splice(0, 0, 1, 2, 3, 4, 5, 6); 315 a.splice(0, 0, 1, 2, 3, 4, 5, 6);
316 assertEquals([1, 2, 3, 4, 5, 6, 7, 8, 9], a); 316 assertEquals([1, 2, 3, 4, 5, 6, 7, 8, 9], a);
317 assertFalse(a.hasOwnProperty(10)); 317 assertFalse(a.hasOwnProperty(10), "a.hasOwnProperty(10)");
318 assertEquals(undefined, a[10]); 318 assertEquals(undefined, a[10]);
319 } 319 }
320 })(); 320 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698