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 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"; | |
|
arv (Not doing code reviews)
2014/10/01 15:20:23
consistency
| |
| 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 | |
|
arv (Not doing code reviews)
2014/10/01 15:20:23
Can you add tests that uses numeric keys?
Can you
| |
| 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 = new Derived(); | |
| 145 assertEquals('derived', derived.testGetter()); | |
| 146 derived = new Derived(); | |
| 147 assertEquals('derived', derived.testGetterStrict()); | |
| 148 }()); | |
| 149 | |
| 150 | |
| 82 (function TestSetter() { | 151 (function TestSetter() { |
| 83 function Base() {} | 152 function Base() {} |
| 84 Base.prototype = { | 153 Base.prototype = { |
| 85 constructor: Base, | 154 constructor: Base, |
| 86 get x() { | 155 get x() { |
| 87 return this._x; | 156 return this._x; |
| 88 }, | 157 }, |
| 89 set x(v) { | 158 set x(v) { |
| 90 this._x = v; | 159 this._x = v; |
| 91 }, | 160 }, |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 532 }()); | 601 }()); |
| 533 | 602 |
| 534 | 603 |
| 535 (function TestUnsupportedCases() { | 604 (function TestUnsupportedCases() { |
| 536 function f1(x) { return super[x]; } | 605 function f1(x) { return super[x]; } |
| 537 function f2(x) { super[x] = 5; } | 606 function f2(x) { super[x] = 5; } |
| 538 var o = {}; | 607 var o = {}; |
| 539 assertThrows(function(){f1.toMethod(o)(x);}, ReferenceError); | 608 assertThrows(function(){f1.toMethod(o)(x);}, ReferenceError); |
| 540 assertThrows(function(){f2.toMethod(o)(x);}, ReferenceError); | 609 assertThrows(function(){f2.toMethod(o)(x);}, ReferenceError); |
| 541 }()); | 610 }()); |
| OLD | NEW |