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 --allow-natives-syntax | 5 // Flags: --harmony-classes --allow-natives-syntax |
6 | 6 |
7 (function TestSuperNamedLoads() { | 7 (function TestSuperNamedLoads() { |
8 function Base() { } | 8 function Base() { } |
9 function fBase() { } | 9 function fBase() { } |
10 Base.prototype = { | 10 Base.prototype = { |
(...skipping 1800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1811 constructor(v1, v2) { | 1811 constructor(v1, v2) { |
1812 super(v1); | 1812 super(v1); |
1813 this.fromDerived = v2; | 1813 this.fromDerived = v2; |
1814 } | 1814 } |
1815 } | 1815 } |
1816 | 1816 |
1817 var d = new Derived2("base", "derived"); | 1817 var d = new Derived2("base", "derived"); |
1818 assertEquals("base", d.fromBase); | 1818 assertEquals("base", d.fromBase); |
1819 assertEquals("derived", d.fromDerived); | 1819 assertEquals("derived", d.fromDerived); |
1820 | 1820 |
1821 class ImplicitSubclassOfFunction { | |
1822 constructor() { | |
1823 super(); | |
1824 this.x = 123; | |
1825 } | |
1826 } | |
1827 | |
1828 var o = new ImplicitSubclassOfFunction(); | |
1829 assertEquals(123, o.x); | |
1830 | |
1831 var calls = 0; | 1821 var calls = 0; |
1832 class G { | 1822 class G { |
1833 constructor() { | 1823 constructor() { |
1834 calls++; | 1824 calls++; |
1835 } | 1825 } |
1836 } | 1826 } |
1837 class F { | 1827 class F extends Object { |
1838 constructor() { | 1828 constructor() { |
1839 super(); | 1829 super(); |
1840 } | 1830 } |
1841 } | 1831 } |
1842 F.__proto__ = G; | 1832 F.__proto__ = G; |
1843 new F(); | 1833 new F(); |
1844 assertEquals(1, calls); | 1834 assertEquals(1, calls); |
1845 F.__proto__ = function() {}; | 1835 F.__proto__ = function() {}; |
1846 new F(); | 1836 new F(); |
1847 assertEquals(1, calls); | 1837 assertEquals(1, calls); |
1848 }()); | 1838 }()); |
1849 | 1839 |
1850 | 1840 |
1851 (function TestSuperCallErrorCases() { | 1841 (function TestSuperCallErrorCases() { |
1852 'use strict'; | 1842 'use strict'; |
1853 class T { | 1843 class T extends Object { |
1854 constructor() { | 1844 constructor() { |
1855 super(); | 1845 super(); |
1856 } | 1846 } |
1857 } | 1847 } |
1858 | 1848 |
1859 T.__proto__ = null; | 1849 T.__proto__ = null; |
1860 assertThrows(function() { new T(); }, TypeError); | 1850 assertThrows(function() { new T(); }, TypeError); |
1861 }()); | 1851 }()); |
1862 | |
1863 | |
1864 (function TestSuperCallSyntacticRestriction() { | |
Dmitry Lomov (no reviews)
2015/02/12 16:25:25
These tests are a duplicate of tests in 'classes.j
| |
1865 'use strict'; | |
1866 assertThrows(function() { | |
1867 class C { | |
1868 constructor() { | |
1869 super(this.x); | |
1870 } | |
1871 } | |
1872 new C(); | |
1873 }, TypeError); | |
1874 assertThrows(function() { | |
1875 class C { | |
1876 constructor() { | |
1877 super(this); | |
1878 } | |
1879 } | |
1880 new C(); | |
1881 }, TypeError); | |
1882 assertThrows(function() { | |
1883 class C { | |
1884 constructor() { | |
1885 super(1, 2, Object.getPrototypeOf(this)); | |
1886 } | |
1887 } | |
1888 new C(); | |
1889 }, TypeError); | |
1890 assertThrows(function() { | |
1891 class C { | |
1892 constructor() { | |
1893 { super(1, 2); } | |
1894 } | |
1895 } | |
1896 new C(); | |
1897 }, TypeError); | |
1898 assertThrows(function() { | |
1899 class C { | |
1900 constructor() { | |
1901 if (1) super(); | |
1902 } | |
1903 } | |
1904 new C(); | |
1905 }, TypeError); | |
1906 | |
1907 class C1 { | |
1908 constructor() { | |
1909 'use strict'; | |
1910 super(); | |
1911 } | |
1912 } | |
1913 new C1(); | |
1914 | |
1915 class C2 { | |
1916 constructor() { | |
1917 ; 'use strict';;;;; | |
1918 super(); | |
1919 } | |
1920 } | |
1921 new C2(); | |
1922 | |
1923 class C3 { | |
1924 constructor() { | |
1925 ; 'use strict';;;;; | |
1926 // This is a comment. | |
1927 super(); | |
1928 } | |
1929 } | |
1930 new C3(); | |
1931 }()); | |
OLD | NEW |