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

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

Issue 618643003: Implement data property creation for assignments to super.x. (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
« src/objects.cc ('K') | « src/objects.cc ('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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 'use strict'; 112 'use strict';
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 TestSetterDataProperties() {
123 function Base() {}
124 Base.prototype = {
125 constructor: Base,
126 x : "x from Base"
arv (Not doing code reviews) 2014/09/30 13:52:17 no ws before :
arv (Not doing code reviews) 2014/09/30 13:52:17 stick to '
127 };
128
129 function Derived() {}
130 Derived.prototype = {
131 __proto__: Base.prototype,
132 constructor: Derived,
133 };
134
135 Derived.prototype.testSetter = function() {
136 assertEquals("x from Base", super.x);
137 super.x = "data property";
138 assertEquals("x from Base", super.x);
139 assertEquals("data property", this.x);
140 }.toMethod(Derived.prototype);
141
142 new Derived().testSetter();
143 }());
144
145
122 (function TestAccessorsOnPrimitives() { 146 (function TestAccessorsOnPrimitives() {
123 var getCalled = 0; 147 var getCalled = 0;
124 var setCalled = 0; 148 var setCalled = 0;
125 function Base() {} 149 function Base() {}
126 Base.prototype = { 150 Base.prototype = {
127 constructor: Base, 151 constructor: Base,
128 get x() { 152 get x() {
129 getCalled++; 153 getCalled++;
130 return 1; 154 return 1;
131 }, 155 },
(...skipping 18 matching lines...) Expand all
150 assertEquals(1, getCalled); 174 assertEquals(1, getCalled);
151 assertEquals(0, setCalled); 175 assertEquals(0, setCalled);
152 176
153 assertEquals(5, super.x = 5); 177 assertEquals(5, super.x = 5);
154 assertEquals(1, getCalled); 178 assertEquals(1, getCalled);
155 assertEquals(1, setCalled); 179 assertEquals(1, setCalled);
156 180
157 assertEquals(6, super.x += 5); 181 assertEquals(6, super.x += 5);
158 assertEquals(2, getCalled); 182 assertEquals(2, getCalled);
159 assertEquals(2, setCalled); 183 assertEquals(2, setCalled);
184
185 super.newProperty = 15;
186 assertEquals(15, this.newProperty);
187 assertEquals(undefined, super.newProperty);
160 }.toMethod(Derived.prototype); 188 }.toMethod(Derived.prototype);
161 189
162 Derived.prototype.testSetterStrict = function() { 190 Derived.prototype.testSetterStrict = function() {
163 'use strict'; 191 'use strict';
164 getCalled = 0; 192 getCalled = 0;
165 setCalled = 0; 193 setCalled = 0;
166 assertTrue(42 === this); 194 assertTrue(42 === this);
167 195
168 assertEquals(1, super.x); 196 assertEquals(1, super.x);
169 assertEquals(1, getCalled); 197 assertEquals(1, getCalled);
170 assertEquals(0, setCalled); 198 assertEquals(0, setCalled);
171 199
172 assertEquals(5, super.x = 5); 200 assertEquals(5, super.x = 5);
173 assertEquals(1, getCalled); 201 assertEquals(1, getCalled);
174 assertEquals(1, setCalled); 202 assertEquals(1, setCalled);
175 203
176 assertEquals(6, super.x += 5); 204 assertEquals(6, super.x += 5);
177 assertEquals(2, getCalled); 205 assertEquals(2, getCalled);
178 assertEquals(2, setCalled); 206 assertEquals(2, setCalled);
207
208 var ex;
209 try {
210 super.newProperty = 15;
arv (Not doing code reviews) 2014/09/30 13:52:17 I'm having a hard time seeing why this should thro
211 } catch(e) { ex = e; }
arv (Not doing code reviews) 2014/09/30 13:52:17 ws between catch and (
212 assertTrue(ex instanceof TypeError);
179 }.toMethod(Derived.prototype); 213 }.toMethod(Derived.prototype);
180 214
181 Derived.prototype.testSetter.call(42); 215 Derived.prototype.testSetter.call(42);
182 Derived.prototype.testSetterStrict.call(42); 216 Derived.prototype.testSetterStrict.call(42);
183 217
184 function DerivedFromString() {} 218 function DerivedFromString() {}
185 DerivedFromString.prototype = Object.create(String.prototype); 219 DerivedFromString.prototype = Object.create(String.prototype);
186 220
187 function f() { 221 function f() {
188 'use strict'; 222 'use strict';
189 assertTrue(42 === this); 223 assertTrue(42 === this);
190 assertEquals(String.prototype.toString, super.toString); 224 assertEquals(String.prototype.toString, super.toString);
191 var ex; 225 var ex;
192 try { 226 try {
193 super.toString(); 227 super.toString();
194 } catch(e) { ex = e; } 228 } catch(e) { ex = e; }
195 229
196 assertTrue(ex instanceof TypeError); 230 assertTrue(ex instanceof TypeError);
197 } 231 }
198 f.toMethod(DerivedFromString.prototype).call(42); 232 f.toMethod(DerivedFromString.prototype).call(42);
199 }()); 233 }());
200 234
201 235
202 (function TestSetterFailures() { 236 (function TestSetterUndefinedProperties() {
203 function Base() {} 237 function Base() {}
204 function Derived() {} 238 function Derived() {}
205 Derived.prototype = { __proto__ : Base.prototype }; 239 Derived.prototype = { __proto__ : Base.prototype };
206 Derived.prototype.mSloppy = function () { 240 Derived.prototype.mSloppy = function () {
241 assertEquals(undefined, super.x);
242 assertEquals(undefined, this.x);
207 super.x = 10; 243 super.x = 10;
244 assertEquals(10, this.x);
208 assertEquals(undefined, super.x); 245 assertEquals(undefined, super.x);
209 }.toMethod(Derived.prototype); 246 }.toMethod(Derived.prototype);
210 247
211 Derived.prototype.mStrict = function () { 248 Derived.prototype.mStrict = function () {
212 'use strict'; 249 'use strict';
250 assertEquals(undefined, super.x);
251 assertEquals(undefined, this.x);
213 super.x = 10; 252 super.x = 10;
253 assertEquals(10, this.x);
254 assertEquals(undefined, super.x);
214 }.toMethod(Derived.prototype); 255 }.toMethod(Derived.prototype);
215 var d = new Derived(); 256 var d = new Derived();
216 d.mSloppy(); 257 d.mSloppy();
217 assertEquals(undefined, d.x); 258 assertEquals(10, d.x);
218 var d1 = new Derived(); 259 var d1 = new Derived();
219 assertThrows(function() { d.mStrict(); }, ReferenceError); 260 d1.mStrict();
220 assertEquals(undefined, d.x); 261 assertEquals(10, d.x);
221 }()); 262 }());
222 263
223 264
265 (function TestSetterCreatingOwnProperties() {
266 function Base() {}
267 function Derived() {}
268 Derived.prototype = { __proto__ : Base.prototype };
269 var setterCalled;
270
271 Derived.prototype.mSloppy = function() {
272 assertEquals(42, this.ownReadOnly);
273 super.ownReadOnly = 55;
274 assertEquals(42, this.ownReadOnly);
275
276 assertEquals(15, this.ownReadonlyAccessor);
277 super.ownReadonlyAccessor = 55;
278 assertEquals(15, this.ownReadonlyAccessor);
279
280 setterCalled = 0;
281 super.ownSetter = 42;
282 assertEquals(1, setterCalled);
283 }.toMethod(Derived.prototype);
284
285 Derived.prototype.mStrict = function() {
286 'use strict';
287 assertEquals(42, this.ownReadOnly);
288 var ex;
289 try {
290 super.ownReadOnly = 55;
291 } catch(e) { ex = e; }
292 assertTrue(ex instanceof TypeError);
293 assertEquals(42, this.ownReadOnly);
294
295 assertEquals(15, this.ownReadonlyAccessor);
296 ex = null;
297 try {
298 super.ownReadonlyAccessor = 55;
299 } catch(e) { ex = e; }
300 assertTrue(ex instanceof TypeError);
301 assertEquals(15, this.ownReadonlyAccessor);
302
303 setterCalled = 0;
304 super.ownSetter = 42;
305 assertEquals(1, setterCalled);
306 }.toMethod(Derived.prototype);
307
308 var d = new Derived();
309 Object.defineProperty(d, 'ownReadOnly', { value : 42, writable : false });
310 Object.defineProperty(d, 'ownSetter',
311 { set : function() { setterCalled++; } });
312 Object.defineProperty(d, 'ownReadonlyAccessor',
313 { get : function() { return 15; }});
314 d.mSloppy();
315 d.mStrict();
316 }());
317
318
319 (function TestSetterNoProtoWalk() {
320 function Base() {}
321 function Derived() {}
322 var getCalled;
323 var setCalled;
324 Derived.prototype = {
325 __proto__ : Base.prototype,
326 get x() { getCalled++; return 42; },
327 set x(v) { setCalled++; }
328 };
329
330 Derived.prototype.mSloppy = function() {
331 setCalled = 0;
332 getCalled = 0;
333 assertEquals(42, this.x);
334 assertEquals(1, getCalled);
335 assertEquals(0, setCalled);
336
337 getCalled = 0;
338 setCalled = 0;
339 this.x = 43;
340 assertEquals(0, getCalled);
341 assertEquals(1, setCalled);
342
343 getCalled = 0;
344 setCalled = 0;
345 super.x = 15;
346 assertEquals(0, setCalled);
347 assertEquals(0, getCalled);
348
349 assertEquals(15, this.x);
350 assertEquals(0, getCalled);
351 assertEquals(0, setCalled);
352
353 }.toMethod(Derived.prototype);
354
355 Derived.prototype.mStrict = function() {
356 'use strict';
357 setCalled = 0;
358 getCalled = 0;
359 assertEquals(42, this.x);
360 assertEquals(1, getCalled);
361 assertEquals(0, setCalled);
362
363 getCalled = 0;
364 setCalled = 0;
365 this.x = 43;
366 assertEquals(0, getCalled);
367 assertEquals(1, setCalled);
368
369 getCalled = 0;
370 setCalled = 0;
371 super.x = 15;
372 assertEquals(0, setCalled);
373 assertEquals(0, getCalled);
374
375 assertEquals(15, this.x);
376 assertEquals(0, getCalled);
377 assertEquals(0, setCalled);
378
379 }.toMethod(Derived.prototype);
380
381 new Derived().mSloppy();
382 new Derived().mStrict();
383 }());
384
385
386 (function TestSetterDoesNotReconfigure() {
387 function Base() {}
388 function Derived() {}
389
390 Derived.prototype.mStrict = function (){
391 'use strict';
392 super.nonEnumConfig = 5;
393 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumConfig');
394 assertEquals(5, d1.value);
395 assertTrue(d1.configurable);
396 assertFalse(d1.enumerable);
397
398 super.nonEnumNonConfig = 5;
399 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumNonConfig');
400 assertEquals(5, d1.value);
401 assertFalse(d1.configurable);
402 assertFalse(d1.enumerable);
403 }.toMethod(Derived.prototype);
404
405 Derived.prototype.mSloppy = function (){
406 super.nonEnumConfig = 42;
407 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumConfig');
408 assertEquals(42, d1.value);
409 assertTrue(d1.configurable);
410 assertFalse(d1.enumerable);
411
412 super.nonEnumNonConfig = 42;
413 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumNonConfig');
414 assertEquals(42, d1.value);
415 assertFalse(d1.configurable);
416 assertFalse(d1.enumerable);
417 }.toMethod(Derived.prototype);
418
419 var d = new Derived();
420 Object.defineProperty(d, 'nonEnumConfig',
421 { value : 0, enumerable : false, configurable : true, writable : true });
422 Object.defineProperty(d, 'nonEnumNonConfig',
423 { value : 0, enumerable : false, configurable : false, writable : true });
424 d.mStrict();
425 d.mSloppy();
426 }());
427
428
224 (function TestCountOperations() { 429 (function TestCountOperations() {
225 function Base() {} 430 function Base() {}
226 Base.prototype = { 431 Base.prototype = {
227 constructor: Base, 432 constructor: Base,
228 get x() { 433 get x() {
229 return this._x; 434 return this._x;
230 }, 435 },
231 set x(v) { 436 set x(v) {
232 this._x = v; 437 this._x = v;
233 }, 438 },
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 }()); 474 }());
270 475
271 476
272 (function TestUnsupportedCases() { 477 (function TestUnsupportedCases() {
273 function f1(x) { return super[x]; } 478 function f1(x) { return super[x]; }
274 function f2(x) { super[x] = 5; } 479 function f2(x) { super[x] = 5; }
275 var o = {}; 480 var o = {};
276 assertThrows(function(){f1.toMethod(o)(x);}, ReferenceError); 481 assertThrows(function(){f1.toMethod(o)(x);}, ReferenceError);
277 assertThrows(function(){f2.toMethod(o)(x);}, ReferenceError); 482 assertThrows(function(){f2.toMethod(o)(x);}, ReferenceError);
278 }()); 483 }());
OLDNEW
« src/objects.cc ('K') | « src/objects.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698