OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Flags: --harmony-classes | 5 // Flags: --harmony-classes |
6 | 6 |
7 | 7 |
8 (function TestSuperNamedLoads() { | 8 (function TestSuperNamedLoads() { |
9 function Base() { } | 9 function Base() { } |
10 function Derived() { | 10 function Derived() { |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 Loading... |
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 Loading... |
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 |
643 (function TestSetterUndefinedProperties() { | 807 (function TestSetterUndefinedProperties() { |
644 function Base() {} | 808 function Base() {} |
645 function Derived() {} | 809 function Derived() {} |
646 Derived.prototype = { __proto__ : Base.prototype }; | 810 Derived.prototype = { __proto__ : Base.prototype }; |
647 Derived.prototype.mSloppy = function () { | 811 Derived.prototype.mSloppy = function () { |
648 assertEquals(undefined, super.x); | 812 assertEquals(undefined, super.x); |
649 assertEquals(undefined, this.x); | 813 assertEquals(undefined, this.x); |
650 super.x = 10; | 814 super.x = 10; |
651 assertEquals(10, this.x); | 815 assertEquals(10, this.x); |
652 assertEquals(undefined, super.x); | 816 assertEquals(undefined, super.x); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 }.toMethod(Derived.prototype); | 856 }.toMethod(Derived.prototype); |
693 var d = new Derived(); | 857 var d = new Derived(); |
694 d.mSloppy(); | 858 d.mSloppy(); |
695 assertEquals(10, d.x); | 859 assertEquals(10, d.x); |
696 var d1 = new Derived(); | 860 var d1 = new Derived(); |
697 d1.mStrict(); | 861 d1.mStrict(); |
698 assertEquals(10, d.x); | 862 assertEquals(10, d.x); |
699 }()); | 863 }()); |
700 | 864 |
701 | 865 |
| 866 (function TestKeyedNumericSetterUndefinedProperties() { |
| 867 var x = 42; |
| 868 function Base() {} |
| 869 function Derived() {} |
| 870 Derived.prototype = { __proto__ : Base.prototype }; |
| 871 Derived.prototype.mSloppy = function () { |
| 872 assertEquals(undefined, super[x]); |
| 873 assertEquals(undefined, this[x]); |
| 874 super[x] = 10; |
| 875 assertEquals(10, this[x]); |
| 876 assertEquals(undefined, super[x]); |
| 877 }.toMethod(Derived.prototype); |
| 878 |
| 879 Derived.prototype.mStrict = function () { |
| 880 'use strict'; |
| 881 assertEquals(undefined, super[x]); |
| 882 assertEquals(undefined, this[x]); |
| 883 super[x] = 10; |
| 884 assertEquals(10, this[x]); |
| 885 assertEquals(undefined, super[x]); |
| 886 }.toMethod(Derived.prototype); |
| 887 var d = new Derived(); |
| 888 d.mSloppy(); |
| 889 assertEquals(10, d[x]); |
| 890 var d1 = new Derived(); |
| 891 d1.mStrict(); |
| 892 assertEquals(10, d[x]); |
| 893 }()); |
| 894 |
| 895 |
702 (function TestSetterCreatingOwnProperties() { | 896 (function TestSetterCreatingOwnProperties() { |
703 function Base() {} | 897 function Base() {} |
704 function Derived() {} | 898 function Derived() {} |
705 Derived.prototype = { __proto__ : Base.prototype }; | 899 Derived.prototype = { __proto__ : Base.prototype }; |
706 var setterCalled; | 900 var setterCalled; |
707 | 901 |
708 Derived.prototype.mSloppy = function() { | 902 Derived.prototype.mSloppy = function() { |
709 assertEquals(42, this.ownReadOnly); | 903 assertEquals(42, this.ownReadOnly); |
710 super.ownReadOnly = 55; | 904 super.ownReadOnly = 55; |
711 assertEquals(42, this.ownReadOnly); | 905 assertEquals(42, this.ownReadOnly); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 Object.defineProperty(d, 'ownReadOnly', { value : 42, writable : false }); | 997 Object.defineProperty(d, 'ownReadOnly', { value : 42, writable : false }); |
804 Object.defineProperty(d, 'ownSetter', | 998 Object.defineProperty(d, 'ownSetter', |
805 { set : function() { setterCalled++; } }); | 999 { set : function() { setterCalled++; } }); |
806 Object.defineProperty(d, 'ownReadonlyAccessor', | 1000 Object.defineProperty(d, 'ownReadonlyAccessor', |
807 { get : function() { return 15; }}); | 1001 { get : function() { return 15; }}); |
808 d.mSloppy(); | 1002 d.mSloppy(); |
809 d.mStrict(); | 1003 d.mStrict(); |
810 }()); | 1004 }()); |
811 | 1005 |
812 | 1006 |
| 1007 (function TestKeyedNumericSetterCreatingOwnProperties() { |
| 1008 var ownReadOnly = 42; |
| 1009 var ownReadonlyAccessor = 43; |
| 1010 var ownSetter = 44; |
| 1011 function Base() {} |
| 1012 function Derived() {} |
| 1013 Derived.prototype = { __proto__ : Base.prototype }; |
| 1014 var setterCalled; |
| 1015 |
| 1016 Derived.prototype.mSloppy = function() { |
| 1017 assertEquals(42, this[ownReadOnly]); |
| 1018 super[ownReadOnly] = 55; |
| 1019 assertEquals(42, this[ownReadOnly]); |
| 1020 |
| 1021 assertEquals(15, this[ownReadonlyAccessor]); |
| 1022 super[ownReadonlyAccessor] = 55; |
| 1023 assertEquals(15, this[ownReadonlyAccessor]); |
| 1024 |
| 1025 setterCalled = 0; |
| 1026 super[ownSetter] = 42; |
| 1027 assertEquals(1, setterCalled); |
| 1028 }.toMethod(Derived.prototype); |
| 1029 |
| 1030 Derived.prototype.mStrict = function() { |
| 1031 'use strict'; |
| 1032 assertEquals(42, this[ownReadOnly]); |
| 1033 var ex; |
| 1034 try { |
| 1035 super[ownReadOnly] = 55; |
| 1036 } catch(e) { ex = e; } |
| 1037 assertTrue(ex instanceof TypeError); |
| 1038 assertEquals(42, this[ownReadOnly]); |
| 1039 |
| 1040 assertEquals(15, this[ownReadonlyAccessor]); |
| 1041 ex = null; |
| 1042 try { |
| 1043 super[ownReadonlyAccessor] = 55; |
| 1044 } catch(e) { ex = e; } |
| 1045 assertTrue(ex instanceof TypeError); |
| 1046 assertEquals(15, this[ownReadonlyAccessor]); |
| 1047 |
| 1048 setterCalled = 0; |
| 1049 super[ownSetter] = 42; |
| 1050 assertEquals(1, setterCalled); |
| 1051 }.toMethod(Derived.prototype); |
| 1052 |
| 1053 var d = new Derived(); |
| 1054 Object.defineProperty(d, ownReadOnly, { value : 42, writable : false }); |
| 1055 Object.defineProperty(d, ownSetter, |
| 1056 { set : function() { setterCalled++; } }); |
| 1057 Object.defineProperty(d, ownReadonlyAccessor, |
| 1058 { get : function() { return 15; }}); |
| 1059 d.mSloppy(); |
| 1060 d.mStrict(); |
| 1061 }()); |
| 1062 |
| 1063 |
813 (function TestSetterNoProtoWalk() { | 1064 (function TestSetterNoProtoWalk() { |
814 function Base() {} | 1065 function Base() {} |
815 function Derived() {} | 1066 function Derived() {} |
816 var getCalled; | 1067 var getCalled; |
817 var setCalled; | 1068 var setCalled; |
818 Derived.prototype = { | 1069 Derived.prototype = { |
819 __proto__ : Base.prototype, | 1070 __proto__ : Base.prototype, |
820 get x() { getCalled++; return 42; }, | 1071 get x() { getCalled++; return 42; }, |
821 set x(v) { setCalled++; } | 1072 set x(v) { setCalled++; } |
822 }; | 1073 }; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 assertEquals(0, getCalled); | 1189 assertEquals(0, getCalled); |
939 assertEquals(0, setCalled); | 1190 assertEquals(0, setCalled); |
940 | 1191 |
941 }.toMethod(Derived.prototype); | 1192 }.toMethod(Derived.prototype); |
942 | 1193 |
943 new Derived().mSloppy(); | 1194 new Derived().mSloppy(); |
944 new Derived().mStrict(); | 1195 new Derived().mStrict(); |
945 }()); | 1196 }()); |
946 | 1197 |
947 | 1198 |
| 1199 (function TestKeyedNumericSetterNoProtoWalk() { |
| 1200 var x = 42; |
| 1201 function Base() {} |
| 1202 function Derived() {} |
| 1203 var getCalled; |
| 1204 var setCalled; |
| 1205 Derived.prototype = { |
| 1206 __proto__ : Base.prototype, |
| 1207 }; |
| 1208 |
| 1209 Object.defineProperty(Derived.prototype, x, { |
| 1210 get: function() { getCalled++; return 42; }, |
| 1211 set: function(v) { setCalled++; } |
| 1212 }); |
| 1213 |
| 1214 Derived.prototype.mSloppy = function() { |
| 1215 setCalled = 0; |
| 1216 getCalled = 0; |
| 1217 assertEquals(42, this[x]); |
| 1218 assertEquals(1, getCalled); |
| 1219 assertEquals(0, setCalled); |
| 1220 |
| 1221 getCalled = 0; |
| 1222 setCalled = 0; |
| 1223 this[x] = 43; |
| 1224 assertEquals(0, getCalled); |
| 1225 assertEquals(1, setCalled); |
| 1226 |
| 1227 getCalled = 0; |
| 1228 setCalled = 0; |
| 1229 super[x] = 15; |
| 1230 assertEquals(0, setCalled); |
| 1231 assertEquals(0, getCalled); |
| 1232 |
| 1233 assertEquals(15, this[x]); |
| 1234 assertEquals(0, getCalled); |
| 1235 assertEquals(0, setCalled); |
| 1236 |
| 1237 }.toMethod(Derived.prototype); |
| 1238 |
| 1239 Derived.prototype.mStrict = function() { |
| 1240 'use strict'; |
| 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 new Derived().mSloppy(); |
| 1266 new Derived().mStrict(); |
| 1267 }()); |
| 1268 |
| 1269 |
948 (function TestSetterDoesNotReconfigure() { | 1270 (function TestSetterDoesNotReconfigure() { |
949 function Base() {} | 1271 function Base() {} |
950 function Derived() {} | 1272 function Derived() {} |
951 | 1273 |
952 Derived.prototype.mStrict = function (){ | 1274 Derived.prototype.mStrict = function (){ |
953 'use strict'; | 1275 'use strict'; |
954 super.nonEnumConfig = 5; | 1276 super.nonEnumConfig = 5; |
955 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumConfig'); | 1277 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumConfig'); |
956 assertEquals(5, d1.value); | 1278 assertEquals(5, d1.value); |
957 assertTrue(d1.configurable); | 1279 assertTrue(d1.configurable); |
(...skipping 29 matching lines...) Expand all Loading... |
987 d.mSloppy(); | 1309 d.mSloppy(); |
988 }()); | 1310 }()); |
989 | 1311 |
990 | 1312 |
991 (function TestKeyedSetterDoesNotReconfigure() { | 1313 (function TestKeyedSetterDoesNotReconfigure() { |
992 var nonEnumConfig = 'nonEnumConfig'; | 1314 var nonEnumConfig = 'nonEnumConfig'; |
993 var nonEnumNonConfig = 'nonEnumNonConfig'; | 1315 var nonEnumNonConfig = 'nonEnumNonConfig'; |
994 function Base() {} | 1316 function Base() {} |
995 function Derived() {} | 1317 function Derived() {} |
996 | 1318 |
| 1319 Derived.prototype = { __proto__: Base.prototype }; |
| 1320 |
997 Derived.prototype.mStrict = function (){ | 1321 Derived.prototype.mStrict = function (){ |
998 'use strict'; | 1322 'use strict'; |
999 super[nonEnumConfig] = 5; | 1323 super[nonEnumConfig] = 5; |
1000 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumConfig'); | 1324 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumConfig); |
1001 assertEquals(5, d1.value); | 1325 assertEquals(5, d1.value); |
1002 assertTrue(d1.configurable); | 1326 assertTrue(d1.configurable); |
1003 assertFalse(d1.enumerable); | 1327 assertFalse(d1.enumerable); |
1004 | 1328 |
1005 super[nonEnumNonConfig] = 5; | 1329 super[nonEnumNonConfig] = 5; |
1006 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumNonConfig'); | 1330 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumNonConfig); |
1007 assertEquals(5, d1.value); | 1331 assertEquals(5, d1.value); |
1008 assertFalse(d1.configurable); | 1332 assertFalse(d1.configurable); |
1009 assertFalse(d1.enumerable); | 1333 assertFalse(d1.enumerable); |
1010 }.toMethod(Derived.prototype); | 1334 }.toMethod(Derived.prototype); |
1011 | 1335 |
1012 Derived.prototype.mSloppy = function (){ | 1336 Derived.prototype.mSloppy = function (){ |
1013 super[nonEnumConfig] = 42; | 1337 super[nonEnumConfig] = 42; |
1014 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumConfig'); | 1338 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumConfig); |
1015 assertEquals(42, d1.value); | 1339 assertEquals(42, d1.value); |
1016 assertTrue(d1.configurable); | 1340 assertTrue(d1.configurable); |
1017 assertFalse(d1.enumerable); | 1341 assertFalse(d1.enumerable); |
1018 | 1342 |
1019 super[nonEnumNonConfig] = 42; | 1343 super[nonEnumNonConfig] = 42; |
1020 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumNonConfig'); | 1344 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumNonConfig); |
1021 assertEquals(42, d1.value); | 1345 assertEquals(42, d1.value); |
1022 assertFalse(d1.configurable); | 1346 assertFalse(d1.configurable); |
1023 assertFalse(d1.enumerable); | 1347 assertFalse(d1.enumerable); |
1024 }.toMethod(Derived.prototype); | 1348 }.toMethod(Derived.prototype); |
1025 | 1349 |
1026 var d = new Derived(); | 1350 var d = new Derived(); |
1027 Object.defineProperty(d, 'nonEnumConfig', | 1351 Object.defineProperty(d, nonEnumConfig, |
1028 { value : 0, enumerable : false, configurable : true, writable : true }); | 1352 { value : 0, enumerable : false, configurable : true, writable : true }); |
1029 Object.defineProperty(d, 'nonEnumNonConfig', | 1353 Object.defineProperty(d, nonEnumNonConfig, |
1030 { value : 0, enumerable : false, configurable : false, writable : true }); | 1354 { value : 0, enumerable : false, configurable : false, writable : true }); |
1031 d.mStrict(); | 1355 d.mStrict(); |
1032 d.mSloppy(); | 1356 d.mSloppy(); |
| 1357 }()); |
| 1358 |
| 1359 |
| 1360 (function TestKeyedNumericSetterDoesNotReconfigure() { |
| 1361 var nonEnumConfig = 42; |
| 1362 var nonEnumNonConfig = 43; |
| 1363 function Base() {} |
| 1364 function Derived() {} |
| 1365 |
| 1366 Derived.prototype = { __proto__: Base.prototype }; |
| 1367 |
| 1368 Derived.prototype.mStrict = function (){ |
| 1369 'use strict'; |
| 1370 super[nonEnumConfig] = 5; |
| 1371 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumConfig); |
| 1372 assertEquals(5, d1.value); |
| 1373 assertTrue(d1.configurable); |
| 1374 assertFalse(d1.enumerable); |
| 1375 |
| 1376 super[nonEnumNonConfig] = 5; |
| 1377 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumNonConfig); |
| 1378 assertEquals(5, d1.value); |
| 1379 assertFalse(d1.configurable); |
| 1380 assertFalse(d1.enumerable); |
| 1381 }.toMethod(Derived.prototype); |
| 1382 |
| 1383 Derived.prototype.mSloppy = function (){ |
| 1384 super[nonEnumConfig] = 42; |
| 1385 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumConfig); |
| 1386 assertEquals(42, d1.value); |
| 1387 assertTrue(d1.configurable); |
| 1388 assertFalse(d1.enumerable); |
| 1389 |
| 1390 super[nonEnumNonConfig] = 42; |
| 1391 var d1 = Object.getOwnPropertyDescriptor(this, nonEnumNonConfig); |
| 1392 assertEquals(42, d1.value); |
| 1393 assertFalse(d1.configurable); |
| 1394 assertFalse(d1.enumerable); |
| 1395 }.toMethod(Derived.prototype); |
| 1396 |
| 1397 var d = new Derived(); |
| 1398 Object.defineProperty(d, nonEnumConfig, |
| 1399 { value : 0, enumerable : false, configurable : true, writable : true }); |
| 1400 Object.defineProperty(d, nonEnumNonConfig, |
| 1401 { value : 0, enumerable : false, configurable : false, writable : true }); |
| 1402 d.mStrict(); |
| 1403 d.mSloppy(); |
1033 }()); | 1404 }()); |
1034 | 1405 |
1035 | 1406 |
1036 (function TestCountOperations() { | 1407 (function TestCountOperations() { |
1037 function Base() {} | 1408 function Base() {} |
1038 Base.prototype = { | 1409 Base.prototype = { |
1039 constructor: Base, | 1410 constructor: Base, |
1040 get x() { | 1411 get x() { |
1041 return this._x; | 1412 return this._x; |
1042 }, | 1413 }, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1123 assertEquals(4, super[x]--); | 1494 assertEquals(4, super[x]--); |
1124 assertEquals(3, super[x]); | 1495 assertEquals(3, super[x]); |
1125 assertEquals(2, --super[x]); | 1496 assertEquals(2, --super[x]); |
1126 assertEquals(2, super[x]); | 1497 assertEquals(2, super[x]); |
1127 assertEquals(2, this._x); | 1498 assertEquals(2, this._x); |
1128 }.toMethod(Derived.prototype); | 1499 }.toMethod(Derived.prototype); |
1129 new Derived().testCounts(); | 1500 new Derived().testCounts(); |
1130 }()); | 1501 }()); |
1131 | 1502 |
1132 | 1503 |
| 1504 (function TestKeyedNumericCountOperations() { |
| 1505 var x = 42; |
| 1506 function Base() {} |
| 1507 Base.prototype = { |
| 1508 constructor: Base, |
| 1509 _x: 1 |
| 1510 }; |
| 1511 |
| 1512 Object.defineProperty(Base.prototype, x, { |
| 1513 get: function() { return this._x; }, |
| 1514 set: function(v) { this._x = v;; } |
| 1515 }); |
| 1516 |
| 1517 function Derived() {} |
| 1518 Derived.__proto__ = Base; |
| 1519 Derived.prototype = { |
| 1520 __proto__: Base.prototype, |
| 1521 constructor: Derived, |
| 1522 _x: 2 |
| 1523 }; |
| 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(); |
| 1549 }()); |
| 1550 |
| 1551 |
| 1552 (function TestSetterSuperNonWritable() { |
| 1553 function Base() {} |
| 1554 Object.defineProperty(Base.prototype, 'x', { value : 27, writable: false }); |
| 1555 function Derived() {} |
| 1556 |
| 1557 Derived.prototype = { __proto__: Base.prototype, constructor: Derived }; |
| 1558 |
| 1559 Derived.prototype.mSloppy = function() { |
| 1560 assertEquals(27, super.x); |
| 1561 assertEquals(27, this.x); |
| 1562 super.x = 10; |
| 1563 assertEquals(27, super.x); |
| 1564 assertEquals(27, this.x); |
| 1565 }.toMethod(Derived.prototype); |
| 1566 Derived.prototype.mStrict = function() { |
| 1567 'use strict'; |
| 1568 assertEquals(27, super.x); |
| 1569 assertEquals(27, this.x); |
| 1570 var ex = null; |
| 1571 try { super.x = 10; } catch(e) { ex = e; } |
| 1572 assertTrue(ex instanceof TypeError); |
| 1573 assertEquals(27, super.x); |
| 1574 assertEquals(27, this.x); |
| 1575 }.toMethod(Derived.prototype); |
| 1576 new Derived().mSloppy(); |
| 1577 new Derived().mStrict(); |
| 1578 }()); |
| 1579 |
| 1580 |
| 1581 (function TestSetterKeyedSuperNonWritable() { |
| 1582 var x = 'xyz'; |
| 1583 function Base() {} |
| 1584 Object.defineProperty(Base.prototype, x, { value : 27, writable: false }); |
| 1585 function Derived() {} |
| 1586 |
| 1587 Derived.prototype = { __proto__: Base.prototype, constructor: Derived }; |
| 1588 |
| 1589 Derived.prototype.mSloppy = function() { |
| 1590 assertEquals(27, super[x]); |
| 1591 assertEquals(27, this[x]); |
| 1592 super[x] = 10; |
| 1593 assertEquals(27, super[x]); |
| 1594 assertEquals(27, this[x]); |
| 1595 }.toMethod(Derived.prototype); |
| 1596 Derived.prototype.mStrict = function() { |
| 1597 'use strict'; |
| 1598 assertEquals(27, super[x]); |
| 1599 assertEquals(27, this[x]); |
| 1600 var ex = null; |
| 1601 try { super[x] = 10; } catch(e) { ex = e; } |
| 1602 assertTrue(ex instanceof TypeError); |
| 1603 assertEquals(27, super[x]); |
| 1604 assertEquals(27, this[x]); |
| 1605 }.toMethod(Derived.prototype); |
| 1606 new Derived().mSloppy(); |
| 1607 new Derived().mStrict(); |
| 1608 }()); |
| 1609 |
| 1610 |
| 1611 (function TestSetterKeyedNumericSuperNonWritable() { |
| 1612 var x = 42; |
| 1613 function Base() {} |
| 1614 Object.defineProperty(Base.prototype, x, { value : 27, writable: false }); |
| 1615 function Derived() {} |
| 1616 |
| 1617 Derived.prototype = { __proto__: Base.prototype, constructor: Derived }; |
| 1618 |
| 1619 Derived.prototype.mSloppy = function() { |
| 1620 assertEquals(27, super[x]); |
| 1621 assertEquals(27, this[x]); |
| 1622 super[x] = 10; |
| 1623 assertEquals(27, super[x]); |
| 1624 assertEquals(27, this[x]); |
| 1625 }.toMethod(Derived.prototype); |
| 1626 Derived.prototype.mStrict = function() { |
| 1627 'use strict'; |
| 1628 assertEquals(27, super[x]); |
| 1629 assertEquals(27, this[x]); |
| 1630 var ex = null; |
| 1631 try { super[x] = 10; } catch(e) { ex = e; } |
| 1632 assertTrue(ex instanceof TypeError); |
| 1633 assertEquals(27, super[x]); |
| 1634 assertEquals(27, this[x]); |
| 1635 }.toMethod(Derived.prototype); |
| 1636 new Derived().mSloppy(); |
| 1637 new Derived().mStrict(); |
| 1638 }()); |
| 1639 |
| 1640 |
1133 (function TestSuperCall() { | 1641 (function TestSuperCall() { |
1134 function Subclass(base, constructor) { | 1642 function Subclass(base, constructor) { |
1135 var homeObject = { __proto__ : base.prototype }; | 1643 var homeObject = { __proto__ : base.prototype }; |
1136 var result = constructor.toMethod(homeObject); | 1644 var result = constructor.toMethod(homeObject); |
1137 homeObject.constructor = result; | 1645 homeObject.constructor = result; |
1138 result.prototype = homeObject; | 1646 result.prototype = homeObject; |
1139 return result; | 1647 return result; |
1140 } | 1648 } |
1141 | 1649 |
1142 var baseCalled = 0; | 1650 var baseCalled = 0; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 } | 1687 } |
1180 var Derived2 = Subclass(Base2, function (v1, v2) { | 1688 var Derived2 = Subclass(Base2, function (v1, v2) { |
1181 super(v1); | 1689 super(v1); |
1182 this.fromDerived = v2; | 1690 this.fromDerived = v2; |
1183 }); | 1691 }); |
1184 | 1692 |
1185 var d = new Derived2("base", "derived"); | 1693 var d = new Derived2("base", "derived"); |
1186 assertEquals("base", d.fromBase); | 1694 assertEquals("base", d.fromBase); |
1187 assertEquals("derived", d.fromDerived); | 1695 assertEquals("derived", d.fromDerived); |
1188 }()); | 1696 }()); |
1189 | |
1190 | |
1191 (function TestUnsupportedCases() { | |
1192 function f(x) { super[x] = 5; } | |
1193 var o = {}; | |
1194 assertThrows(function(){f.toMethod(o)(15);}, ReferenceError); | |
1195 }()); | |
OLD | NEW |