Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(458)

Side by Side Diff: test/mjsunit/array-reduce.js

Issue 7053035: Fix a number of tests that incorrectly used assertUnreachable. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address comments. Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/function-call.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 404
405 testReduce("reduceRight", "ArrayWithNonElementPropertiesReduceRight", 6, 405 testReduce("reduceRight", "ArrayWithNonElementPropertiesReduceRight", 6,
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 var exception = false;
414 try { 415 try {
415 [1].reduce("not a function"); 416 [1].reduce("not a function");
416 assertUnreachable("Reduce callback not a function not throwing");
417 } catch (e) { 417 } catch (e) {
418 exception = true;
418 assertTrue(e instanceof TypeError, 419 assertTrue(e instanceof TypeError,
419 "reduce callback not a function not throwing TypeError"); 420 "reduce callback not a function not throwing TypeError");
420 assertEquals("called_non_callable", e.type, 421 assertEquals("called_non_callable", e.type,
421 "reduce non function TypeError type"); 422 "reduce non function TypeError type");
422 } 423 }
424 assertTrue(exception);
423 425
426 exception = false;
424 try { 427 try {
425 [1].reduceRight("not a function"); 428 [1].reduceRight("not a function");
426 assertUnreachable("ReduceRight callback not a function not throwing");
427 } catch (e) { 429 } catch (e) {
430 exception = true;
428 assertTrue(e instanceof TypeError, 431 assertTrue(e instanceof TypeError,
429 "reduceRight callback not a function not throwing TypeError"); 432 "reduceRight callback not a function not throwing TypeError");
430 assertEquals("called_non_callable", e.type, 433 assertEquals("called_non_callable", e.type,
431 "reduceRight non function TypeError type"); 434 "reduceRight non function TypeError type");
432 } 435 }
436 assertTrue(exception);
433 437
434 438 exception = false;
435 try { 439 try {
436 [].reduce(sum); 440 [].reduce(sum);
437 assertUnreachable("Reduce no initial value not throwing");
438 } catch (e) { 441 } catch (e) {
442 exception = true;
439 assertTrue(e instanceof TypeError, 443 assertTrue(e instanceof TypeError,
440 "reduce no initial value not throwing TypeError"); 444 "reduce no initial value not throwing TypeError");
441 assertEquals("reduce_no_initial", e.type, 445 assertEquals("reduce_no_initial", e.type,
442 "reduce no initial TypeError type"); 446 "reduce no initial TypeError type");
443 } 447 }
448 assertTrue(exception);
444 449
450 exception = false;
445 try { 451 try {
446 [].reduceRight(sum); 452 [].reduceRight(sum);
447 assertUnreachable("ReduceRight no initial value not throwing");
448 } catch (e) { 453 } catch (e) {
454 exception = true;
449 assertTrue(e instanceof TypeError, 455 assertTrue(e instanceof TypeError,
450 "reduceRight no initial value not throwing TypeError"); 456 "reduceRight no initial value not throwing TypeError");
451 assertEquals("reduce_no_initial", e.type, 457 assertEquals("reduce_no_initial", e.type,
452 "reduceRight no initial TypeError type"); 458 "reduceRight no initial TypeError type");
453 } 459 }
460 assertTrue(exception);
454 461
455 462 exception = false;
456 try { 463 try {
457 [,,,].reduce(sum); 464 [,,,].reduce(sum);
458 assertUnreachable("Reduce sparse no initial value not throwing");
459 } catch (e) { 465 } catch (e) {
466 exception = true;
460 assertTrue(e instanceof TypeError, 467 assertTrue(e instanceof TypeError,
461 "reduce sparse no initial value not throwing TypeError"); 468 "reduce sparse no initial value not throwing TypeError");
462 assertEquals("reduce_no_initial", e.type, 469 assertEquals("reduce_no_initial", e.type,
463 "reduce no initial TypeError type"); 470 "reduce no initial TypeError type");
464 } 471 }
472 assertTrue(exception);
465 473
474 exception = false;
466 try { 475 try {
467 [,,,].reduceRight(sum); 476 [,,,].reduceRight(sum);
468 assertUnreachable("ReduceRight sparse no initial value not throwing");
469 } catch (e) { 477 } catch (e) {
478 exception = true;
470 assertTrue(e instanceof TypeError, 479 assertTrue(e instanceof TypeError,
471 "reduceRight sparse no initial value not throwing TypeError"); 480 "reduceRight sparse no initial value not throwing TypeError");
472 assertEquals("reduce_no_initial", e.type, 481 assertEquals("reduce_no_initial", e.type,
473 "reduceRight no initial TypeError type"); 482 "reduceRight no initial TypeError type");
474 } 483 }
484 assertTrue(exception);
475 485
476 486
477 // Array changing length 487 // Array changing length
478 488
479 function manipulator(a, b, i, s) { 489 function manipulator(a, b, i, s) {
480 if (s.length % 2) { 490 if (s.length % 2) {
481 s[s.length * 3] = i; 491 s[s.length * 3] = i;
482 } else { 492 } else {
483 s.length = s.length >> 1; 493 s.length = s.length >> 1;
484 } 494 }
(...skipping 19 matching lines...) Expand all
504 return a + b; 514 return a + b;
505 } 515 }
506 516
507 var arr = [1, 2, 3, 4]; 517 var arr = [1, 2, 3, 4];
508 testReduce("reduce", "ArrayManipulationExtender", 10, 518 testReduce("reduce", "ArrayManipulationExtender", 10,
509 [[0, 1, 0, [1, 2, 3, 4], 1], 519 [[0, 1, 0, [1, 2, 3, 4], 1],
510 [1, 2, 1, [1, 2, 3, 4, 4], 3], 520 [1, 2, 1, [1, 2, 3, 4, 4], 3],
511 [3, 3, 2, [1, 2, 3, 4, 4, 5], 6], 521 [3, 3, 2, [1, 2, 3, 4, 4, 5], 6],
512 [6, 4, 3, [1, 2, 3, 4, 4, 5, 6], 10], 522 [6, 4, 3, [1, 2, 3, 4, 4, 5, 6], 10],
513 ], arr, extender, 0); 523 ], arr, extender, 0);
514
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/function-call.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698