| 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 assertFalse(array.hasOwnProperty(3)); | 187 assertFalse(array.hasOwnProperty(3)); |
| 188 | 188 |
| 189 assertEquals(array[7], array_proto[7]); | 189 assertEquals(array[7], array_proto[7]); |
| 190 assertFalse(array.hasOwnProperty(7)); | 190 assertFalse(array.hasOwnProperty(7)); |
| 191 })(); | 191 })(); |
| 192 | 192 |
| 193 // Check the behaviour when approaching maximal values for length. | 193 // Check the behaviour when approaching maximal values for length. |
| 194 (function() { | 194 (function() { |
| 195 for (var i = 0; i < 7; i++) { | 195 for (var i = 0; i < 7; i++) { |
| 196 try { | 196 try { |
| 197 var a1 = []; | 197 new Array(Math.pow(2, 32) - 3).unshift(1, 2, 3, 4, 5); |
| 198 a1[Math.pow(2, 32) - 3 - 1] = 0; | |
| 199 a1.unshift(1, 2, 3, 4, 5); | |
| 200 throw 'Should have thrown RangeError'; | 198 throw 'Should have thrown RangeError'; |
| 201 } catch (e) { | 199 } catch (e) { |
| 202 assertTrue(e instanceof RangeError); | 200 assertTrue(e instanceof RangeError); |
| 203 } | 201 } |
| 204 | 202 |
| 205 // Check smi boundary | 203 // Check smi boundary |
| 206 var bigNum = (1 << 30) - 3; | 204 var bigNum = (1 << 30) - 3; |
| 207 var a2 = []; | 205 assertEquals(bigNum + 7, new Array(bigNum).unshift(1, 2, 3, 4, 5, 6, 7)); |
| 208 a2[bigNum - 1] = 0; | |
| 209 assertEquals(bigNum + 7, a2.unshift(1, 2, 3, 4, 5, 6, 7)); | |
| 210 } | 206 } |
| 211 })(); | 207 })(); |
| 212 | 208 |
| 213 (function() { | 209 (function() { |
| 214 for (var i = 0; i < 7; i++) { | 210 for (var i = 0; i < 7; i++) { |
| 215 var a = [6, 7, 8, 9]; | 211 var a = [6, 7, 8, 9]; |
| 216 a.unshift(1, 2, 3, 4, 5); | 212 a.unshift(1, 2, 3, 4, 5); |
| 217 assertEquals([1, 2, 3, 4, 5, 6, 7, 8, 9], a); | 213 assertEquals([1, 2, 3, 4, 5, 6, 7, 8, 9], a); |
| 218 } | 214 } |
| 219 })(); | 215 })(); |
| 220 | 216 |
| 221 // Check that non-enumerable elements are treated appropriately | 217 // Check that non-enumerable elements are treated appropriately |
| 222 (function() { | 218 (function() { |
| 223 var array = [2, 3]; | 219 var array = [2, 3]; |
| 224 Object.defineProperty(array, '1', {enumerable: false}); | 220 Object.defineProperty(array, '1', {enumerable: false}); |
| 225 array.unshift(1) | 221 array.unshift(1) |
| 226 assertEquals([1, 2, 3], array); | 222 assertEquals([1, 2, 3], array); |
| 227 | 223 |
| 228 array = [2]; | 224 array = [2]; |
| 229 array.length = 2; | 225 array.length = 2; |
| 230 array.__proto__[1] = 3; | 226 array.__proto__[1] = 3; |
| 231 Object.defineProperty(array.__proto__, '1', {enumerable: false}); | 227 Object.defineProperty(array.__proto__, '1', {enumerable: false}); |
| 232 array.unshift(1); | 228 array.unshift(1); |
| 233 assertEquals([1, 2, 3], array); | 229 assertEquals([1, 2, 3], array); |
| 234 })(); | 230 })(); |
| OLD | NEW |