| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 120       assertEquals([], sliced);  // Length was 0, nothing to get. | 120       assertEquals([], sliced);  // Length was 0, nothing to get. | 
| 121     } else { | 121     } else { | 
| 122       // Actually out of array [0..i] we get [i - 1] as length is i. | 122       // Actually out of array [0..i] we get [i - 1] as length is i. | 
| 123       assertEquals([i - 1], sliced); | 123       assertEquals([i - 1], sliced); | 
| 124     } | 124     } | 
| 125   } | 125   } | 
| 126 })(); | 126 })(); | 
| 127 | 127 | 
| 128 | 128 | 
| 129 // Now check the case with array of holes and some elements on prototype. | 129 // Now check the case with array of holes and some elements on prototype. | 
|  | 130 // Note: that is important that this test runs before the next one | 
|  | 131 // as the next one tampers Array.prototype. | 
|  | 132 (function() { | 
|  | 133   var len = 9; | 
|  | 134   var array = new Array(len); | 
|  | 135 | 
|  | 136   var at3 = "@3"; | 
|  | 137   var at7 = "@7"; | 
|  | 138 | 
|  | 139   for (var i = 0; i < 7; i++) { | 
|  | 140     var array_proto = []; | 
|  | 141     array_proto[3] = at3; | 
|  | 142     array_proto[7] = at7; | 
|  | 143     array.__proto__ = array_proto; | 
|  | 144 | 
|  | 145     assertEquals(len, array.length); | 
|  | 146     for (var i = 0; i < array.length; i++) { | 
|  | 147       assertEquals(array[i], array_proto[i]); | 
|  | 148     } | 
|  | 149 | 
|  | 150     var sliced = array.slice(); | 
|  | 151 | 
|  | 152     assertEquals(len, sliced.length); | 
|  | 153 | 
|  | 154     assertTrue(delete array_proto[3]); | 
|  | 155     assertTrue(delete array_proto[7]); | 
|  | 156 | 
|  | 157     // Note that slice copies values from prototype into the array. | 
|  | 158     assertEquals(array[3], undefined); | 
|  | 159     assertFalse(array.hasOwnProperty(3)); | 
|  | 160     assertEquals(sliced[3], at3); | 
|  | 161     assertTrue(sliced.hasOwnProperty(3)); | 
|  | 162 | 
|  | 163     assertEquals(array[7], undefined); | 
|  | 164     assertFalse(array.hasOwnProperty(7)); | 
|  | 165     assertEquals(sliced[7], at7); | 
|  | 166     assertTrue(sliced.hasOwnProperty(7)); | 
|  | 167 | 
|  | 168     // ... but keeps the rest as holes: | 
|  | 169     array_proto[5] = "@5"; | 
|  | 170     assertEquals(array[5], array_proto[5]); | 
|  | 171     assertFalse(array.hasOwnProperty(5)); | 
|  | 172   } | 
|  | 173 })(); | 
|  | 174 | 
|  | 175 | 
|  | 176 // Now check the case with array of holes and some elements on prototype. | 
| 130 (function() { | 177 (function() { | 
| 131   var len = 9; | 178   var len = 9; | 
| 132   var array = new Array(len); | 179   var array = new Array(len); | 
| 133 | 180 | 
| 134   var at3 = "@3"; | 181   var at3 = "@3"; | 
| 135   var at7 = "@7"; | 182   var at7 = "@7"; | 
| 136 | 183 | 
| 137   for (var i = 0; i < 7; i++) { | 184   for (var i = 0; i < 7; i++) { | 
| 138     Array.prototype[3] = at3; | 185     Array.prototype[3] = at3; | 
| 139     Array.prototype[7] = at7; | 186     Array.prototype[7] = at7; | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
| 164     // ... but keeps the rest as holes: | 211     // ... but keeps the rest as holes: | 
| 165     Array.prototype[5] = "@5"; | 212     Array.prototype[5] = "@5"; | 
| 166     assertEquals(array[5], Array.prototype[5]); | 213     assertEquals(array[5], Array.prototype[5]); | 
| 167     assertFalse(array.hasOwnProperty(5)); | 214     assertFalse(array.hasOwnProperty(5)); | 
| 168     assertEquals(sliced[5], Array.prototype[5]); | 215     assertEquals(sliced[5], Array.prototype[5]); | 
| 169     assertFalse(sliced.hasOwnProperty(5)); | 216     assertFalse(sliced.hasOwnProperty(5)); | 
| 170 | 217 | 
| 171     assertTrue(delete Array.prototype[5]); | 218     assertTrue(delete Array.prototype[5]); | 
| 172   } | 219   } | 
| 173 })(); | 220 })(); | 
| OLD | NEW | 
|---|