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); |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 class Derived extends Base {} | 617 class Derived extends Base {} |
618 var object = new Derived; | 618 var object = new Derived; |
619 assertEquals(1, calls); | 619 assertEquals(1, calls); |
620 | 620 |
621 calls = 0; | 621 calls = 0; |
622 Derived(); | 622 Derived(); |
623 assertEquals(1, calls); | 623 assertEquals(1, calls); |
624 })(); | 624 })(); |
625 | 625 |
626 | 626 |
| 627 (function TestDefaultConstructorArguments() { |
| 628 var args, self; |
| 629 class Base { |
| 630 constructor() { |
| 631 self = this; |
| 632 args = arguments; |
| 633 } |
| 634 } |
| 635 class Derived extends Base {} |
| 636 |
| 637 new Derived; |
| 638 assertEquals(0, args.length); |
| 639 |
| 640 new Derived(0, 1, 2); |
| 641 assertEquals(3, args.length); |
| 642 assertTrue(self instanceof Derived); |
| 643 |
| 644 var arr = new Array(100); |
| 645 var obj = {}; |
| 646 Derived.apply(obj, arr); |
| 647 assertEquals(100, args.length); |
| 648 assertEquals(obj, self); |
| 649 })(); |
| 650 |
| 651 |
| 652 (function TestDefaultConstructorArguments2() { |
| 653 var args; |
| 654 class Base { |
| 655 constructor(x, y) { |
| 656 args = arguments; |
| 657 } |
| 658 } |
| 659 class Derived extends Base {} |
| 660 |
| 661 new Derived; |
| 662 assertEquals(0, args.length); |
| 663 |
| 664 new Derived(1); |
| 665 assertEquals(1, args.length); |
| 666 assertEquals(1, args[0]); |
| 667 |
| 668 new Derived(1, 2, 3); |
| 669 assertEquals(3, args.length); |
| 670 assertEquals(1, args[0]); |
| 671 assertEquals(2, args[1]); |
| 672 assertEquals(3, args[2]); |
| 673 })(); |
| 674 |
| 675 |
627 /* TODO(arv): Implement | 676 /* TODO(arv): Implement |
628 (function TestNameBindingInConstructor() { | 677 (function TestNameBindingInConstructor() { |
629 class C { | 678 class C { |
630 constructor() { | 679 constructor() { |
631 assertThrows(function() { | 680 assertThrows(function() { |
632 C = 42; | 681 C = 42; |
633 }, ReferenceError); | 682 }, ReferenceError); |
634 } | 683 } |
635 } | 684 } |
636 new C(); | 685 new C(); |
637 })(); | 686 })(); |
638 */ | 687 */ |
OLD | NEW |