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

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

Issue 844006: Merge changes up to V8 version 2.1.3 into the partial snapshots (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/partial_snapshots/
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 | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/array-slice.js ('k') | test/mjsunit/array-unshift.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 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 }
42 })();
43
44
45 // Check various variants of empty array's splicing.
46 (function() {
47 for (var i = 0; i < 7; i++) {
48 assertEquals([], [].splice(0, 0));
49 assertEquals([], [].splice(1, 0));
50 assertEquals([], [].splice(0, 1));
51 assertEquals([], [].splice(-1, 0));
52 }
53 })();
54
55
56 // Check that even if result array is empty, receiver gets sliced.
57 (function() {
58 for (var i = 0; i < 7; i++) {
59 var a = [1, 2, 3];
60 assertEquals([], a.splice(1, 0, 'a', 'b', 'c'));
61 assertEquals([1, 'a', 'b', 'c', 2, 3], a);
41 } 62 }
42 })(); 63 })();
43 64
44 65
45 // Check various forms of arguments omission. 66 // Check various forms of arguments omission.
46 (function() { 67 (function() {
47 var array; 68 var array;
48 for (var i = 0; i < 7; i++) { 69 for (var i = 0; i < 7; i++) {
49 // SpiderMonkey and JSC return undefined in the case where no 70 // SpiderMonkey and JSC return undefined in the case where no
50 // arguments are given instead of using the implicit undefined 71 // arguments are given instead of using the implicit undefined
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 // Second hole (at index 3) of array turns into 263 // Second hole (at index 3) of array turns into
243 // value of Array.prototype[3] while copying. 264 // value of Array.prototype[3] while copying.
244 assertEquals([, at3], spliced); 265 assertEquals([, at3], spliced);
245 assertEquals([, , 'one', undefined, 'two', , , at7, at7, ,], array); 266 assertEquals([, , 'one', undefined, 'two', , , at7, at7, ,], array);
246 267
247 // ... but array[7] is actually a hole: 268 // ... but array[7] is actually a hole:
248 assertTrue(delete Array.prototype[7]); 269 assertTrue(delete Array.prototype[7]);
249 assertEquals(undefined, array[7]); 270 assertEquals(undefined, array[7]);
250 271
251 // and now check hasOwnProperty 272 // and now check hasOwnProperty
252 assertFalse(array.hasOwnProperty(0)); 273 assertFalse(array.hasOwnProperty(0), "array.hasOwnProperty(0)");
253 assertFalse(array.hasOwnProperty(1)); 274 assertFalse(array.hasOwnProperty(1), "array.hasOwnProperty(1)");
254 assertTrue(array.hasOwnProperty(2)); 275 assertTrue(array.hasOwnProperty(2));
255 assertTrue(array.hasOwnProperty(3)); 276 assertTrue(array.hasOwnProperty(3));
256 assertTrue(array.hasOwnProperty(4)); 277 assertTrue(array.hasOwnProperty(4));
257 assertFalse(array.hasOwnProperty(5)); 278 assertFalse(array.hasOwnProperty(5), "array.hasOwnProperty(5)");
258 assertFalse(array.hasOwnProperty(6)); 279 assertFalse(array.hasOwnProperty(6), "array.hasOwnProperty(6)");
259 assertFalse(array.hasOwnProperty(7)); 280 assertFalse(array.hasOwnProperty(7), "array.hasOwnProperty(7)");
260 assertTrue(array.hasOwnProperty(8)); 281 assertTrue(array.hasOwnProperty(8));
261 assertFalse(array.hasOwnProperty(9)); 282 assertFalse(array.hasOwnProperty(9), "array.hasOwnProperty(9)");
262 283
263 // and now check couple of indices above length. 284 // and now check couple of indices above length.
264 assertFalse(array.hasOwnProperty(10)); 285 assertFalse(array.hasOwnProperty(10), "array.hasOwnProperty(10)");
265 assertFalse(array.hasOwnProperty(15)); 286 assertFalse(array.hasOwnProperty(15), "array.hasOwnProperty(15)");
266 assertFalse(array.hasOwnProperty(31)); 287 assertFalse(array.hasOwnProperty(31), "array.hasOwnProperty(31)");
267 assertFalse(array.hasOwnProperty(63)); 288 assertFalse(array.hasOwnProperty(63), "array.hasOwnProperty(63)");
268 assertFalse(array.hasOwnProperty(2 << 32 - 1)); 289 assertFalse(array.hasOwnProperty(2 << 32 - 1), "array.hasOwnProperty(2 << 31 - 1)");
269 } 290 }
270 })(); 291 })();
271 292
272 293
273 // Check the behaviour when approaching maximal values for length. 294 // Check the behaviour when approaching maximal values for length.
274 (function() { 295 (function() {
275 for (var i = 0; i < 7; i++) { 296 for (var i = 0; i < 7; i++) {
276 try { 297 try {
277 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);
278 throw 'Should have thrown RangeError'; 299 throw 'Should have thrown RangeError';
279 } catch (e) { 300 } catch (e) {
280 assertTrue(e instanceof RangeError); 301 assertTrue(e instanceof RangeError);
281 } 302 }
282 303
283 // Check smi boundary 304 // Check smi boundary
284 var bigNum = (1 << 30) - 3; 305 var bigNum = (1 << 30) - 3;
285 var array = new Array(bigNum); 306 var array = new Array(bigNum);
286 array.splice(-1, 0, 1, 2, 3, 4, 5, 6, 7); 307 array.splice(-1, 0, 1, 2, 3, 4, 5, 6, 7);
287 assertEquals(bigNum + 7, array.length); 308 assertEquals(bigNum + 7, array.length);
288 } 309 }
289 })(); 310 })();
311
312 (function() {
313 for (var i = 0; i < 7; i++) {
314 var a = [7, 8, 9];
315 a.splice(0, 0, 1, 2, 3, 4, 5, 6);
316 assertEquals([1, 2, 3, 4, 5, 6, 7, 8, 9], a);
317 assertFalse(a.hasOwnProperty(10), "a.hasOwnProperty(10)");
318 assertEquals(undefined, a[10]);
319 }
320 })();
OLDNEW
« no previous file with comments | « test/mjsunit/array-slice.js ('k') | test/mjsunit/array-unshift.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698