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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 [1, 2, 1, arrayPlus, 3], | 401 [1, 2, 1, arrayPlus, 3], |
402 [3, 3, 3, arrayPlus, 6], | 402 [3, 3, 3, arrayPlus, 6], |
403 ], arrayPlus, sum, 0); | 403 ], arrayPlus, sum, 0); |
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 // Test passing undefined as initial value (to test missing parameter |
| 412 // detection). |
| 413 [1].reduce((a, b) => { assertEquals(a, undefined); assertEquals(b, 1) }, |
| 414 undefined); |
| 415 [1, 2].reduce((a, b) => { assertEquals(a, 1); assertEquals(b, 2); }); |
| 416 [1].reduce((a, b) => { assertTrue(false); }); |
411 | 417 |
412 // Test error conditions: | 418 // Test error conditions: |
413 | 419 |
414 var exception = false; | 420 var exception = false; |
415 try { | 421 try { |
416 [1].reduce("not a function"); | 422 [1].reduce("not a function"); |
417 } catch (e) { | 423 } catch (e) { |
418 exception = true; | 424 exception = true; |
419 assertTrue(e instanceof TypeError, | 425 assertTrue(e instanceof TypeError, |
420 "reduce callback not a function not throwing TypeError"); | 426 "reduce callback not a function not throwing TypeError"); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 | 530 |
525 var arr = []; | 531 var arr = []; |
526 Object.defineProperty(arr, "0", { get: function() { delete this[0] }, | 532 Object.defineProperty(arr, "0", { get: function() { delete this[0] }, |
527 configurable: true }); | 533 configurable: true }); |
528 assertEquals(undefined, arr.reduce(function(val) { return val })); | 534 assertEquals(undefined, arr.reduce(function(val) { return val })); |
529 | 535 |
530 var arr = []; | 536 var arr = []; |
531 Object.defineProperty(arr, "0", { get: function() { delete this[0] }, | 537 Object.defineProperty(arr, "0", { get: function() { delete this[0] }, |
532 configurable: true}); | 538 configurable: true}); |
533 assertEquals(undefined, arr.reduceRight(function(val) { return val })); | 539 assertEquals(undefined, arr.reduceRight(function(val) { return val })); |
OLD | NEW |