OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 Proxy.createFunction({}, function(x) { receiver = this; value = x }) | 604 Proxy.createFunction({}, function(x) { receiver = this; value = x }) |
605 ) | 605 ) |
606 | 606 |
607 TestAccessorCall( | 607 TestAccessorCall( |
608 CreateFrozen({}, function() { receiver = this; return 42 }), | 608 CreateFrozen({}, function() { receiver = this; return 42 }), |
609 CreateFrozen({}, function(x) { receiver = this; value = x }) | 609 CreateFrozen({}, function(x) { receiver = this; value = x }) |
610 ) | 610 ) |
611 | 611 |
612 | 612 |
613 | 613 |
| 614 // Passing a proxy function to higher-order library functions. |
| 615 |
| 616 function TestHigherOrder(f) { |
| 617 assertEquals(6, [6, 2].map(f)[0]) |
| 618 assertEquals(4, [5, 2].reduce(f, 4)) |
| 619 assertTrue([1, 2].some(f)) |
| 620 assertEquals("a.b.c", "a.b.c".replace(".", f)) |
| 621 } |
| 622 |
| 623 TestHigherOrder(function(x) { return x }) |
| 624 TestHigherOrder(function(x) { "use strict"; return x }) |
| 625 TestHigherOrder(Proxy.createFunction({}, function(x) { return x })) |
| 626 TestHigherOrder(CreateFrozen({}, function(x) { return x })) |
| 627 |
| 628 |
| 629 |
614 // TODO(rossberg): Ultimately, I want to have the following test function | 630 // TODO(rossberg): Ultimately, I want to have the following test function |
615 // run through, but it currently fails on so many cases (some not even | 631 // run through, but it currently fails on so many cases (some not even |
616 // involving proxies), that I leave that for later... | 632 // involving proxies), that I leave that for later... |
617 /* | 633 /* |
618 function TestCalls() { | 634 function TestCalls() { |
619 var handler = { | 635 var handler = { |
620 get: function(r, k) { | 636 get: function(r, k) { |
621 return k == "length" ? 2 : Function.prototype[k] | 637 return k == "length" ? 2 : Function.prototype[k] |
622 } | 638 } |
623 } | 639 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 } | 739 } |
724 } | 740 } |
725 } | 741 } |
726 } | 742 } |
727 } | 743 } |
728 } | 744 } |
729 } | 745 } |
730 | 746 |
731 TestCalls() | 747 TestCalls() |
732 */ | 748 */ |
OLD | NEW |