OLD | NEW |
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 16 matching lines...) Expand all Loading... |
27 | 27 |
28 // Check that shifting array of holes keeps it as array of holes | 28 // Check that shifting array of holes keeps it as array of holes |
29 (function() { | 29 (function() { |
30 var array = new Array(10); | 30 var array = new Array(10); |
31 array.shift(); | 31 array.shift(); |
32 assertFalse(0 in array); | 32 assertFalse(0 in array); |
33 })(); | 33 })(); |
34 | 34 |
35 // Now check the case with array of holes and some elements on prototype. | 35 // Now check the case with array of holes and some elements on prototype. |
36 (function() { | 36 (function() { |
37 var array = new Array(10); | 37 var len = 9; |
| 38 var array = new Array(len); |
| 39 Array.prototype[3] = "@3"; |
38 Array.prototype[7] = "@7"; | 40 Array.prototype[7] = "@7"; |
39 assertEquals(array[0], undefined); | 41 |
40 assertEquals(array[7], Array.prototype[7]); | 42 assertEquals(len, array.length); |
| 43 for (var i = 0; i < array.length; i++) { |
| 44 assertEquals(array[i], Array.prototype[i]); |
| 45 } |
41 | 46 |
42 array.shift(); | 47 array.shift(); |
43 | 48 |
44 assertEquals(array[0], undefined); | 49 assertEquals(len - 1, array.length); |
| 50 // Note that shift copies values from prototype into the array. |
| 51 assertEquals(array[2], Array.prototype[3]); |
| 52 assertTrue(array.hasOwnProperty(2)); |
| 53 |
| 54 assertEquals(array[6], Array.prototype[7]); |
| 55 assertTrue(array.hasOwnProperty(6)); |
| 56 |
| 57 // ... but keeps the rest as holes: |
| 58 Array.prototype[5] = "@5"; |
| 59 assertEquals(array[5], Array.prototype[5]); |
| 60 assertFalse(array.hasOwnProperty(5)); |
| 61 |
| 62 assertEquals(array[3], Array.prototype[3]); |
| 63 assertFalse(array.hasOwnProperty(3)); |
| 64 |
45 assertEquals(array[7], Array.prototype[7]); | 65 assertEquals(array[7], Array.prototype[7]); |
| 66 assertFalse(array.hasOwnProperty(7)); |
| 67 |
| 68 assertTrue(delete Array.prototype[3]); |
| 69 assertTrue(delete Array.prototype[5]); |
| 70 assertTrue(delete Array.prototype[7]); |
46 })(); | 71 })(); |
OLD | NEW |