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

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

Issue 915563003: super is only allowed in methods, accessors and constructor (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Use i:: to qualify function name Created 5 years, 10 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
« no previous file with comments | « test/mjsunit/harmony/object-literals-super.js ('k') | test/mjsunit/mjsunit.status » ('j') | 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
8 (function TestSuperNamedLoads() { 7 (function TestSuperNamedLoads() {
9 function Base() { } 8 function Base() { }
9 function fBase() { }
10 Base.prototype = {
11 f() {
12 return "Base " + this.toString();
13 },
14 x: 15,
15 toString() {
16 return "this is Base";
17 }
18 };
19
10 function Derived() { 20 function Derived() {
11 this.derivedDataProperty = "xxx"; 21 this.derivedDataProperty = "xxx";
12 } 22 }
13 Derived.prototype = Object.create(Base.prototype); 23 Derived.prototype = {
14 24 __proto__: Base.prototype,
15 function fBase() { return "Base " + this.toString(); } 25 toString() { return "this is Derived"; },
16 26 x: 27,
17 Base.prototype.f = fBase.toMethod(Base.prototype); 27 f() {
18 28 assertEquals("Base this is Derived", super.f());
19 function fDerived() { 29 var a = super.x;
20 assertEquals("Base this is Derived", super.f()); 30 assertEquals(15, a);
21 var a = super.x; 31 assertEquals(15, super.x);
22 assertEquals(15, a); 32 assertEquals(27, this.x);
23 assertEquals(15, super.x); 33 return "Derived";
24 assertEquals(27, this.x); 34 }
25 35 };
26 return "Derived"
27 }
28
29 Base.prototype.x = 15;
30 Base.prototype.toString = function() { return "this is Base"; };
31 Derived.prototype.toString = function() { return "this is Derived"; };
32 Derived.prototype.x = 27;
33 Derived.prototype.f = fDerived.toMethod(Derived.prototype);
34 36
35 assertEquals("Base this is Base", new Base().f()); 37 assertEquals("Base this is Base", new Base().f());
36 assertEquals("Derived", new Derived().f()); 38 assertEquals("Derived", new Derived().f());
37 }()); 39 }());
38 40
39 41
40 (function TestSuperKeyedLoads() { 42 (function TestSuperKeyedLoads() {
41 var x = 'x'; 43 var x = 'x';
42 var derivedDataProperty = 'derivedDataProperty'; 44 var derivedDataProperty = 'derivedDataProperty';
43 var f = 'f'; 45 var f = 'f';
46
44 function Base() { } 47 function Base() { }
45 function Derived() {
46 this[derivedDataProperty] = 'xxx';
47 }
48 Derived.prototype = Object.create(Base.prototype);
49
50 function fBase() { return "Base " + this.toString(); } 48 function fBase() { return "Base " + this.toString(); }
51
52 Base.prototype[f] = fBase.toMethod(Base.prototype); 49 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; 50 Base.prototype[x] = 15;
65 Base.prototype.toString = function() { return "this is Base"; }; 51 Base.prototype.toString = function() { return "this is Base"; };
66 Derived.prototype.toString = function() { return "this is Derived"; }; 52
67 Derived.prototype[x] = 27; 53 function Derived() {
68 Derived.prototype[f] = fDerived.toMethod(Derived.prototype); 54 this[derivedDataProperty] = "xxx";
55 }
56 Derived.prototype = {
57 __proto__: Base.prototype,
58 toString() { return "this is Derived"; },
59 x: 27,
60 f() {
61 assertEquals("Base this is Derived", super[f]());
62 var a = super[x];
63 assertEquals(15, a);
64 assertEquals(15, super[x]);
65 assertEquals(27, this[x]);
66 return "Derived";
67 }
68 };
69 69
70 assertEquals("Base this is Base", new Base().f()); 70 assertEquals("Base this is Base", new Base().f());
71 assertEquals("Derived", new Derived().f()); 71 assertEquals("Derived", new Derived().f());
72 }()); 72 }());
73 73
74 74
75 (function TestSuperNumericKeyedLoads() { 75 (function TestSuperNumericKeyedLoads() {
76 var x = 1; 76 var x = 1;
77 var derivedDataProperty = 2; 77 var derivedDataProperty = 2;
78 var f = 3; 78 var f = 3;
79
79 function Base() { } 80 function Base() { }
80 function Derived() {
81 this[derivedDataProperty] = 'xxx';
82 }
83 Derived.prototype = Object.create(Base.prototype);
84
85 function fBase() { return "Base " + this.toString(); } 81 function fBase() { return "Base " + this.toString(); }
86
87 Base.prototype[f] = fBase.toMethod(Base.prototype); 82 Base.prototype[f] = fBase.toMethod(Base.prototype);
88
89 function fDerived() {
90 assertEquals("Base this is Derived", super[f]());
91 var a = super[x];
92 assertEquals(15, a);
93 assertEquals(15, super[x]);
94 assertEquals(27, this[x]);
95
96 return "Derived"
97 }
98
99 Base.prototype[x] = 15; 83 Base.prototype[x] = 15;
100 Base.prototype.toString = function() { return "this is Base"; }; 84 Base.prototype.toString = function() { return "this is Base"; };
101 Derived.prototype.toString = function() { return "this is Derived"; }; 85
102 Derived.prototype[x] = 27; 86 function Derived() {
103 Derived.prototype[f] = fDerived.toMethod(Derived.prototype); 87 this[derivedDataProperty] = "xxx";
88 }
89 Derived.prototype = {
90 __proto__: Base.prototype,
91 toString() { return "this is Derived"; },
92 1: 27,
93 3() {
94 assertEquals("Base this is Derived", super[f]());
95 var a = super[x];
96 assertEquals(15, a);
97 assertEquals(15, super[x]);
98 assertEquals(27, this[x]);
99 return "Derived";
100 }
101 };
104 102
105 assertEquals("Base this is Base", new Base()[f]()); 103 assertEquals("Base this is Base", new Base()[f]());
106 assertEquals("Derived", new Derived()[f]()); 104 assertEquals("Derived", new Derived()[f]());
107 }()); 105 }());
108 106
109 107
110 (function TestSuperKeywordNonMethod() { 108 (function TestSuperKeywordNonMethod() {
111 function f() { 109 'use strict';
112 super.unknown(); 110
111 class C {
112 f() {
113 super.unknown();
114 }
113 } 115 }
114 116
115 assertThrows(f, ReferenceError); 117 assertThrows(function() {
118 new C().f();
119 }, TypeError);
116 }()); 120 }());
117 121
118 122
119 (function TestGetter() { 123 (function TestGetter() {
120 function Base() {} 124 function Base() {}
121 var derived; 125 var derived;
122 Base.prototype = { 126 Base.prototype = {
123 constructor: Base, 127 constructor: Base,
124 get x() { 128 get x() {
125 assertSame(this, derived); 129 assertSame(this, derived);
126 return this._x; 130 return this._x;
127 }, 131 },
128 _x: 'base' 132 _x: 'base'
129 }; 133 };
130 134
131 function Derived() {} 135 function Derived() {}
132 Derived.__proto__ = Base; 136 Derived.__proto__ = Base;
133 Derived.prototype = { 137 Derived.prototype = {
134 __proto__: Base.prototype, 138 __proto__: Base.prototype,
135 constructor: Derived, 139 constructor: Derived,
136 _x: 'derived' 140 _x: 'derived',
141 testGetter() {
142 return super.x;
143 },
144 testGetterStrict() {
145 'use strict';
146 return super.x;
147 }
137 }; 148 };
138 Derived.prototype.testGetter = function() { 149
139 return super.x;
140 }.toMethod(Derived.prototype);
141 Derived.prototype.testGetterStrict = function() {
142 'use strict';
143 return super.x;
144 }.toMethod(Derived.prototype);
145 derived = new Derived(); 150 derived = new Derived();
146 assertEquals('derived', derived.testGetter()); 151 assertEquals('derived', derived.testGetter());
147 derived = new Derived(); 152 derived = new Derived();
148 assertEquals('derived', derived.testGetterStrict()); 153 assertEquals('derived', derived.testGetterStrict());
149 }()); 154 }());
150 155
151 156
152 (function TestGetterKeyed() { 157 (function TestGetterKeyed() {
153 var x = 'x'; 158 var x = 'x';
154 function Base() {} 159 function Base() {}
155 var derived; 160 var derived;
156 Base.prototype = { 161 Base.prototype = {
157 constructor: Base, 162 constructor: Base,
158 get x() { 163 get x() {
159 assertSame(this, derived); 164 assertSame(this, derived);
160 return this._x; 165 return this._x;
161 }, 166 },
162 _x: 'base' 167 _x: 'base'
163 }; 168 };
164 169
165 function Derived() {} 170 function Derived() {}
166 Derived.__proto__ = Base; 171 Derived.__proto__ = Base;
167 Derived.prototype = { 172 Derived.prototype = {
168 __proto__: Base.prototype, 173 __proto__: Base.prototype,
169 constructor: Derived, 174 constructor: Derived,
170 _x: 'derived' 175 _x: 'derived',
176 testGetter() {
177 return super[x];
178 },
179 testGetterStrict() {
180 'use strict';
181 return super[x];
182 },
183 testGetterWithToString() {
184 var toStringCalled;
185 var o = { toString: function() {
186 toStringCalled++;
187 return 'x';
188 } };
189
190 toStringCalled = 0;
191 assertEquals('derived', super[o]);
192 assertEquals(1, toStringCalled);
193
194 var eToThrow = new Error();
195 var oThrowsInToString = { toString: function() {
196 throw eToThrow;
197 } };
198
199 var ex = null;
200 try {
201 super[oThrowsInToString];
202 } catch(e) { ex = e }
203 assertEquals(eToThrow, ex);
204
205 var oReturnsNumericString = { toString: function() {
206 return "1";
207 } };
208
209 assertEquals(undefined, super[oReturnsNumericString]);
210 assertEquals(undefined, super[1]);
211 }
171 }; 212 };
172 Derived.prototype.testGetter = function() {
173 return super[x];
174 }.toMethod(Derived.prototype);
175 Derived.prototype.testGetterStrict = function() {
176 'use strict';
177 return super[x];
178 }.toMethod(Derived.prototype);
179 Derived.prototype.testGetterWithToString = function() {
180 var toStringCalled;
181 var o = { toString: function() {
182 toStringCalled++;
183 return 'x';
184 } };
185 213
186 toStringCalled = 0;
187 assertEquals('derived', super[o]);
188 assertEquals(1, toStringCalled);
189
190 var eToThrow = new Error();
191 var oThrowsInToString = { toString: function() {
192 throw eToThrow;
193 } };
194
195 var ex = null;
196 try {
197 super[oThrowsInToString];
198 } catch(e) { ex = e }
199 assertEquals(eToThrow, ex);
200
201 var oReturnsNumericString = { toString: function() {
202 return "1";
203 } };
204
205 assertEquals(undefined, super[oReturnsNumericString]);
206 assertEquals(undefined, super[1]);
207 }.toMethod(Derived.prototype);
208 derived = new Derived(); 214 derived = new Derived();
209 assertEquals('derived', derived.testGetter()); 215 assertEquals('derived', derived.testGetter());
210 derived = new Derived(); 216 derived = new Derived();
211 assertEquals('derived', derived.testGetterStrict()); 217 assertEquals('derived', derived.testGetterStrict());
212 derived = new Derived(); 218 derived = new Derived();
213 derived.testGetterWithToString(); 219 derived.testGetterWithToString();
214 }()); 220 }());
215 221
216 222
217 (function TestGetterNumericKeyed() { 223 (function TestGetterNumericKeyed() {
218 var x = 42; 224 var x = 42;
219 function Base() {} 225 function Base() {}
220 var derived; 226 var derived;
221 Base.prototype = { 227 Base.prototype = {
222 constructor: Base, 228 constructor: Base,
223 _x: 'base' 229 _x: 'base'
224 }; 230 };
225 231
226 Object.defineProperty(Base.prototype, x, { get: function() { 232 Object.defineProperty(Base.prototype, x, { get: function() {
227 assertSame(this, derived); 233 assertSame(this, derived);
228 return this._x; 234 return this._x;
229 }}); 235 }});
230 236
231 function Derived() {} 237 function Derived() {}
232 Derived.__proto__ = Base; 238 Derived.__proto__ = Base;
233 Derived.prototype = { 239 Derived.prototype = {
234 __proto__: Base.prototype, 240 __proto__: Base.prototype,
235 constructor: Derived, 241 constructor: Derived,
236 _x: 'derived' 242 _x: 'derived',
243 testGetter() {
244 return super[x];
245 },
246 testGetterStrict() {
247 'use strict';
248 return super[x];
249 },
250 testGetterWithToString() {
251 var toStringCalled;
252 var o = {
253 toString: function() {
254 toStringCalled++;
255 return '42';
256 }
257 };
258
259 toStringCalled = 0;
260 assertEquals('derived', super[o]);
261 assertEquals(1, toStringCalled);
262
263 var eToThrow = new Error();
264 var oThrowsInToString = {
265 toString: function() {
266 throw eToThrow;
267 }
268 };
269
270 var ex = null;
271 try {
272 super[oThrowsInToString];
273 } catch(e) { ex = e }
274 assertEquals(eToThrow, ex);
275
276 var oReturnsNumericString = {
277 toString: function() {
278 return "42";
279 }
280 };
281
282 assertEquals('derived', super[oReturnsNumericString]);
283 assertEquals('derived', super[42]);
284 }
237 }; 285 };
238 Derived.prototype.testGetter = function() {
239 return super[x];
240 }.toMethod(Derived.prototype);
241 Derived.prototype.testGetterStrict = function() {
242 'use strict';
243 return super[x];
244 }.toMethod(Derived.prototype);
245 286
246 Derived.prototype.testGetterWithToString = function() {
247 var toStringCalled;
248 var o = { toString: function() {
249 toStringCalled++;
250 return '42';
251 } };
252
253 toStringCalled = 0;
254 assertEquals('derived', super[o]);
255 assertEquals(1, toStringCalled);
256
257 var eToThrow = new Error();
258 var oThrowsInToString = { toString: function() {
259 throw eToThrow;
260 } };
261
262 var ex = null;
263 try {
264 super[oThrowsInToString];
265 } catch(e) { ex = e }
266 assertEquals(eToThrow, ex);
267
268 var oReturnsNumericString = { toString: function() {
269 return "42";
270 } };
271
272 assertEquals('derived', super[oReturnsNumericString]);
273 assertEquals('derived', super[42]);
274 }.toMethod(Derived.prototype);
275 derived = new Derived(); 287 derived = new Derived();
276 assertEquals('derived', derived.testGetter()); 288 assertEquals('derived', derived.testGetter());
277 derived = new Derived(); 289 derived = new Derived();
278 assertEquals('derived', derived.testGetterStrict()); 290 assertEquals('derived', derived.testGetterStrict());
279 derived = new Derived(); 291 derived = new Derived();
280 derived.testGetterWithToString(); 292 derived.testGetterWithToString();
281 }()); 293 }());
282 294
283 295
284 (function TestSetter() { 296 (function TestSetter() {
285 function Base() {} 297 function Base() {}
286 Base.prototype = { 298 Base.prototype = {
287 constructor: Base, 299 constructor: Base,
288 get x() { 300 get x() {
289 return this._x; 301 return this._x;
290 }, 302 },
291 set x(v) { 303 set x(v) {
292 this._x = v; 304 this._x = v;
293 }, 305 },
294 _x: 'base' 306 _x: 'base'
295 }; 307 };
296 308
297 function Derived() {} 309 function Derived() {}
298 Derived.__proto__ = Base; 310 Derived.__proto__ = Base;
299 Derived.prototype = { 311 Derived.prototype = {
300 __proto__: Base.prototype, 312 __proto__: Base.prototype,
301 constructor: Derived, 313 constructor: Derived,
302 _x: 'derived' 314 _x: 'derived',
315 testSetter() {
316 assertEquals('foobar', super.x = 'foobar');
317 assertEquals('foobarabc', super.x += 'abc');
318 },
319 testSetterStrict() {
320 'use strict';
321 assertEquals('foobar', super.x = 'foobar');
322 assertEquals('foobarabc', super.x += 'abc');
323 }
303 }; 324 };
304 Derived.prototype.testSetter = function() { 325
305 assertEquals('foobar', super.x = 'foobar');
306 assertEquals('foobarabc', super.x += 'abc');
307 }.toMethod(Derived.prototype);
308 var d = new Derived(); 326 var d = new Derived();
309 d.testSetter(); 327 d.testSetter();
310 assertEquals('base', Base.prototype._x); 328 assertEquals('base', Base.prototype._x);
311 assertEquals('foobarabc', d._x); 329 assertEquals('foobarabc', d._x);
312 d._x = ''; 330 d._x = '';
313 Derived.prototype.testSetterStrict = function() { 331
314 'use strict';
315 assertEquals('foobar', super.x = 'foobar');
316 assertEquals('foobarabc', super.x += 'abc');
317 }.toMethod(Derived.prototype);
318 d.testSetterStrict(); 332 d.testSetterStrict();
319 assertEquals('base', Base.prototype._x); 333 assertEquals('base', Base.prototype._x);
320 assertEquals('foobarabc', d._x); 334 assertEquals('foobarabc', d._x);
321 }()); 335 }());
322 336
323 337
324 (function TestSetterNumericKeyed() { 338 (function TestSetterNumericKeyed() {
325 var x = 42; 339 var x = 42;
326 function Base() {} 340 function Base() {}
327 Base.prototype = { 341 Base.prototype = {
328 constructor: Base, 342 constructor: Base,
329 _x: 'base' 343 _x: 'base'
330 }; 344 };
331 345
332 Object.defineProperty(Base.prototype, x, 346 Object.defineProperty(Base.prototype, x,
333 { get: function() { return this._x; }, 347 { get: function() { return this._x; },
334 set: function(v) { this._x = v; } 348 set: function(v) { this._x = v; }
335 }); 349 });
336 350
337 function Derived() {} 351 function Derived() {}
338 Derived.__proto__ = Base; 352 Derived.__proto__ = Base;
339 Derived.prototype = { 353 Derived.prototype = {
340 __proto__: Base.prototype, 354 __proto__: Base.prototype,
341 constructor: Derived, 355 constructor: Derived,
342 _x: 'derived' 356 _x: 'derived',
357 testSetter() {
358 assertEquals('foobar', super[x] = 'foobar');
359 assertEquals('foobarabc', super[x] += 'abc');
360 },
361 testSetterStrict() {
362 'use strict';
363 assertEquals('foobar', super[x] = 'foobar');
364 assertEquals('foobarabc', super[x] += 'abc');
365 },
366 testSetterWithToString() {
367 var toStringCalled;
368 var o = {
369 toString: function() {
370 toStringCalled++;
371 return x;
372 }
373 };
374
375 toStringCalled = 0;
376 super[o] = 'set';
377 assertEquals(1, toStringCalled);
378 assertEquals('set', this._x);
379
380 var eToThrow = new Error();
381 var oThrowsInToString = {
382 toString: function() {
383 throw eToThrow;
384 }
385 };
386
387 var ex = null;
388 try {
389 super[oThrowsInToString] = 'xyz';
390 } catch(e) { ex = e }
391 assertEquals(eToThrow, ex);
392 assertEquals('set', this._x);
393 }
343 }; 394 };
344 Derived.prototype.testSetter = function() { 395
345 assertEquals('foobar', super[x] = 'foobar');
346 assertEquals('foobarabc', super[x] += 'abc');
347 }.toMethod(Derived.prototype);
348 var d = new Derived(); 396 var d = new Derived();
349 d.testSetter(); 397 d.testSetter();
350 assertEquals('base', Base.prototype._x); 398 assertEquals('base', Base.prototype._x);
351 assertEquals('foobarabc', d._x); 399 assertEquals('foobarabc', d._x);
352 d._x = ''; 400 d._x = '';
353 Derived.prototype.testSetterStrict = function() { 401
354 'use strict';
355 assertEquals('foobar', super[x] = 'foobar');
356 assertEquals('foobarabc', super[x] += 'abc');
357 }.toMethod(Derived.prototype);
358 d.testSetterStrict(); 402 d.testSetterStrict();
359 assertEquals('base', Base.prototype._x); 403 assertEquals('base', Base.prototype._x);
360 assertEquals('foobarabc', d._x); 404 assertEquals('foobarabc', d._x);
361 405
362
363 Derived.prototype.testSetterWithToString = function() {
364 var toStringCalled;
365 var o = { toString: function() {
366 toStringCalled++;
367 return x;
368 } };
369
370 toStringCalled = 0;
371 super[o] = 'set';
372 assertEquals(1, toStringCalled);
373 assertEquals('set', this._x);
374
375 var eToThrow = new Error();
376 var oThrowsInToString = { toString: function() {
377 throw eToThrow;
378 } };
379
380 var ex = null;
381 try {
382 super[oThrowsInToString] = 'xyz';
383 } catch(e) { ex = e }
384 assertEquals(eToThrow, ex);
385 assertEquals('set', this._x);
386 }.toMethod(Derived.prototype);
387 d = new Derived(); 406 d = new Derived();
388 d.testSetterWithToString(); 407 d.testSetterWithToString();
389 }()); 408 }());
390 409
391 410
392 (function TestSetterKeyed() { 411 (function TestSetterKeyed() {
393 var x = 'x'; 412 var x = 'x';
394 function Base() {} 413 function Base() {}
395 Base.prototype = { 414 Base.prototype = {
396 constructor: Base, 415 constructor: Base,
397 get x() { 416 get x() {
398 return this._x; 417 return this._x;
399 }, 418 },
400 set x(v) { 419 set x(v) {
401 this._x = v; 420 this._x = v;
402 }, 421 },
403 _x: 'base' 422 _x: 'base'
404 }; 423 };
405 424
406 function Derived() {} 425 function Derived() {}
407 Derived.__proto__ = Base; 426 Derived.__proto__ = Base;
408 Derived.prototype = { 427 Derived.prototype = {
409 __proto__: Base.prototype, 428 __proto__: Base.prototype,
410 constructor: Derived, 429 constructor: Derived,
411 _x: 'derived' 430 _x: 'derived',
431 testSetter() {
432 assertEquals('foobar', super[x] = 'foobar');
433 assertEquals('foobarabc', super[x] += 'abc');
434 },
435 testSetterStrict() {
436 'use strict';
437 assertEquals('foobar', super[x] = 'foobar');
438 assertEquals('foobarabc', super[x] += 'abc');
439 },
440 testSetterWithToString() {
441 var toStringCalled;
442 var o = {
443 toString: function() {
444 toStringCalled++;
445 return 'x';
446 }
447 };
448
449 toStringCalled = 0;
450 super[o] = 'set';
451 assertEquals(1, toStringCalled);
452 assertEquals('set', this._x);
453
454 var eToThrow = new Error();
455 var oThrowsInToString = {
456 toString: function() {
457 throw eToThrow;
458 }
459 };
460
461 var ex = null;
462 try {
463 super[oThrowsInToString] = 'xyz';
464 } catch(e) { ex = e }
465 assertEquals(eToThrow, ex);
466 assertEquals('set', this._x);
467
468 var oReturnsNumericString = {
469 toString: function() {
470 return "1";
471 }
472 };
473
474 assertEquals('abc', super[oReturnsNumericString] = 'abc');
475
476 assertEquals('set', this._x);
477
478 assertEquals(10, super[1] = 10);
479 }
412 }; 480 };
413 Derived.prototype.testSetter = function() { 481
414 assertEquals('foobar', super[x] = 'foobar');
415 assertEquals('foobarabc', super[x] += 'abc');
416 }.toMethod(Derived.prototype);
417 var d = new Derived(); 482 var d = new Derived();
418 d.testSetter(); 483 d.testSetter();
419 assertEquals('base', Base.prototype._x); 484 assertEquals('base', Base.prototype._x);
420 assertEquals('foobarabc', d._x); 485 assertEquals('foobarabc', d._x);
421 d._x = ''; 486 d._x = '';
422 Derived.prototype.testSetterStrict = function() {
423 'use strict';
424 assertEquals('foobar', super[x] = 'foobar');
425 assertEquals('foobarabc', super[x] += 'abc');
426 }.toMethod(Derived.prototype);
427 d.testSetterStrict(); 487 d.testSetterStrict();
428 assertEquals('base', Base.prototype._x); 488 assertEquals('base', Base.prototype._x);
429 assertEquals('foobarabc', d._x); 489 assertEquals('foobarabc', d._x);
430 490
431
432 Derived.prototype.testSetterWithToString = function() {
433 var toStringCalled;
434 var o = { toString: function() {
435 toStringCalled++;
436 return 'x';
437 } };
438
439 toStringCalled = 0;
440 super[o] = 'set';
441 assertEquals(1, toStringCalled);
442 assertEquals('set', this._x);
443
444 var eToThrow = new Error();
445 var oThrowsInToString = { toString: function() {
446 throw eToThrow;
447 } };
448
449 var ex = null;
450 try {
451 super[oThrowsInToString] = 'xyz';
452 } catch(e) { ex = e }
453 assertEquals(eToThrow, ex);
454 assertEquals('set', this._x);
455
456 var oReturnsNumericString = { toString: function() {
457 return "1";
458 } };
459
460 assertEquals('abc', super[oReturnsNumericString] = 'abc');
461
462 assertEquals('set', this._x);
463
464 assertEquals(10, super[1] = 10);
465 }.toMethod(Derived.prototype);
466 d = new Derived(); 491 d = new Derived();
467 d.testSetterWithToString(); 492 d.testSetterWithToString();
468 }()); 493 }());
469 494
470 495
471 (function TestSetterDataProperties() { 496 (function TestSetterDataProperties() {
472 function Base() {} 497 function Base() {}
473 Base.prototype = { 498 Base.prototype = {
474 constructor: Base, 499 constructor: Base,
475 x: 'x from Base' 500 x: 'x from Base'
476 }; 501 };
477 502
478 function Derived() {} 503 function Derived() {}
479 Derived.prototype = { 504 Derived.prototype = {
480 __proto__: Base.prototype, 505 __proto__: Base.prototype,
481 constructor: Derived, 506 constructor: Derived,
507 testSetter() {
508 assertEquals('x from Base', super.x);
509 super.x = 'data property';
510 assertEquals('x from Base', super.x);
511 assertEquals('data property', this.x);
512 }
482 }; 513 };
483 514
484 Derived.prototype.testSetter = function() {
485 assertEquals('x from Base', super.x);
486 super.x = 'data property';
487 assertEquals('x from Base', super.x);
488 assertEquals('data property', this.x);
489 }.toMethod(Derived.prototype);
490
491 new Derived().testSetter(); 515 new Derived().testSetter();
492 }()); 516 }());
493 517
494 518
495 (function TestKeyedSetterDataProperties() { 519 (function TestKeyedSetterDataProperties() {
496 var x = 'x'; 520 var x = 'x';
497 function Base() {} 521 function Base() {}
498 Base.prototype = { 522 Base.prototype = {
499 constructor: Base, 523 constructor: Base,
500 x: 'x from Base' 524 x: 'x from Base'
501 }; 525 };
502 526
503 function Derived() {} 527 function Derived() {}
504 Derived.prototype = { 528 Derived.prototype = {
505 __proto__: Base.prototype, 529 __proto__: Base.prototype,
506 constructor: Derived, 530 constructor: Derived,
531 testSetter() {
532 assertEquals('x from Base', super[x]);
533 super[x] = 'data property';
534 assertEquals('x from Base', super[x]);
535 assertEquals('data property', this[x]);
536 }
507 }; 537 };
508 538
509 Derived.prototype.testSetter = function() {
510 assertEquals('x from Base', super[x]);
511 super[x] = 'data property';
512 assertEquals('x from Base', super[x]);
513 assertEquals('data property', this[x]);
514 }.toMethod(Derived.prototype);
515
516 new Derived().testSetter(); 539 new Derived().testSetter();
517 }()); 540 }());
518 541
519 542
520 (function TestKeyedNumericSetterDataProperties() { 543 (function TestKeyedNumericSetterDataProperties() {
521 var x = 42; 544 var x = 42;
522 function Base() {} 545 function Base() {}
523 Base.prototype = { 546 Base.prototype = {
524 constructor: Base, 547 constructor: Base,
525 42: 'x from Base' 548 42: 'x from Base'
526 }; 549 };
527 550
528 function Derived() {} 551 function Derived() {}
529 Derived.prototype = { 552 Derived.prototype = {
530 __proto__: Base.prototype, 553 __proto__: Base.prototype,
531 constructor: Derived, 554 constructor: Derived,
555 testSetter() {
556 assertEquals('x from Base', super[x]);
557 super[x] = 'data property';
558 assertEquals('x from Base', super[x]);
559 assertEquals('data property', this[x]);
560 }
532 }; 561 };
533 562
534 Derived.prototype.testSetter = function() {
535 assertEquals('x from Base', super[x]);
536 super[x] = 'data property';
537 assertEquals('x from Base', super[x]);
538 assertEquals('data property', this[x]);
539 }.toMethod(Derived.prototype);
540
541 new Derived().testSetter(); 563 new Derived().testSetter();
542 }()); 564 }());
543 565
544 566
545 (function TestAccessorsOnPrimitives() { 567 (function TestAccessorsOnPrimitives() {
546 var getCalled = 0; 568 var getCalled = 0;
547 var setCalled = 0; 569 var setCalled = 0;
548 function Base() {} 570 function Base() {}
549 Base.prototype = { 571 Base.prototype = {
550 constructor: Base, 572 constructor: Base,
551 get x() { 573 get x() {
552 getCalled++; 574 getCalled++;
553 return 1; 575 return 1;
554 }, 576 },
555 set x(v) { 577 set x(v) {
556 setCalled++; 578 setCalled++;
557 return v; 579 return v;
558 }, 580 },
559 }; 581 };
560 582
561 function Derived() {} 583 function Derived() {}
562 Derived.prototype = { 584 Derived.prototype = {
563 __proto__: Base.prototype, 585 __proto__: Base.prototype,
564 constructor: Derived, 586 constructor: Derived,
565 }; 587 testSetter() {
566 Derived.prototype.testSetter = function() { 588 setCalled = 0;
567 setCalled = 0; 589 getCalled = 0;
568 getCalled = 0; 590 assertEquals('object', typeof this);
569 assertEquals('object', typeof this); 591 assertTrue(this instanceof Number)
570 assertTrue(this instanceof Number) 592 assertEquals(42, this.valueOf());
571 assertEquals(42, this.valueOf()); 593 assertEquals(1, super.x);
572 assertEquals(1, super.x); 594 assertEquals(1, getCalled);
573 assertEquals(1, getCalled); 595 assertEquals(0, setCalled);
574 assertEquals(0, setCalled);
575 596
576 assertEquals(5, super.x = 5); 597 assertEquals(5, super.x = 5);
577 assertEquals(1, getCalled); 598 assertEquals(1, getCalled);
578 assertEquals(1, setCalled); 599 assertEquals(1, setCalled);
579 600
580 assertEquals(6, super.x += 5); 601 assertEquals(6, super.x += 5);
581 assertEquals(2, getCalled); 602 assertEquals(2, getCalled);
582 assertEquals(2, setCalled); 603 assertEquals(2, setCalled);
583 604
584 super.newProperty = 15; 605 super.newProperty = 15;
585 assertEquals(15, this.newProperty); 606 assertEquals(15, this.newProperty);
586 assertEquals(undefined, super.newProperty); 607 assertEquals(undefined, super.newProperty);
587 }.toMethod(Derived.prototype); 608 },
609 testSetterStrict() {
610 'use strict';
611 getCalled = 0;
612 setCalled = 0;
613 assertTrue(42 === this);
588 614
589 Derived.prototype.testSetterStrict = function() { 615 assertEquals(1, super.x);
590 'use strict'; 616 assertEquals(1, getCalled);
591 getCalled = 0; 617 assertEquals(0, setCalled);
592 setCalled = 0;
593 assertTrue(42 === this);
594 618
595 assertEquals(1, super.x); 619 assertEquals(5, super.x = 5);
596 assertEquals(1, getCalled); 620 assertEquals(1, getCalled);
597 assertEquals(0, setCalled); 621 assertEquals(1, setCalled);
598 622
599 assertEquals(5, super.x = 5); 623 assertEquals(6, super.x += 5);
600 assertEquals(1, getCalled); 624 assertEquals(2, getCalled);
601 assertEquals(1, setCalled); 625 assertEquals(2, setCalled);
602 626
603 assertEquals(6, super.x += 5); 627 var ex;
604 assertEquals(2, getCalled); 628 try {
605 assertEquals(2, setCalled); 629 super.newProperty = 15;
606 630 } catch (e) { ex = e; }
607 var ex; 631 assertTrue(ex instanceof TypeError);
608 try { 632 }
609 super.newProperty = 15; 633 }
610 } catch (e) { ex = e; }
611 assertTrue(ex instanceof TypeError);
612 }.toMethod(Derived.prototype);
613 634
614 Derived.prototype.testSetter.call(42); 635 Derived.prototype.testSetter.call(42);
615 Derived.prototype.testSetterStrict.call(42); 636 Derived.prototype.testSetterStrict.call(42);
616 637
617 function DerivedFromString() {} 638 function DerivedFromString() {}
618 DerivedFromString.prototype = Object.create(String.prototype); 639 DerivedFromString.prototype = {
640 __proto__: String.prototype,
641 f() {
642 'use strict';
643 assertTrue(42 === this);
644 assertEquals(String.prototype.toString, super.toString);
645 var ex;
646 try {
647 super.toString();
648 } catch(e) { ex = e; }
619 649
620 function f() { 650 assertTrue(ex instanceof TypeError);
621 'use strict'; 651 }
622 assertTrue(42 === this); 652 };
623 assertEquals(String.prototype.toString, super.toString);
624 var ex;
625 try {
626 super.toString();
627 } catch(e) { ex = e; }
628 653
629 assertTrue(ex instanceof TypeError); 654 DerivedFromString.prototype.f.call(42);
630 }
631 f.toMethod(DerivedFromString.prototype).call(42);
632 }()); 655 }());
633 656
634 657
635 (function TestKeyedAccessorsOnPrimitives() { 658 (function TestKeyedAccessorsOnPrimitives() {
636 var x = 'x'; 659 var x = 'x';
637 var newProperty = 'newProperty'; 660 var newProperty = 'newProperty';
638 var toString = 'toString'; 661 var toString = 'toString';
639 var getCalled = 0; 662 var getCalled = 0;
640 var setCalled = 0; 663 var setCalled = 0;
641 function Base() {} 664 function Base() {}
642 Base.prototype = { 665 Base.prototype = {
643 constructor: Base, 666 constructor: Base,
644 get x() { 667 get x() {
645 getCalled++; 668 getCalled++;
646 return 1; 669 return 1;
647 }, 670 },
648 set x(v) { 671 set x(v) {
649 setCalled++; 672 setCalled++;
650 return v; 673 return v;
651 }, 674 },
652 }; 675 };
653 676
654 function Derived() {} 677 function Derived() {}
655 Derived.prototype = { 678 Derived.prototype = {
656 __proto__: Base.prototype, 679 __proto__: Base.prototype,
657 constructor: Derived, 680 constructor: Derived,
681 testSetter() {
682 setCalled = 0;
683 getCalled = 0;
684 assertEquals('object', typeof this);
685 assertTrue(this instanceof Number)
686 assertEquals(42, this.valueOf());
687 assertEquals(1, super[x]);
688 assertEquals(1, getCalled);
689 assertEquals(0, setCalled);
690
691 assertEquals(5, super[x] = 5);
692 assertEquals(1, getCalled);
693 assertEquals(1, setCalled);
694
695 assertEquals(6, super[x] += 5);
696 assertEquals(2, getCalled);
697 assertEquals(2, setCalled);
698
699 super[newProperty] = 15;
700 assertEquals(15, this[newProperty]);
701 assertEquals(undefined, super[newProperty]);
702 },
703 testSetterStrict() {
704 'use strict';
705 getCalled = 0;
706 setCalled = 0;
707 assertTrue(42 === this);
708
709 assertEquals(1, super[x]);
710 assertEquals(1, getCalled);
711 assertEquals(0, setCalled);
712
713 assertEquals(5, super[x] = 5);
714 assertEquals(1, getCalled);
715 assertEquals(1, setCalled);
716
717 assertEquals(6, super[x] += 5);
718 assertEquals(2, getCalled);
719 assertEquals(2, setCalled);
720
721 var ex;
722 try {
723 super[newProperty] = 15;
724 } catch (e) { ex = e; }
725 assertTrue(ex instanceof TypeError);
726 }
658 }; 727 };
659 Derived.prototype.testSetter = function() {
660 setCalled = 0;
661 getCalled = 0;
662 assertEquals('object', typeof this);
663 assertTrue(this instanceof Number)
664 assertEquals(42, this.valueOf());
665 assertEquals(1, super[x]);
666 assertEquals(1, getCalled);
667 assertEquals(0, setCalled);
668
669 assertEquals(5, super[x] = 5);
670 assertEquals(1, getCalled);
671 assertEquals(1, setCalled);
672
673 assertEquals(6, super[x] += 5);
674 assertEquals(2, getCalled);
675 assertEquals(2, setCalled);
676
677 super[newProperty] = 15;
678 assertEquals(15, this[newProperty]);
679 assertEquals(undefined, super[newProperty]);
680 }.toMethod(Derived.prototype);
681
682 Derived.prototype.testSetterStrict = function() {
683 'use strict';
684 getCalled = 0;
685 setCalled = 0;
686 assertTrue(42 === this);
687
688 assertEquals(1, super[x]);
689 assertEquals(1, getCalled);
690 assertEquals(0, setCalled);
691
692 assertEquals(5, super[x] = 5);
693 assertEquals(1, getCalled);
694 assertEquals(1, setCalled);
695
696 assertEquals(6, super[x] += 5);
697 assertEquals(2, getCalled);
698 assertEquals(2, setCalled);
699
700 var ex;
701 try {
702 super[newProperty] = 15;
703 } catch (e) { ex = e; }
704 assertTrue(ex instanceof TypeError);
705 }.toMethod(Derived.prototype);
706 728
707 Derived.prototype.testSetter.call(42); 729 Derived.prototype.testSetter.call(42);
708 Derived.prototype.testSetterStrict.call(42); 730 Derived.prototype.testSetterStrict.call(42);
709 731
710 function DerivedFromString() {} 732 function DerivedFromString() {}
711 DerivedFromString.prototype = Object.create(String.prototype); 733 DerivedFromString.prototype = {
734 __proto__: String.prototype,
735 f() {
736 'use strict';
737 assertTrue(42 === this);
738 assertEquals(String.prototype.toString, super[toString]);
739 var ex;
740 try {
741 super[toString]();
742 } catch(e) { ex = e; }
712 743
713 function f() { 744 assertTrue(ex instanceof TypeError);
714 'use strict'; 745 }
715 assertTrue(42 === this); 746 };
716 assertEquals(String.prototype.toString, super[toString]); 747 DerivedFromString.prototype.f.call(42);
717 var ex;
718 try {
719 super[toString]();
720 } catch(e) { ex = e; }
721
722 assertTrue(ex instanceof TypeError);
723 }
724 f.toMethod(DerivedFromString.prototype).call(42);
725 }()); 748 }());
726 749
727 750
728 (function TestNumericKeyedAccessorsOnPrimitives() { 751 (function TestNumericKeyedAccessorsOnPrimitives() {
729 var x = 42; 752 var x = 42;
730 var newProperty = 43; 753 var newProperty = 43;
731 var getCalled = 0; 754 var getCalled = 0;
732 var setCalled = 0; 755 var setCalled = 0;
733 function Base() {} 756 function Base() {}
734 Base.prototype = { 757 Base.prototype = {
735 constructor: Base, 758 constructor: Base,
736 }; 759 };
737 760
738 Object.defineProperty(Base.prototype, x, { 761 Object.defineProperty(Base.prototype, x, {
739 get: function() { 762 get: function() {
740 getCalled++; 763 getCalled++;
741 return 1; 764 return 1;
742 }, 765 },
743 set: function(v) { 766 set: function(v) {
744 setCalled++; 767 setCalled++;
745 return v; 768 return v;
746 } 769 }
747 }); 770 });
748 771
749 function Derived() {} 772 function Derived() {}
750 Derived.prototype = { 773 Derived.prototype = {
751 __proto__: Base.prototype, 774 __proto__: Base.prototype,
752 constructor: Derived, 775 constructor: Derived,
776 testSetter() {
777 setCalled = 0;
778 getCalled = 0;
779 assertEquals('object', typeof this);
780 assertTrue(this instanceof Number)
781 assertEquals(42, this.valueOf());
782 assertEquals(1, super[x]);
783 assertEquals(1, getCalled);
784 assertEquals(0, setCalled);
785
786 assertEquals(5, super[x] = 5);
787 assertEquals(1, getCalled);
788 assertEquals(1, setCalled);
789
790 assertEquals(6, super[x] += 5);
791 assertEquals(2, getCalled);
792 assertEquals(2, setCalled);
793
794 super[newProperty] = 15;
795 assertEquals(15, this[newProperty]);
796 assertEquals(undefined, super[newProperty]);
797 },
798 testSetterStrict() {
799 'use strict';
800 getCalled = 0;
801 setCalled = 0;
802 assertTrue(42 === this);
803
804 assertEquals(1, super[x]);
805 assertEquals(1, getCalled);
806 assertEquals(0, setCalled);
807
808 assertEquals(5, super[x] = 5);
809 assertEquals(1, getCalled);
810 assertEquals(1, setCalled);
811
812 assertEquals(6, super[x] += 5);
813 assertEquals(2, getCalled);
814 assertEquals(2, setCalled);
815
816 var ex;
817 try {
818 super[newProperty] = 15;
819 } catch (e) { ex = e; }
820 assertTrue(ex instanceof TypeError);
821 }
753 }; 822 };
754 Derived.prototype.testSetter = function() {
755 setCalled = 0;
756 getCalled = 0;
757 assertEquals('object', typeof this);
758 assertTrue(this instanceof Number)
759 assertEquals(42, this.valueOf());
760 assertEquals(1, super[x]);
761 assertEquals(1, getCalled);
762 assertEquals(0, setCalled);
763
764 assertEquals(5, super[x] = 5);
765 assertEquals(1, getCalled);
766 assertEquals(1, setCalled);
767
768 assertEquals(6, super[x] += 5);
769 assertEquals(2, getCalled);
770 assertEquals(2, setCalled);
771
772 super[newProperty] = 15;
773 assertEquals(15, this[newProperty]);
774 assertEquals(undefined, super[newProperty]);
775 }.toMethod(Derived.prototype);
776
777 Derived.prototype.testSetterStrict = function() {
778 'use strict';
779 getCalled = 0;
780 setCalled = 0;
781 assertTrue(42 === this);
782
783 assertEquals(1, super[x]);
784 assertEquals(1, getCalled);
785 assertEquals(0, setCalled);
786
787 assertEquals(5, super[x] = 5);
788 assertEquals(1, getCalled);
789 assertEquals(1, setCalled);
790
791 assertEquals(6, super[x] += 5);
792 assertEquals(2, getCalled);
793 assertEquals(2, setCalled);
794
795 var ex;
796 try {
797 super[newProperty] = 15;
798 } catch (e) { ex = e; }
799 assertTrue(ex instanceof TypeError);
800 }.toMethod(Derived.prototype);
801 823
802 Derived.prototype.testSetter.call(42); 824 Derived.prototype.testSetter.call(42);
803 Derived.prototype.testSetterStrict.call(42); 825 Derived.prototype.testSetterStrict.call(42);
804 }()); 826 }());
805 827
806 828
807 (function TestKeyedNumericSetterOnExotics() { 829 (function TestKeyedNumericSetterOnExotics() {
808 function Base() {} 830 function Base() {}
809 function Derived() {} 831 function Derived() {}
810 Derived.prototype = { __proto__: Base.prototype }; 832 Derived.prototype = {
833 __proto__: Base.prototype,
834 callSetterOnArray() {
835 super[42] = 1;
836 },
837 callStrictSetterOnString() {
838 'use strict';
839 assertEquals('string', typeof this);
840 assertTrue('abcdef' === this);
841 var ex = null;
842 try {
843 super[5] = 'q';
844 } catch(e) { ex = e; }
845 assertTrue(ex instanceof TypeError);
811 846
812 Derived.prototype.callSetterOnArray = function() { 847 ex = null;
813 super[42] = 1; 848 try {
814 }.toMethod(Derived.prototype); 849 super[1024] = 'q';
815 850 } catch(e) { ex = e; }
816 Derived.prototype.callStrictSetterOnString = function() { 851 assertTrue(ex instanceof TypeError);
817 'use strict'; 852 }
818 assertEquals('string', typeof this); 853 };
819 assertTrue('abcdef' === this);
820 var ex = null;
821 try {
822 super[5] = 'q';
823 } catch(e) { ex = e; }
824 assertTrue(ex instanceof TypeError);
825
826 ex = null;
827 try {
828 super[1024] = 'q';
829 } catch(e) { ex = e; }
830 assertTrue(ex instanceof TypeError);
831 }.toMethod(Derived.prototype);
832 854
833 var x = []; 855 var x = [];
834 assertEquals(0, x.length); 856 assertEquals(0, x.length);
835 Derived.prototype.callSetterOnArray.call(x); 857 Derived.prototype.callSetterOnArray.call(x);
836 assertEquals(43, x.length); 858 assertEquals(43, x.length);
837 assertEquals(1, x[42]); 859 assertEquals(1, x[42]);
838 860
839 var s = 'abcdef'; 861 var s = 'abcdef';
840 Derived.prototype.callStrictSetterOnString.call(s) 862 Derived.prototype.callStrictSetterOnString.call(s)
841 }()); 863 }());
842 864
843 865
844 (function TestSetterUndefinedProperties() { 866 (function TestSetterUndefinedProperties() {
845 function Base() {} 867 function Base() {}
846 function Derived() {} 868 function Derived() {}
847 Derived.prototype = { __proto__ : Base.prototype }; 869 Derived.prototype = {
848 Derived.prototype.mSloppy = function () { 870 __proto__: Base.prototype,
849 assertEquals(undefined, super.x); 871 mSloppy() {
850 assertEquals(undefined, this.x); 872 assertEquals(undefined, super.x);
851 super.x = 10; 873 assertEquals(undefined, this.x);
852 assertEquals(10, this.x); 874 super.x = 10;
853 assertEquals(undefined, super.x); 875 assertEquals(10, this.x);
854 }.toMethod(Derived.prototype); 876 assertEquals(undefined, super.x);
877 },
878 mStrict() {
879 'use strict';
880 assertEquals(undefined, super.x);
881 assertEquals(undefined, this.x);
882 super.x = 10;
883 assertEquals(10, this.x);
884 assertEquals(undefined, super.x);
885 }
886 };
855 887
856 Derived.prototype.mStrict = function () {
857 'use strict';
858 assertEquals(undefined, super.x);
859 assertEquals(undefined, this.x);
860 super.x = 10;
861 assertEquals(10, this.x);
862 assertEquals(undefined, super.x);
863 }.toMethod(Derived.prototype);
864 var d = new Derived(); 888 var d = new Derived();
865 d.mSloppy(); 889 d.mSloppy();
866 assertEquals(10, d.x); 890 assertEquals(10, d.x);
867 var d1 = new Derived(); 891 var d1 = new Derived();
868 d1.mStrict(); 892 d1.mStrict();
869 assertEquals(10, d.x); 893 assertEquals(10, d.x);
870 }()); 894 }());
871 895
872 896
873 (function TestKeyedSetterUndefinedProperties() { 897 (function TestKeyedSetterUndefinedProperties() {
874 var x = 'x'; 898 var x = 'x';
875 function Base() {} 899 function Base() {}
876 function Derived() {} 900 function Derived() {}
877 Derived.prototype = { __proto__ : Base.prototype }; 901 Derived.prototype = {
878 Derived.prototype.mSloppy = function () { 902 __proto__: Base.prototype,
879 assertEquals(undefined, super[x]); 903 mSloppy() {
880 assertEquals(undefined, this[x]); 904 assertEquals(undefined, super[x]);
881 super[x] = 10; 905 assertEquals(undefined, this[x]);
882 assertEquals(10, this[x]); 906 super[x] = 10;
883 assertEquals(undefined, super[x]); 907 assertEquals(10, this[x]);
884 }.toMethod(Derived.prototype); 908 assertEquals(undefined, super[x]);
885 909 },
886 Derived.prototype.mStrict = function () { 910 mStrict() {
887 'use strict'; 911 'use strict';
888 assertEquals(undefined, super[x]); 912 assertEquals(undefined, super[x]);
889 assertEquals(undefined, this[x]); 913 assertEquals(undefined, this[x]);
890 super[x] = 10; 914 super[x] = 10;
891 assertEquals(10, this[x]); 915 assertEquals(10, this[x]);
892 assertEquals(undefined, super[x]); 916 assertEquals(undefined, super[x]);
893 }.toMethod(Derived.prototype); 917 }
918 };
894 var d = new Derived(); 919 var d = new Derived();
895 d.mSloppy(); 920 d.mSloppy();
896 assertEquals(10, d.x); 921 assertEquals(10, d.x);
897 var d1 = new Derived(); 922 var d1 = new Derived();
898 d1.mStrict(); 923 d1.mStrict();
899 assertEquals(10, d.x); 924 assertEquals(10, d.x);
900 }()); 925 }());
901 926
902 927
903 (function TestKeyedNumericSetterUndefinedProperties() { 928 (function TestKeyedNumericSetterUndefinedProperties() {
904 var x = 42; 929 var x = 42;
905 function Base() {} 930 function Base() {}
906 function Derived() {} 931 function Derived() {}
907 Derived.prototype = { __proto__ : Base.prototype }; 932 Derived.prototype = {
908 Derived.prototype.mSloppy = function () { 933 __proto__: Base.prototype,
909 assertEquals(undefined, super[x]); 934 mSloppy() {
910 assertEquals(undefined, this[x]); 935 assertEquals(undefined, super[x]);
911 super[x] = 10; 936 assertEquals(undefined, this[x]);
912 assertEquals(10, this[x]); 937 super[x] = 10;
913 assertEquals(undefined, super[x]); 938 assertEquals(10, this[x]);
914 }.toMethod(Derived.prototype); 939 assertEquals(undefined, super[x]);
915 940 },
916 Derived.prototype.mStrict = function () { 941 mStrict() {
917 'use strict'; 942 'use strict';
918 assertEquals(undefined, super[x]); 943 assertEquals(undefined, super[x]);
919 assertEquals(undefined, this[x]); 944 assertEquals(undefined, this[x]);
920 super[x] = 10; 945 super[x] = 10;
921 assertEquals(10, this[x]); 946 assertEquals(10, this[x]);
922 assertEquals(undefined, super[x]); 947 assertEquals(undefined, super[x]);
923 }.toMethod(Derived.prototype); 948 }
949 };
924 var d = new Derived(); 950 var d = new Derived();
925 d.mSloppy(); 951 d.mSloppy();
926 assertEquals(10, d[x]); 952 assertEquals(10, d[x]);
927 var d1 = new Derived(); 953 var d1 = new Derived();
928 d1.mStrict(); 954 d1.mStrict();
929 assertEquals(10, d[x]); 955 assertEquals(10, d[x]);
930 }()); 956 }());
931 957
932 958
933 (function TestSetterCreatingOwnProperties() { 959 (function TestSetterCreatingOwnProperties() {
960 var setterCalled;
934 function Base() {} 961 function Base() {}
935 function Derived() {} 962 function Derived() {}
936 Derived.prototype = { __proto__ : Base.prototype }; 963 Derived.prototype = {
937 var setterCalled; 964 __proto__: Base.prototype,
965 mSloppy() {
966 assertEquals(42, this.ownReadOnly);
967 super.ownReadOnly = 55;
968 assertEquals(42, this.ownReadOnly);
938 969
939 Derived.prototype.mSloppy = function() { 970 assertEquals(15, this.ownReadonlyAccessor);
940 assertEquals(42, this.ownReadOnly); 971 super.ownReadonlyAccessor = 55;
941 super.ownReadOnly = 55; 972 assertEquals(15, this.ownReadonlyAccessor);
942 assertEquals(42, this.ownReadOnly);
943 973
944 assertEquals(15, this.ownReadonlyAccessor); 974 setterCalled = 0;
945 super.ownReadonlyAccessor = 55; 975 super.ownSetter = 42;
946 assertEquals(15, this.ownReadonlyAccessor); 976 assertEquals(1, setterCalled);
977 },
978 mStrict() {
979 'use strict';
980 assertEquals(42, this.ownReadOnly);
981 var ex;
982 try {
983 super.ownReadOnly = 55;
984 } catch(e) { ex = e; }
985 assertTrue(ex instanceof TypeError);
986 assertEquals(42, this.ownReadOnly);
947 987
948 setterCalled = 0; 988 assertEquals(15, this.ownReadonlyAccessor);
949 super.ownSetter = 42; 989 ex = null;
950 assertEquals(1, setterCalled); 990 try {
951 }.toMethod(Derived.prototype); 991 super.ownReadonlyAccessor = 55;
992 } catch(e) { ex = e; }
993 assertTrue(ex instanceof TypeError);
994 assertEquals(15, this.ownReadonlyAccessor);
952 995
953 Derived.prototype.mStrict = function() { 996 setterCalled = 0;
954 'use strict'; 997 super.ownSetter = 42;
955 assertEquals(42, this.ownReadOnly); 998 assertEquals(1, setterCalled);
956 var ex; 999 }
957 try { 1000 };
958 super.ownReadOnly = 55;
959 } catch(e) { ex = e; }
960 assertTrue(ex instanceof TypeError);
961 assertEquals(42, this.ownReadOnly);
962
963 assertEquals(15, this.ownReadonlyAccessor);
964 ex = null;
965 try {
966 super.ownReadonlyAccessor = 55;
967 } catch(e) { ex = e; }
968 assertTrue(ex instanceof TypeError);
969 assertEquals(15, this.ownReadonlyAccessor);
970
971 setterCalled = 0;
972 super.ownSetter = 42;
973 assertEquals(1, setterCalled);
974 }.toMethod(Derived.prototype);
975 1001
976 var d = new Derived(); 1002 var d = new Derived();
977 Object.defineProperty(d, 'ownReadOnly', { value : 42, writable : false }); 1003 Object.defineProperty(d, 'ownReadOnly', { value : 42, writable : false });
978 Object.defineProperty(d, 'ownSetter', 1004 Object.defineProperty(d, 'ownSetter',
979 { set : function() { setterCalled++; } }); 1005 { set : function() { setterCalled++; } });
980 Object.defineProperty(d, 'ownReadonlyAccessor', 1006 Object.defineProperty(d, 'ownReadonlyAccessor',
981 { get : function() { return 15; }}); 1007 { get : function() { return 15; }});
982 d.mSloppy(); 1008 d.mSloppy();
983 d.mStrict(); 1009 d.mStrict();
984 }()); 1010 }());
(...skipping 14 matching lines...) Expand all
999 this.x_.push(v); 1025 this.x_.push(v);
1000 }, 1026 },
1001 }; 1027 };
1002 1028
1003 function Derived() { 1029 function Derived() {
1004 this.x_ = []; 1030 this.x_ = [];
1005 } 1031 }
1006 Derived.prototype = { 1032 Derived.prototype = {
1007 __proto__: Base.prototype, 1033 __proto__: Base.prototype,
1008 constructor: Derived, 1034 constructor: Derived,
1035 testIter() {
1036 setCalled = 0;
1037 getCalled = 0;
1038 for (super.x in [1,2,3]) {}
1039 assertEquals(0, getCalled);
1040 assertEquals(3, setCalled);
1041 assertEquals(["0", "1", "2"], this.x_);
1042 },
1043 testIterKeyed() {
1044 setCalled = 0;
1045 getCalled = 0;
1046 for (super[x] in [1,2,3]) {}
1047 assertEquals(0, getCalled);
1048 assertEquals(3, setCalled);
1049 assertEquals(["0","1","2"], this.x_);
1050
1051 this.x_ = [];
1052 setCalled = 0;
1053 getCalled = 0;
1054 var toStringCalled = 0;
1055 var o = {toString: function () { toStringCalled++; return x }};
1056 for (super[o] in [1,2,3]) {}
1057 assertEquals(0, getCalled);
1058 assertEquals(3, setCalled);
1059 assertEquals(3, toStringCalled);
1060 assertEquals(["0","1","2"], this.x_);
1061 }
1009 }; 1062 };
1010 1063
1011 Derived.prototype.testIter = function() {
1012 setCalled = 0;
1013 getCalled = 0;
1014 for (super.x in [1,2,3]) {}
1015 assertEquals(0, getCalled);
1016 assertEquals(3, setCalled);
1017 assertEquals(["0","1","2"], this.x_);
1018 }.toMethod(Derived.prototype);
1019
1020 new Derived().testIter(); 1064 new Derived().testIter();
1021 1065
1022 var x = 'x'; 1066 var x = 'x';
1023 Derived.prototype.testIterKeyed = function() {
1024 setCalled = 0;
1025 getCalled = 0;
1026 for (super[x] in [1,2,3]) {}
1027 assertEquals(0, getCalled);
1028 assertEquals(3, setCalled);
1029 assertEquals(["0","1","2"], this.x_);
1030
1031 this.x_ = [];
1032 setCalled = 0;
1033 getCalled = 0;
1034 var toStringCalled = 0;
1035 var o = {toString: function () { toStringCalled++; return x }};
1036 for (super[o] in [1,2,3]) {}
1037 assertEquals(0, getCalled);
1038 assertEquals(3, setCalled);
1039 assertEquals(3, toStringCalled);
1040 assertEquals(["0","1","2"], this.x_);
1041 }.toMethod(Derived.prototype);
1042 1067
1043 new Derived().testIterKeyed(); 1068 new Derived().testIterKeyed();
1044 }()); 1069 }());
1045 1070
1046 1071
1047 (function TestKeyedSetterCreatingOwnProperties() { 1072 (function TestKeyedSetterCreatingOwnProperties() {
1048 var ownReadOnly = 'ownReadOnly'; 1073 var ownReadOnly = 'ownReadOnly';
1049 var ownReadonlyAccessor = 'ownReadonlyAccessor'; 1074 var ownReadonlyAccessor = 'ownReadonlyAccessor';
1050 var ownSetter = 'ownSetter'; 1075 var ownSetter = 'ownSetter';
1076 var setterCalled;
1051 function Base() {} 1077 function Base() {}
1052 function Derived() {} 1078 function Derived() {}
1053 Derived.prototype = { __proto__ : Base.prototype }; 1079 Derived.prototype = {
1054 var setterCalled; 1080 __proto__: Base.prototype,
1081 mSloppy() {
1082 assertEquals(42, this[ownReadOnly]);
1083 super[ownReadOnly] = 55;
1084 assertEquals(42, this[ownReadOnly]);
1055 1085
1056 Derived.prototype.mSloppy = function() { 1086 assertEquals(15, this[ownReadonlyAccessor]);
1057 assertEquals(42, this[ownReadOnly]); 1087 super[ownReadonlyAccessor] = 55;
1058 super[ownReadOnly] = 55; 1088 assertEquals(15, this[ownReadonlyAccessor]);
1059 assertEquals(42, this[ownReadOnly]);
1060 1089
1061 assertEquals(15, this[ownReadonlyAccessor]); 1090 setterCalled = 0;
1062 super[ownReadonlyAccessor] = 55; 1091 super[ownSetter] = 42;
1063 assertEquals(15, this[ownReadonlyAccessor]); 1092 assertEquals(1, setterCalled);
1093 },
1094 mStrict() {
1095 'use strict';
1096 assertEquals(42, this[ownReadOnly]);
1097 var ex;
1098 try {
1099 super[ownReadOnly] = 55;
1100 } catch(e) { ex = e; }
1101 assertTrue(ex instanceof TypeError);
1102 assertEquals(42, this[ownReadOnly]);
1064 1103
1065 setterCalled = 0; 1104 assertEquals(15, this[ownReadonlyAccessor]);
1066 super[ownSetter] = 42; 1105 ex = null;
1067 assertEquals(1, setterCalled); 1106 try {
1068 }.toMethod(Derived.prototype); 1107 super[ownReadonlyAccessor] = 55;
1108 } catch(e) { ex = e; }
1109 assertTrue(ex instanceof TypeError);
1110 assertEquals(15, this[ownReadonlyAccessor]);
1069 1111
1070 Derived.prototype.mStrict = function() { 1112 setterCalled = 0;
1071 'use strict'; 1113 super[ownSetter] = 42;
1072 assertEquals(42, this[ownReadOnly]); 1114 assertEquals(1, setterCalled);
1073 var ex; 1115 }
1074 try { 1116 };
1075 super[ownReadOnly] = 55;
1076 } catch(e) { ex = e; }
1077 assertTrue(ex instanceof TypeError);
1078 assertEquals(42, this[ownReadOnly]);
1079
1080 assertEquals(15, this[ownReadonlyAccessor]);
1081 ex = null;
1082 try {
1083 super[ownReadonlyAccessor] = 55;
1084 } catch(e) { ex = e; }
1085 assertTrue(ex instanceof TypeError);
1086 assertEquals(15, this[ownReadonlyAccessor]);
1087
1088 setterCalled = 0;
1089 super[ownSetter] = 42;
1090 assertEquals(1, setterCalled);
1091 }.toMethod(Derived.prototype);
1092 1117
1093 var d = new Derived(); 1118 var d = new Derived();
1094 Object.defineProperty(d, 'ownReadOnly', { value : 42, writable : false }); 1119 Object.defineProperty(d, 'ownReadOnly', { value : 42, writable : false });
1095 Object.defineProperty(d, 'ownSetter', 1120 Object.defineProperty(d, 'ownSetter',
1096 { set : function() { setterCalled++; } }); 1121 { set : function() { setterCalled++; } });
1097 Object.defineProperty(d, 'ownReadonlyAccessor', 1122 Object.defineProperty(d, 'ownReadonlyAccessor',
1098 { get : function() { return 15; }}); 1123 { get : function() { return 15; }});
1099 d.mSloppy(); 1124 d.mSloppy();
1100 d.mStrict(); 1125 d.mStrict();
1101 }()); 1126 }());
1102 1127
1103 1128
1104 (function TestKeyedNumericSetterCreatingOwnProperties() { 1129 (function TestKeyedNumericSetterCreatingOwnProperties() {
1105 var ownReadOnly = 42; 1130 var ownReadOnly = 42;
1106 var ownReadonlyAccessor = 43; 1131 var ownReadonlyAccessor = 43;
1107 var ownSetter = 44; 1132 var ownSetter = 44;
1133 var setterCalled;
1108 function Base() {} 1134 function Base() {}
1109 function Derived() {} 1135 function Derived() {}
1110 Derived.prototype = { __proto__ : Base.prototype }; 1136 Derived.prototype = {
1111 var setterCalled; 1137 __proto__: Base.prototype,
1138 mSloppy() {
1139 assertEquals(42, this[ownReadOnly]);
1140 super[ownReadOnly] = 55;
1141 assertEquals(42, this[ownReadOnly]);
1112 1142
1113 Derived.prototype.mSloppy = function() { 1143 assertEquals(15, this[ownReadonlyAccessor]);
1114 assertEquals(42, this[ownReadOnly]); 1144 super[ownReadonlyAccessor] = 55;
1115 super[ownReadOnly] = 55; 1145 assertEquals(15, this[ownReadonlyAccessor]);
1116 assertEquals(42, this[ownReadOnly]);
1117 1146
1118 assertEquals(15, this[ownReadonlyAccessor]); 1147 setterCalled = 0;
1119 super[ownReadonlyAccessor] = 55; 1148 super[ownSetter] = 42;
1120 assertEquals(15, this[ownReadonlyAccessor]); 1149 assertEquals(1, setterCalled);
1150 },
1151 mStrict() {
1152 'use strict';
1153 assertEquals(42, this[ownReadOnly]);
1154 var ex;
1155 try {
1156 super[ownReadOnly] = 55;
1157 } catch(e) { ex = e; }
1158 assertTrue(ex instanceof TypeError);
1159 assertEquals(42, this[ownReadOnly]);
1121 1160
1122 setterCalled = 0; 1161 assertEquals(15, this[ownReadonlyAccessor]);
1123 super[ownSetter] = 42; 1162 ex = null;
1124 assertEquals(1, setterCalled); 1163 try {
1125 }.toMethod(Derived.prototype); 1164 super[ownReadonlyAccessor] = 55;
1165 } catch(e) { ex = e; }
1166 assertTrue(ex instanceof TypeError);
1167 assertEquals(15, this[ownReadonlyAccessor]);
1126 1168
1127 Derived.prototype.mStrict = function() { 1169 setterCalled = 0;
1128 'use strict'; 1170 super[ownSetter] = 42;
1129 assertEquals(42, this[ownReadOnly]); 1171 assertEquals(1, setterCalled);
1130 var ex; 1172 }
1131 try { 1173 }
1132 super[ownReadOnly] = 55;
1133 } catch(e) { ex = e; }
1134 assertTrue(ex instanceof TypeError);
1135 assertEquals(42, this[ownReadOnly]);
1136
1137 assertEquals(15, this[ownReadonlyAccessor]);
1138 ex = null;
1139 try {
1140 super[ownReadonlyAccessor] = 55;
1141 } catch(e) { ex = e; }
1142 assertTrue(ex instanceof TypeError);
1143 assertEquals(15, this[ownReadonlyAccessor]);
1144
1145 setterCalled = 0;
1146 super[ownSetter] = 42;
1147 assertEquals(1, setterCalled);
1148 }.toMethod(Derived.prototype);
1149 1174
1150 var d = new Derived(); 1175 var d = new Derived();
1151 Object.defineProperty(d, ownReadOnly, { value : 42, writable : false }); 1176 Object.defineProperty(d, ownReadOnly, { value : 42, writable : false });
1152 Object.defineProperty(d, ownSetter, 1177 Object.defineProperty(d, ownSetter,
1153 { set : function() { setterCalled++; } }); 1178 { set : function() { setterCalled++; } });
1154 Object.defineProperty(d, ownReadonlyAccessor, 1179 Object.defineProperty(d, ownReadonlyAccessor,
1155 { get : function() { return 15; }}); 1180 { get : function() { return 15; }});
1156 d.mSloppy(); 1181 d.mSloppy();
1157 d.mStrict(); 1182 d.mStrict();
1158 }()); 1183 }());
1159 1184
1160 1185
1161 (function TestSetterNoProtoWalk() { 1186 (function TestSetterNoProtoWalk() {
1162 function Base() {} 1187 function Base() {}
1163 function Derived() {} 1188 function Derived() {}
1164 var getCalled; 1189 var getCalled;
1165 var setCalled; 1190 var setCalled;
1166 Derived.prototype = { 1191 Derived.prototype = {
1167 __proto__ : Base.prototype, 1192 __proto__: Base.prototype,
1168 get x() { getCalled++; return 42; }, 1193 get x() { getCalled++; return 42; },
1169 set x(v) { setCalled++; } 1194 set x(v) { setCalled++; },
1195 mSloppy() {
1196 setCalled = 0;
1197 getCalled = 0;
1198 assertEquals(42, this.x);
1199 assertEquals(1, getCalled);
1200 assertEquals(0, setCalled);
1201
1202 getCalled = 0;
1203 setCalled = 0;
1204 this.x = 43;
1205 assertEquals(0, getCalled);
1206 assertEquals(1, setCalled);
1207
1208 getCalled = 0;
1209 setCalled = 0;
1210 super.x = 15;
1211 assertEquals(0, setCalled);
1212 assertEquals(0, getCalled);
1213
1214 assertEquals(15, this.x);
1215 assertEquals(0, getCalled);
1216 assertEquals(0, setCalled);
1217 },
1218 mStrict() {
1219 'use strict';
1220 setCalled = 0;
1221 getCalled = 0;
1222 assertEquals(42, this.x);
1223 assertEquals(1, getCalled);
1224 assertEquals(0, setCalled);
1225
1226 getCalled = 0;
1227 setCalled = 0;
1228 this.x = 43;
1229 assertEquals(0, getCalled);
1230 assertEquals(1, setCalled);
1231
1232 getCalled = 0;
1233 setCalled = 0;
1234 super.x = 15;
1235 assertEquals(0, setCalled);
1236 assertEquals(0, getCalled);
1237
1238 assertEquals(15, this.x);
1239 assertEquals(0, getCalled);
1240 assertEquals(0, setCalled);
1241 }
1170 }; 1242 };
1171 1243
1172 Derived.prototype.mSloppy = function() {
1173 setCalled = 0;
1174 getCalled = 0;
1175 assertEquals(42, this.x);
1176 assertEquals(1, getCalled);
1177 assertEquals(0, setCalled);
1178
1179 getCalled = 0;
1180 setCalled = 0;
1181 this.x = 43;
1182 assertEquals(0, getCalled);
1183 assertEquals(1, setCalled);
1184
1185 getCalled = 0;
1186 setCalled = 0;
1187 super.x = 15;
1188 assertEquals(0, setCalled);
1189 assertEquals(0, getCalled);
1190
1191 assertEquals(15, this.x);
1192 assertEquals(0, getCalled);
1193 assertEquals(0, setCalled);
1194
1195 }.toMethod(Derived.prototype);
1196
1197 Derived.prototype.mStrict = function() {
1198 'use strict';
1199 setCalled = 0;
1200 getCalled = 0;
1201 assertEquals(42, this.x);
1202 assertEquals(1, getCalled);
1203 assertEquals(0, setCalled);
1204
1205 getCalled = 0;
1206 setCalled = 0;
1207 this.x = 43;
1208 assertEquals(0, getCalled);
1209 assertEquals(1, setCalled);
1210
1211 getCalled = 0;
1212 setCalled = 0;
1213 super.x = 15;
1214 assertEquals(0, setCalled);
1215 assertEquals(0, getCalled);
1216
1217 assertEquals(15, this.x);
1218 assertEquals(0, getCalled);
1219 assertEquals(0, setCalled);
1220
1221 }.toMethod(Derived.prototype);
1222
1223 new Derived().mSloppy(); 1244 new Derived().mSloppy();
1224 new Derived().mStrict(); 1245 new Derived().mStrict();
1225 }()); 1246 }());
1226 1247
1227 1248
1228 (function TestKeyedSetterNoProtoWalk() { 1249 (function TestKeyedSetterNoProtoWalk() {
1229 var x = 'x'; 1250 var x = 'x';
1230 function Base() {} 1251 function Base() {}
1231 function Derived() {} 1252 function Derived() {}
1232 var getCalled; 1253 var getCalled;
1233 var setCalled; 1254 var setCalled;
1234 Derived.prototype = { 1255 Derived.prototype = {
1235 __proto__ : Base.prototype, 1256 __proto__: Base.prototype,
1236 get x() { getCalled++; return 42; }, 1257 get x() { getCalled++; return 42; },
1237 set x(v) { setCalled++; } 1258 set x(v) { setCalled++; },
1259 mSloppy() {
1260 setCalled = 0;
1261 getCalled = 0;
1262 assertEquals(42, this[x]);
1263 assertEquals(1, getCalled);
1264 assertEquals(0, setCalled);
1265
1266 getCalled = 0;
1267 setCalled = 0;
1268 this[x] = 43;
1269 assertEquals(0, getCalled);
1270 assertEquals(1, setCalled);
1271
1272 getCalled = 0;
1273 setCalled = 0;
1274 super[x] = 15;
1275 assertEquals(0, setCalled);
1276 assertEquals(0, getCalled);
1277
1278 assertEquals(15, this[x]);
1279 assertEquals(0, getCalled);
1280 assertEquals(0, setCalled);
1281 },
1282 mStrict() {
1283 'use strict';
1284 setCalled = 0;
1285 getCalled = 0;
1286 assertEquals(42, this[x]);
1287 assertEquals(1, getCalled);
1288 assertEquals(0, setCalled);
1289
1290 getCalled = 0;
1291 setCalled = 0;
1292 this[x] = 43;
1293 assertEquals(0, getCalled);
1294 assertEquals(1, setCalled);
1295
1296 getCalled = 0;
1297 setCalled = 0;
1298 super[x] = 15;
1299 assertEquals(0, setCalled);
1300 assertEquals(0, getCalled);
1301
1302 assertEquals(15, this[x]);
1303 assertEquals(0, getCalled);
1304 assertEquals(0, setCalled);
1305 }
1238 }; 1306 };
1239 1307
1240 Derived.prototype.mSloppy = function() {
1241 setCalled = 0;
1242 getCalled = 0;
1243 assertEquals(42, this[x]);
1244 assertEquals(1, getCalled);
1245 assertEquals(0, setCalled);
1246
1247 getCalled = 0;
1248 setCalled = 0;
1249 this[x] = 43;
1250 assertEquals(0, getCalled);
1251 assertEquals(1, setCalled);
1252
1253 getCalled = 0;
1254 setCalled = 0;
1255 super[x] = 15;
1256 assertEquals(0, setCalled);
1257 assertEquals(0, getCalled);
1258
1259 assertEquals(15, this[x]);
1260 assertEquals(0, getCalled);
1261 assertEquals(0, setCalled);
1262
1263 }.toMethod(Derived.prototype);
1264
1265 Derived.prototype.mStrict = function() {
1266 'use strict';
1267 setCalled = 0;
1268 getCalled = 0;
1269 assertEquals(42, this[x]);
1270 assertEquals(1, getCalled);
1271 assertEquals(0, setCalled);
1272
1273 getCalled = 0;
1274 setCalled = 0;
1275 this[x] = 43;
1276 assertEquals(0, getCalled);
1277 assertEquals(1, setCalled);
1278
1279 getCalled = 0;
1280 setCalled = 0;
1281 super[x] = 15;
1282 assertEquals(0, setCalled);
1283 assertEquals(0, getCalled);
1284
1285 assertEquals(15, this[x]);
1286 assertEquals(0, getCalled);
1287 assertEquals(0, setCalled);
1288
1289 }.toMethod(Derived.prototype);
1290
1291 new Derived().mSloppy(); 1308 new Derived().mSloppy();
1292 new Derived().mStrict(); 1309 new Derived().mStrict();
1293 }()); 1310 }());
1294 1311
1295 1312
1296 (function TestKeyedNumericSetterNoProtoWalk() { 1313 (function TestKeyedNumericSetterNoProtoWalk() {
1297 var x = 42; 1314 var x = 42;
1298 function Base() {} 1315 function Base() {}
1299 function Derived() {} 1316 function Derived() {}
1300 var getCalled; 1317 var getCalled;
1301 var setCalled; 1318 var setCalled;
1302 Derived.prototype = { 1319 Derived.prototype = {
1303 __proto__ : Base.prototype, 1320 __proto__: Base.prototype,
1321 mSloppy() {
1322 setCalled = 0;
1323 getCalled = 0;
1324 assertEquals(42, this[x]);
1325 assertEquals(1, getCalled);
1326 assertEquals(0, setCalled);
1327
1328 getCalled = 0;
1329 setCalled = 0;
1330 this[x] = 43;
1331 assertEquals(0, getCalled);
1332 assertEquals(1, setCalled);
1333
1334 getCalled = 0;
1335 setCalled = 0;
1336 super[x] = 15;
1337 assertEquals(0, setCalled);
1338 assertEquals(0, getCalled);
1339
1340 assertEquals(15, this[x]);
1341 assertEquals(0, getCalled);
1342 assertEquals(0, setCalled);
1343 },
1344 mStrict() {
1345 'use strict';
1346 setCalled = 0;
1347 getCalled = 0;
1348 assertEquals(42, this[x]);
1349 assertEquals(1, getCalled);
1350 assertEquals(0, setCalled);
1351
1352 getCalled = 0;
1353 setCalled = 0;
1354 this[x] = 43;
1355 assertEquals(0, getCalled);
1356 assertEquals(1, setCalled);
1357
1358 getCalled = 0;
1359 setCalled = 0;
1360 super[x] = 15;
1361 assertEquals(0, setCalled);
1362 assertEquals(0, getCalled);
1363
1364 assertEquals(15, this[x]);
1365 assertEquals(0, getCalled);
1366 assertEquals(0, setCalled);
1367 }
1304 }; 1368 };
1305 1369
1306 Object.defineProperty(Derived.prototype, x, { 1370 Object.defineProperty(Derived.prototype, x, {
1307 get: function() { getCalled++; return 42; }, 1371 get: function() { getCalled++; return 42; },
1308 set: function(v) { setCalled++; } 1372 set: function(v) { setCalled++; }
1309 }); 1373 });
1310 1374
1311 Derived.prototype.mSloppy = function() {
1312 setCalled = 0;
1313 getCalled = 0;
1314 assertEquals(42, this[x]);
1315 assertEquals(1, getCalled);
1316 assertEquals(0, setCalled);
1317
1318 getCalled = 0;
1319 setCalled = 0;
1320 this[x] = 43;
1321 assertEquals(0, getCalled);
1322 assertEquals(1, setCalled);
1323
1324 getCalled = 0;
1325 setCalled = 0;
1326 super[x] = 15;
1327 assertEquals(0, setCalled);
1328 assertEquals(0, getCalled);
1329
1330 assertEquals(15, this[x]);
1331 assertEquals(0, getCalled);
1332 assertEquals(0, setCalled);
1333
1334 }.toMethod(Derived.prototype);
1335
1336 Derived.prototype.mStrict = function() {
1337 'use strict';
1338 setCalled = 0;
1339 getCalled = 0;
1340 assertEquals(42, this[x]);
1341 assertEquals(1, getCalled);
1342 assertEquals(0, setCalled);
1343
1344 getCalled = 0;
1345 setCalled = 0;
1346 this[x] = 43;
1347 assertEquals(0, getCalled);
1348 assertEquals(1, setCalled);
1349
1350 getCalled = 0;
1351 setCalled = 0;
1352 super[x] = 15;
1353 assertEquals(0, setCalled);
1354 assertEquals(0, getCalled);
1355
1356 assertEquals(15, this[x]);
1357 assertEquals(0, getCalled);
1358 assertEquals(0, setCalled);
1359
1360 }.toMethod(Derived.prototype);
1361
1362 new Derived().mSloppy(); 1375 new Derived().mSloppy();
1363 new Derived().mStrict(); 1376 new Derived().mStrict();
1364 }()); 1377 }());
1365 1378
1366 1379
1367 (function TestSetterDoesNotReconfigure() { 1380 (function TestSetterDoesNotReconfigure() {
1368 function Base() {} 1381 function Base() {}
1369 function Derived() {} 1382 function Derived() {}
1383 Derived.prototype = {
1384 __proto__: Derived.prototype,
1385 mStrict(){
1386 'use strict';
1387 super.nonEnumConfig = 5;
1388 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumConfig');
1389 assertEquals(5, d1.value);
1390 assertTrue(d1.configurable);
1391 assertFalse(d1.enumerable);
1370 1392
1371 Derived.prototype.mStrict = function (){ 1393 super.nonEnumNonConfig = 5;
1372 'use strict'; 1394 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumNonConfig');
1373 super.nonEnumConfig = 5; 1395 assertEquals(5, d1.value);
1374 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumConfig'); 1396 assertFalse(d1.configurable);
1375 assertEquals(5, d1.value); 1397 assertFalse(d1.enumerable);
1376 assertTrue(d1.configurable); 1398 },
1377 assertFalse(d1.enumerable); 1399 mSloppy(){
1400 super.nonEnumConfig = 42;
1401 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumConfig');
1402 assertEquals(42, d1.value);
1403 assertTrue(d1.configurable);
1404 assertFalse(d1.enumerable);
1378 1405
1379 super.nonEnumNonConfig = 5; 1406 super.nonEnumNonConfig = 42;
1380 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumNonConfig'); 1407 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumNonConfig');
1381 assertEquals(5, d1.value); 1408 assertEquals(42, d1.value);
1382 assertFalse(d1.configurable); 1409 assertFalse(d1.configurable);
1383 assertFalse(d1.enumerable); 1410 assertFalse(d1.enumerable);
1384 }.toMethod(Derived.prototype); 1411 }
1385 1412 };
1386 Derived.prototype.mSloppy = function (){
1387 super.nonEnumConfig = 42;
1388 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumConfig');
1389 assertEquals(42, d1.value);
1390 assertTrue(d1.configurable);
1391 assertFalse(d1.enumerable);
1392
1393 super.nonEnumNonConfig = 42;
1394 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumNonConfig');
1395 assertEquals(42, d1.value);
1396 assertFalse(d1.configurable);
1397 assertFalse(d1.enumerable);
1398 }.toMethod(Derived.prototype);
1399 1413
1400 var d = new Derived(); 1414 var d = new Derived();
1401 Object.defineProperty(d, 'nonEnumConfig', 1415 Object.defineProperty(d, 'nonEnumConfig',
1402 { value : 0, enumerable : false, configurable : true, writable : true }); 1416 { value : 0, enumerable : false, configurable : true, writable : true });
1403 Object.defineProperty(d, 'nonEnumNonConfig', 1417 Object.defineProperty(d, 'nonEnumNonConfig',
1404 { value : 0, enumerable : false, configurable : false, writable : true }); 1418 { value : 0, enumerable : false, configurable : false, writable : true });
1405 d.mStrict(); 1419 d.mStrict();
1406 d.mSloppy(); 1420 d.mSloppy();
1407 }()); 1421 }());
1408 1422
1409 1423
1410 (function TestKeyedSetterDoesNotReconfigure() { 1424 (function TestKeyedSetterDoesNotReconfigure() {
1411 var nonEnumConfig = 'nonEnumConfig'; 1425 var nonEnumConfig = 'nonEnumConfig';
1412 var nonEnumNonConfig = 'nonEnumNonConfig'; 1426 var nonEnumNonConfig = 'nonEnumNonConfig';
1413 function Base() {} 1427 function Base() {}
1414 function Derived() {} 1428 function Derived() {}
1415 1429
1416 Derived.prototype = { __proto__: Base.prototype }; 1430 Derived.prototype = {
1431 __proto__: Base.prototype,
1432 mStrict(){
1433 'use strict';
1434 super[nonEnumConfig] = 5;
1435 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumConfig);
1436 assertEquals(5, d1.value);
1437 assertTrue(d1.configurable);
1438 assertFalse(d1.enumerable);
1417 1439
1418 Derived.prototype.mStrict = function (){ 1440 super[nonEnumNonConfig] = 5;
1419 'use strict'; 1441 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumNonConfig);
1420 super[nonEnumConfig] = 5; 1442 assertEquals(5, d1.value);
1421 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumConfig); 1443 assertFalse(d1.configurable);
1422 assertEquals(5, d1.value); 1444 assertFalse(d1.enumerable);
1423 assertTrue(d1.configurable); 1445 },
1424 assertFalse(d1.enumerable); 1446 mSloppy(){
1447 super[nonEnumConfig] = 42;
1448 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumConfig);
1449 assertEquals(42, d1.value);
1450 assertTrue(d1.configurable);
1451 assertFalse(d1.enumerable);
1425 1452
1426 super[nonEnumNonConfig] = 5; 1453 super[nonEnumNonConfig] = 42;
1427 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumNonConfig); 1454 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumNonConfig);
1428 assertEquals(5, d1.value); 1455 assertEquals(42, d1.value);
1429 assertFalse(d1.configurable); 1456 assertFalse(d1.configurable);
1430 assertFalse(d1.enumerable); 1457 assertFalse(d1.enumerable);
1431 }.toMethod(Derived.prototype); 1458 }
1432 1459 };
1433 Derived.prototype.mSloppy = function (){
1434 super[nonEnumConfig] = 42;
1435 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumConfig);
1436 assertEquals(42, d1.value);
1437 assertTrue(d1.configurable);
1438 assertFalse(d1.enumerable);
1439
1440 super[nonEnumNonConfig] = 42;
1441 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumNonConfig);
1442 assertEquals(42, d1.value);
1443 assertFalse(d1.configurable);
1444 assertFalse(d1.enumerable);
1445 }.toMethod(Derived.prototype);
1446 1460
1447 var d = new Derived(); 1461 var d = new Derived();
1448 Object.defineProperty(d, nonEnumConfig, 1462 Object.defineProperty(d, nonEnumConfig,
1449 { value : 0, enumerable : false, configurable : true, writable : true }); 1463 { value : 0, enumerable : false, configurable : true, writable : true });
1450 Object.defineProperty(d, nonEnumNonConfig, 1464 Object.defineProperty(d, nonEnumNonConfig,
1451 { value : 0, enumerable : false, configurable : false, writable : true }); 1465 { value : 0, enumerable : false, configurable : false, writable : true });
1452 d.mStrict(); 1466 d.mStrict();
1453 d.mSloppy(); 1467 d.mSloppy();
1454 }()); 1468 }());
1455 1469
1456 1470
1457 (function TestKeyedNumericSetterDoesNotReconfigure() { 1471 (function TestKeyedNumericSetterDoesNotReconfigure() {
1458 var nonEnumConfig = 42; 1472 var nonEnumConfig = 42;
1459 var nonEnumNonConfig = 43; 1473 var nonEnumNonConfig = 43;
1460 function Base() {} 1474 function Base() {}
1461 function Derived() {} 1475 function Derived() {}
1462 1476
1463 Derived.prototype = { __proto__: Base.prototype }; 1477 Derived.prototype = {
1478 __proto__: Base.prototype,
1479 mStrict(){
1480 'use strict';
1481 super[nonEnumConfig] = 5;
1482 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumConfig);
1483 assertEquals(5, d1.value);
1484 assertTrue(d1.configurable);
1485 assertFalse(d1.enumerable);
1464 1486
1465 Derived.prototype.mStrict = function (){ 1487 super[nonEnumNonConfig] = 5;
1466 'use strict'; 1488 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumNonConfig);
1467 super[nonEnumConfig] = 5; 1489 assertEquals(5, d1.value);
1468 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumConfig); 1490 assertFalse(d1.configurable);
1469 assertEquals(5, d1.value); 1491 assertFalse(d1.enumerable);
1470 assertTrue(d1.configurable); 1492 },
1471 assertFalse(d1.enumerable); 1493 mSloppy(){
1494 super[nonEnumConfig] = 42;
1495 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumConfig);
1496 assertEquals(42, d1.value);
1497 assertTrue(d1.configurable);
1498 assertFalse(d1.enumerable);
1472 1499
1473 super[nonEnumNonConfig] = 5; 1500 super[nonEnumNonConfig] = 42;
1474 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumNonConfig); 1501 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumNonConfig);
1475 assertEquals(5, d1.value); 1502 assertEquals(42, d1.value);
1476 assertFalse(d1.configurable); 1503 assertFalse(d1.configurable);
1477 assertFalse(d1.enumerable); 1504 assertFalse(d1.enumerable);
1478 }.toMethod(Derived.prototype); 1505 }
1479 1506 };
1480 Derived.prototype.mSloppy = function (){
1481 super[nonEnumConfig] = 42;
1482 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumConfig);
1483 assertEquals(42, d1.value);
1484 assertTrue(d1.configurable);
1485 assertFalse(d1.enumerable);
1486
1487 super[nonEnumNonConfig] = 42;
1488 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumNonConfig);
1489 assertEquals(42, d1.value);
1490 assertFalse(d1.configurable);
1491 assertFalse(d1.enumerable);
1492 }.toMethod(Derived.prototype);
1493 1507
1494 var d = new Derived(); 1508 var d = new Derived();
1495 Object.defineProperty(d, nonEnumConfig, 1509 Object.defineProperty(d, nonEnumConfig,
1496 { value : 0, enumerable : false, configurable : true, writable : true }); 1510 { value : 0, enumerable : false, configurable : true, writable : true });
1497 Object.defineProperty(d, nonEnumNonConfig, 1511 Object.defineProperty(d, nonEnumNonConfig,
1498 { value : 0, enumerable : false, configurable : false, writable : true }); 1512 { value : 0, enumerable : false, configurable : false, writable : true });
1499 d.mStrict(); 1513 d.mStrict();
1500 d.mSloppy(); 1514 d.mSloppy();
1501 }()); 1515 }());
1502 1516
1503 1517
1504 (function TestCountOperations() { 1518 (function TestCountOperations() {
1505 function Base() {} 1519 function Base() {}
1506 Base.prototype = { 1520 Base.prototype = {
1507 constructor: Base, 1521 constructor: Base,
1508 get x() { 1522 get x() {
1509 return this._x; 1523 return this._x;
1510 }, 1524 },
1511 set x(v) { 1525 set x(v) {
1512 this._x = v; 1526 this._x = v;
1513 }, 1527 },
1514 _x: 1 1528 _x: 1
1515 }; 1529 };
1516 1530
1517 function Derived() {} 1531 function Derived() {}
1518 Derived.__proto__ = Base; 1532 Derived.__proto__ = Base;
1519 Derived.prototype = { 1533 Derived.prototype = {
1520 __proto__: Base.prototype, 1534 __proto__: Base.prototype,
1521 constructor: Derived, 1535 constructor: Derived,
1522 _x: 2 1536 _x: 2,
1537 testCounts() {
1538 assertEquals(2, this._x);
1539 assertEquals(2, super.x);
1540 super.x++;
1541 assertEquals(3, super.x);
1542 ++super.x;
1543 assertEquals(4, super.x);
1544 assertEquals(4, super.x++);
1545 assertEquals(5, super.x);
1546 assertEquals(6, ++super.x);
1547 assertEquals(6, super.x);
1548 assertEquals(6, this._x);
1549
1550 super.x--;
1551 assertEquals(5, super.x);
1552 --super.x;
1553 assertEquals(4, super.x);
1554 assertEquals(4, super.x--);
1555 assertEquals(3, super.x);
1556 assertEquals(2, --super.x);
1557 assertEquals(2, super.x);
1558 assertEquals(2, this._x);
1559 }
1523 }; 1560 };
1524
1525 Derived.prototype.testCounts = function() {
1526 assertEquals(2, this._x);
1527 assertEquals(2, super.x);
1528 super.x++;
1529 assertEquals(3, super.x);
1530 ++super.x;
1531 assertEquals(4, super.x);
1532 assertEquals(4, super.x++);
1533 assertEquals(5, super.x);
1534 assertEquals(6, ++super.x);
1535 assertEquals(6, super.x);
1536 assertEquals(6, this._x);
1537
1538 super.x--;
1539 assertEquals(5, super.x);
1540 --super.x;
1541 assertEquals(4, super.x);
1542 assertEquals(4, super.x--);
1543 assertEquals(3, super.x);
1544 assertEquals(2, --super.x);
1545 assertEquals(2, super.x);
1546 assertEquals(2, this._x);
1547 }.toMethod(Derived.prototype);
1548 new Derived().testCounts(); 1561 new Derived().testCounts();
1549 }()); 1562 }());
1550 1563
1551 1564
1552 (function TestKeyedCountOperations() { 1565 (function TestKeyedCountOperations() {
1553 var x = 'x'; 1566 var x = 'x';
1554 function Base() {} 1567 function Base() {}
1555 Base.prototype = { 1568 Base.prototype = {
1556 constructor: Base, 1569 constructor: Base,
1557 get x() { 1570 get x() {
1558 return this._x; 1571 return this._x;
1559 }, 1572 },
1560 set x(v) { 1573 set x(v) {
1561 this._x = v; 1574 this._x = v;
1562 }, 1575 },
1563 _x: 1 1576 _x: 1
1564 }; 1577 };
1565 1578
1566 function Derived() {} 1579 function Derived() {}
1567 Derived.__proto__ = Base; 1580 Derived.__proto__ = Base;
1568 Derived.prototype = { 1581 Derived.prototype = {
1569 __proto__: Base.prototype, 1582 __proto__: Base.prototype,
1570 constructor: Derived, 1583 constructor: Derived,
1571 _x: 2 1584 _x: 2,
1585 testCounts() {
1586 assertEquals(2, this._x);
1587 assertEquals(2, super[x]);
1588 super[x]++;
1589 assertEquals(3, super[x]);
1590 ++super[x];
1591 assertEquals(4, super[x]);
1592 assertEquals(4, super[x]++);
1593 assertEquals(5, super[x]);
1594 assertEquals(6, ++super[x]);
1595 assertEquals(6, super[x]);
1596 assertEquals(6, this._x);
1597
1598 super[x]--;
1599 assertEquals(5, super[x]);
1600 --super[x];
1601 assertEquals(4, super[x]);
1602 assertEquals(4, super[x]--);
1603 assertEquals(3, super[x]);
1604 assertEquals(2, --super[x]);
1605 assertEquals(2, super[x]);
1606 assertEquals(2, this._x);
1607 }
1572 }; 1608 };
1573
1574 Derived.prototype.testCounts = function() {
1575 assertEquals(2, this._x);
1576 assertEquals(2, super[x]);
1577 super[x]++;
1578 assertEquals(3, super[x]);
1579 ++super[x];
1580 assertEquals(4, super[x]);
1581 assertEquals(4, super[x]++);
1582 assertEquals(5, super[x]);
1583 assertEquals(6, ++super[x]);
1584 assertEquals(6, super[x]);
1585 assertEquals(6, this._x);
1586
1587 super[x]--;
1588 assertEquals(5, super[x]);
1589 --super[x];
1590 assertEquals(4, super[x]);
1591 assertEquals(4, super[x]--);
1592 assertEquals(3, super[x]);
1593 assertEquals(2, --super[x]);
1594 assertEquals(2, super[x]);
1595 assertEquals(2, this._x);
1596 }.toMethod(Derived.prototype);
1597 new Derived().testCounts(); 1609 new Derived().testCounts();
1598 }()); 1610 }());
1599 1611
1600 1612
1601 (function TestKeyedNumericCountOperations() { 1613 (function TestKeyedNumericCountOperations() {
1602 var x = 42; 1614 var x = 42;
1603 function Base() {} 1615 function Base() {}
1604 Base.prototype = { 1616 Base.prototype = {
1605 constructor: Base, 1617 constructor: Base,
1606 _x: 1 1618 _x: 1
1607 }; 1619 };
1608 1620
1609 Object.defineProperty(Base.prototype, x, { 1621 Object.defineProperty(Base.prototype, x, {
1610 get: function() { return this._x; }, 1622 get: function() { return this._x; },
1611 set: function(v) { this._x = v;; } 1623 set: function(v) { this._x = v;; }
1612 }); 1624 });
1613 1625
1614 function Derived() {} 1626 function Derived() {}
1615 Derived.__proto__ = Base; 1627 Derived.__proto__ = Base;
1616 Derived.prototype = { 1628 Derived.prototype = {
1617 __proto__: Base.prototype, 1629 __proto__: Base.prototype,
1618 constructor: Derived, 1630 constructor: Derived,
1619 _x: 2 1631 _x: 2,
1632 testCounts() {
1633 assertEquals(2, this._x);
1634 assertEquals(2, super[x]);
1635 super[x]++;
1636 assertEquals(3, super[x]);
1637 ++super[x];
1638 assertEquals(4, super[x]);
1639 assertEquals(4, super[x]++);
1640 assertEquals(5, super[x]);
1641 assertEquals(6, ++super[x]);
1642 assertEquals(6, super[x]);
1643 assertEquals(6, this._x);
1644
1645 super[x]--;
1646 assertEquals(5, super[x]);
1647 --super[x];
1648 assertEquals(4, super[x]);
1649 assertEquals(4, super[x]--);
1650 assertEquals(3, super[x]);
1651 assertEquals(2, --super[x]);
1652 assertEquals(2, super[x]);
1653 assertEquals(2, this._x);
1654 }
1620 }; 1655 };
1621
1622 Derived.prototype.testCounts = function() {
1623 assertEquals(2, this._x);
1624 assertEquals(2, super[x]);
1625 super[x]++;
1626 assertEquals(3, super[x]);
1627 ++super[x];
1628 assertEquals(4, super[x]);
1629 assertEquals(4, super[x]++);
1630 assertEquals(5, super[x]);
1631 assertEquals(6, ++super[x]);
1632 assertEquals(6, super[x]);
1633 assertEquals(6, this._x);
1634
1635 super[x]--;
1636 assertEquals(5, super[x]);
1637 --super[x];
1638 assertEquals(4, super[x]);
1639 assertEquals(4, super[x]--);
1640 assertEquals(3, super[x]);
1641 assertEquals(2, --super[x]);
1642 assertEquals(2, super[x]);
1643 assertEquals(2, this._x);
1644 }.toMethod(Derived.prototype);
1645 new Derived().testCounts(); 1656 new Derived().testCounts();
1646 }()); 1657 }());
1647 1658
1648 1659
1649 (function TestSetterSuperNonWritable() { 1660 (function TestSetterSuperNonWritable() {
1650 function Base() {} 1661 function Base() {}
1651 Object.defineProperty(Base.prototype, 'x', { value : 27, writable: false }); 1662 Object.defineProperty(Base.prototype, 'x', { value : 27, writable: false });
1652 function Derived() {} 1663 function Derived() {}
1653 1664 Derived.prototype = {
1654 Derived.prototype = { __proto__: Base.prototype, constructor: Derived }; 1665 __proto__: Base.prototype,
1655 1666 constructor: Derived,
1656 Derived.prototype.mSloppy = function() { 1667 mSloppy() {
1657 assertEquals(27, super.x); 1668 assertEquals(27, super.x);
1658 assertEquals(27, this.x); 1669 assertEquals(27, this.x);
1659 super.x = 10; 1670 super.x = 10;
1660 assertEquals(27, super.x); 1671 assertEquals(27, super.x);
1661 assertEquals(27, this.x); 1672 assertEquals(27, this.x);
1662 }.toMethod(Derived.prototype); 1673 },
1663 Derived.prototype.mStrict = function() { 1674 mStrict() {
1664 'use strict'; 1675 'use strict';
1665 assertEquals(27, super.x); 1676 assertEquals(27, super.x);
1666 assertEquals(27, this.x); 1677 assertEquals(27, this.x);
1667 var ex = null; 1678 var ex = null;
1668 try { super.x = 10; } catch(e) { ex = e; } 1679 try { super.x = 10; } catch(e) { ex = e; }
1669 assertTrue(ex instanceof TypeError); 1680 assertTrue(ex instanceof TypeError);
1670 assertEquals(27, super.x); 1681 assertEquals(27, super.x);
1671 assertEquals(27, this.x); 1682 assertEquals(27, this.x);
1672 }.toMethod(Derived.prototype); 1683 }
1684 };
1673 new Derived().mSloppy(); 1685 new Derived().mSloppy();
1674 new Derived().mStrict(); 1686 new Derived().mStrict();
1675 }()); 1687 }());
1676 1688
1677 1689
1678 (function TestSetterKeyedSuperNonWritable() { 1690 (function TestSetterKeyedSuperNonWritable() {
1679 var x = 'xyz'; 1691 var x = 'xyz';
1680 function Base() {} 1692 function Base() {}
1681 Object.defineProperty(Base.prototype, x, { value : 27, writable: false }); 1693 Object.defineProperty(Base.prototype, x, { value : 27, writable: false });
1682 function Derived() {} 1694 function Derived() {}
1683 1695
1684 Derived.prototype = { __proto__: Base.prototype, constructor: Derived }; 1696 Derived.prototype = {
1685 1697 __proto__: Base.prototype,
1686 Derived.prototype.mSloppy = function() { 1698 constructor: Derived,
1687 assertEquals(27, super[x]); 1699 mSloppy() {
1688 assertEquals(27, this[x]); 1700 assertEquals(27, super[x]);
1689 super[x] = 10; 1701 assertEquals(27, this[x]);
1690 assertEquals(27, super[x]); 1702 super[x] = 10;
1691 assertEquals(27, this[x]); 1703 assertEquals(27, super[x]);
1692 }.toMethod(Derived.prototype); 1704 assertEquals(27, this[x]);
1693 Derived.prototype.mStrict = function() { 1705 },
1694 'use strict'; 1706 mStrict() {
1695 assertEquals(27, super[x]); 1707 'use strict';
1696 assertEquals(27, this[x]); 1708 assertEquals(27, super[x]);
1697 var ex = null; 1709 assertEquals(27, this[x]);
1698 try { super[x] = 10; } catch(e) { ex = e; } 1710 var ex = null;
1699 assertTrue(ex instanceof TypeError); 1711 try { super[x] = 10; } catch(e) { ex = e; }
1700 assertEquals(27, super[x]); 1712 assertTrue(ex instanceof TypeError);
1701 assertEquals(27, this[x]); 1713 assertEquals(27, super[x]);
1702 }.toMethod(Derived.prototype); 1714 assertEquals(27, this[x]);
1715 }
1716 };
1703 new Derived().mSloppy(); 1717 new Derived().mSloppy();
1704 new Derived().mStrict(); 1718 new Derived().mStrict();
1705 }()); 1719 }());
1706 1720
1707 1721
1708 (function TestSetterKeyedNumericSuperNonWritable() { 1722 (function TestSetterKeyedNumericSuperNonWritable() {
1709 var x = 42; 1723 var x = 42;
1710 function Base() {} 1724 function Base() {}
1711 Object.defineProperty(Base.prototype, x, { value : 27, writable: false }); 1725 Object.defineProperty(Base.prototype, x, { value : 27, writable: false });
1712 function Derived() {} 1726 function Derived() {}
1713 1727
1714 Derived.prototype = { __proto__: Base.prototype, constructor: Derived }; 1728 Derived.prototype = {
1715 1729 __proto__: Base.prototype,
1716 Derived.prototype.mSloppy = function() { 1730 constructor: Derived,
1717 assertEquals(27, super[x]); 1731 mSloppy() {
1718 assertEquals(27, this[x]); 1732 assertEquals(27, super[x]);
1719 super[x] = 10; 1733 assertEquals(27, this[x]);
1720 assertEquals(27, super[x]); 1734 super[x] = 10;
1721 assertEquals(27, this[x]); 1735 assertEquals(27, super[x]);
1722 }.toMethod(Derived.prototype); 1736 assertEquals(27, this[x]);
1723 Derived.prototype.mStrict = function() { 1737 },
1724 'use strict'; 1738 mStrict() {
1725 assertEquals(27, super[x]); 1739 'use strict';
1726 assertEquals(27, this[x]); 1740 assertEquals(27, super[x]);
1727 var ex = null; 1741 assertEquals(27, this[x]);
1728 try { super[x] = 10; } catch(e) { ex = e; } 1742 var ex = null;
1729 assertTrue(ex instanceof TypeError); 1743 try { super[x] = 10; } catch(e) { ex = e; }
1730 assertEquals(27, super[x]); 1744 assertTrue(ex instanceof TypeError);
1731 assertEquals(27, this[x]); 1745 assertEquals(27, super[x]);
1732 }.toMethod(Derived.prototype); 1746 assertEquals(27, this[x]);
1747 }
1748 };
1733 new Derived().mSloppy(); 1749 new Derived().mSloppy();
1734 new Derived().mStrict(); 1750 new Derived().mStrict();
1735 }()); 1751 }());
1736 1752
1737 1753
1738 function Subclass(base, constructor) { 1754 (function TestSuperCall() {
1739 var homeObject = { 1755 'use strict';
1740 __proto__: base.prototype,
1741 constructor: constructor
1742 };
1743 constructor.__proto__ = base;
1744 constructor.prototype = homeObject;
1745 // not doing toMethod: home object is not required for
1746 // super constructor calls.
1747 return constructor;
1748 }
1749 1756
1750 (function TestSuperCall() {
1751 var baseCalled = 0; 1757 var baseCalled = 0;
1752 var derivedCalled = 0; 1758 var derivedCalled = 0;
1753 var derivedDerivedCalled = 0; 1759 var derivedDerivedCalled = 0;
1754 1760
1755 function Base() { 1761 class Base {
1756 baseCalled++; 1762 constructor() {
1763 baseCalled++;
1764 }
1757 } 1765 }
1758 1766
1759 var Derived = Subclass(Base, function () { 1767 class Derived extends Base {
1760 super(); 1768 constructor() {
1761 derivedCalled++; 1769 super();
1762 }); 1770 derivedCalled++;
1771 }
1772 }
1763 1773
1764 assertEquals(Base, Base.prototype.constructor); 1774 assertEquals(Base, Base.prototype.constructor);
1765 assertEquals(Base.prototype, Derived.prototype.__proto__); 1775 assertEquals(Base.prototype, Derived.prototype.__proto__);
1766 1776
1767 baseCalled = 0; 1777 baseCalled = 0;
1768 derivedCalled = 0; 1778 derivedCalled = 0;
1769 new Derived(); 1779 new Derived();
1770 assertEquals(1, baseCalled); 1780 assertEquals(1, baseCalled);
1771 assertEquals(1, derivedCalled); 1781 assertEquals(1, derivedCalled);
1772 1782
1773 var DerivedDerived = Subclass(Derived, function () { 1783 class DerivedDerived extends Derived {
1774 super(); 1784 constructor() {
1775 derivedDerivedCalled++; 1785 super();
1776 }); 1786 derivedDerivedCalled++;
1787 }
1788 }
1777 1789
1778 baseCalled = 0; 1790 baseCalled = 0;
1779 derivedCalled = 0; 1791 derivedCalled = 0;
1780 derivedDerivedCalled = 0; 1792 derivedDerivedCalled = 0;
1781 new DerivedDerived(); 1793 new DerivedDerived();
1782 assertEquals(1, baseCalled); 1794 assertEquals(1, baseCalled);
1783 assertEquals(1, derivedCalled); 1795 assertEquals(1, derivedCalled);
1784 assertEquals(1, derivedDerivedCalled); 1796 assertEquals(1, derivedDerivedCalled);
1785 1797
1786 function Base2(v) { 1798 class Base2 {
1787 this.fromBase = v; 1799 constructor(v) {
1800 this.fromBase = v;
1801 }
1788 } 1802 }
1789 var Derived2 = Subclass(Base2, function (v1, v2) { 1803 class Derived2 extends Base2 {
1790 super(v1); 1804 constructor(v1, v2) {
1791 this.fromDerived = v2; 1805 super(v1);
1792 }); 1806 this.fromDerived = v2;
1807 }
1808 }
1793 1809
1794 var d = new Derived2("base", "derived"); 1810 var d = new Derived2("base", "derived");
1795 assertEquals("base", d.fromBase); 1811 assertEquals("base", d.fromBase);
1796 assertEquals("derived", d.fromDerived); 1812 assertEquals("derived", d.fromDerived);
1797 1813
1798 function ImplicitSubclassOfFunction() { 1814 class ImplicitSubclassOfFunction {
1799 super(); 1815 constructor() {
1800 this.x = 123; 1816 super();
1817 this.x = 123;
1818 }
1801 } 1819 }
1802 1820
1803 var o = new ImplicitSubclassOfFunction(); 1821 var o = new ImplicitSubclassOfFunction();
1804 assertEquals(123, o.x); 1822 assertEquals(123, o.x);
1805 1823
1806 var calls = 0; 1824 var calls = 0;
1807 function G() { 1825 class G {
1808 calls++; 1826 constructor() {
1827 calls++;
1828 }
1809 } 1829 }
1810 function F() { 1830 class F {
1811 super(); 1831 constructor() {
1832 super();
1833 }
1812 } 1834 }
1813 F.__proto__ = G; 1835 F.__proto__ = G;
1814 new F(); 1836 new F();
1815 assertEquals(1, calls); 1837 assertEquals(1, calls);
1816 F.__proto__ = function() {}; 1838 F.__proto__ = function() {};
1817 new F(); 1839 new F();
1818 assertEquals(1, calls); 1840 assertEquals(1, calls);
1819 }()); 1841 }());
1820 1842
1821 1843
1822 (function TestNewSuper() {
1823 var baseCalled = 0;
1824 var derivedCalled = 0;
1825
1826 function Base() {
1827 baseCalled++;
1828 this.x = 15;
1829 }
1830
1831
1832 var Derived = Subclass(Base, function() {
1833 baseCalled = 0;
1834 var b = new super();
1835 assertEquals(1, baseCalled)
1836 assertEquals(Base.prototype, b.__proto__);
1837 assertEquals(15, b.x);
1838 assertEquals(undefined, this.x);
1839 derivedCalled++;
1840 });
1841
1842 derivedCalled = 0;
1843 new Derived();
1844 assertEquals(1, derivedCalled);
1845 }());
1846
1847
1848 (function TestSuperCallErrorCases() { 1844 (function TestSuperCallErrorCases() {
1849 function T() { 1845 'use strict';
1850 super(); 1846 class T {
1847 constructor() {
1848 super();
1849 }
1851 } 1850 }
1851
1852 T.__proto__ = null; 1852 T.__proto__ = null;
1853 // Spec says ReferenceError here, but for other IsCallable failures
1854 // we throw TypeError.
1855 // Filed https://bugs.ecmascript.org/show_bug.cgi?id=3282
1856 assertThrows(function() { new T(); }, TypeError); 1853 assertThrows(function() { new T(); }, TypeError);
1857
1858 function T1() {
1859 var b = new super();
1860 }
1861 T1.__proto = null;
1862 assertThrows(function() { new T1(); }, TypeError);
1863 }()); 1854 }());
1864 1855
1865 1856
1866 (function TestSuperCallSyntacticRestriction() { 1857 (function TestSuperCallSyntacticRestriction() {
1858 'use strict';
1867 assertThrows(function() { 1859 assertThrows(function() {
1868 function C() { 1860 class C {
1869 var y; 1861 constructor() {
1870 super(); 1862 super(this.x);
1863 }
1871 } 1864 }
1872 new C(); 1865 new C();
1873 }, TypeError); 1866 }, TypeError);
1874 assertThrows(function() { 1867 assertThrows(function() {
1875 function C() { 1868 class C {
1876 super(this.x); 1869 constructor() {
1870 super(this);
1871 }
1877 } 1872 }
1878 new C(); 1873 new C();
1879 }, TypeError); 1874 }, TypeError);
1880 assertThrows(function() { 1875 assertThrows(function() {
1881 function C() { 1876 class C {
1882 super(this); 1877 constructor() {
1878 super(1, 2, Object.getPrototypeOf(this));
1879 }
1883 } 1880 }
1884 new C(); 1881 new C();
1885 }, TypeError); 1882 }, TypeError);
1886 assertThrows(function() { 1883 assertThrows(function() {
1887 function C() { 1884 class C {
1888 super(1, 2, Object.getPrototypeOf(this)); 1885 constructor() {
1886 { super(1, 2); }
1887 }
1889 } 1888 }
1890 new C(); 1889 new C();
1891 }, TypeError); 1890 }, TypeError);
1892 assertThrows(function() { 1891 assertThrows(function() {
1893 function C() { 1892 class C {
1894 { super(1, 2); } 1893 constructor() {
1895 }; new C(); 1894 if (1) super();
1896 }, TypeError); 1895 }
1897 assertThrows(function() { 1896 }
1898 function C() { 1897 new C();
1899 if (1) super();
1900 }; new C();
1901 }, TypeError); 1898 }, TypeError);
1902 1899
1903 function C1() { 1900 class C1 {
1904 'use strict'; 1901 constructor() {
1905 super(); 1902 'use strict';
1906 }; 1903 super();
1904 }
1905 }
1907 new C1(); 1906 new C1();
1908 1907
1909 function C2() { 1908 class C2 {
1910 ; 'use strict';;;;; 1909 constructor() {
1911 super(); 1910 ; 'use strict';;;;;
1912 }; 1911 super();
1912 }
1913 }
1913 new C2(); 1914 new C2();
1914 1915
1915 function C3() { 1916 class C3 {
1916 ; 'use strict';;;;; 1917 constructor() {
1917 // This is a comment. 1918 ; 'use strict';;;;;
1918 super(); 1919 // This is a comment.
1920 super();
1921 }
1919 } 1922 }
1920 new C3(); 1923 new C3();
1921 }()); 1924 }());
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/object-literals-super.js ('k') | test/mjsunit/mjsunit.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698