| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // Flags: --harmony-classes | 5 // Flags: --harmony-classes |
| 6 | 6 |
| 7 | 7 |
| 8 (function TestSuperNamedLoads() { | 8 (function TestSuperNamedLoads() { |
| 9 function Base() { } | 9 function Base() { } |
| 10 function Derived() { | 10 function Derived() { |
| (...skipping 1717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1728 try { super[x] = 10; } catch(e) { ex = e; } | 1728 try { super[x] = 10; } catch(e) { ex = e; } |
| 1729 assertTrue(ex instanceof TypeError); | 1729 assertTrue(ex instanceof TypeError); |
| 1730 assertEquals(27, super[x]); | 1730 assertEquals(27, super[x]); |
| 1731 assertEquals(27, this[x]); | 1731 assertEquals(27, this[x]); |
| 1732 }.toMethod(Derived.prototype); | 1732 }.toMethod(Derived.prototype); |
| 1733 new Derived().mSloppy(); | 1733 new Derived().mSloppy(); |
| 1734 new Derived().mStrict(); | 1734 new Derived().mStrict(); |
| 1735 }()); | 1735 }()); |
| 1736 | 1736 |
| 1737 | 1737 |
| 1738 function Subclass(base, constructor) { | 1738 (function TestSuperCall() { |
| 1739 var homeObject = { | 1739 function Subclass(base, constructor) { |
| 1740 __proto__: base.prototype, | 1740 var homeObject = { |
| 1741 constructor: constructor | 1741 __proto__: base.prototype, |
| 1742 }; | 1742 constructor: constructor |
| 1743 constructor.__proto__ = base; | 1743 }; |
| 1744 constructor.prototype = homeObject; | 1744 constructor.__proto__ = base; |
| 1745 // not doing toMethod: home object is not required for | 1745 constructor.prototype = homeObject; |
| 1746 // super constructor calls. | 1746 // not doing toMethod: home object is not required for |
| 1747 return constructor; | 1747 // super constructor calls. |
| 1748 } | 1748 return constructor; |
| 1749 } |
| 1749 | 1750 |
| 1750 (function TestSuperCall() { | |
| 1751 var baseCalled = 0; | 1751 var baseCalled = 0; |
| 1752 var derivedCalled = 0; | 1752 var derivedCalled = 0; |
| 1753 var derivedDerivedCalled = 0; | 1753 var derivedDerivedCalled = 0; |
| 1754 | 1754 |
| 1755 function Base() { | 1755 function Base() { |
| 1756 baseCalled++; | 1756 baseCalled++; |
| 1757 } | 1757 } |
| 1758 | 1758 |
| 1759 var Derived = Subclass(Base, function () { | 1759 var Derived = Subclass(Base, function () { |
| 1760 super(); | 1760 super(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1812 } | 1812 } |
| 1813 F.__proto__ = G; | 1813 F.__proto__ = G; |
| 1814 new F(); | 1814 new F(); |
| 1815 assertEquals(1, calls); | 1815 assertEquals(1, calls); |
| 1816 F.__proto__ = function() {}; | 1816 F.__proto__ = function() {}; |
| 1817 new F(); | 1817 new F(); |
| 1818 assertEquals(1, calls); | 1818 assertEquals(1, calls); |
| 1819 }()); | 1819 }()); |
| 1820 | 1820 |
| 1821 | 1821 |
| 1822 (function TestNewSuper() { | |
| 1823 var baseCalled = 0; | |
| 1824 var derivedCalled = 0; | |
| 1825 | |
| 1826 function Base() { | |
| 1827 baseCalled++; | |
| 1828 this.x = 15; | |
| 1829 } | |
| 1830 | |
| 1831 | |
| 1832 var Derived = Subclass(Base, function() { | |
| 1833 baseCalled = 0; | |
| 1834 var b = new super(); | |
| 1835 assertEquals(1, baseCalled) | |
| 1836 assertEquals(Base.prototype, b.__proto__); | |
| 1837 assertEquals(15, b.x); | |
| 1838 assertEquals(undefined, this.x); | |
| 1839 derivedCalled++; | |
| 1840 }); | |
| 1841 | |
| 1842 derivedCalled = 0; | |
| 1843 new Derived(); | |
| 1844 assertEquals(1, derivedCalled); | |
| 1845 }()); | |
| 1846 | |
| 1847 | |
| 1848 (function TestSuperCallErrorCases() { | 1822 (function TestSuperCallErrorCases() { |
| 1849 function T() { | 1823 function T() { |
| 1850 super(); | 1824 super(); |
| 1851 } | 1825 } |
| 1852 T.__proto__ = null; | 1826 T.__proto__ = null; |
| 1853 // Spec says ReferenceError here, but for other IsCallable failures | 1827 // Spec says ReferenceError here, but for other IsCallable failures |
| 1854 // we throw TypeError. | 1828 // we throw TypeError. |
| 1855 // Filed https://bugs.ecmascript.org/show_bug.cgi?id=3282 | 1829 // Filed https://bugs.ecmascript.org/show_bug.cgi?id=3282 |
| 1856 assertThrows(function() { new T(); }, TypeError); | 1830 assertThrows(function() { new T(); }, TypeError); |
| 1857 | |
| 1858 function T1() { | |
| 1859 var b = new super(); | |
| 1860 } | |
| 1861 T1.__proto = null; | |
| 1862 assertThrows(function() { new T1(); }, TypeError); | |
| 1863 }()); | 1831 }()); |
| OLD | NEW |