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 --harmony-sloppy | 5 // Flags: --harmony-classes --harmony-sloppy |
6 | 6 |
7 (function TestBasics() { | 7 (function TestBasics() { |
8 var C = class C {} | 8 var C = class C {} |
9 assertEquals(typeof C, 'function'); | 9 assertEquals(typeof C, 'function'); |
10 assertEquals(C.__proto__, Function.prototype); | 10 assertEquals(C.__proto__, Function.prototype); |
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 | 868 |
869 class C3 extends Object { | 869 class C3 extends Object { |
870 constructor() { | 870 constructor() { |
871 ; 'use strict';;;;; | 871 ; 'use strict';;;;; |
872 // This is a comment. | 872 // This is a comment. |
873 super(); | 873 super(); |
874 } | 874 } |
875 }; | 875 }; |
876 new C3(); | 876 new C3(); |
877 }()); | 877 }()); |
| 878 |
| 879 |
| 880 function testClassRestrictedProperties(C) { |
| 881 assertEquals(false, C.hasOwnProperty("arguments")); |
| 882 assertThrows(function() { return C.arguments; }, TypeError); |
| 883 assertThrows(function() { C.arguments = {}; }, TypeError); |
| 884 |
| 885 assertEquals(false, C.hasOwnProperty("caller")); |
| 886 assertThrows(function() { return C.caller; }, TypeError); |
| 887 assertThrows(function() { C.caller = {}; }, TypeError); |
| 888 |
| 889 assertEquals(false, (new C).method.hasOwnProperty("arguments")); |
| 890 assertThrows(function() { return new C().method.arguments; }, TypeError); |
| 891 assertThrows(function() { new C().method.arguments = {}; }, TypeError); |
| 892 |
| 893 assertEquals(false, (new C).method.hasOwnProperty("caller")); |
| 894 assertThrows(function() { return new C().method.caller; }, TypeError); |
| 895 assertThrows(function() { new C().method.caller = {}; }, TypeError); |
| 896 } |
| 897 |
| 898 |
| 899 (function testRestrictedPropertiesStrict() { |
| 900 "use strict"; |
| 901 class ClassWithDefaultConstructor { |
| 902 method() {} |
| 903 } |
| 904 class Class { |
| 905 constructor() {} |
| 906 method() {} |
| 907 } |
| 908 class DerivedClassWithDefaultConstructor extends Class {} |
| 909 class DerivedClass extends Class { constructor() { super(); } } |
| 910 |
| 911 testClassRestrictedProperties(ClassWithDefaultConstructor); |
| 912 testClassRestrictedProperties(Class); |
| 913 testClassRestrictedProperties(DerivedClassWithDefaultConstructor); |
| 914 testClassRestrictedProperties(DerivedClass); |
| 915 testClassRestrictedProperties(class { method() {} }); |
| 916 testClassRestrictedProperties(class { constructor() {} method() {} }); |
| 917 testClassRestrictedProperties(class extends Class { }); |
| 918 testClassRestrictedProperties( |
| 919 class extends Class { constructor() { super(); } }); |
| 920 })(); |
| 921 |
| 922 |
| 923 (function testRestrictedPropertiesSloppy() { |
| 924 class ClassWithDefaultConstructor { |
| 925 method() {} |
| 926 } |
| 927 class Class { |
| 928 constructor() {} |
| 929 method() {} |
| 930 } |
| 931 class DerivedClassWithDefaultConstructor extends Class {} |
| 932 class DerivedClass extends Class { constructor() { super(); } } |
| 933 |
| 934 testClassRestrictedProperties(ClassWithDefaultConstructor); |
| 935 testClassRestrictedProperties(Class); |
| 936 testClassRestrictedProperties(DerivedClassWithDefaultConstructor); |
| 937 testClassRestrictedProperties(DerivedClass); |
| 938 testClassRestrictedProperties(class { method() {} }); |
| 939 testClassRestrictedProperties(class { constructor() {} method() {} }); |
| 940 testClassRestrictedProperties(class extends Class { }); |
| 941 testClassRestrictedProperties( |
| 942 class extends Class { constructor() { super(); } }); |
| 943 })(); |
OLD | NEW |