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