Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 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 1662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1673 assertThrows(function(){ Function.prototype.apply.call(f, {}, [1]) }, "myexn") | 1673 assertThrows(function(){ Function.prototype.apply.call(f, {}, [1]) }, "myexn") |
| 1674 } | 1674 } |
| 1675 | 1675 |
| 1676 TestCallThrow(function() { throw "myexn" }) | 1676 TestCallThrow(function() { throw "myexn" }) |
| 1677 TestCallThrow(Proxy.createFunction({}, function() { throw "myexn" })) | 1677 TestCallThrow(Proxy.createFunction({}, function() { throw "myexn" })) |
| 1678 | 1678 |
| 1679 var p = Proxy.createFunction( | 1679 var p = Proxy.createFunction( |
| 1680 {fix: function() {return {}}}, function() { throw "myexn" }) | 1680 {fix: function() {return {}}}, function() { throw "myexn" }) |
| 1681 Object.freeze(p) | 1681 Object.freeze(p) |
| 1682 TestCallThrow(p) | 1682 TestCallThrow(p) |
| 1683 | |
| 1684 | |
| 1685 | |
| 1686 // TODO(rossberg): once we merge with 7799026, remove this. | |
| 1687 function createFrozen(handler, callTrap) { | |
| 1688 if (!("fix" in handler)) handler.fix = function() { return {} } | |
| 1689 var f = Proxy.createFunction(handler, callTrap) | |
| 1690 Object.freeze(f) | |
| 1691 return f | |
| 1692 } | |
| 1693 | |
| 1694 | |
| 1695 // Getters and setters. | |
| 1696 | |
| 1697 var value | |
| 1698 var receiver | |
| 1699 | |
| 1700 function TestAccessorCall(getterCallTrap, setterCallTrap) { | |
| 1701 var handler = {fix: function() { return {} }} | |
| 1702 var pgetter = Proxy.createFunction(handler, getterCallTrap) | |
| 1703 var psetter = Proxy.createFunction(handler, setterCallTrap) | |
| 1704 | |
| 1705 var o = {} | |
| 1706 var oo = Object.create(o) | |
| 1707 Object.defineProperty(o, "a", {get: pgetter, set: psetter}) | |
| 1708 Object.defineProperty(o, "b", {get: pgetter}) | |
| 1709 Object.defineProperty(o, "c", {set: psetter}) | |
| 1710 Object.defineProperty(o, "3", {get: pgetter, set: psetter}) | |
| 1711 Object.defineProperty(oo, "a", {value: 43}) | |
| 1712 | |
| 1713 receiver = "" | |
| 1714 assertEquals(42, o.a) | |
| 1715 assertSame(o, receiver) | |
| 1716 receiver = "" | |
| 1717 assertEquals(42, o.b) | |
| 1718 assertSame(o, receiver) | |
| 1719 receiver = "" | |
| 1720 assertEquals(undefined, o.c) | |
| 1721 assertSame("", receiver) | |
|
Jakob Kummerow
2011/09/22 12:23:19
This works, but you're implicitly testing an unrel
rossberg
2011/09/22 16:39:52
Done.
| |
| 1722 receiver = "" | |
| 1723 assertEquals(42, o["a"]) | |
| 1724 assertSame(o, receiver) | |
| 1725 receiver = "" | |
| 1726 // TODO(rossberg): test once we merge with elements branch | |
|
Jakob Kummerow
2011/09/22 12:23:19
nit: please indent to the same level as the surrou
rossberg
2011/09/22 16:39:52
Actually, uncommented the code, since the tests wo
| |
| 1727 // assertEquals(42, o[3]) | |
| 1728 // assertSame(o, receiver) | |
| 1729 | |
| 1730 receiver = "" | |
| 1731 assertEquals(43, oo.a) | |
| 1732 assertSame("", receiver) | |
| 1733 receiver = "" | |
| 1734 assertEquals(42, oo.b) | |
| 1735 assertSame(o, receiver) | |
| 1736 receiver = "" | |
| 1737 assertEquals(undefined, oo.c) | |
| 1738 assertSame("", receiver) | |
| 1739 receiver = "" | |
| 1740 assertEquals(43, oo["a"]) | |
| 1741 assertSame("", receiver) | |
| 1742 receiver = "" | |
| 1743 // TODO(rossberg): test once we merge with elements branch | |
| 1744 // assertEquals(42, oo[3]) | |
| 1745 // assertSame(o, receiver) | |
| 1746 | |
| 1747 receiver = "" | |
| 1748 assertEquals(50, o.a = 50) | |
| 1749 assertSame(o, receiver) | |
| 1750 assertEquals(50, value) | |
| 1751 receiver = "" | |
| 1752 assertEquals(51, o.b = 51) | |
| 1753 assertSame("", receiver) | |
| 1754 assertEquals(50, value) // no setter | |
| 1755 assertThrows(function(){ "use strict"; o.b = 51 }, TypeError) | |
|
Jakob Kummerow
2011/09/22 12:23:19
nit: space before '{'
rossberg
2011/09/22 16:39:52
Done.
| |
| 1756 receiver = "" | |
| 1757 assertEquals(52, o.c = 52) | |
| 1758 assertSame(o, receiver) | |
| 1759 assertEquals(52, value) | |
| 1760 receiver = "" | |
| 1761 assertEquals(53, o["a"] = 53) | |
| 1762 assertSame(o, receiver) | |
| 1763 assertEquals(53, value) | |
| 1764 receiver = "" | |
| 1765 assertEquals(54, o[3] = 54) | |
| 1766 // TODO(rossberg): test once we merge with elements branch | |
| 1767 // assertSame(o, receiver) | |
| 1768 // assertEquals(54, value) | |
| 1769 | |
| 1770 value = 0 | |
| 1771 receiver = "" | |
| 1772 assertEquals(60, oo.a = 60) | |
| 1773 assertSame("", receiver) | |
| 1774 assertEquals(0, value) // oo has own `a' | |
|
Jakob Kummerow
2011/09/22 12:23:19
nit: s/`/'/
rossberg
2011/09/22 16:39:52
Done.
| |
| 1775 assertEquals(61, oo.b = 61) | |
| 1776 assertSame("", receiver) | |
| 1777 assertEquals(0, value) // no setter | |
| 1778 assertThrows(function(){ "use strict"; oo.b = 61 }, TypeError) | |
|
Jakob Kummerow
2011/09/22 12:23:19
nit: space before '{'
rossberg
2011/09/22 16:39:52
Done.
| |
| 1779 receiver = "" | |
| 1780 assertEquals(62, oo.c = 62) | |
| 1781 assertSame(oo, receiver) | |
| 1782 assertEquals(62, value) | |
| 1783 receiver = "" | |
| 1784 assertEquals(63, oo["c"] = 63) | |
| 1785 assertSame(oo, receiver) | |
| 1786 assertEquals(63, value) | |
| 1787 receiver = "" | |
| 1788 assertEquals(64, oo[3] = 64) | |
| 1789 // TODO(rossberg): test once we merge with elements branch | |
| 1790 // assertSame(oo, receiver) | |
| 1791 // assertEquals(64, value) | |
| 1792 } | |
| 1793 | |
| 1794 TestAccessorCall( | |
| 1795 function() { receiver = this; return 42 }, | |
| 1796 function(x) { receiver = this; value = x } | |
| 1797 ) | |
| 1798 | |
| 1799 TestAccessorCall( | |
| 1800 function() { "use strict"; receiver = this; return 42 }, | |
| 1801 function(x) { "use strict"; receiver = this; value = x } | |
| 1802 ) | |
| 1803 | |
| 1804 TestAccessorCall( | |
| 1805 Proxy.createFunction({}, function() { receiver = this; return 42 }), | |
| 1806 Proxy.createFunction({}, function(x) { receiver = this; value = x }) | |
| 1807 ) | |
| 1808 | |
| 1809 TestAccessorCall( | |
| 1810 createFrozen({}, function() { receiver = this; return 42 }), | |
| 1811 createFrozen({}, function(x) { receiver = this; value = x }) | |
| 1812 ) | |
| OLD | NEW |