OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 // |
| 5 // Flags: --harmony-classes |
| 6 |
| 7 |
| 8 (function TestSuperNamedLoads() { |
| 9 function Base() { } |
| 10 function Derived() { |
| 11 this.derivedDataProperty = "xxx"; |
| 12 } |
| 13 Derived.prototype = Object.create(Base.prototype); |
| 14 |
| 15 function fBase() { return "Base " + this.toString(); } |
| 16 |
| 17 Base.prototype.f = fBase.toMethod(Base.prototype); |
| 18 |
| 19 function fDerived() { |
| 20 assertEquals("Base this is Derived", super.f()); |
| 21 assertEquals(15, super.x); |
| 22 assertEquals(27, this.x); |
| 23 |
| 24 return "Derived" |
| 25 } |
| 26 |
| 27 Base.prototype.x = 15; |
| 28 Base.prototype.toString = function() { return "this is Base"; }; |
| 29 Derived.prototype.toString = function() { return "this is Derived"; }; |
| 30 Derived.prototype.x = 27; |
| 31 Derived.prototype.f = fDerived.toMethod(Derived.prototype); |
| 32 |
| 33 assertEquals("Base this is Base", new Base().f()); |
| 34 assertEquals("Derived", new Derived().f()); |
| 35 }()); |
| 36 |
| 37 (function TestSuperKeywordNonMethod() { |
| 38 function f() { |
| 39 super.unknown(); |
| 40 } |
| 41 |
| 42 assertThrows(f, ReferenceError); |
| 43 }()); |
| 44 |
| 45 |
| 46 (function TestGetter() { |
| 47 function Base() {} |
| 48 var derived; |
| 49 Base.prototype = { |
| 50 constructor: Base, |
| 51 get x() { |
| 52 assertSame(this, derived); |
| 53 return this._x; |
| 54 }, |
| 55 _x: 'base' |
| 56 }; |
| 57 |
| 58 function Derived() {} |
| 59 Derived.__proto__ = Base; |
| 60 Derived.prototype = { |
| 61 __proto__: Base.prototype, |
| 62 constructor: Derived, |
| 63 _x: 'derived' |
| 64 }; |
| 65 Derived.prototype.testGetter = function() { |
| 66 return super.x; |
| 67 }.toMethod(Derived.prototype); |
| 68 derived = new Derived(); |
| 69 assertEquals('derived', derived.testGetter()); |
| 70 }()); |
| 71 |
| 72 /* |
| 73 * TODO[dslomov]: named stores and keyed loads/stores not implemented yet. |
| 74 (function TestSetter() { |
| 75 function Base() {} |
| 76 Base.prototype = { |
| 77 constructor: Base, |
| 78 get x() { |
| 79 return this._x; |
| 80 }, |
| 81 set x(v) { |
| 82 this._x = v; |
| 83 }, |
| 84 _x: 'base' |
| 85 }; |
| 86 |
| 87 function Derived() {} |
| 88 Derived.__proto__ = Base; |
| 89 Derived.prototype = { |
| 90 __proto__: Base.prototype, |
| 91 constructor: Derived, |
| 92 _x: 'derived' |
| 93 }; |
| 94 Derived.prototype.testSetter = function() { |
| 95 super.x = 'foobar'; |
| 96 }.toMethod(Derived.prototype); |
| 97 var d = new Derived(); |
| 98 d.testSetter(); |
| 99 assertEquals('base', Base.prototype._x); |
| 100 assertEquals('foobar', d._x); |
| 101 }()); |
| 102 |
| 103 |
| 104 (function TestKeyedGetter() { |
| 105 function Base() {} |
| 106 Base.prototype = { |
| 107 constructor: Base, |
| 108 _x: 'base' |
| 109 }; |
| 110 |
| 111 Object.defineProperty(Base.prototype, '0', |
| 112 { get: function() { return this._x; } }); |
| 113 |
| 114 function Derived() {} |
| 115 Derived.__proto__ = Base; |
| 116 Derived.prototype = { |
| 117 __proto__: Base.prototype, |
| 118 constructor: Derived, |
| 119 _x: 'derived' |
| 120 }; |
| 121 Derived.prototype.testGetter = function() { |
| 122 return super[0]; |
| 123 }.toMethod(Derived.prototype); |
| 124 assertEquals('derived', new Derived()[0]); |
| 125 // assertEquals('derived', new Derived().testGetter()); |
| 126 }()); |
| 127 */ |
OLD | NEW |