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() { |
11 this.derivedDataProperty = "xxx"; | 11 this.derivedDataProperty = "xxx"; |
12 } | 12 } |
13 Derived.prototype = Object.create(Base.prototype); | 13 Derived.prototype = Object.create(Base.prototype); |
14 | 14 |
15 function fBase() { return "Base " + this.toString(); } | 15 function fBase() { return "Base " + this.toString(); } |
16 | 16 |
17 Base.prototype.f = fBase.toMethod(Base.prototype); | 17 Base.prototype.f = fBase.toMethod(Base.prototype); |
18 | 18 |
19 function fDerived() { | 19 function fDerived() { |
20 assertEquals("Base this is Derived", super.f()); | 20 assertEquals("Base this is Derived", super.f()); |
21 var a = super.x; | |
22 assertEquals(15, a); | |
21 assertEquals(15, super.x); | 23 assertEquals(15, super.x); |
22 assertEquals(27, this.x); | 24 assertEquals(27, this.x); |
23 | 25 |
24 return "Derived" | 26 return "Derived" |
25 } | 27 } |
26 | 28 |
27 Base.prototype.x = 15; | 29 Base.prototype.x = 15; |
28 Base.prototype.toString = function() { return "this is Base"; }; | 30 Base.prototype.toString = function() { return "this is Base"; }; |
29 Derived.prototype.toString = function() { return "this is Derived"; }; | 31 Derived.prototype.toString = function() { return "this is Derived"; }; |
30 Derived.prototype.x = 27; | 32 Derived.prototype.x = 27; |
31 Derived.prototype.f = fDerived.toMethod(Derived.prototype); | 33 Derived.prototype.f = fDerived.toMethod(Derived.prototype); |
32 | 34 |
33 assertEquals("Base this is Base", new Base().f()); | 35 assertEquals("Base this is Base", new Base().f()); |
34 assertEquals("Derived", new Derived().f()); | 36 assertEquals("Derived", new Derived().f()); |
35 }()); | 37 }()); |
36 | 38 |
39 | |
37 (function TestSuperKeywordNonMethod() { | 40 (function TestSuperKeywordNonMethod() { |
38 function f() { | 41 function f() { |
39 super.unknown(); | 42 super.unknown(); |
40 } | 43 } |
41 | 44 |
42 assertThrows(f, ReferenceError); | 45 assertThrows(f, ReferenceError); |
43 }()); | 46 }()); |
44 | 47 |
45 | 48 |
46 (function TestGetter() { | 49 (function TestGetter() { |
(...skipping 15 matching lines...) Expand all Loading... | |
62 constructor: Derived, | 65 constructor: Derived, |
63 _x: 'derived' | 66 _x: 'derived' |
64 }; | 67 }; |
65 Derived.prototype.testGetter = function() { | 68 Derived.prototype.testGetter = function() { |
66 return super.x; | 69 return super.x; |
67 }.toMethod(Derived.prototype); | 70 }.toMethod(Derived.prototype); |
68 derived = new Derived(); | 71 derived = new Derived(); |
69 assertEquals('derived', derived.testGetter()); | 72 assertEquals('derived', derived.testGetter()); |
70 }()); | 73 }()); |
71 | 74 |
72 /* | 75 |
73 * TODO[dslomov]: named stores and keyed loads/stores not implemented yet. | |
74 (function TestSetter() { | 76 (function TestSetter() { |
75 function Base() {} | 77 function Base() {} |
76 Base.prototype = { | 78 Base.prototype = { |
77 constructor: Base, | 79 constructor: Base, |
78 get x() { | 80 get x() { |
79 return this._x; | 81 return this._x; |
80 }, | 82 }, |
81 set x(v) { | 83 set x(v) { |
82 this._x = v; | 84 this._x = v; |
83 }, | 85 }, |
84 _x: 'base' | 86 _x: 'base' |
85 }; | 87 }; |
86 | 88 |
87 function Derived() {} | 89 function Derived() {} |
88 Derived.__proto__ = Base; | 90 Derived.__proto__ = Base; |
89 Derived.prototype = { | 91 Derived.prototype = { |
90 __proto__: Base.prototype, | 92 __proto__: Base.prototype, |
91 constructor: Derived, | 93 constructor: Derived, |
92 _x: 'derived' | 94 _x: 'derived' |
93 }; | 95 }; |
94 Derived.prototype.testSetter = function() { | 96 Derived.prototype.testSetter = function() { |
95 super.x = 'foobar'; | 97 assertEquals('foobar', super.x = 'foobar'); |
96 }.toMethod(Derived.prototype); | 98 assertEquals('foobarabc', super.x += 'abc'); |
99 }.toMethod(Derived.prototype); | |
97 var d = new Derived(); | 100 var d = new Derived(); |
98 d.testSetter(); | 101 d.testSetter(); |
99 assertEquals('base', Base.prototype._x); | 102 assertEquals('base', Base.prototype._x); |
100 assertEquals('foobar', d._x); | 103 assertEquals('foobarabc', d._x); |
104 d._x = ''; | |
105 Derived.prototype.testSetterStrict = function() { | |
106 'use strict'; | |
107 assertEquals('foobar', super.x = 'foobar'); | |
108 assertEquals('foobarabc', super.x += 'abc'); | |
109 }.toMethod(Derived.prototype); | |
110 d.testSetterStrict(); | |
111 assertEquals('base', Base.prototype._x); | |
112 assertEquals('foobarabc', d._x); | |
101 }()); | 113 }()); |
102 | 114 |
103 | 115 |
104 (function TestKeyedGetter() { | 116 (function TestSetterFailures() { |
105 function Base() {} | 117 function Base() {} |
106 Base.prototype = { | 118 function Derived() {} |
107 constructor: Base, | 119 Derived.prototype = { __proto__ : Base.prototype }; |
108 _x: 'base' | 120 Derived.prototype.mSloppy = function () { |
109 }; | 121 super.x = 10; |
122 assertEquals(undefined, super.x); | |
123 }.toMethod(Derived.prototype); | |
110 | 124 |
111 Object.defineProperty(Base.prototype, '0', | 125 Derived.prototype.mStrict = function () { |
112 { get: function() { return this._x; } }); | 126 "use strict"; |
127 super.x = 10; | |
128 }.toMethod(Derived.prototype); | |
129 var d = new Derived(); | |
130 d.mSloppy(); | |
131 assertEquals(undefined, d.x); | |
132 var d1 = new Derived(); | |
133 assertThrows(function() { d.mStrict(); }, ReferenceError); | |
134 assertEquals(undefined, d.x); | |
135 }()); | |
113 | 136 |
114 function Derived() {} | 137 |
115 Derived.__proto__ = Base; | 138 (function TestUnsupportedCases() { |
116 Derived.prototype = { | 139 function f1(x) { return super[x]; } |
117 __proto__: Base.prototype, | 140 var o = {} |
118 constructor: Derived, | 141 assertThrows(function(){f1.toMethod(o)(x);}, ReferenceError); |
119 _x: 'derived' | 142 function f2() { super.x++; } |
120 }; | 143 assertThrows(function(){f2.toMethod(o)();}, ReferenceError); |
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 }()); | 144 }()); |
arv (Not doing code reviews)
2014/09/25 15:39:24
Can you add a test of a strict function, used as a
Dmitry Lomov (no reviews)
2014/09/26 10:35:26
Done.
| |
127 */ | |
OLD | NEW |