| 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); |
| 11 assertEquals(Object.prototype, Object.getPrototypeOf(C.prototype)); | 11 assertEquals(Object.prototype, Object.getPrototypeOf(C.prototype)); |
| 12 assertEquals(Function.prototype, Object.getPrototypeOf(C)); | 12 assertEquals(Function.prototype, Object.getPrototypeOf(C)); |
| 13 assertEquals('C', C.name); | 13 assertEquals('C', C.name); |
| 14 | 14 |
| 15 class D {} | 15 class D {} |
| 16 assertEquals(typeof D, 'function'); | 16 assertEquals(typeof D, 'function'); |
| 17 assertEquals(D.__proto__, Function.prototype); | 17 assertEquals(D.__proto__, Function.prototype); |
| 18 assertEquals(Object.prototype, Object.getPrototypeOf(D.prototype)); | 18 assertEquals(Object.prototype, Object.getPrototypeOf(D.prototype)); |
| 19 assertEquals(Function.prototype, Object.getPrototypeOf(D)); | 19 assertEquals(Function.prototype, Object.getPrototypeOf(D)); |
| 20 assertEquals('D', D.name); | 20 assertEquals('D', D.name); |
| 21 | 21 |
| 22 class D2 { constructor() {} } |
| 23 assertEquals('D2', D2.name); |
| 24 |
| 25 class D3 {} |
| 26 class D4 {} |
| 27 assertEquals('D3', D3.name); |
| 28 assertEquals('D4', D4.name); |
| 29 |
| 30 // TODO(arv): The logic for the name of anonymous functions in ES6 requires |
| 31 // the below to be 'E'; |
| 22 var E = class {} | 32 var E = class {} |
| 23 assertEquals('', E.name); | 33 assertEquals('', E.name); // Should be 'E'. |
| 34 |
| 35 var F = class { constructor() {} }; |
| 36 assertEquals('', F.name); // Should be 'F'. |
| 24 })(); | 37 })(); |
| 25 | 38 |
| 26 | 39 |
| 27 (function TestBasicsExtends() { | 40 (function TestBasicsExtends() { |
| 28 class C extends null {} | 41 class C extends null {} |
| 29 assertEquals(typeof C, 'function'); | 42 assertEquals(typeof C, 'function'); |
| 30 assertEquals(C.__proto__, Function.prototype); | 43 assertEquals(C.__proto__, Function.prototype); |
| 31 assertEquals(null, Object.getPrototypeOf(C.prototype)); | 44 assertEquals(null, Object.getPrototypeOf(C.prototype)); |
| 32 | 45 |
| 33 class D extends C {} | 46 class D extends C {} |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 582 static get 5() { return super[5]; } | 595 static get 5() { return super[5]; } |
| 583 } | 596 } |
| 584 | 597 |
| 585 assertEquals(1, new C()[1]()); | 598 assertEquals(1, new C()[1]()); |
| 586 assertEquals(2, new C()[2]); | 599 assertEquals(2, new C()[2]); |
| 587 assertEquals(4, C[4]()); | 600 assertEquals(4, C[4]()); |
| 588 assertEquals(5, C[5]); | 601 assertEquals(5, C[5]); |
| 589 })(); | 602 })(); |
| 590 | 603 |
| 591 | 604 |
| 605 (function TestDefaultConstructorNoCrash() { |
| 606 // Regression test for https://code.google.com/p/v8/issues/detail?id=3661 |
| 607 class C {} |
| 608 assertEquals(undefined, C()); |
| 609 assertEquals(undefined, C(1)); |
| 610 assertTrue(new C() instanceof C); |
| 611 assertTrue(new C(1) instanceof C); |
| 612 })(); |
| 613 |
| 614 |
| 615 (function TestDefaultConstructor() { |
| 616 var calls = 0; |
| 617 class Base { |
| 618 constructor() { |
| 619 calls++; |
| 620 } |
| 621 } |
| 622 class Derived extends Base {} |
| 623 var object = new Derived; |
| 624 assertEquals(1, calls); |
| 625 |
| 626 calls = 0; |
| 627 Derived(); |
| 628 assertEquals(1, calls); |
| 629 })(); |
| 630 |
| 631 |
| 592 /* TODO(arv): Implement | 632 /* TODO(arv): Implement |
| 593 (function TestNameBindingInConstructor() { | 633 (function TestNameBindingInConstructor() { |
| 594 class C { | 634 class C { |
| 595 constructor() { | 635 constructor() { |
| 596 assertThrows(function() { | 636 assertThrows(function() { |
| 597 C = 42; | 637 C = 42; |
| 598 }, ReferenceError); | 638 }, ReferenceError); |
| 599 } | 639 } |
| 600 } | 640 } |
| 601 new C(); | 641 new C(); |
| 602 })(); | 642 })(); |
| 603 */ | 643 */ |
| OLD | NEW |