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

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

Issue 649603003: Keyed stores to super with numeric keys. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/runtime/runtime-classes.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Flags: --harmony-classes 5 // Flags: --harmony-classes
6 6
7 7
8 (function TestSuperNamedLoads() { 8 (function TestSuperNamedLoads() {
9 function Base() { } 9 function Base() { }
10 function Derived() { 10 function Derived() {
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 'use strict'; 314 'use strict';
315 assertEquals('foobar', super.x = 'foobar'); 315 assertEquals('foobar', super.x = 'foobar');
316 assertEquals('foobarabc', super.x += 'abc'); 316 assertEquals('foobarabc', super.x += 'abc');
317 }.toMethod(Derived.prototype); 317 }.toMethod(Derived.prototype);
318 d.testSetterStrict(); 318 d.testSetterStrict();
319 assertEquals('base', Base.prototype._x); 319 assertEquals('base', Base.prototype._x);
320 assertEquals('foobarabc', d._x); 320 assertEquals('foobarabc', d._x);
321 }()); 321 }());
322 322
323 323
324 (function TestSetterNumericKeyed() {
325 var x = 42;
326 function Base() {}
327 Base.prototype = {
328 constructor: Base,
329 _x: 'base'
330 };
331
332 Object.defineProperty(Base.prototype, x,
333 { get: function() { return this._x; },
334 set: function(v) { this._x = v; }
335 });
336
337 function Derived() {}
338 Derived.__proto__ = Base;
339 Derived.prototype = {
340 __proto__: Base.prototype,
341 constructor: Derived,
342 _x: 'derived'
343 };
344 Derived.prototype.testSetter = function() {
345 assertEquals('foobar', super[x] = 'foobar');
346 assertEquals('foobarabc', super[x] += 'abc');
347 }.toMethod(Derived.prototype);
348 var d = new Derived();
349 d.testSetter();
350 assertEquals('base', Base.prototype._x);
351 assertEquals('foobarabc', d._x);
352 d._x = '';
353 Derived.prototype.testSetterStrict = function() {
354 'use strict';
355 assertEquals('foobar', super[x] = 'foobar');
356 assertEquals('foobarabc', super[x] += 'abc');
357 }.toMethod(Derived.prototype);
358 d.testSetterStrict();
359 assertEquals('base', Base.prototype._x);
360 assertEquals('foobarabc', d._x);
361
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();
388 d.testSetterWithToString();
389 }());
390
391
324 (function TestSetterKeyed() { 392 (function TestSetterKeyed() {
325 var x = 'x'; 393 var x = 'x';
326 function Base() {} 394 function Base() {}
327 Base.prototype = { 395 Base.prototype = {
328 constructor: Base, 396 constructor: Base,
329 get x() { 397 get x() {
330 return this._x; 398 return this._x;
331 }, 399 },
332 set x(v) { 400 set x(v) {
333 this._x = v; 401 this._x = v;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 try { 450 try {
383 super[oThrowsInToString] = 'xyz'; 451 super[oThrowsInToString] = 'xyz';
384 } catch(e) { ex = e } 452 } catch(e) { ex = e }
385 assertEquals(eToThrow, ex); 453 assertEquals(eToThrow, ex);
386 assertEquals('set', this._x); 454 assertEquals('set', this._x);
387 455
388 var oReturnsNumericString = { toString: function() { 456 var oReturnsNumericString = { toString: function() {
389 return "1"; 457 return "1";
390 } }; 458 } };
391 459
392 ex = null; 460 assertEquals('abc', super[oReturnsNumericString] = 'abc');
393 try {
394 super[oReturnsNumericString] = 'abc';
395 } catch(e) { ex = e }
396 assertTrue(ex instanceof ReferenceError);
397 461
398 assertEquals('set', this._x); 462 assertEquals('set', this._x);
399 463
400 ex = null; 464 assertEquals(10, super[1] = 10);
401 try {
402 super[1] = 10; // Indexed properties unsupported yet.
403 } catch (e) { ex = e; }
404 assertTrue(ex instanceof ReferenceError);
405 }.toMethod(Derived.prototype); 465 }.toMethod(Derived.prototype);
406 d = new Derived(); 466 d = new Derived();
407 d.testSetterWithToString(); 467 d.testSetterWithToString();
408 }()); 468 }());
409 469
410 470
411 (function TestSetterDataProperties() { 471 (function TestSetterDataProperties() {
412 function Base() {} 472 function Base() {}
413 Base.prototype = { 473 Base.prototype = {
414 constructor: Base, 474 constructor: Base,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 assertEquals('x from Base', super[x]); 510 assertEquals('x from Base', super[x]);
451 super[x] = 'data property'; 511 super[x] = 'data property';
452 assertEquals('x from Base', super[x]); 512 assertEquals('x from Base', super[x]);
453 assertEquals('data property', this[x]); 513 assertEquals('data property', this[x]);
454 }.toMethod(Derived.prototype); 514 }.toMethod(Derived.prototype);
455 515
456 new Derived().testSetter(); 516 new Derived().testSetter();
457 }()); 517 }());
458 518
459 519
520 (function TestKeyedNumericSetterDataProperties() {
521 var x = 42;
522 function Base() {}
523 Base.prototype = {
524 constructor: Base,
525 42: 'x from Base'
526 };
527
528 function Derived() {}
529 Derived.prototype = {
530 __proto__: Base.prototype,
531 constructor: Derived,
532 };
533
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();
542 }());
543
544
460 (function TestAccessorsOnPrimitives() { 545 (function TestAccessorsOnPrimitives() {
461 var getCalled = 0; 546 var getCalled = 0;
462 var setCalled = 0; 547 var setCalled = 0;
463 function Base() {} 548 function Base() {}
464 Base.prototype = { 549 Base.prototype = {
465 constructor: Base, 550 constructor: Base,
466 get x() { 551 get x() {
467 getCalled++; 552 getCalled++;
468 return 1; 553 return 1;
469 }, 554 },
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 try { 718 try {
634 super[toString](); 719 super[toString]();
635 } catch(e) { ex = e; } 720 } catch(e) { ex = e; }
636 721
637 assertTrue(ex instanceof TypeError); 722 assertTrue(ex instanceof TypeError);
638 } 723 }
639 f.toMethod(DerivedFromString.prototype).call(42); 724 f.toMethod(DerivedFromString.prototype).call(42);
640 }()); 725 }());
641 726
642 727
728 (function TestNumericKeyedAccessorsOnPrimitives() {
729 var x = 42;
730 var newProperty = 43;
731 var getCalled = 0;
732 var setCalled = 0;
733 function Base() {}
734 Base.prototype = {
735 constructor: Base,
736 };
737
738 Object.defineProperty(Base.prototype, x, {
739 get: function() {
740 getCalled++;
741 return 1;
742 },
743 set: function(v) {
744 setCalled++;
745 return v;
746 }
747 });
748
749 function Derived() {}
750 Derived.prototype = {
751 __proto__: Base.prototype,
752 constructor: Derived,
753 };
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
802 Derived.prototype.testSetter.call(42);
803 Derived.prototype.testSetterStrict.call(42);
804 }());
805
806
807 (function TestKeyedNumericSetterOnExotics() {
808 function Base() {}
809 function Derived() {}
810 Derived.prototype = { __proto__: Base.prototype };
811
812 Derived.prototype.callSetterOnArray = function() {
813 super[42] = 1;
814 }.toMethod(Derived.prototype);
815
816 Derived.prototype.callStrictSetterOnString = function() {
817 'use strict';
818 assertEquals('string', typeof this);
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
833 var x = [];
834 assertEquals(0, x.length);
835 Derived.prototype.callSetterOnArray.call(x);
836 assertEquals(43, x.length);
837 assertEquals(1, x[42]);
838
839 var s = 'abcdef';
840 Derived.prototype.callStrictSetterOnString.call(s)
841 }());
842
843
643 (function TestSetterUndefinedProperties() { 844 (function TestSetterUndefinedProperties() {
644 function Base() {} 845 function Base() {}
645 function Derived() {} 846 function Derived() {}
646 Derived.prototype = { __proto__ : Base.prototype }; 847 Derived.prototype = { __proto__ : Base.prototype };
647 Derived.prototype.mSloppy = function () { 848 Derived.prototype.mSloppy = function () {
648 assertEquals(undefined, super.x); 849 assertEquals(undefined, super.x);
649 assertEquals(undefined, this.x); 850 assertEquals(undefined, this.x);
650 super.x = 10; 851 super.x = 10;
651 assertEquals(10, this.x); 852 assertEquals(10, this.x);
652 assertEquals(undefined, super.x); 853 assertEquals(undefined, super.x);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 }.toMethod(Derived.prototype); 893 }.toMethod(Derived.prototype);
693 var d = new Derived(); 894 var d = new Derived();
694 d.mSloppy(); 895 d.mSloppy();
695 assertEquals(10, d.x); 896 assertEquals(10, d.x);
696 var d1 = new Derived(); 897 var d1 = new Derived();
697 d1.mStrict(); 898 d1.mStrict();
698 assertEquals(10, d.x); 899 assertEquals(10, d.x);
699 }()); 900 }());
700 901
701 902
903 (function TestKeyedNumericSetterUndefinedProperties() {
904 var x = 42;
905 function Base() {}
906 function Derived() {}
907 Derived.prototype = { __proto__ : Base.prototype };
908 Derived.prototype.mSloppy = function () {
909 assertEquals(undefined, super[x]);
910 assertEquals(undefined, this[x]);
911 super[x] = 10;
912 assertEquals(10, this[x]);
913 assertEquals(undefined, super[x]);
914 }.toMethod(Derived.prototype);
915
916 Derived.prototype.mStrict = function () {
917 'use strict';
918 assertEquals(undefined, super[x]);
919 assertEquals(undefined, this[x]);
920 super[x] = 10;
921 assertEquals(10, this[x]);
922 assertEquals(undefined, super[x]);
923 }.toMethod(Derived.prototype);
924 var d = new Derived();
925 d.mSloppy();
926 assertEquals(10, d[x]);
927 var d1 = new Derived();
928 d1.mStrict();
929 assertEquals(10, d[x]);
930 }());
931
932
702 (function TestSetterCreatingOwnProperties() { 933 (function TestSetterCreatingOwnProperties() {
703 function Base() {} 934 function Base() {}
704 function Derived() {} 935 function Derived() {}
705 Derived.prototype = { __proto__ : Base.prototype }; 936 Derived.prototype = { __proto__ : Base.prototype };
706 var setterCalled; 937 var setterCalled;
707 938
708 Derived.prototype.mSloppy = function() { 939 Derived.prototype.mSloppy = function() {
709 assertEquals(42, this.ownReadOnly); 940 assertEquals(42, this.ownReadOnly);
710 super.ownReadOnly = 55; 941 super.ownReadOnly = 55;
711 assertEquals(42, this.ownReadOnly); 942 assertEquals(42, this.ownReadOnly);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 Object.defineProperty(d, 'ownReadOnly', { value : 42, writable : false }); 1094 Object.defineProperty(d, 'ownReadOnly', { value : 42, writable : false });
864 Object.defineProperty(d, 'ownSetter', 1095 Object.defineProperty(d, 'ownSetter',
865 { set : function() { setterCalled++; } }); 1096 { set : function() { setterCalled++; } });
866 Object.defineProperty(d, 'ownReadonlyAccessor', 1097 Object.defineProperty(d, 'ownReadonlyAccessor',
867 { get : function() { return 15; }}); 1098 { get : function() { return 15; }});
868 d.mSloppy(); 1099 d.mSloppy();
869 d.mStrict(); 1100 d.mStrict();
870 }()); 1101 }());
871 1102
872 1103
1104 (function TestKeyedNumericSetterCreatingOwnProperties() {
1105 var ownReadOnly = 42;
1106 var ownReadonlyAccessor = 43;
1107 var ownSetter = 44;
1108 function Base() {}
1109 function Derived() {}
1110 Derived.prototype = { __proto__ : Base.prototype };
1111 var setterCalled;
1112
1113 Derived.prototype.mSloppy = function() {
1114 assertEquals(42, this[ownReadOnly]);
1115 super[ownReadOnly] = 55;
1116 assertEquals(42, this[ownReadOnly]);
1117
1118 assertEquals(15, this[ownReadonlyAccessor]);
1119 super[ownReadonlyAccessor] = 55;
1120 assertEquals(15, this[ownReadonlyAccessor]);
1121
1122 setterCalled = 0;
1123 super[ownSetter] = 42;
1124 assertEquals(1, setterCalled);
1125 }.toMethod(Derived.prototype);
1126
1127 Derived.prototype.mStrict = function() {
1128 'use strict';
1129 assertEquals(42, this[ownReadOnly]);
1130 var ex;
1131 try {
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
1150 var d = new Derived();
1151 Object.defineProperty(d, ownReadOnly, { value : 42, writable : false });
1152 Object.defineProperty(d, ownSetter,
1153 { set : function() { setterCalled++; } });
1154 Object.defineProperty(d, ownReadonlyAccessor,
1155 { get : function() { return 15; }});
1156 d.mSloppy();
1157 d.mStrict();
1158 }());
1159
1160
873 (function TestSetterNoProtoWalk() { 1161 (function TestSetterNoProtoWalk() {
874 function Base() {} 1162 function Base() {}
875 function Derived() {} 1163 function Derived() {}
876 var getCalled; 1164 var getCalled;
877 var setCalled; 1165 var setCalled;
878 Derived.prototype = { 1166 Derived.prototype = {
879 __proto__ : Base.prototype, 1167 __proto__ : Base.prototype,
880 get x() { getCalled++; return 42; }, 1168 get x() { getCalled++; return 42; },
881 set x(v) { setCalled++; } 1169 set x(v) { setCalled++; }
882 }; 1170 };
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 assertEquals(0, getCalled); 1286 assertEquals(0, getCalled);
999 assertEquals(0, setCalled); 1287 assertEquals(0, setCalled);
1000 1288
1001 }.toMethod(Derived.prototype); 1289 }.toMethod(Derived.prototype);
1002 1290
1003 new Derived().mSloppy(); 1291 new Derived().mSloppy();
1004 new Derived().mStrict(); 1292 new Derived().mStrict();
1005 }()); 1293 }());
1006 1294
1007 1295
1296 (function TestKeyedNumericSetterNoProtoWalk() {
1297 var x = 42;
1298 function Base() {}
1299 function Derived() {}
1300 var getCalled;
1301 var setCalled;
1302 Derived.prototype = {
1303 __proto__ : Base.prototype,
1304 };
1305
1306 Object.defineProperty(Derived.prototype, x, {
1307 get: function() { getCalled++; return 42; },
1308 set: function(v) { setCalled++; }
1309 });
1310
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();
1363 new Derived().mStrict();
1364 }());
1365
1366
1008 (function TestSetterDoesNotReconfigure() { 1367 (function TestSetterDoesNotReconfigure() {
1009 function Base() {} 1368 function Base() {}
1010 function Derived() {} 1369 function Derived() {}
1011 1370
1012 Derived.prototype.mStrict = function (){ 1371 Derived.prototype.mStrict = function (){
1013 'use strict'; 1372 'use strict';
1014 super.nonEnumConfig = 5; 1373 super.nonEnumConfig = 5;
1015 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumConfig'); 1374 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumConfig');
1016 assertEquals(5, d1.value); 1375 assertEquals(5, d1.value);
1017 assertTrue(d1.configurable); 1376 assertTrue(d1.configurable);
(...skipping 29 matching lines...) Expand all
1047 d.mSloppy(); 1406 d.mSloppy();
1048 }()); 1407 }());
1049 1408
1050 1409
1051 (function TestKeyedSetterDoesNotReconfigure() { 1410 (function TestKeyedSetterDoesNotReconfigure() {
1052 var nonEnumConfig = 'nonEnumConfig'; 1411 var nonEnumConfig = 'nonEnumConfig';
1053 var nonEnumNonConfig = 'nonEnumNonConfig'; 1412 var nonEnumNonConfig = 'nonEnumNonConfig';
1054 function Base() {} 1413 function Base() {}
1055 function Derived() {} 1414 function Derived() {}
1056 1415
1416 Derived.prototype = { __proto__: Base.prototype };
1417
1057 Derived.prototype.mStrict = function (){ 1418 Derived.prototype.mStrict = function (){
1058 'use strict'; 1419 'use strict';
1059 super[nonEnumConfig] = 5; 1420 super[nonEnumConfig] = 5;
1060 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumConfig'); 1421 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumConfig);
1061 assertEquals(5, d1.value); 1422 assertEquals(5, d1.value);
1062 assertTrue(d1.configurable); 1423 assertTrue(d1.configurable);
1063 assertFalse(d1.enumerable); 1424 assertFalse(d1.enumerable);
1064 1425
1065 super[nonEnumNonConfig] = 5; 1426 super[nonEnumNonConfig] = 5;
1066 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumNonConfig'); 1427 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumNonConfig);
1067 assertEquals(5, d1.value); 1428 assertEquals(5, d1.value);
1068 assertFalse(d1.configurable); 1429 assertFalse(d1.configurable);
1069 assertFalse(d1.enumerable); 1430 assertFalse(d1.enumerable);
1070 }.toMethod(Derived.prototype); 1431 }.toMethod(Derived.prototype);
1071 1432
1072 Derived.prototype.mSloppy = function (){ 1433 Derived.prototype.mSloppy = function (){
1073 super[nonEnumConfig] = 42; 1434 super[nonEnumConfig] = 42;
1074 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumConfig'); 1435 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumConfig);
1075 assertEquals(42, d1.value); 1436 assertEquals(42, d1.value);
1076 assertTrue(d1.configurable); 1437 assertTrue(d1.configurable);
1077 assertFalse(d1.enumerable); 1438 assertFalse(d1.enumerable);
1078 1439
1079 super[nonEnumNonConfig] = 42; 1440 super[nonEnumNonConfig] = 42;
1080 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumNonConfig'); 1441 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumNonConfig);
1081 assertEquals(42, d1.value); 1442 assertEquals(42, d1.value);
1082 assertFalse(d1.configurable); 1443 assertFalse(d1.configurable);
1083 assertFalse(d1.enumerable); 1444 assertFalse(d1.enumerable);
1084 }.toMethod(Derived.prototype); 1445 }.toMethod(Derived.prototype);
1085 1446
1086 var d = new Derived(); 1447 var d = new Derived();
1087 Object.defineProperty(d, 'nonEnumConfig', 1448 Object.defineProperty(d, nonEnumConfig,
1088 { value : 0, enumerable : false, configurable : true, writable : true }); 1449 { value : 0, enumerable : false, configurable : true, writable : true });
1089 Object.defineProperty(d, 'nonEnumNonConfig', 1450 Object.defineProperty(d, nonEnumNonConfig,
1090 { value : 0, enumerable : false, configurable : false, writable : true }); 1451 { value : 0, enumerable : false, configurable : false, writable : true });
1091 d.mStrict(); 1452 d.mStrict();
1092 d.mSloppy(); 1453 d.mSloppy();
1454 }());
1455
1456
1457 (function TestKeyedNumericSetterDoesNotReconfigure() {
1458 var nonEnumConfig = 42;
1459 var nonEnumNonConfig = 43;
1460 function Base() {}
1461 function Derived() {}
1462
1463 Derived.prototype = { __proto__: Base.prototype };
1464
1465 Derived.prototype.mStrict = function (){
1466 'use strict';
1467 super[nonEnumConfig] = 5;
1468 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumConfig);
1469 assertEquals(5, d1.value);
1470 assertTrue(d1.configurable);
1471 assertFalse(d1.enumerable);
1472
1473 super[nonEnumNonConfig] = 5;
1474 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumNonConfig);
1475 assertEquals(5, d1.value);
1476 assertFalse(d1.configurable);
1477 assertFalse(d1.enumerable);
1478 }.toMethod(Derived.prototype);
1479
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
1494 var d = new Derived();
1495 Object.defineProperty(d, nonEnumConfig,
1496 { value : 0, enumerable : false, configurable : true, writable : true });
1497 Object.defineProperty(d, nonEnumNonConfig,
1498 { value : 0, enumerable : false, configurable : false, writable : true });
1499 d.mStrict();
1500 d.mSloppy();
1093 }()); 1501 }());
1094 1502
1095 1503
1096 (function TestCountOperations() { 1504 (function TestCountOperations() {
1097 function Base() {} 1505 function Base() {}
1098 Base.prototype = { 1506 Base.prototype = {
1099 constructor: Base, 1507 constructor: Base,
1100 get x() { 1508 get x() {
1101 return this._x; 1509 return this._x;
1102 }, 1510 },
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 assertEquals(4, super[x]--); 1591 assertEquals(4, super[x]--);
1184 assertEquals(3, super[x]); 1592 assertEquals(3, super[x]);
1185 assertEquals(2, --super[x]); 1593 assertEquals(2, --super[x]);
1186 assertEquals(2, super[x]); 1594 assertEquals(2, super[x]);
1187 assertEquals(2, this._x); 1595 assertEquals(2, this._x);
1188 }.toMethod(Derived.prototype); 1596 }.toMethod(Derived.prototype);
1189 new Derived().testCounts(); 1597 new Derived().testCounts();
1190 }()); 1598 }());
1191 1599
1192 1600
1601 (function TestKeyedNumericCountOperations() {
1602 var x = 42;
1603 function Base() {}
1604 Base.prototype = {
1605 constructor: Base,
1606 _x: 1
1607 };
1608
1609 Object.defineProperty(Base.prototype, x, {
1610 get: function() { return this._x; },
1611 set: function(v) { this._x = v;; }
1612 });
1613
1614 function Derived() {}
1615 Derived.__proto__ = Base;
1616 Derived.prototype = {
1617 __proto__: Base.prototype,
1618 constructor: Derived,
1619 _x: 2
1620 };
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();
1646 }());
1647
1648
1649 (function TestSetterSuperNonWritable() {
1650 function Base() {}
1651 Object.defineProperty(Base.prototype, 'x', { value : 27, writable: false });
1652 function Derived() {}
1653
1654 Derived.prototype = { __proto__: Base.prototype, constructor: Derived };
1655
1656 Derived.prototype.mSloppy = function() {
1657 assertEquals(27, super.x);
1658 assertEquals(27, this.x);
1659 super.x = 10;
1660 assertEquals(27, super.x);
1661 assertEquals(27, this.x);
1662 }.toMethod(Derived.prototype);
1663 Derived.prototype.mStrict = function() {
1664 'use strict';
1665 assertEquals(27, super.x);
1666 assertEquals(27, this.x);
1667 var ex = null;
1668 try { super.x = 10; } catch(e) { ex = e; }
1669 assertTrue(ex instanceof TypeError);
1670 assertEquals(27, super.x);
1671 assertEquals(27, this.x);
1672 }.toMethod(Derived.prototype);
1673 new Derived().mSloppy();
1674 new Derived().mStrict();
1675 }());
1676
1677
1678 (function TestSetterKeyedSuperNonWritable() {
1679 var x = 'xyz';
1680 function Base() {}
1681 Object.defineProperty(Base.prototype, x, { value : 27, writable: false });
1682 function Derived() {}
1683
1684 Derived.prototype = { __proto__: Base.prototype, constructor: Derived };
1685
1686 Derived.prototype.mSloppy = function() {
1687 assertEquals(27, super[x]);
1688 assertEquals(27, this[x]);
1689 super[x] = 10;
1690 assertEquals(27, super[x]);
1691 assertEquals(27, this[x]);
1692 }.toMethod(Derived.prototype);
1693 Derived.prototype.mStrict = function() {
1694 'use strict';
1695 assertEquals(27, super[x]);
1696 assertEquals(27, this[x]);
1697 var ex = null;
1698 try { super[x] = 10; } catch(e) { ex = e; }
1699 assertTrue(ex instanceof TypeError);
1700 assertEquals(27, super[x]);
1701 assertEquals(27, this[x]);
1702 }.toMethod(Derived.prototype);
1703 new Derived().mSloppy();
1704 new Derived().mStrict();
1705 }());
1706
1707
1708 (function TestSetterKeyedNumericSuperNonWritable() {
1709 var x = 42;
1710 function Base() {}
1711 Object.defineProperty(Base.prototype, x, { value : 27, writable: false });
1712 function Derived() {}
1713
1714 Derived.prototype = { __proto__: Base.prototype, constructor: Derived };
1715
1716 Derived.prototype.mSloppy = function() {
1717 assertEquals(27, super[x]);
1718 assertEquals(27, this[x]);
1719 super[x] = 10;
1720 assertEquals(27, super[x]);
1721 assertEquals(27, this[x]);
1722 }.toMethod(Derived.prototype);
1723 Derived.prototype.mStrict = function() {
1724 'use strict';
1725 assertEquals(27, super[x]);
1726 assertEquals(27, this[x]);
1727 var ex = null;
1728 try { super[x] = 10; } catch(e) { ex = e; }
1729 assertTrue(ex instanceof TypeError);
1730 assertEquals(27, super[x]);
1731 assertEquals(27, this[x]);
1732 }.toMethod(Derived.prototype);
1733 new Derived().mSloppy();
1734 new Derived().mStrict();
1735 }());
1736
1737
1193 (function TestSuperCall() { 1738 (function TestSuperCall() {
1194 function Subclass(base, constructor) { 1739 function Subclass(base, constructor) {
1195 var homeObject = { 1740 var homeObject = {
1196 __proto__: base.prototype, 1741 __proto__: base.prototype,
1197 constructor: constructor 1742 constructor: constructor
1198 }; 1743 };
1199 constructor.__proto__ = base; 1744 constructor.__proto__ = base;
1200 constructor.prototype = homeObject; 1745 constructor.prototype = homeObject;
1201 // not doing toMethod: home object is not required for 1746 // not doing toMethod: home object is not required for
1202 // super constructor calls. 1747 // super constructor calls.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 (function TestSuperCallErrorCases() { 1822 (function TestSuperCallErrorCases() {
1278 function T() { 1823 function T() {
1279 super(); 1824 super();
1280 } 1825 }
1281 T.__proto__ = null; 1826 T.__proto__ = null;
1282 // Spec says ReferenceError here, but for other IsCallable failures 1827 // Spec says ReferenceError here, but for other IsCallable failures
1283 // we throw TypeError. 1828 // we throw TypeError.
1284 // Filed https://bugs.ecmascript.org/show_bug.cgi?id=3282 1829 // Filed https://bugs.ecmascript.org/show_bug.cgi?id=3282
1285 assertThrows(function() { new T(); }, TypeError); 1830 assertThrows(function() { new T(); }, TypeError);
1286 }()); 1831 }());
1287
1288
1289 (function TestUnsupportedCases() {
1290 function f(x) { super[x] = 5; }
1291 var o = {};
1292 assertThrows(function(){f.toMethod(o)(15);}, ReferenceError);
1293 }());
OLDNEW
« no previous file with comments | « src/runtime/runtime-classes.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698