OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // Flags: --harmony-class-fields |
| 6 |
| 7 // ASI |
| 8 |
| 9 { |
| 10 class C { |
| 11 a = 0 |
| 12 b(){} |
| 13 } |
| 14 |
| 15 let c = new C; |
| 16 assertArrayEquals(['constructor', 'b'], Object.getOwnPropertyNames(C.prototype
)); |
| 17 assertArrayEquals(['a'], Object.getOwnPropertyNames(c)); |
| 18 } |
| 19 |
| 20 { |
| 21 class C { |
| 22 a |
| 23 b(){} |
| 24 } |
| 25 |
| 26 let c = new C; |
| 27 assertArrayEquals(['constructor', 'b'], Object.getOwnPropertyNames(C.prototype
)); |
| 28 assertArrayEquals(['a'], Object.getOwnPropertyNames(c)); |
| 29 } |
| 30 |
| 31 { |
| 32 class C { |
| 33 a |
| 34 b |
| 35 } |
| 36 |
| 37 let c = new C; |
| 38 assertArrayEquals(['constructor'], Object.getOwnPropertyNames(C.prototype)); |
| 39 assertArrayEquals(['a', 'b'], Object.getOwnPropertyNames(c)); |
| 40 } |
| 41 |
| 42 { |
| 43 class C { |
| 44 a |
| 45 *b(){} |
| 46 } |
| 47 |
| 48 let c = new C; |
| 49 assertArrayEquals(['constructor', 'b'], Object.getOwnPropertyNames(C.prototype
)); |
| 50 assertArrayEquals(['a'], Object.getOwnPropertyNames(c)); |
| 51 } |
| 52 |
| 53 { |
| 54 class C { |
| 55 a |
| 56 ['b'](){} |
| 57 } |
| 58 |
| 59 let c = new C; |
| 60 assertArrayEquals(['constructor', 'b'], Object.getOwnPropertyNames(C.prototype
)); |
| 61 assertArrayEquals(['a'], Object.getOwnPropertyNames(c)); |
| 62 } |
| 63 |
| 64 { |
| 65 class C { // a property named 'a' and a property named 'get' |
| 66 a |
| 67 get |
| 68 } |
| 69 |
| 70 let c = new C; |
| 71 assertArrayEquals(['constructor'], Object.getOwnPropertyNames(C.prototype)); |
| 72 assertArrayEquals(['a', 'get'], Object.getOwnPropertyNames(c)); |
| 73 } |
| 74 |
| 75 { |
| 76 class C { |
| 77 get |
| 78 *a(){} |
| 79 } |
| 80 |
| 81 let c = new C; |
| 82 assertArrayEquals(['constructor', 'a'], Object.getOwnPropertyNames(C.prototype
)); |
| 83 assertArrayEquals(['get'], Object.getOwnPropertyNames(c)); |
| 84 } |
| 85 |
| 86 { |
| 87 class C { // a single static property named 'a' |
| 88 static |
| 89 a |
| 90 } |
| 91 |
| 92 let c = new C; |
| 93 //assertArrayEquals(['length', 'name', 'prototype', 'a'], Object.getOwnPropert
yNames(C)); // TODO(bakkot) re-enable once no longer using fields to communicate |
| 94 assertArrayEquals([], Object.getOwnPropertyNames(c)); |
| 95 } |
| 96 |
| 97 { |
| 98 class C { // a property named 'a' and a property named 'static' |
| 99 a |
| 100 static |
| 101 } |
| 102 |
| 103 let c = new C; |
| 104 //assertArrayEquals(['length', 'name', 'prototype'], Object.getOwnPropertyName
s(C)); // TODO(bakkot) re-enable once no longer using fields to communicate |
| 105 assertArrayEquals(['a', 'static'], Object.getOwnPropertyNames(c)); |
| 106 } |
| 107 |
| 108 |
| 109 // ASI non-examples / errors |
| 110 |
| 111 assertThrows(() => eval(` |
| 112 class C { a b } |
| 113 `)); // There is no line terminator after 'a', so ASI does not occur |
| 114 |
| 115 assertThrows(() => eval(` |
| 116 class C { |
| 117 a = 0 |
| 118 *b(){} |
| 119 } |
| 120 `)); // '*' may follow 0 in an AssignmentExpression, so no ASI occurs after 0 |
| 121 |
| 122 assertThrows(() => eval(` |
| 123 class C { |
| 124 a = 0 |
| 125 ['b'](){} |
| 126 } |
| 127 `)); // '[' may follow 0 in an AssignmentExpression, so no ASI occurs after 0 |
| 128 |
| 129 assertThrows(() => eval(` |
| 130 class C { |
| 131 get |
| 132 a |
| 133 } |
| 134 `)); // 'a' may follow 'get' in a MethodDefinition, so no ASI occurs after 'get' |
| 135 |
| 136 |
| 137 // Forbid static properties named 'prototype' |
| 138 |
| 139 // assertThrows(() => eval(` |
| 140 // class C { |
| 141 // static prototype; |
| 142 // } |
| 143 // `), SyntaxError); // TODO(bakkot) re-enable once this restriction is spec'd a
nd added |
| 144 |
| 145 // assertThrows(() => eval(` |
| 146 // class C { |
| 147 // static prototype; |
| 148 // } |
| 149 // `), TypeError); // TODO(bakkot) re-enable once this restriction is spec'd and
added |
| 150 |
| 151 |
| 152 // Non-examples |
| 153 |
| 154 { |
| 155 class C { // a getter for 'a' on C.prototype; this is pre-existing syntax |
| 156 get |
| 157 a(){} |
| 158 } |
| 159 |
| 160 let c = new C; |
| 161 assertTrue(Object.getOwnPropertyDescriptor(C.prototype, 'a').hasOwnProperty('g
et')); |
| 162 assertArrayEquals([], Object.getOwnPropertyNames(c)); |
| 163 } |
OLD | NEW |