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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 assertEquals(array[3], Array.prototype[3]); | 62 assertEquals(array[3], Array.prototype[3]); |
63 assertFalse(array.hasOwnProperty(3)); | 63 assertFalse(array.hasOwnProperty(3)); |
64 | 64 |
65 assertEquals(array[7], Array.prototype[7]); | 65 assertEquals(array[7], Array.prototype[7]); |
66 assertFalse(array.hasOwnProperty(7)); | 66 assertFalse(array.hasOwnProperty(7)); |
67 | 67 |
68 assertTrue(delete Array.prototype[3]); | 68 assertTrue(delete Array.prototype[3]); |
69 assertTrue(delete Array.prototype[5]); | 69 assertTrue(delete Array.prototype[5]); |
70 assertTrue(delete Array.prototype[7]); | 70 assertTrue(delete Array.prototype[7]); |
71 })(); | 71 })(); |
| 72 |
| 73 // Now check the case with array of holes and some elements on prototype |
| 74 // which is an array itself. |
| 75 (function() { |
| 76 var len = 9; |
| 77 var array = new Array(len); |
| 78 var array_proto = new Array(); |
| 79 array_proto[3] = "@3"; |
| 80 array_proto[7] = "@7"; |
| 81 array.__proto__ = array_proto; |
| 82 |
| 83 assertEquals(len, array.length); |
| 84 for (var i = 0; i < array.length; i++) { |
| 85 assertEquals(array[i], array_proto[i]); |
| 86 } |
| 87 |
| 88 array.shift(); |
| 89 |
| 90 assertEquals(len - 1, array.length); |
| 91 // Note that shift copies values from prototype into the array. |
| 92 assertEquals(array[2], array_proto[3]); |
| 93 assertTrue(array.hasOwnProperty(2)); |
| 94 |
| 95 assertEquals(array[6], array_proto[7]); |
| 96 assertTrue(array.hasOwnProperty(6)); |
| 97 |
| 98 // ... but keeps the rest as holes: |
| 99 array_proto[5] = "@5"; |
| 100 assertEquals(array[5], array_proto[5]); |
| 101 assertFalse(array.hasOwnProperty(5)); |
| 102 |
| 103 assertEquals(array[3], array_proto[3]); |
| 104 assertFalse(array.hasOwnProperty(3)); |
| 105 |
| 106 assertEquals(array[7], array_proto[7]); |
| 107 assertFalse(array.hasOwnProperty(7)); |
| 108 })(); |
OLD | NEW |