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 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 assertEquals(2, --super[x]); | 1185 assertEquals(2, --super[x]); |
1186 assertEquals(2, super[x]); | 1186 assertEquals(2, super[x]); |
1187 assertEquals(2, this._x); | 1187 assertEquals(2, this._x); |
1188 }.toMethod(Derived.prototype); | 1188 }.toMethod(Derived.prototype); |
1189 new Derived().testCounts(); | 1189 new Derived().testCounts(); |
1190 }()); | 1190 }()); |
1191 | 1191 |
1192 | 1192 |
1193 (function TestSuperCall() { | 1193 (function TestSuperCall() { |
1194 function Subclass(base, constructor) { | 1194 function Subclass(base, constructor) { |
1195 var homeObject = { __proto__ : base.prototype }; | 1195 var homeObject = { |
1196 var result = constructor.toMethod(homeObject); | 1196 __proto__: base.prototype, |
1197 homeObject.constructor = result; | 1197 constructor: constructor |
1198 result.prototype = homeObject; | 1198 }; |
1199 return result; | 1199 constructor.__proto__ = base; |
| 1200 constructor.prototype = homeObject; |
| 1201 // not doing toMethod: home object is not required for |
| 1202 // super constructor calls. |
| 1203 return constructor; |
1200 } | 1204 } |
1201 | 1205 |
1202 var baseCalled = 0; | 1206 var baseCalled = 0; |
1203 var derivedCalled = 0; | 1207 var derivedCalled = 0; |
1204 var derivedDerivedCalled = 0; | 1208 var derivedDerivedCalled = 0; |
1205 | 1209 |
1206 function Base() { | 1210 function Base() { |
1207 baseCalled++; | 1211 baseCalled++; |
1208 } | 1212 } |
1209 | 1213 |
(...skipping 28 matching lines...) Expand all Loading... |
1238 this.fromBase = v; | 1242 this.fromBase = v; |
1239 } | 1243 } |
1240 var Derived2 = Subclass(Base2, function (v1, v2) { | 1244 var Derived2 = Subclass(Base2, function (v1, v2) { |
1241 super(v1); | 1245 super(v1); |
1242 this.fromDerived = v2; | 1246 this.fromDerived = v2; |
1243 }); | 1247 }); |
1244 | 1248 |
1245 var d = new Derived2("base", "derived"); | 1249 var d = new Derived2("base", "derived"); |
1246 assertEquals("base", d.fromBase); | 1250 assertEquals("base", d.fromBase); |
1247 assertEquals("derived", d.fromDerived); | 1251 assertEquals("derived", d.fromDerived); |
| 1252 |
| 1253 function ImplicitSubclassOfFunction() { |
| 1254 super(); |
| 1255 this.x = 123; |
| 1256 } |
| 1257 |
| 1258 var o = new ImplicitSubclassOfFunction(); |
| 1259 assertEquals(123, o.x); |
| 1260 |
| 1261 var calls = 0; |
| 1262 function G() { |
| 1263 calls++; |
| 1264 } |
| 1265 function F() { |
| 1266 super(); |
| 1267 } |
| 1268 F.__proto__ = G; |
| 1269 new F(); |
| 1270 assertEquals(1, calls); |
| 1271 F.__proto__ = function() {}; |
| 1272 new F(); |
| 1273 assertEquals(1, calls); |
1248 }()); | 1274 }()); |
1249 | 1275 |
1250 | 1276 |
| 1277 (function TestSuperCallErrorCases() { |
| 1278 function T() { |
| 1279 super(); |
| 1280 } |
| 1281 T.__proto__ = null; |
| 1282 // Spec says ReferenceError here, but for other IsCallable failures |
| 1283 // we throw TypeError. |
| 1284 // Filed https://bugs.ecmascript.org/show_bug.cgi?id=3282 |
| 1285 assertThrows(function() { new T(); }, TypeError); |
| 1286 }()); |
| 1287 |
| 1288 |
1251 (function TestUnsupportedCases() { | 1289 (function TestUnsupportedCases() { |
1252 function f(x) { super[x] = 5; } | 1290 function f(x) { super[x] = 5; } |
1253 var o = {}; | 1291 var o = {}; |
1254 assertThrows(function(){f.toMethod(o)(15);}, ReferenceError); | 1292 assertThrows(function(){f.toMethod(o)(15);}, ReferenceError); |
1255 }()); | 1293 }()); |
OLD | NEW |