Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: test/mjsunit/harmony/super.js

Issue 617443003: Clean-up tests for super getters and setters (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/full-codegen.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 assertEquals('foobar', super.x = 'foobar'); 113 assertEquals('foobar', super.x = 'foobar');
114 assertEquals('foobarabc', super.x += 'abc'); 114 assertEquals('foobarabc', super.x += 'abc');
115 }.toMethod(Derived.prototype); 115 }.toMethod(Derived.prototype);
116 d.testSetterStrict(); 116 d.testSetterStrict();
117 assertEquals('base', Base.prototype._x); 117 assertEquals('base', Base.prototype._x);
118 assertEquals('foobarabc', d._x); 118 assertEquals('foobarabc', d._x);
119 }()); 119 }());
120 120
121 121
122 (function TestAccessorsOnPrimitives() { 122 (function TestAccessorsOnPrimitives() {
123 var getCalled = false; 123 var getCalled = 0;
124 var setCalled = false; 124 var setCalled = 0;
125 function Base() {} 125 function Base() {}
126 Base.prototype = { 126 Base.prototype = {
127 constructor: Base, 127 constructor: Base,
128 get x() { 128 get x() {
129 getCalled = true; 129 getCalled++;
130 return 1; 130 return 1;
131 }, 131 },
132 set x(v) { 132 set x(v) {
133 setCalled = true; 133 setCalled++;
134 return v; 134 return v;
135 }, 135 },
136 }; 136 };
137 137
138 function Derived() {} 138 function Derived() {}
139 Derived.prototype = { 139 Derived.prototype = {
140 __proto__: Base.prototype, 140 __proto__: Base.prototype,
141 constructor: Derived, 141 constructor: Derived,
142 }; 142 };
143 Derived.prototype.testSetter = function() { 143 Derived.prototype.testSetter = function() {
144 assertTrue(42 == this); 144 setCalled = 0;
145 getCalled = false; 145 getCalled = 0;
146 setCalled = false; 146 assertEquals('object', typeof this);
147 assertTrue(this instanceof Number)
148 assertEquals(42, this.valueOf());
147 assertEquals(1, super.x); 149 assertEquals(1, super.x);
148 assertTrue(getCalled); 150 assertEquals(1, getCalled);
149 assertFalse(setCalled); 151 assertEquals(0, setCalled);
150 152
151 setCalled = false;
152 getCalled = false;
153 assertEquals(5, super.x = 5); 153 assertEquals(5, super.x = 5);
154 assertFalse(getCalled); 154 assertEquals(1, getCalled);
155 assertTrue(setCalled); 155 assertEquals(1, setCalled);
156 156
157 getCalled = false;
158 setCalled = false;
159 assertEquals(6, super.x += 5); 157 assertEquals(6, super.x += 5);
160 assertTrue(getCalled); 158 assertEquals(2, getCalled);
161 assertTrue(setCalled); 159 assertEquals(2, setCalled);
162 }.toMethod(Derived.prototype); 160 }.toMethod(Derived.prototype);
163 161
164 Derived.prototype.testSetterStrict = function() { 162 Derived.prototype.testSetterStrict = function() {
165 'use strict'; 163 'use strict';
166 assertTrue(42 == this); 164 getCalled = 0;
167 getCalled = false; 165 setCalled = 0;
168 setCalled = false; 166 assertTrue(42 === this);
167
169 assertEquals(1, super.x); 168 assertEquals(1, super.x);
170 assertTrue(getCalled); 169 assertEquals(1, getCalled);
171 assertFalse(setCalled); 170 assertEquals(0, setCalled);
172 171
173 setCalled = false;
174 getCalled = false;
175 assertEquals(5, super.x = 5); 172 assertEquals(5, super.x = 5);
176 assertFalse(getCalled); 173 assertEquals(1, getCalled);
177 assertTrue(setCalled); 174 assertEquals(1, setCalled);
178 175
179 getCalled = false;
180 setCalled = false;
181 assertEquals(6, super.x += 5); 176 assertEquals(6, super.x += 5);
182 assertTrue(getCalled); 177 assertEquals(2, getCalled);
183 assertTrue(setCalled); 178 assertEquals(2, setCalled);
184 }.toMethod(Derived.prototype); 179 }.toMethod(Derived.prototype);
185 180
186 Derived.prototype.testSetter.call(42); 181 Derived.prototype.testSetter.call(42);
187 Derived.prototype.testSetterStrict.call(42); 182 Derived.prototype.testSetterStrict.call(42);
188 183
189 function DerivedFromString() {} 184 function DerivedFromString() {}
190 DerivedFromString.prototype = Object.create(String.prototype); 185 DerivedFromString.prototype = Object.create(String.prototype);
191 186
192 function f() { 187 function f() {
193 'use strict'; 188 'use strict';
194 assertTrue(42 == this); 189 assertTrue(42 === this);
195 assertEquals(String.prototype.toString, super.toString); 190 assertEquals(String.prototype.toString, super.toString);
196 var except = false; 191 var ex;
197 try { 192 try {
198 super.toString(); 193 super.toString();
199 } catch(e) { except = true; } 194 } catch(e) { ex = e; }
200 assertTrue(except); 195
196 assertTrue(ex instanceof TypeError);
201 } 197 }
202 f.toMethod(DerivedFromString.prototype).call(42); 198 f.toMethod(DerivedFromString.prototype).call(42);
203 }()); 199 }());
204 200
205 201
206 (function TestSetterFailures() { 202 (function TestSetterFailures() {
207 function Base() {} 203 function Base() {}
208 function Derived() {} 204 function Derived() {}
209 Derived.prototype = { __proto__ : Base.prototype }; 205 Derived.prototype = { __proto__ : Base.prototype };
210 Derived.prototype.mSloppy = function () { 206 Derived.prototype.mSloppy = function () {
211 super.x = 10; 207 super.x = 10;
212 assertEquals(undefined, super.x); 208 assertEquals(undefined, super.x);
213 }.toMethod(Derived.prototype); 209 }.toMethod(Derived.prototype);
214 210
215 Derived.prototype.mStrict = function () { 211 Derived.prototype.mStrict = function () {
216 "use strict"; 212 'use strict';
217 super.x = 10; 213 super.x = 10;
218 }.toMethod(Derived.prototype); 214 }.toMethod(Derived.prototype);
219 var d = new Derived(); 215 var d = new Derived();
220 d.mSloppy(); 216 d.mSloppy();
221 assertEquals(undefined, d.x); 217 assertEquals(undefined, d.x);
222 var d1 = new Derived(); 218 var d1 = new Derived();
223 assertThrows(function() { d.mStrict(); }, ReferenceError); 219 assertThrows(function() { d.mStrict(); }, ReferenceError);
224 assertEquals(undefined, d.x); 220 assertEquals(undefined, d.x);
225 }()); 221 }());
226 222
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 assertEquals(2, super.x); 265 assertEquals(2, super.x);
270 assertEquals(2, this._x); 266 assertEquals(2, this._x);
271 }.toMethod(Derived.prototype); 267 }.toMethod(Derived.prototype);
272 new Derived().testCounts(); 268 new Derived().testCounts();
273 }()); 269 }());
274 270
275 271
276 (function TestUnsupportedCases() { 272 (function TestUnsupportedCases() {
277 function f1(x) { return super[x]; } 273 function f1(x) { return super[x]; }
278 function f2(x) { super[x] = 5; } 274 function f2(x) { super[x] = 5; }
279 var o = {} 275 var o = {};
280 assertThrows(function(){f1.toMethod(o)(x);}, ReferenceError); 276 assertThrows(function(){f1.toMethod(o)(x);}, ReferenceError);
281 assertThrows(function(){f2.toMethod(o)(x);}, ReferenceError); 277 assertThrows(function(){f2.toMethod(o)(x);}, ReferenceError);
282 }()); 278 }());
OLDNEW
« no previous file with comments | « src/full-codegen.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698