Chromium Code Reviews| 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 ImplicitSubclassOfObject() { | |
| 1254 super(); | |
| 
 
arv (Not doing code reviews)
2014/10/15 14:47:18
Just to be clear that I understand this. This one
 
Dmitry Lomov (no reviews)
2014/10/15 17:22:57
You are right, this has to be called ImplicitSubcl
 
 | |
| 1255 this.x = 123; | |
| 1256 } | |
| 1257 | |
| 1258 var o = new ImplicitSubclassOfObject(); | |
| 1259 assertEquals(123, o.x); | |
| 1248 }()); | 1260 }()); | 
| 1249 | 1261 | 
| 1250 | 1262 | 
| 1263 (function TestSuperCallErrorCases() { | |
| 1264 function T() { | |
| 1265 super(); | |
| 1266 } | |
| 1267 T.__proto__ = null; | |
| 1268 // Spec says ReferenceError here, but for other IsCallable failures | |
| 1269 // we throw TypeError. | |
| 
 
arv (Not doing code reviews)
2014/10/15 14:47:18
Completely agree. I was reading up on the changes
 
 | |
| 1270 // Filed https://bugs.ecmascript.org/show_bug.cgi?id=3282 | |
| 1271 assertThrows(function() { new T(); }, TypeError); | |
| 1272 }()); | |
| 
 
arv (Not doing code reviews)
2014/10/15 14:49:54
maybe add a test that mutates __proto__ and then u
 
Dmitry Lomov (no reviews)
2014/10/15 17:22:57
Done.
 
 | |
| 1273 | |
| 1274 | |
| 1251 (function TestUnsupportedCases() { | 1275 (function TestUnsupportedCases() { | 
| 1252 function f(x) { super[x] = 5; } | 1276 function f(x) { super[x] = 5; } | 
| 1253 var o = {}; | 1277 var o = {}; | 
| 1254 assertThrows(function(){f.toMethod(o)(15);}, ReferenceError); | 1278 assertThrows(function(){f.toMethod(o)(15);}, ReferenceError); | 
| 1255 }()); | 1279 }()); | 
| OLD | NEW |