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 | 7 |
8 (function TestSuperNamedLoads() { | 8 (function TestSuperNamedLoads() { |
9 function Base() { } | 9 function Base() { } |
10 function Derived() { | 10 function Derived() { |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 Object.defineProperty(d, 'ownReadOnly', { value : 42, writable : false }); | 653 Object.defineProperty(d, 'ownReadOnly', { value : 42, writable : false }); |
654 Object.defineProperty(d, 'ownSetter', | 654 Object.defineProperty(d, 'ownSetter', |
655 { set : function() { setterCalled++; } }); | 655 { set : function() { setterCalled++; } }); |
656 Object.defineProperty(d, 'ownReadonlyAccessor', | 656 Object.defineProperty(d, 'ownReadonlyAccessor', |
657 { get : function() { return 15; }}); | 657 { get : function() { return 15; }}); |
658 d.mSloppy(); | 658 d.mSloppy(); |
659 d.mStrict(); | 659 d.mStrict(); |
660 }()); | 660 }()); |
661 | 661 |
662 | 662 |
| 663 (function TestSetterInForIn() { |
| 664 var setCalled = 0; |
| 665 var getCalled = 0; |
| 666 function Base() {} |
| 667 Base.prototype = { |
| 668 constructor: Base, |
| 669 get x() { |
| 670 getCalled++; |
| 671 return 1; |
| 672 }, |
| 673 set x(v) { |
| 674 setCalled++; |
| 675 this.x_.push(v); |
| 676 }, |
| 677 }; |
| 678 |
| 679 function Derived() { |
| 680 this.x_ = []; |
| 681 } |
| 682 Derived.prototype = { |
| 683 __proto__: Base.prototype, |
| 684 constructor: Derived, |
| 685 }; |
| 686 |
| 687 Derived.prototype.testIter = function() { |
| 688 setCalled = 0; |
| 689 getCalled = 0; |
| 690 for (super.x in [1,2,3]) {} |
| 691 assertEquals(0, getCalled); |
| 692 assertEquals(3, setCalled); |
| 693 assertEquals(["0","1","2"], this.x_); |
| 694 }.toMethod(Derived.prototype); |
| 695 |
| 696 new Derived().testIter(); |
| 697 |
| 698 var x = 'x'; |
| 699 Derived.prototype.testIterKeyed = function() { |
| 700 setCalled = 0; |
| 701 getCalled = 0; |
| 702 for (super[x] in [1,2,3]) {} |
| 703 assertEquals(0, getCalled); |
| 704 assertEquals(3, setCalled); |
| 705 assertEquals(["0","1","2"], this.x_); |
| 706 |
| 707 this.x_ = []; |
| 708 setCalled = 0; |
| 709 getCalled = 0; |
| 710 var toStringCalled = 0; |
| 711 var o = {toString: function () { toStringCalled++; return x }}; |
| 712 for (super[o] in [1,2,3]) {} |
| 713 assertEquals(0, getCalled); |
| 714 assertEquals(3, setCalled); |
| 715 assertEquals(3, toStringCalled); |
| 716 assertEquals(["0","1","2"], this.x_); |
| 717 }.toMethod(Derived.prototype); |
| 718 |
| 719 new Derived().testIterKeyed(); |
| 720 }()); |
| 721 |
| 722 |
663 (function TestKeyedSetterCreatingOwnProperties() { | 723 (function TestKeyedSetterCreatingOwnProperties() { |
664 var ownReadOnly = 'ownReadOnly'; | 724 var ownReadOnly = 'ownReadOnly'; |
665 var ownReadonlyAccessor = 'ownReadonlyAccessor'; | 725 var ownReadonlyAccessor = 'ownReadonlyAccessor'; |
666 var ownSetter = 'ownSetter'; | 726 var ownSetter = 'ownSetter'; |
667 function Base() {} | 727 function Base() {} |
668 function Derived() {} | 728 function Derived() {} |
669 Derived.prototype = { __proto__ : Base.prototype }; | 729 Derived.prototype = { __proto__ : Base.prototype }; |
670 var setterCalled; | 730 var setterCalled; |
671 | 731 |
672 Derived.prototype.mSloppy = function() { | 732 Derived.prototype.mSloppy = function() { |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 }()); | 1155 }()); |
1096 | 1156 |
1097 | 1157 |
1098 (function TestUnsupportedCases() { | 1158 (function TestUnsupportedCases() { |
1099 function f1(x) { return super[x]; } | 1159 function f1(x) { return super[x]; } |
1100 function f2(x) { super[x] = 5; } | 1160 function f2(x) { super[x] = 5; } |
1101 var o = {}; | 1161 var o = {}; |
1102 assertThrows(function(){f1.toMethod(o)(15);}, ReferenceError); | 1162 assertThrows(function(){f1.toMethod(o)(15);}, ReferenceError); |
1103 assertThrows(function(){f2.toMethod(o)(15);}, ReferenceError); | 1163 assertThrows(function(){f2.toMethod(o)(15);}, ReferenceError); |
1104 }()); | 1164 }()); |
OLD | NEW |