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 19 matching lines...) Expand all Loading... |
30 Base.prototype.toString = function() { return "this is Base"; }; | 30 Base.prototype.toString = function() { return "this is Base"; }; |
31 Derived.prototype.toString = function() { return "this is Derived"; }; | 31 Derived.prototype.toString = function() { return "this is Derived"; }; |
32 Derived.prototype.x = 27; | 32 Derived.prototype.x = 27; |
33 Derived.prototype.f = fDerived.toMethod(Derived.prototype); | 33 Derived.prototype.f = fDerived.toMethod(Derived.prototype); |
34 | 34 |
35 assertEquals("Base this is Base", new Base().f()); | 35 assertEquals("Base this is Base", new Base().f()); |
36 assertEquals("Derived", new Derived().f()); | 36 assertEquals("Derived", new Derived().f()); |
37 }()); | 37 }()); |
38 | 38 |
39 | 39 |
| 40 (function TestSuperKeyedLoads() { |
| 41 var x = 'x'; |
| 42 var derivedDataProperty = 'derivedDataProperty'; |
| 43 var f = 'f'; |
| 44 function Base() { } |
| 45 function Derived() { |
| 46 this[derivedDataProperty] = "xxx"; |
| 47 } |
| 48 Derived.prototype = Object.create(Base.prototype); |
| 49 |
| 50 function fBase() { return "Base " + this.toString(); } |
| 51 |
| 52 Base.prototype[f] = fBase.toMethod(Base.prototype); |
| 53 |
| 54 function fDerived() { |
| 55 assertEquals("Base this is Derived", super[f]()); |
| 56 var a = super[x]; |
| 57 assertEquals(15, a); |
| 58 assertEquals(15, super[x]); |
| 59 assertEquals(27, this[x]); |
| 60 |
| 61 return "Derived" |
| 62 } |
| 63 |
| 64 Base.prototype[x] = 15; |
| 65 Base.prototype.toString = function() { return "this is Base"; }; |
| 66 Derived.prototype.toString = function() { return "this is Derived"; }; |
| 67 Derived.prototype[x] = 27; |
| 68 Derived.prototype[f] = fDerived.toMethod(Derived.prototype); |
| 69 |
| 70 assertEquals("Base this is Base", new Base().f()); |
| 71 assertEquals("Derived", new Derived().f()); |
| 72 }()); |
| 73 |
| 74 |
40 (function TestSuperKeywordNonMethod() { | 75 (function TestSuperKeywordNonMethod() { |
41 function f() { | 76 function f() { |
42 super.unknown(); | 77 super.unknown(); |
43 } | 78 } |
44 | 79 |
45 assertThrows(f, ReferenceError); | 80 assertThrows(f, ReferenceError); |
46 }()); | 81 }()); |
47 | 82 |
48 | 83 |
49 (function TestGetter() { | 84 (function TestGetter() { |
(...skipping 22 matching lines...) Expand all Loading... |
72 'use strict'; | 107 'use strict'; |
73 return super.x; | 108 return super.x; |
74 }.toMethod(Derived.prototype); | 109 }.toMethod(Derived.prototype); |
75 derived = new Derived(); | 110 derived = new Derived(); |
76 assertEquals('derived', derived.testGetter()); | 111 assertEquals('derived', derived.testGetter()); |
77 derived = new Derived(); | 112 derived = new Derived(); |
78 assertEquals('derived', derived.testGetterStrict()); | 113 assertEquals('derived', derived.testGetterStrict()); |
79 }()); | 114 }()); |
80 | 115 |
81 | 116 |
| 117 (function TestGetterKeyed() { |
| 118 var x = 'x'; |
| 119 function Base() {} |
| 120 var derived; |
| 121 Base.prototype = { |
| 122 constructor: Base, |
| 123 get x() { |
| 124 assertSame(this, derived); |
| 125 return this._x; |
| 126 }, |
| 127 _x: 'base' |
| 128 }; |
| 129 |
| 130 function Derived() {} |
| 131 Derived.__proto__ = Base; |
| 132 Derived.prototype = { |
| 133 __proto__: Base.prototype, |
| 134 constructor: Derived, |
| 135 _x: 'derived' |
| 136 }; |
| 137 Derived.prototype.testGetter = function() { |
| 138 return super[x]; |
| 139 }.toMethod(Derived.prototype); |
| 140 Derived.prototype.testGetterStrict = function() { |
| 141 'use strict'; |
| 142 return super[x]; |
| 143 }.toMethod(Derived.prototype); |
| 144 Derived.prototype.testGetterWithToString = function() { |
| 145 var toStringCalled; |
| 146 var o = { toString: function() { |
| 147 toStringCalled++; |
| 148 return 'x'; |
| 149 } }; |
| 150 |
| 151 toStringCalled = 0; |
| 152 assertEquals('derived', super[o]); |
| 153 assertEquals(1, toStringCalled); |
| 154 |
| 155 var ex; |
| 156 try { |
| 157 super[1]; // Indexed properties unsupported yet. |
| 158 } catch (e) { ex = e; } |
| 159 assertTrue(ex instanceof ReferenceError); |
| 160 }.toMethod(Derived.prototype); |
| 161 derived = new Derived(); |
| 162 assertEquals('derived', derived.testGetter()); |
| 163 derived = new Derived(); |
| 164 assertEquals('derived', derived.testGetterStrict()); |
| 165 derived = new Derived(); |
| 166 derived.testGetterWithToString(); |
| 167 }()); |
| 168 |
| 169 |
82 (function TestSetter() { | 170 (function TestSetter() { |
83 function Base() {} | 171 function Base() {} |
84 Base.prototype = { | 172 Base.prototype = { |
85 constructor: Base, | 173 constructor: Base, |
86 get x() { | 174 get x() { |
87 return this._x; | 175 return this._x; |
88 }, | 176 }, |
89 set x(v) { | 177 set x(v) { |
90 this._x = v; | 178 this._x = v; |
91 }, | 179 }, |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 var d = new Derived2("base", "derived"); | 617 var d = new Derived2("base", "derived"); |
530 assertEquals("base", d.fromBase); | 618 assertEquals("base", d.fromBase); |
531 assertEquals("derived", d.fromDerived); | 619 assertEquals("derived", d.fromDerived); |
532 }()); | 620 }()); |
533 | 621 |
534 | 622 |
535 (function TestUnsupportedCases() { | 623 (function TestUnsupportedCases() { |
536 function f1(x) { return super[x]; } | 624 function f1(x) { return super[x]; } |
537 function f2(x) { super[x] = 5; } | 625 function f2(x) { super[x] = 5; } |
538 var o = {}; | 626 var o = {}; |
539 assertThrows(function(){f1.toMethod(o)(x);}, ReferenceError); | 627 assertThrows(function(){f2.toMethod(o)(15);}, ReferenceError); |
540 assertThrows(function(){f2.toMethod(o)(x);}, ReferenceError); | 628 assertThrows(function(){f2.toMethod(o)(15);}, ReferenceError); |
541 }()); | 629 }()); |
OLD | NEW |