| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 [[0, 3, 3, arrayPlus, 3], | 406 [[0, 3, 3, arrayPlus, 3], |
| 407 [3, 2, 1, arrayPlus, 5], | 407 [3, 2, 1, arrayPlus, 5], |
| 408 [5, 1, 0, arrayPlus, 6], | 408 [5, 1, 0, arrayPlus, 6], |
| 409 ], arrayPlus, sum, 0); | 409 ], arrayPlus, sum, 0); |
| 410 | 410 |
| 411 | 411 |
| 412 // Test error conditions: | 412 // Test error conditions: |
| 413 | 413 |
| 414 try { | 414 try { |
| 415 [1].reduce("not a function"); | 415 [1].reduce("not a function"); |
| 416 fail("Reduce callback not a function not throwing"); | 416 assertUnreachable("Reduce callback not a function not throwing"); |
| 417 } catch (e) { | 417 } catch (e) { |
| 418 assertTrue(e instanceof TypeError, | 418 assertTrue(e instanceof TypeError, |
| 419 "reduce callback not a function not throwing TypeError"); | 419 "reduce callback not a function not throwing TypeError"); |
| 420 assertEquals("called_non_callable", e.type, | 420 assertEquals("called_non_callable", e.type, |
| 421 "reduce non function TypeError type"); | 421 "reduce non function TypeError type"); |
| 422 } | 422 } |
| 423 | 423 |
| 424 try { | 424 try { |
| 425 [1].reduceRight("not a function"); | 425 [1].reduceRight("not a function"); |
| 426 fail("ReduceRight callback not a function not throwing"); | 426 assertUnreachable("ReduceRight callback not a function not throwing"); |
| 427 } catch (e) { | 427 } catch (e) { |
| 428 assertTrue(e instanceof TypeError, | 428 assertTrue(e instanceof TypeError, |
| 429 "reduceRight callback not a function not throwing TypeError"); | 429 "reduceRight callback not a function not throwing TypeError"); |
| 430 assertEquals("called_non_callable", e.type, | 430 assertEquals("called_non_callable", e.type, |
| 431 "reduceRight non function TypeError type"); | 431 "reduceRight non function TypeError type"); |
| 432 } | 432 } |
| 433 | 433 |
| 434 | 434 |
| 435 try { | 435 try { |
| 436 [].reduce(sum); | 436 [].reduce(sum); |
| 437 fail("Reduce no initial value not throwing"); | 437 assertUnreachable("Reduce no initial value not throwing"); |
| 438 } catch (e) { | 438 } catch (e) { |
| 439 assertTrue(e instanceof TypeError, | 439 assertTrue(e instanceof TypeError, |
| 440 "reduce no initial value not throwing TypeError"); | 440 "reduce no initial value not throwing TypeError"); |
| 441 assertEquals("reduce_no_initial", e.type, | 441 assertEquals("reduce_no_initial", e.type, |
| 442 "reduce no initial TypeError type"); | 442 "reduce no initial TypeError type"); |
| 443 } | 443 } |
| 444 | 444 |
| 445 try { | 445 try { |
| 446 [].reduceRight(sum); | 446 [].reduceRight(sum); |
| 447 fail("ReduceRight no initial value not throwing"); | 447 assertUnreachable("ReduceRight no initial value not throwing"); |
| 448 } catch (e) { | 448 } catch (e) { |
| 449 assertTrue(e instanceof TypeError, | 449 assertTrue(e instanceof TypeError, |
| 450 "reduceRight no initial value not throwing TypeError"); | 450 "reduceRight no initial value not throwing TypeError"); |
| 451 assertEquals("reduce_no_initial", e.type, | 451 assertEquals("reduce_no_initial", e.type, |
| 452 "reduceRight no initial TypeError type"); | 452 "reduceRight no initial TypeError type"); |
| 453 } | 453 } |
| 454 | 454 |
| 455 | 455 |
| 456 try { | 456 try { |
| 457 [,,,].reduce(sum); | 457 [,,,].reduce(sum); |
| 458 fail("Reduce sparse no initial value not throwing"); | 458 assertUnreachable("Reduce sparse no initial value not throwing"); |
| 459 } catch (e) { | 459 } catch (e) { |
| 460 assertTrue(e instanceof TypeError, | 460 assertTrue(e instanceof TypeError, |
| 461 "reduce sparse no initial value not throwing TypeError"); | 461 "reduce sparse no initial value not throwing TypeError"); |
| 462 assertEquals("reduce_no_initial", e.type, | 462 assertEquals("reduce_no_initial", e.type, |
| 463 "reduce no initial TypeError type"); | 463 "reduce no initial TypeError type"); |
| 464 } | 464 } |
| 465 | 465 |
| 466 try { | 466 try { |
| 467 [,,,].reduceRight(sum); | 467 [,,,].reduceRight(sum); |
| 468 fail("ReduceRight sparse no initial value not throwing"); | 468 assertUnreachable("ReduceRight sparse no initial value not throwing"); |
| 469 } catch (e) { | 469 } catch (e) { |
| 470 assertTrue(e instanceof TypeError, | 470 assertTrue(e instanceof TypeError, |
| 471 "reduceRight sparse no initial value not throwing TypeError"); | 471 "reduceRight sparse no initial value not throwing TypeError"); |
| 472 assertEquals("reduce_no_initial", e.type, | 472 assertEquals("reduce_no_initial", e.type, |
| 473 "reduceRight no initial TypeError type"); | 473 "reduceRight no initial TypeError type"); |
| 474 } | 474 } |
| 475 | 475 |
| 476 | 476 |
| 477 // Array changing length | 477 // Array changing length |
| 478 | 478 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 505 } | 505 } |
| 506 | 506 |
| 507 var arr = [1, 2, 3, 4]; | 507 var arr = [1, 2, 3, 4]; |
| 508 testReduce("reduce", "ArrayManipulationExtender", 10, | 508 testReduce("reduce", "ArrayManipulationExtender", 10, |
| 509 [[0, 1, 0, [1, 2, 3, 4], 1], | 509 [[0, 1, 0, [1, 2, 3, 4], 1], |
| 510 [1, 2, 1, [1, 2, 3, 4, 4], 3], | 510 [1, 2, 1, [1, 2, 3, 4, 4], 3], |
| 511 [3, 3, 2, [1, 2, 3, 4, 4, 5], 6], | 511 [3, 3, 2, [1, 2, 3, 4, 4, 5], 6], |
| 512 [6, 4, 3, [1, 2, 3, 4, 4, 5, 6], 10], | 512 [6, 4, 3, [1, 2, 3, 4, 4, 5, 6], 10], |
| 513 ], arr, extender, 0); | 513 ], arr, extender, 0); |
| 514 | 514 |
| OLD | NEW |