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 | 5 // Flags: --harmony |
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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 (function TestToString() { | 170 (function TestToString() { |
171 class C {} | 171 class C {} |
172 assertEquals('class C {}', C.toString()); | 172 assertEquals('class C {}', C.toString()); |
173 | 173 |
174 class D { constructor() { 42; } } | 174 class D { constructor() { 42; } } |
175 assertEquals('class D { constructor() { 42; } }', D.toString()); | 175 assertEquals('class D { constructor() { 42; } }', D.toString()); |
176 | 176 |
177 class E { x() { 42; } } | 177 class E { x() { 42; } } |
178 assertEquals('class E { x() { 42; } }', E.toString()); | 178 assertEquals('class E { x() { 42; } }', E.toString()); |
179 })(); | 179 })(); |
180 | |
Dmitry Lomov (no reviews)
2014/10/27 21:37:14
Additional tests:
1. Test that 'DefineProperty' i
arv (Not doing code reviews)
2014/10/27 22:20:53
I thought I tested that but I guess my tests where
Dmitry Lomov (no reviews)
2014/10/28 10:34:08
Acknowledged.
| |
181 | |
182 (function TestMethods() { | |
183 class C { | |
184 method() { return 1; } | |
185 static staticMethod() { return 2; } | |
186 method2() { return 3; } | |
187 static staticMethod2() { return 4; } | |
188 } | |
189 | |
190 assertEquals('function', typeof C.prototype.method); | |
191 assertEquals('function', typeof C.prototype.method2); | |
192 assertEquals('function', typeof C.staticMethod); | |
193 assertEquals('function', typeof C.staticMethod2); | |
194 | |
195 assertEquals(1, new C().method()); | |
196 assertEquals(2, C.staticMethod()); | |
197 assertEquals(3, new C().method2()); | |
198 assertEquals(4, C.staticMethod2()); | |
199 })(); | |
200 | |
201 | |
202 (function TestGetters() { | |
203 class C { | |
204 get x() { return 1; } | |
205 static get staticX() { return 2; } | |
206 get y() { return 3; } | |
207 static get staticY() { return 4; } | |
208 } | |
209 | |
210 assertTrue(C.prototype.hasOwnProperty('x')); | |
211 assertTrue(C.hasOwnProperty('staticX')); | |
212 assertTrue(C.prototype.hasOwnProperty('y')); | |
213 assertTrue(C.hasOwnProperty('staticY')); | |
214 | |
215 assertEquals(1, new C().x); | |
216 assertEquals(2, C.staticX); | |
217 assertEquals(3, new C().y); | |
218 assertEquals(4, C.staticY); | |
219 })(); | |
220 | |
221 | |
222 | |
223 (function TestSetters() { | |
224 var x, staticX, y, staticY; | |
225 class C { | |
226 set x(v) { x = v; } | |
227 static set staticX(v) { staticX = v; } | |
228 set y(v) { y = v; } | |
229 static set staticY(v) { staticY = v; } | |
230 } | |
231 | |
232 assertTrue(C.prototype.hasOwnProperty('x')); | |
233 assertTrue(C.hasOwnProperty('staticX')); | |
234 assertTrue(C.prototype.hasOwnProperty('y')); | |
235 assertTrue(C.hasOwnProperty('staticY')); | |
236 | |
237 assertEquals(1, new C().x = 1); | |
238 assertEquals(1, x); | |
239 assertEquals(2, C.staticX = 2); | |
240 assertEquals(2, staticX); | |
241 assertEquals(3, new C().y = 3); | |
242 assertEquals(3, y); | |
243 assertEquals(4, C.staticY = 4); | |
244 assertEquals(4, staticY); | |
245 })(); | |
246 | |
247 | |
248 (function TestSideEffectsInPropertyDefine() { | |
249 function B() {} | |
250 B.prototype = { | |
251 constructor: B, | |
252 set m(v) { | |
253 throw Error(); | |
254 } | |
255 }; | |
256 | |
257 class C extends B { | |
258 m() { return 1; } | |
259 } | |
260 | |
261 assertEquals(1, new C().m()); | |
262 })(); | |
263 | |
264 | |
265 (function TestAccessors() { | |
266 class C { | |
267 constructor(x) { | |
268 this._x = x; | |
269 } | |
270 | |
271 get x() { return this._x; } | |
272 set x(v) { this._x = v; } | |
273 | |
274 static get staticX() { return this._x; } | |
275 static set staticX(v) { this._x = v; } | |
276 } | |
277 | |
278 assertTrue(C.prototype.hasOwnProperty('x')); | |
279 assertTrue(C.hasOwnProperty('staticX')); | |
280 | |
281 var c = new C(1); | |
282 c._x = 1; | |
283 assertEquals(1, c.x); | |
284 c.x = 2; | |
285 assertEquals(2, c._x); | |
286 | |
287 C._x = 3; | |
288 assertEquals(3, C.staticX); | |
289 C._x = 4; | |
290 assertEquals(4, C.staticX ); | |
291 })(); | |
292 | |
293 | |
294 (function TestProto() { | |
295 class C { | |
296 __proto__() { return 1; } | |
297 } | |
298 var descr = Object.getOwnPropertyDescriptor(C.prototype, '__proto__'); | |
299 assertTrue(descr.configurable); | |
300 assertTrue(descr.enumerable); | |
301 assertTrue(descr.writable); | |
302 assertEquals('function', typeof descr.value); | |
303 assertEquals(1, descr.value()); | |
304 assertEquals(1, C.prototype.__proto__()); | |
305 assertEquals(1, new C().__proto__()); | |
306 })(); | |
307 | |
308 | |
309 (function TestProtoStatic() { | |
310 class C { | |
311 static __proto__() { return 1; } | |
312 } | |
313 var descr = Object.getOwnPropertyDescriptor(C, '__proto__'); | |
314 assertTrue(descr.configurable); | |
315 assertTrue(descr.enumerable); | |
316 assertTrue(descr.writable); | |
317 assertEquals('function', typeof descr.value); | |
318 assertEquals(1, descr.value()); | |
319 assertEquals(1, C.__proto__()); | |
320 })(); | |
321 | |
322 | |
323 (function TestProtoAccessor() { | |
324 class C { | |
325 get __proto__() { return this._p; } | |
326 set __proto__(v) { this._p = v; } | |
327 } | |
328 var descr = Object.getOwnPropertyDescriptor(C.prototype, '__proto__'); | |
329 assertTrue(descr.configurable); | |
330 assertTrue(descr.enumerable); | |
331 assertEquals('function', typeof descr.get); | |
332 assertEquals('function', typeof descr.set); | |
333 var c = new C(); | |
334 c._p = 1; | |
335 assertEquals(1, c.__proto__); | |
336 c.__proto__ = 2; | |
337 assertEquals(2, c.__proto__); | |
338 })(); | |
339 | |
340 | |
341 (function TestStaticProtoAccessor() { | |
342 class C { | |
343 static get __proto__() { return this._p; } | |
344 static set __proto__(v) { this._p = v; } | |
345 } | |
346 var descr = Object.getOwnPropertyDescriptor(C, '__proto__'); | |
347 assertTrue(descr.configurable); | |
348 assertTrue(descr.enumerable); | |
349 assertEquals('function', typeof descr.get); | |
350 assertEquals('function', typeof descr.set); | |
351 C._p = 1; | |
352 assertEquals(1, C.__proto__); | |
353 C.__proto__ = 2; | |
354 assertEquals(2, C.__proto__); | |
355 })(); | |
OLD | NEW |