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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 | 411 |
412 // Test error conditions: | 412 // Test error conditions: |
413 | 413 |
414 var exception = false; | 414 var exception = false; |
415 try { | 415 try { |
416 [1].reduce("not a function"); | 416 [1].reduce("not a function"); |
417 } catch (e) { | 417 } catch (e) { |
418 exception = true; | 418 exception = true; |
419 assertTrue(e instanceof TypeError, | 419 assertTrue(e instanceof TypeError, |
420 "reduce callback not a function not throwing TypeError"); | 420 "reduce callback not a function not throwing TypeError"); |
421 assertEquals("called_non_callable", e.type, | 421 assertTrue(e.message.indexOf(" is not a function") >= 0, |
422 "reduce non function TypeError type"); | 422 "reduce non function TypeError type"); |
423 } | 423 } |
424 assertTrue(exception); | 424 assertTrue(exception); |
425 | 425 |
426 exception = false; | 426 exception = false; |
427 try { | 427 try { |
428 [1].reduceRight("not a function"); | 428 [1].reduceRight("not a function"); |
429 } catch (e) { | 429 } catch (e) { |
430 exception = true; | 430 exception = true; |
431 assertTrue(e instanceof TypeError, | 431 assertTrue(e instanceof TypeError, |
432 "reduceRight callback not a function not throwing TypeError"); | 432 "reduceRight callback not a function not throwing TypeError"); |
433 assertEquals("called_non_callable", e.type, | 433 assertTrue(e.message.indexOf(" is not a function") >= 0, |
434 "reduceRight non function TypeError type"); | 434 "reduceRight non function TypeError type"); |
435 } | 435 } |
436 assertTrue(exception); | 436 assertTrue(exception); |
437 | 437 |
438 exception = false; | 438 exception = false; |
439 try { | 439 try { |
440 [].reduce(sum); | 440 [].reduce(sum); |
441 } catch (e) { | 441 } catch (e) { |
442 exception = true; | 442 exception = true; |
443 assertTrue(e instanceof TypeError, | 443 assertTrue(e instanceof TypeError, |
444 "reduce no initial value not throwing TypeError"); | 444 "reduce no initial value not throwing TypeError"); |
445 assertEquals("reduce_no_initial", e.type, | 445 assertEquals("Reduce of empty array with no initial value", e.message, |
446 "reduce no initial TypeError type"); | 446 "reduce no initial TypeError type"); |
447 } | 447 } |
448 assertTrue(exception); | 448 assertTrue(exception); |
449 | 449 |
450 exception = false; | 450 exception = false; |
451 try { | 451 try { |
452 [].reduceRight(sum); | 452 [].reduceRight(sum); |
453 } catch (e) { | 453 } catch (e) { |
454 exception = true; | 454 exception = true; |
455 assertTrue(e instanceof TypeError, | 455 assertTrue(e instanceof TypeError, |
456 "reduceRight no initial value not throwing TypeError"); | 456 "reduceRight no initial value not throwing TypeError"); |
457 assertEquals("reduce_no_initial", e.type, | 457 assertEquals("Reduce of empty array with no initial value", e.message, |
458 "reduceRight no initial TypeError type"); | 458 "reduceRight no initial TypeError type"); |
459 } | 459 } |
460 assertTrue(exception); | 460 assertTrue(exception); |
461 | 461 |
462 exception = false; | 462 exception = false; |
463 try { | 463 try { |
464 [,,,].reduce(sum); | 464 [,,,].reduce(sum); |
465 } catch (e) { | 465 } catch (e) { |
466 exception = true; | 466 exception = true; |
467 assertTrue(e instanceof TypeError, | 467 assertTrue(e instanceof TypeError, |
468 "reduce sparse no initial value not throwing TypeError"); | 468 "reduce sparse no initial value not throwing TypeError"); |
469 assertEquals("reduce_no_initial", e.type, | 469 assertEquals("Reduce of empty array with no initial value", e.message, |
470 "reduce no initial TypeError type"); | 470 "reduce no initial TypeError type"); |
471 } | 471 } |
472 assertTrue(exception); | 472 assertTrue(exception); |
473 | 473 |
474 exception = false; | 474 exception = false; |
475 try { | 475 try { |
476 [,,,].reduceRight(sum); | 476 [,,,].reduceRight(sum); |
477 } catch (e) { | 477 } catch (e) { |
478 exception = true; | 478 exception = true; |
479 assertTrue(e instanceof TypeError, | 479 assertTrue(e instanceof TypeError, |
480 "reduceRight sparse no initial value not throwing TypeError"); | 480 "reduceRight sparse no initial value not throwing TypeError"); |
481 assertEquals("reduce_no_initial", e.type, | 481 assertEquals("Reduce of empty array with no initial value", e.message, |
482 "reduceRight no initial TypeError type"); | 482 "reduceRight no initial TypeError type"); |
483 } | 483 } |
484 assertTrue(exception); | 484 assertTrue(exception); |
485 | 485 |
486 | 486 |
487 // Array changing length | 487 // Array changing length |
488 | 488 |
489 function manipulator(a, b, i, s) { | 489 function manipulator(a, b, i, s) { |
490 if (s.length % 2) { | 490 if (s.length % 2) { |
491 s[s.length * 3] = i; | 491 s[s.length * 3] = i; |
(...skipping 22 matching lines...) Expand all Loading... |
514 return a + b; | 514 return a + b; |
515 } | 515 } |
516 | 516 |
517 var arr = [1, 2, 3, 4]; | 517 var arr = [1, 2, 3, 4]; |
518 testReduce("reduce", "ArrayManipulationExtender", 10, | 518 testReduce("reduce", "ArrayManipulationExtender", 10, |
519 [[0, 1, 0, [1, 2, 3, 4], 1], | 519 [[0, 1, 0, [1, 2, 3, 4], 1], |
520 [1, 2, 1, [1, 2, 3, 4, 4], 3], | 520 [1, 2, 1, [1, 2, 3, 4, 4], 3], |
521 [3, 3, 2, [1, 2, 3, 4, 4, 5], 6], | 521 [3, 3, 2, [1, 2, 3, 4, 4, 5], 6], |
522 [6, 4, 3, [1, 2, 3, 4, 4, 5, 6], 10], | 522 [6, 4, 3, [1, 2, 3, 4, 4, 5, 6], 10], |
523 ], arr, extender, 0); | 523 ], arr, extender, 0); |
OLD | NEW |