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

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

Issue 6357025: ArraySplice builtin should return empty array and not alter receiver if invoked with no arguments. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Minor correction Created 9 years, 10 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 | Annotate | Revision Log
« src/array.js ('K') | « src/builtins.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 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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 assertFalse(array.hasOwnProperty(10), "array.hasOwnProperty(10)"); 332 assertFalse(array.hasOwnProperty(10), "array.hasOwnProperty(10)");
333 assertFalse(array.hasOwnProperty(15), "array.hasOwnProperty(15)"); 333 assertFalse(array.hasOwnProperty(15), "array.hasOwnProperty(15)");
334 assertFalse(array.hasOwnProperty(31), "array.hasOwnProperty(31)"); 334 assertFalse(array.hasOwnProperty(31), "array.hasOwnProperty(31)");
335 assertFalse(array.hasOwnProperty(63), "array.hasOwnProperty(63)"); 335 assertFalse(array.hasOwnProperty(63), "array.hasOwnProperty(63)");
336 assertFalse(array.hasOwnProperty(2 << 32 - 1), 336 assertFalse(array.hasOwnProperty(2 << 32 - 1),
337 "array.hasOwnProperty(2 << 31 - 1)"); 337 "array.hasOwnProperty(2 << 31 - 1)");
338 } 338 }
339 })(); 339 })();
340 340
341 341
342 // Check the case of JS builtin .splice()
343 (function() {
344 for (var i = 0; i < 7; i++) {
345 var array = [1, 2, 3, 4];
346 Array.prototype[3] = 'foo'; // To force JS builtin.
347
348 var spliced = array.splice();
349
350 assertEquals([], spliced);
351 assertEquals([1, 2, 3, 4], array);
352 }
353 })();
354
355
342 // Check the behaviour when approaching maximal values for length. 356 // Check the behaviour when approaching maximal values for length.
343 (function() { 357 (function() {
344 for (var i = 0; i < 7; i++) { 358 for (var i = 0; i < 7; i++) {
345 try { 359 try {
346 new Array((1 << 32) - 3).splice(-1, 0, 1, 2, 3, 4, 5); 360 new Array((1 << 32) - 3).splice(-1, 0, 1, 2, 3, 4, 5);
347 throw 'Should have thrown RangeError'; 361 throw 'Should have thrown RangeError';
348 } catch (e) { 362 } catch (e) {
349 assertTrue(e instanceof RangeError); 363 assertTrue(e instanceof RangeError);
350 } 364 }
351 365
352 // Check smi boundary 366 // Check smi boundary
353 var bigNum = (1 << 30) - 3; 367 var bigNum = (1 << 30) - 3;
354 var array = new Array(bigNum); 368 var array = new Array(bigNum);
355 array.splice(-1, 0, 1, 2, 3, 4, 5, 6, 7); 369 array.splice(-1, 0, 1, 2, 3, 4, 5, 6, 7);
356 assertEquals(bigNum + 7, array.length); 370 assertEquals(bigNum + 7, array.length);
357 } 371 }
358 })(); 372 })();
359 373
360 (function() { 374 (function() {
361 for (var i = 0; i < 7; i++) { 375 for (var i = 0; i < 7; i++) {
362 var a = [7, 8, 9]; 376 var a = [7, 8, 9];
363 a.splice(0, 0, 1, 2, 3, 4, 5, 6); 377 a.splice(0, 0, 1, 2, 3, 4, 5, 6);
364 assertEquals([1, 2, 3, 4, 5, 6, 7, 8, 9], a); 378 assertEquals([1, 2, 3, 4, 5, 6, 7, 8, 9], a);
365 assertFalse(a.hasOwnProperty(10), "a.hasOwnProperty(10)"); 379 assertFalse(a.hasOwnProperty(10), "a.hasOwnProperty(10)");
366 assertEquals(undefined, a[10]); 380 assertEquals(undefined, a[10]);
367 } 381 }
368 })(); 382 })();
OLDNEW
« src/array.js ('K') | « src/builtins.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698