| 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 // Flags: --harmony-computed-property-names --harmony-classes | 7 // Flags: --harmony-computed-property-names --harmony-classes |
| 8 | 8 |
| 9 | 9 |
| 10 function ID(x) { | 10 function ID(x) { |
| 11 return x; | 11 return x; |
| 12 } | 12 } |
| 13 | 13 |
| 14 | 14 |
| 15 (function TestClassMethodString() { | 15 (function TestClassMethodString() { |
| 16 class C { | 16 class C { |
| 17 a() { return 'A'} | 17 a() { return 'A'} |
| 18 ['b']() { return 'B'; } | 18 ['b']() { return 'B'; } |
| 19 c() { return 'C'; } | 19 c() { return 'C'; } |
| 20 [ID('d')]() { return 'D'; } | 20 [ID('d')]() { return 'D'; } |
| 21 } | 21 } |
| 22 assertEquals('A', new C().a()); | 22 assertEquals('A', new C().a()); |
| 23 assertEquals('B', new C().b()); | 23 assertEquals('B', new C().b()); |
| 24 assertEquals('C', new C().c()); | 24 assertEquals('C', new C().c()); |
| 25 assertEquals('D', new C().d()); | 25 assertEquals('D', new C().d()); |
| 26 assertArrayEquals(['a', 'b', 'c', 'd'], Object.keys(C.prototype)); | 26 assertArrayEquals([], Object.keys(C.prototype)); |
| 27 assertArrayEquals(['constructor', 'a', 'b', 'c', 'd'], |
| 28 Object.getOwnPropertyNames(C.prototype)); |
| 27 })(); | 29 })(); |
| 28 | 30 |
| 29 | 31 |
| 30 (function TestClassMethodNumber() { | 32 (function TestClassMethodNumber() { |
| 31 class C { | 33 class C { |
| 32 a() { return 'A'; } | 34 a() { return 'A'; } |
| 33 [1]() { return 'B'; } | 35 [1]() { return 'B'; } |
| 34 c() { return 'C'; } | 36 c() { return 'C'; } |
| 35 [ID(2)]() { return 'D'; } | 37 [ID(2)]() { return 'D'; } |
| 36 } | 38 } |
| 37 assertEquals('A', new C().a()); | 39 assertEquals('A', new C().a()); |
| 38 assertEquals('B', new C()[1]()); | 40 assertEquals('B', new C()[1]()); |
| 39 assertEquals('C', new C().c()); | 41 assertEquals('C', new C().c()); |
| 40 assertEquals('D', new C()[2]()); | 42 assertEquals('D', new C()[2]()); |
| 41 // Array indexes first. | 43 // Array indexes first. |
| 42 assertArrayEquals(['1', '2', 'a', 'c'], Object.keys(C.prototype)); | 44 assertArrayEquals([], Object.keys(C.prototype)); |
| 45 assertArrayEquals(['1', '2', 'constructor', 'a', 'c'], |
| 46 Object.getOwnPropertyNames(C.prototype)); |
| 43 })(); | 47 })(); |
| 44 | 48 |
| 45 | 49 |
| 46 (function TestClassMethodSymbol() { | 50 (function TestClassMethodSymbol() { |
| 47 var sym1 = Symbol(); | 51 var sym1 = Symbol(); |
| 48 var sym2 = Symbol(); | 52 var sym2 = Symbol(); |
| 49 class C { | 53 class C { |
| 50 a() { return 'A'; } | 54 a() { return 'A'; } |
| 51 [sym1]() { return 'B'; } | 55 [sym1]() { return 'B'; } |
| 52 c() { return 'C'; } | 56 c() { return 'C'; } |
| 53 [ID(sym2)]() { return 'D'; } | 57 [ID(sym2)]() { return 'D'; } |
| 54 } | 58 } |
| 55 assertEquals('A', new C().a()); | 59 assertEquals('A', new C().a()); |
| 56 assertEquals('B', new C()[sym1]()); | 60 assertEquals('B', new C()[sym1]()); |
| 57 assertEquals('C', new C().c()); | 61 assertEquals('C', new C().c()); |
| 58 assertEquals('D', new C()[sym2]()); | 62 assertEquals('D', new C()[sym2]()); |
| 59 assertArrayEquals(['a', 'c'], Object.keys(C.prototype)); | 63 assertArrayEquals([], Object.keys(C.prototype)); |
| 64 assertArrayEquals(['constructor', 'a', 'c'], |
| 65 Object.getOwnPropertyNames(C.prototype)); |
| 60 assertArrayEquals([sym1, sym2], Object.getOwnPropertySymbols(C.prototype)); | 66 assertArrayEquals([sym1, sym2], Object.getOwnPropertySymbols(C.prototype)); |
| 61 })(); | 67 })(); |
| 62 | 68 |
| 63 | 69 |
| 64 | 70 |
| 65 (function TestStaticClassMethodString() { | 71 (function TestStaticClassMethodString() { |
| 66 class C { | 72 class C { |
| 67 static a() { return 'A'} | 73 static a() { return 'A'} |
| 68 static ['b']() { return 'B'; } | 74 static ['b']() { return 'B'; } |
| 69 static c() { return 'C'; } | 75 static c() { return 'C'; } |
| 70 static ['d']() { return 'D'; } | 76 static ['d']() { return 'D'; } |
| 71 } | 77 } |
| 72 assertEquals('A', C.a()); | 78 assertEquals('A', C.a()); |
| 73 assertEquals('B', C.b()); | 79 assertEquals('B', C.b()); |
| 74 assertEquals('C', C.c()); | 80 assertEquals('C', C.c()); |
| 75 assertEquals('D', C.d()); | 81 assertEquals('D', C.d()); |
| 76 assertArrayEquals(['a', 'b', 'c', 'd'], Object.keys(C)); | 82 assertArrayEquals([], Object.keys(C)); |
| 83 // TODO(arv): It is not clear that we are adding the "standard" properties |
| 84 // in the right order. As far as I can tell the spec adds them in alphabetical |
| 85 // order. |
| 86 assertArrayEquals(['length', 'name', 'arguments', 'caller', 'prototype', |
| 87 'a', 'b', 'c', 'd'], |
| 88 Object.getOwnPropertyNames(C)); |
| 77 })(); | 89 })(); |
| 78 | 90 |
| 79 | 91 |
| 80 (function TestStaticClassMethodNumber() { | 92 (function TestStaticClassMethodNumber() { |
| 81 class C { | 93 class C { |
| 82 static a() { return 'A'; } | 94 static a() { return 'A'; } |
| 83 static [1]() { return 'B'; } | 95 static [1]() { return 'B'; } |
| 84 static c() { return 'C'; } | 96 static c() { return 'C'; } |
| 85 static [2]() { return 'D'; } | 97 static [2]() { return 'D'; } |
| 86 } | 98 } |
| 87 assertEquals('A', C.a()); | 99 assertEquals('A', C.a()); |
| 88 assertEquals('B', C[1]()); | 100 assertEquals('B', C[1]()); |
| 89 assertEquals('C', C.c()); | 101 assertEquals('C', C.c()); |
| 90 assertEquals('D', C[2]()); | 102 assertEquals('D', C[2]()); |
| 91 // Array indexes first. | 103 // Array indexes first. |
| 92 assertArrayEquals(['1', '2', 'a', 'c'], Object.keys(C)); | 104 assertArrayEquals([], Object.keys(C)); |
| 105 assertArrayEquals(['1', '2', 'length', 'name', 'arguments', 'caller', |
| 106 'prototype', 'a', 'c'], Object.getOwnPropertyNames(C)); |
| 93 })(); | 107 })(); |
| 94 | 108 |
| 95 | 109 |
| 96 (function TestStaticClassMethodSymbol() { | 110 (function TestStaticClassMethodSymbol() { |
| 97 var sym1 = Symbol(); | 111 var sym1 = Symbol(); |
| 98 var sym2 = Symbol(); | 112 var sym2 = Symbol(); |
| 99 class C { | 113 class C { |
| 100 static a() { return 'A'; } | 114 static a() { return 'A'; } |
| 101 static [sym1]() { return 'B'; } | 115 static [sym1]() { return 'B'; } |
| 102 static c() { return 'C'; } | 116 static c() { return 'C'; } |
| 103 static [sym2]() { return 'D'; } | 117 static [sym2]() { return 'D'; } |
| 104 } | 118 } |
| 105 assertEquals('A', C.a()); | 119 assertEquals('A', C.a()); |
| 106 assertEquals('B', C[sym1]()); | 120 assertEquals('B', C[sym1]()); |
| 107 assertEquals('C', C.c()); | 121 assertEquals('C', C.c()); |
| 108 assertEquals('D', C[sym2]()); | 122 assertEquals('D', C[sym2]()); |
| 109 assertArrayEquals(['a', 'c'], Object.keys(C)); | 123 assertArrayEquals([], Object.keys(C)); |
| 124 assertArrayEquals(['length', 'name', 'arguments', 'caller', 'prototype', |
| 125 'a', 'c'], |
| 126 Object.getOwnPropertyNames(C)); |
| 110 assertArrayEquals([sym1, sym2], Object.getOwnPropertySymbols(C)); | 127 assertArrayEquals([sym1, sym2], Object.getOwnPropertySymbols(C)); |
| 111 })(); | 128 })(); |
| 112 | 129 |
| 113 | 130 |
| 114 | 131 |
| 115 function assertIteratorResult(value, done, result) { | 132 function assertIteratorResult(value, done, result) { |
| 116 assertEquals({ value: value, done: done}, result); | 133 assertEquals({ value: value, done: done}, result); |
| 117 } | 134 } |
| 118 | 135 |
| 119 | 136 |
| 120 (function TestGeneratorComputedName() { | 137 (function TestGeneratorComputedName() { |
| 121 class C { | 138 class C { |
| 122 *['a']() { | 139 *['a']() { |
| 123 yield 1; | 140 yield 1; |
| 124 yield 2; | 141 yield 2; |
| 125 } | 142 } |
| 126 } | 143 } |
| 127 var iter = new C().a(); | 144 var iter = new C().a(); |
| 128 assertIteratorResult(1, false, iter.next()); | 145 assertIteratorResult(1, false, iter.next()); |
| 129 assertIteratorResult(2, false, iter.next()); | 146 assertIteratorResult(2, false, iter.next()); |
| 130 assertIteratorResult(undefined, true, iter.next()); | 147 assertIteratorResult(undefined, true, iter.next()); |
| 131 assertArrayEquals(['a'], Object.keys(C.prototype)); | 148 assertArrayEquals([], Object.keys(C.prototype)); |
| 149 assertArrayEquals(['constructor', 'a'], |
| 150 Object.getOwnPropertyNames(C.prototype)); |
| 132 })(); | 151 })(); |
| 133 | 152 |
| 134 | 153 |
| 135 (function TestToNameSideEffects() { | 154 (function TestToNameSideEffects() { |
| 136 var counter = 0; | 155 var counter = 0; |
| 137 var key1 = { | 156 var key1 = { |
| 138 toString: function() { | 157 toString: function() { |
| 139 assertEquals(0, counter++); | 158 assertEquals(0, counter++); |
| 140 return 'b'; | 159 return 'b'; |
| 141 } | 160 } |
| 142 }; | 161 }; |
| 143 var key2 = { | 162 var key2 = { |
| 144 toString: function() { | 163 toString: function() { |
| 145 assertEquals(1, counter++); | 164 assertEquals(1, counter++); |
| 146 return 'd'; | 165 return 'd'; |
| 147 } | 166 } |
| 148 }; | 167 }; |
| 149 class C { | 168 class C { |
| 150 a() { return 'A'; } | 169 a() { return 'A'; } |
| 151 [key1]() { return 'B'; } | 170 [key1]() { return 'B'; } |
| 152 c() { return 'C'; } | 171 c() { return 'C'; } |
| 153 [key2]() { return 'D'; } | 172 [key2]() { return 'D'; } |
| 154 } | 173 } |
| 155 assertEquals(2, counter); | 174 assertEquals(2, counter); |
| 156 assertEquals('A', new C().a()); | 175 assertEquals('A', new C().a()); |
| 157 assertEquals('B', new C().b()); | 176 assertEquals('B', new C().b()); |
| 158 assertEquals('C', new C().c()); | 177 assertEquals('C', new C().c()); |
| 159 assertEquals('D', new C().d()); | 178 assertEquals('D', new C().d()); |
| 160 assertArrayEquals(['a', 'b', 'c', 'd'], Object.keys(C.prototype)); | 179 assertArrayEquals([], Object.keys(C.prototype)); |
| 180 assertArrayEquals(['constructor', 'a', 'b', 'c', 'd'], |
| 181 Object.getOwnPropertyNames(C.prototype)); |
| 161 })(); | 182 })(); |
| 162 | 183 |
| 163 | 184 |
| 164 (function TestToNameSideEffectsNumbers() { | 185 (function TestToNameSideEffectsNumbers() { |
| 165 var counter = 0; | 186 var counter = 0; |
| 166 var key1 = { | 187 var key1 = { |
| 167 valueOf: function() { | 188 valueOf: function() { |
| 168 assertEquals(0, counter++); | 189 assertEquals(0, counter++); |
| 169 return 1; | 190 return 1; |
| 170 }, | 191 }, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 183 [key1]() { return 'B'; } | 204 [key1]() { return 'B'; } |
| 184 c() { return 'C'; } | 205 c() { return 'C'; } |
| 185 [key2]() { return 'D'; } | 206 [key2]() { return 'D'; } |
| 186 } | 207 } |
| 187 assertEquals(2, counter); | 208 assertEquals(2, counter); |
| 188 assertEquals('A', new C().a()); | 209 assertEquals('A', new C().a()); |
| 189 assertEquals('B', new C()[1]()); | 210 assertEquals('B', new C()[1]()); |
| 190 assertEquals('C', new C().c()); | 211 assertEquals('C', new C().c()); |
| 191 assertEquals('D', new C()[2]()); | 212 assertEquals('D', new C()[2]()); |
| 192 // Array indexes first. | 213 // Array indexes first. |
| 193 assertArrayEquals(['1', '2', 'a', 'c'], Object.keys(C.prototype)); | 214 assertArrayEquals([], Object.keys(C.prototype)); |
| 215 assertArrayEquals(['1', '2', 'constructor', 'a', 'c'], |
| 216 Object.getOwnPropertyNames(C.prototype)); |
| 194 })(); | 217 })(); |
| 195 | 218 |
| 196 | 219 |
| 197 (function TestGetter() { | 220 (function TestGetter() { |
| 198 class C { | 221 class C { |
| 199 get ['a']() { | 222 get ['a']() { |
| 200 return 'A'; | 223 return 'A'; |
| 201 } | 224 } |
| 202 } | 225 } |
| 203 assertEquals('A', new C().a); | 226 assertEquals('A', new C().a); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 *['constructor']() { | 381 *['constructor']() { |
| 359 yield 1; | 382 yield 1; |
| 360 yield 2; | 383 yield 2; |
| 361 } | 384 } |
| 362 } | 385 } |
| 363 var iter = new C4().constructor(); | 386 var iter = new C4().constructor(); |
| 364 assertIteratorResult(1, false, iter.next()); | 387 assertIteratorResult(1, false, iter.next()); |
| 365 assertIteratorResult(2, false, iter.next()); | 388 assertIteratorResult(2, false, iter.next()); |
| 366 assertIteratorResult(undefined, true, iter.next()); | 389 assertIteratorResult(undefined, true, iter.next()); |
| 367 })(); | 390 })(); |
| OLD | NEW |