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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 assertFalse(array.hasOwnProperty(6), "array.hasOwnProperty(6)"); | 278 assertFalse(array.hasOwnProperty(6), "array.hasOwnProperty(6)"); |
279 assertFalse(array.hasOwnProperty(7), "array.hasOwnProperty(7)"); | 279 assertFalse(array.hasOwnProperty(7), "array.hasOwnProperty(7)"); |
280 assertTrue(array.hasOwnProperty(8)); | 280 assertTrue(array.hasOwnProperty(8)); |
281 assertFalse(array.hasOwnProperty(9), "array.hasOwnProperty(9)"); | 281 assertFalse(array.hasOwnProperty(9), "array.hasOwnProperty(9)"); |
282 | 282 |
283 // and now check couple of indices above length. | 283 // and now check couple of indices above length. |
284 assertFalse(array.hasOwnProperty(10), "array.hasOwnProperty(10)"); | 284 assertFalse(array.hasOwnProperty(10), "array.hasOwnProperty(10)"); |
285 assertFalse(array.hasOwnProperty(15), "array.hasOwnProperty(15)"); | 285 assertFalse(array.hasOwnProperty(15), "array.hasOwnProperty(15)"); |
286 assertFalse(array.hasOwnProperty(31), "array.hasOwnProperty(31)"); | 286 assertFalse(array.hasOwnProperty(31), "array.hasOwnProperty(31)"); |
287 assertFalse(array.hasOwnProperty(63), "array.hasOwnProperty(63)"); | 287 assertFalse(array.hasOwnProperty(63), "array.hasOwnProperty(63)"); |
288 assertFalse(array.hasOwnProperty(2 << 32 - 1), | 288 assertFalse(array.hasOwnProperty(Math.pow(2, 32) - 2), |
adamk
2013/03/21 22:22:37
Wasn't sure what these were supposed to be, happy
| |
289 "array.hasOwnProperty(2 << 31 - 1)"); | 289 "array.hasOwnProperty(Math.pow(2, 32) - 2)"); |
290 } | 290 } |
291 })(); | 291 })(); |
292 | 292 |
293 | 293 |
294 // Now check the case with array of holes and some elements on prototype. | 294 // Now check the case with array of holes and some elements on prototype. |
295 (function() { | 295 (function() { |
296 var len = 9; | 296 var len = 9; |
297 | 297 |
298 var at3 = "@3"; | 298 var at3 = "@3"; |
299 var at7 = "@7"; | 299 var at7 = "@7"; |
(...skipping 26 matching lines...) Expand all Loading... | |
326 assertFalse(array.hasOwnProperty(6), "array.hasOwnProperty(6)"); | 326 assertFalse(array.hasOwnProperty(6), "array.hasOwnProperty(6)"); |
327 assertFalse(array.hasOwnProperty(7), "array.hasOwnProperty(7)"); | 327 assertFalse(array.hasOwnProperty(7), "array.hasOwnProperty(7)"); |
328 assertTrue(array.hasOwnProperty(8)); | 328 assertTrue(array.hasOwnProperty(8)); |
329 assertFalse(array.hasOwnProperty(9), "array.hasOwnProperty(9)"); | 329 assertFalse(array.hasOwnProperty(9), "array.hasOwnProperty(9)"); |
330 | 330 |
331 // and now check couple of indices above length. | 331 // and now check couple of indices above length. |
332 assertFalse(array.hasOwnProperty(10), "array.hasOwnProperty(10)"); | 332 assertFalse(array.hasOwnProperty(10), "array.hasOwnProperty(10)"); |
333 assertFalse(array.hasOwnProperty(15), "array.hasOwnProperty(15)"); | 333 assertFalse(array.hasOwnProperty(15), "array.hasOwnProperty(15)"); |
334 assertFalse(array.hasOwnProperty(31), "array.hasOwnProperty(31)"); | 334 assertFalse(array.hasOwnProperty(31), "array.hasOwnProperty(31)"); |
335 assertFalse(array.hasOwnProperty(63), "array.hasOwnProperty(63)"); | 335 assertFalse(array.hasOwnProperty(63), "array.hasOwnProperty(63)"); |
336 assertFalse(array.hasOwnProperty(2 << 32 - 1), | 336 assertFalse(array.hasOwnProperty(Math.pow(2, 32) - 2), |
337 "array.hasOwnProperty(2 << 31 - 1)"); | 337 "array.hasOwnProperty(Math.pow(2, 32) - 2)"); |
338 } | 338 } |
339 })(); | 339 })(); |
340 | 340 |
341 | 341 |
342 // Check the case of JS builtin .splice() | 342 // Check the case of JS builtin .splice() |
343 (function() { | 343 (function() { |
344 for (var i = 0; i < 7; i++) { | 344 for (var i = 0; i < 7; i++) { |
345 var array = [1, 2, 3, 4]; | 345 var array = [1, 2, 3, 4]; |
346 Array.prototype[3] = 'foo'; // To force JS builtin. | 346 Array.prototype[3] = 'foo'; // To force JS builtin. |
347 | 347 |
348 var spliced = array.splice(); | 348 var spliced = array.splice(); |
349 | 349 |
350 assertEquals([], spliced); | 350 assertEquals([], spliced); |
351 assertEquals([1, 2, 3, 4], array); | 351 assertEquals([1, 2, 3, 4], array); |
352 } | 352 } |
353 })(); | 353 })(); |
354 | 354 |
355 | 355 |
356 // Check the behaviour when approaching maximal values for length. | 356 // Check the behaviour when approaching maximal values for length. |
357 (function() { | 357 (function() { |
358 for (var i = 0; i < 7; i++) { | 358 for (var i = 0; i < 7; i++) { |
359 try { | 359 try { |
360 new Array((1 << 32) - 3).splice(-1, 0, 1, 2, 3, 4, 5); | 360 new Array(Math.pow(2, 32) - 3).splice(-1, 0, 1, 2, 3, 4, 5); |
361 throw 'Should have thrown RangeError'; | 361 throw 'Should have thrown RangeError'; |
362 } catch (e) { | 362 } catch (e) { |
363 assertTrue(e instanceof RangeError); | 363 assertTrue(e instanceof RangeError); |
364 } | 364 } |
365 | 365 |
366 // Check smi boundary | 366 // Check smi boundary |
367 var bigNum = (1 << 30) - 3; | 367 var bigNum = (1 << 30) - 3; |
368 var array = new Array(bigNum); | 368 var array = new Array(bigNum); |
369 array.splice(-1, 0, 1, 2, 3, 4, 5, 6, 7); | 369 array.splice(-1, 0, 1, 2, 3, 4, 5, 6, 7); |
370 assertEquals(bigNum + 7, array.length); | 370 assertEquals(bigNum + 7, array.length); |
371 } | 371 } |
372 })(); | 372 })(); |
373 | 373 |
374 (function() { | 374 (function() { |
375 for (var i = 0; i < 7; i++) { | 375 for (var i = 0; i < 7; i++) { |
376 var a = [7, 8, 9]; | 376 var a = [7, 8, 9]; |
377 a.splice(0, 0, 1, 2, 3, 4, 5, 6); | 377 a.splice(0, 0, 1, 2, 3, 4, 5, 6); |
378 assertEquals([1, 2, 3, 4, 5, 6, 7, 8, 9], a); | 378 assertEquals([1, 2, 3, 4, 5, 6, 7, 8, 9], a); |
379 assertFalse(a.hasOwnProperty(10), "a.hasOwnProperty(10)"); | 379 assertFalse(a.hasOwnProperty(10), "a.hasOwnProperty(10)"); |
380 assertEquals(undefined, a[10]); | 380 assertEquals(undefined, a[10]); |
381 } | 381 } |
382 })(); | 382 })(); |
OLD | NEW |