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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 'use strict'; | 221 'use strict'; |
222 assertEquals('foobar', super.x = 'foobar'); | 222 assertEquals('foobar', super.x = 'foobar'); |
223 assertEquals('foobarabc', super.x += 'abc'); | 223 assertEquals('foobarabc', super.x += 'abc'); |
224 }.toMethod(Derived.prototype); | 224 }.toMethod(Derived.prototype); |
225 d.testSetterStrict(); | 225 d.testSetterStrict(); |
226 assertEquals('base', Base.prototype._x); | 226 assertEquals('base', Base.prototype._x); |
227 assertEquals('foobarabc', d._x); | 227 assertEquals('foobarabc', d._x); |
228 }()); | 228 }()); |
229 | 229 |
230 | 230 |
| 231 (function TestSetterKeyed() { |
| 232 var x = 'x'; |
| 233 function Base() {} |
| 234 Base.prototype = { |
| 235 constructor: Base, |
| 236 get x() { |
| 237 return this._x; |
| 238 }, |
| 239 set x(v) { |
| 240 this._x = v; |
| 241 }, |
| 242 _x: 'base' |
| 243 }; |
| 244 |
| 245 function Derived() {} |
| 246 Derived.__proto__ = Base; |
| 247 Derived.prototype = { |
| 248 __proto__: Base.prototype, |
| 249 constructor: Derived, |
| 250 _x: 'derived' |
| 251 }; |
| 252 Derived.prototype.testSetter = function() { |
| 253 assertEquals('foobar', super[x] = 'foobar'); |
| 254 assertEquals('foobarabc', super[x] += 'abc'); |
| 255 }.toMethod(Derived.prototype); |
| 256 var d = new Derived(); |
| 257 d.testSetter(); |
| 258 assertEquals('base', Base.prototype._x); |
| 259 assertEquals('foobarabc', d._x); |
| 260 d._x = ''; |
| 261 Derived.prototype.testSetterStrict = function() { |
| 262 'use strict'; |
| 263 assertEquals('foobar', super[x] = 'foobar'); |
| 264 assertEquals('foobarabc', super[x] += 'abc'); |
| 265 }.toMethod(Derived.prototype); |
| 266 d.testSetterStrict(); |
| 267 assertEquals('base', Base.prototype._x); |
| 268 assertEquals('foobarabc', d._x); |
| 269 |
| 270 |
| 271 Derived.prototype.testSetterWithToString = function() { |
| 272 var toStringCalled; |
| 273 var o = { toString: function() { |
| 274 toStringCalled++; |
| 275 return 'x'; |
| 276 } }; |
| 277 |
| 278 toStringCalled = 0; |
| 279 super[o] = 'set'; |
| 280 assertEquals(1, toStringCalled); |
| 281 assertEquals('set', this._x); |
| 282 |
| 283 var eToThrow = new Error(); |
| 284 var oThrowsInToString = { toString: function() { |
| 285 throw eToThrow; |
| 286 } }; |
| 287 |
| 288 var ex = null; |
| 289 try { |
| 290 super[oThrowsInToString] = 'xyz'; |
| 291 } catch(e) { ex = e } |
| 292 assertEquals(eToThrow, ex); |
| 293 assertEquals('set', this._x); |
| 294 |
| 295 var oReturnsNumericString = { toString: function() { |
| 296 return "1"; |
| 297 } }; |
| 298 |
| 299 ex = null; |
| 300 try { |
| 301 super[oReturnsNumericString] = 'abc'; |
| 302 } catch(e) { ex = e } |
| 303 assertTrue(ex instanceof ReferenceError); |
| 304 |
| 305 assertEquals('set', this._x); |
| 306 |
| 307 ex = null; |
| 308 try { |
| 309 super[1] = 10; // Indexed properties unsupported yet. |
| 310 } catch (e) { ex = e; } |
| 311 assertTrue(ex instanceof ReferenceError); |
| 312 }.toMethod(Derived.prototype); |
| 313 d = new Derived(); |
| 314 d.testSetterWithToString(); |
| 315 }()); |
| 316 |
| 317 |
231 (function TestSetterDataProperties() { | 318 (function TestSetterDataProperties() { |
232 function Base() {} | 319 function Base() {} |
233 Base.prototype = { | 320 Base.prototype = { |
234 constructor: Base, | 321 constructor: Base, |
235 x: 'x from Base' | 322 x: 'x from Base' |
236 }; | 323 }; |
237 | 324 |
238 function Derived() {} | 325 function Derived() {} |
239 Derived.prototype = { | 326 Derived.prototype = { |
240 __proto__: Base.prototype, | 327 __proto__: Base.prototype, |
241 constructor: Derived, | 328 constructor: Derived, |
242 }; | 329 }; |
243 | 330 |
244 Derived.prototype.testSetter = function() { | 331 Derived.prototype.testSetter = function() { |
245 assertEquals('x from Base', super.x); | 332 assertEquals('x from Base', super.x); |
246 super.x = 'data property'; | 333 super.x = 'data property'; |
247 assertEquals('x from Base', super.x); | 334 assertEquals('x from Base', super.x); |
248 assertEquals('data property', this.x); | 335 assertEquals('data property', this.x); |
249 }.toMethod(Derived.prototype); | 336 }.toMethod(Derived.prototype); |
250 | 337 |
251 new Derived().testSetter(); | 338 new Derived().testSetter(); |
252 }()); | 339 }()); |
253 | 340 |
254 | 341 |
| 342 (function TestKeyedSetterDataProperties() { |
| 343 var x = 'x'; |
| 344 function Base() {} |
| 345 Base.prototype = { |
| 346 constructor: Base, |
| 347 x: 'x from Base' |
| 348 }; |
| 349 |
| 350 function Derived() {} |
| 351 Derived.prototype = { |
| 352 __proto__: Base.prototype, |
| 353 constructor: Derived, |
| 354 }; |
| 355 |
| 356 Derived.prototype.testSetter = function() { |
| 357 assertEquals('x from Base', super[x]); |
| 358 super[x] = 'data property'; |
| 359 assertEquals('x from Base', super[x]); |
| 360 assertEquals('data property', this[x]); |
| 361 }.toMethod(Derived.prototype); |
| 362 |
| 363 new Derived().testSetter(); |
| 364 }()); |
| 365 |
| 366 |
255 (function TestAccessorsOnPrimitives() { | 367 (function TestAccessorsOnPrimitives() { |
256 var getCalled = 0; | 368 var getCalled = 0; |
257 var setCalled = 0; | 369 var setCalled = 0; |
258 function Base() {} | 370 function Base() {} |
259 Base.prototype = { | 371 Base.prototype = { |
260 constructor: Base, | 372 constructor: Base, |
261 get x() { | 373 get x() { |
262 getCalled++; | 374 getCalled++; |
263 return 1; | 375 return 1; |
264 }, | 376 }, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 try { | 447 try { |
336 super.toString(); | 448 super.toString(); |
337 } catch(e) { ex = e; } | 449 } catch(e) { ex = e; } |
338 | 450 |
339 assertTrue(ex instanceof TypeError); | 451 assertTrue(ex instanceof TypeError); |
340 } | 452 } |
341 f.toMethod(DerivedFromString.prototype).call(42); | 453 f.toMethod(DerivedFromString.prototype).call(42); |
342 }()); | 454 }()); |
343 | 455 |
344 | 456 |
| 457 (function TestKeyedAccessorsOnPrimitives() { |
| 458 var x = 'x'; |
| 459 var newProperty = 'newProperty'; |
| 460 var toString = 'toString'; |
| 461 var getCalled = 0; |
| 462 var setCalled = 0; |
| 463 function Base() {} |
| 464 Base.prototype = { |
| 465 constructor: Base, |
| 466 get x() { |
| 467 getCalled++; |
| 468 return 1; |
| 469 }, |
| 470 set x(v) { |
| 471 setCalled++; |
| 472 return v; |
| 473 }, |
| 474 }; |
| 475 |
| 476 function Derived() {} |
| 477 Derived.prototype = { |
| 478 __proto__: Base.prototype, |
| 479 constructor: Derived, |
| 480 }; |
| 481 Derived.prototype.testSetter = function() { |
| 482 setCalled = 0; |
| 483 getCalled = 0; |
| 484 assertEquals('object', typeof this); |
| 485 assertTrue(this instanceof Number) |
| 486 assertEquals(42, this.valueOf()); |
| 487 assertEquals(1, super[x]); |
| 488 assertEquals(1, getCalled); |
| 489 assertEquals(0, setCalled); |
| 490 |
| 491 assertEquals(5, super[x] = 5); |
| 492 assertEquals(1, getCalled); |
| 493 assertEquals(1, setCalled); |
| 494 |
| 495 assertEquals(6, super[x] += 5); |
| 496 assertEquals(2, getCalled); |
| 497 assertEquals(2, setCalled); |
| 498 |
| 499 super[newProperty] = 15; |
| 500 assertEquals(15, this[newProperty]); |
| 501 assertEquals(undefined, super[newProperty]); |
| 502 }.toMethod(Derived.prototype); |
| 503 |
| 504 Derived.prototype.testSetterStrict = function() { |
| 505 'use strict'; |
| 506 getCalled = 0; |
| 507 setCalled = 0; |
| 508 assertTrue(42 === this); |
| 509 |
| 510 assertEquals(1, super[x]); |
| 511 assertEquals(1, getCalled); |
| 512 assertEquals(0, setCalled); |
| 513 |
| 514 assertEquals(5, super[x] = 5); |
| 515 assertEquals(1, getCalled); |
| 516 assertEquals(1, setCalled); |
| 517 |
| 518 assertEquals(6, super[x] += 5); |
| 519 assertEquals(2, getCalled); |
| 520 assertEquals(2, setCalled); |
| 521 |
| 522 var ex; |
| 523 try { |
| 524 super[newProperty] = 15; |
| 525 } catch (e) { ex = e; } |
| 526 assertTrue(ex instanceof TypeError); |
| 527 }.toMethod(Derived.prototype); |
| 528 |
| 529 Derived.prototype.testSetter.call(42); |
| 530 Derived.prototype.testSetterStrict.call(42); |
| 531 |
| 532 function DerivedFromString() {} |
| 533 DerivedFromString.prototype = Object.create(String.prototype); |
| 534 |
| 535 function f() { |
| 536 'use strict'; |
| 537 assertTrue(42 === this); |
| 538 assertEquals(String.prototype.toString, super[toString]); |
| 539 var ex; |
| 540 try { |
| 541 super[toString](); |
| 542 } catch(e) { ex = e; } |
| 543 |
| 544 assertTrue(ex instanceof TypeError); |
| 545 } |
| 546 f.toMethod(DerivedFromString.prototype).call(42); |
| 547 }()); |
| 548 |
| 549 |
345 (function TestSetterUndefinedProperties() { | 550 (function TestSetterUndefinedProperties() { |
346 function Base() {} | 551 function Base() {} |
347 function Derived() {} | 552 function Derived() {} |
348 Derived.prototype = { __proto__ : Base.prototype }; | 553 Derived.prototype = { __proto__ : Base.prototype }; |
349 Derived.prototype.mSloppy = function () { | 554 Derived.prototype.mSloppy = function () { |
350 assertEquals(undefined, super.x); | 555 assertEquals(undefined, super.x); |
351 assertEquals(undefined, this.x); | 556 assertEquals(undefined, this.x); |
352 super.x = 10; | 557 super.x = 10; |
353 assertEquals(10, this.x); | 558 assertEquals(10, this.x); |
354 assertEquals(undefined, super.x); | 559 assertEquals(undefined, super.x); |
355 }.toMethod(Derived.prototype); | 560 }.toMethod(Derived.prototype); |
356 | 561 |
357 Derived.prototype.mStrict = function () { | 562 Derived.prototype.mStrict = function () { |
358 'use strict'; | 563 'use strict'; |
359 assertEquals(undefined, super.x); | 564 assertEquals(undefined, super.x); |
360 assertEquals(undefined, this.x); | 565 assertEquals(undefined, this.x); |
361 super.x = 10; | 566 super.x = 10; |
362 assertEquals(10, this.x); | 567 assertEquals(10, this.x); |
363 assertEquals(undefined, super.x); | 568 assertEquals(undefined, super.x); |
364 }.toMethod(Derived.prototype); | 569 }.toMethod(Derived.prototype); |
365 var d = new Derived(); | 570 var d = new Derived(); |
366 d.mSloppy(); | 571 d.mSloppy(); |
367 assertEquals(10, d.x); | 572 assertEquals(10, d.x); |
368 var d1 = new Derived(); | 573 var d1 = new Derived(); |
369 d1.mStrict(); | 574 d1.mStrict(); |
370 assertEquals(10, d.x); | 575 assertEquals(10, d.x); |
371 }()); | 576 }()); |
372 | 577 |
373 | 578 |
| 579 (function TestKeyedSetterUndefinedProperties() { |
| 580 var x = 'x'; |
| 581 function Base() {} |
| 582 function Derived() {} |
| 583 Derived.prototype = { __proto__ : Base.prototype }; |
| 584 Derived.prototype.mSloppy = function () { |
| 585 assertEquals(undefined, super[x]); |
| 586 assertEquals(undefined, this[x]); |
| 587 super[x] = 10; |
| 588 assertEquals(10, this[x]); |
| 589 assertEquals(undefined, super[x]); |
| 590 }.toMethod(Derived.prototype); |
| 591 |
| 592 Derived.prototype.mStrict = function () { |
| 593 'use strict'; |
| 594 assertEquals(undefined, super[x]); |
| 595 assertEquals(undefined, this[x]); |
| 596 super[x] = 10; |
| 597 assertEquals(10, this[x]); |
| 598 assertEquals(undefined, super[x]); |
| 599 }.toMethod(Derived.prototype); |
| 600 var d = new Derived(); |
| 601 d.mSloppy(); |
| 602 assertEquals(10, d.x); |
| 603 var d1 = new Derived(); |
| 604 d1.mStrict(); |
| 605 assertEquals(10, d.x); |
| 606 }()); |
| 607 |
| 608 |
374 (function TestSetterCreatingOwnProperties() { | 609 (function TestSetterCreatingOwnProperties() { |
375 function Base() {} | 610 function Base() {} |
376 function Derived() {} | 611 function Derived() {} |
377 Derived.prototype = { __proto__ : Base.prototype }; | 612 Derived.prototype = { __proto__ : Base.prototype }; |
378 var setterCalled; | 613 var setterCalled; |
379 | 614 |
380 Derived.prototype.mSloppy = function() { | 615 Derived.prototype.mSloppy = function() { |
381 assertEquals(42, this.ownReadOnly); | 616 assertEquals(42, this.ownReadOnly); |
382 super.ownReadOnly = 55; | 617 super.ownReadOnly = 55; |
383 assertEquals(42, this.ownReadOnly); | 618 assertEquals(42, this.ownReadOnly); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 Object.defineProperty(d, 'ownReadOnly', { value : 42, writable : false }); | 653 Object.defineProperty(d, 'ownReadOnly', { value : 42, writable : false }); |
419 Object.defineProperty(d, 'ownSetter', | 654 Object.defineProperty(d, 'ownSetter', |
420 { set : function() { setterCalled++; } }); | 655 { set : function() { setterCalled++; } }); |
421 Object.defineProperty(d, 'ownReadonlyAccessor', | 656 Object.defineProperty(d, 'ownReadonlyAccessor', |
422 { get : function() { return 15; }}); | 657 { get : function() { return 15; }}); |
423 d.mSloppy(); | 658 d.mSloppy(); |
424 d.mStrict(); | 659 d.mStrict(); |
425 }()); | 660 }()); |
426 | 661 |
427 | 662 |
| 663 (function TestKeyedSetterCreatingOwnProperties() { |
| 664 var ownReadOnly = 'ownReadOnly'; |
| 665 var ownReadonlyAccessor = 'ownReadonlyAccessor'; |
| 666 var ownSetter = 'ownSetter'; |
| 667 function Base() {} |
| 668 function Derived() {} |
| 669 Derived.prototype = { __proto__ : Base.prototype }; |
| 670 var setterCalled; |
| 671 |
| 672 Derived.prototype.mSloppy = function() { |
| 673 assertEquals(42, this[ownReadOnly]); |
| 674 super[ownReadOnly] = 55; |
| 675 assertEquals(42, this[ownReadOnly]); |
| 676 |
| 677 assertEquals(15, this[ownReadonlyAccessor]); |
| 678 super[ownReadonlyAccessor] = 55; |
| 679 assertEquals(15, this[ownReadonlyAccessor]); |
| 680 |
| 681 setterCalled = 0; |
| 682 super[ownSetter] = 42; |
| 683 assertEquals(1, setterCalled); |
| 684 }.toMethod(Derived.prototype); |
| 685 |
| 686 Derived.prototype.mStrict = function() { |
| 687 'use strict'; |
| 688 assertEquals(42, this[ownReadOnly]); |
| 689 var ex; |
| 690 try { |
| 691 super[ownReadOnly] = 55; |
| 692 } catch(e) { ex = e; } |
| 693 assertTrue(ex instanceof TypeError); |
| 694 assertEquals(42, this[ownReadOnly]); |
| 695 |
| 696 assertEquals(15, this[ownReadonlyAccessor]); |
| 697 ex = null; |
| 698 try { |
| 699 super[ownReadonlyAccessor] = 55; |
| 700 } catch(e) { ex = e; } |
| 701 assertTrue(ex instanceof TypeError); |
| 702 assertEquals(15, this[ownReadonlyAccessor]); |
| 703 |
| 704 setterCalled = 0; |
| 705 super[ownSetter] = 42; |
| 706 assertEquals(1, setterCalled); |
| 707 }.toMethod(Derived.prototype); |
| 708 |
| 709 var d = new Derived(); |
| 710 Object.defineProperty(d, 'ownReadOnly', { value : 42, writable : false }); |
| 711 Object.defineProperty(d, 'ownSetter', |
| 712 { set : function() { setterCalled++; } }); |
| 713 Object.defineProperty(d, 'ownReadonlyAccessor', |
| 714 { get : function() { return 15; }}); |
| 715 d.mSloppy(); |
| 716 d.mStrict(); |
| 717 }()); |
| 718 |
| 719 |
428 (function TestSetterNoProtoWalk() { | 720 (function TestSetterNoProtoWalk() { |
429 function Base() {} | 721 function Base() {} |
430 function Derived() {} | 722 function Derived() {} |
431 var getCalled; | 723 var getCalled; |
432 var setCalled; | 724 var setCalled; |
433 Derived.prototype = { | 725 Derived.prototype = { |
434 __proto__ : Base.prototype, | 726 __proto__ : Base.prototype, |
435 get x() { getCalled++; return 42; }, | 727 get x() { getCalled++; return 42; }, |
436 set x(v) { setCalled++; } | 728 set x(v) { setCalled++; } |
437 }; | 729 }; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 assertEquals(0, getCalled); | 777 assertEquals(0, getCalled); |
486 assertEquals(0, setCalled); | 778 assertEquals(0, setCalled); |
487 | 779 |
488 }.toMethod(Derived.prototype); | 780 }.toMethod(Derived.prototype); |
489 | 781 |
490 new Derived().mSloppy(); | 782 new Derived().mSloppy(); |
491 new Derived().mStrict(); | 783 new Derived().mStrict(); |
492 }()); | 784 }()); |
493 | 785 |
494 | 786 |
| 787 (function TestKeyedSetterNoProtoWalk() { |
| 788 var x = 'x'; |
| 789 function Base() {} |
| 790 function Derived() {} |
| 791 var getCalled; |
| 792 var setCalled; |
| 793 Derived.prototype = { |
| 794 __proto__ : Base.prototype, |
| 795 get x() { getCalled++; return 42; }, |
| 796 set x(v) { setCalled++; } |
| 797 }; |
| 798 |
| 799 Derived.prototype.mSloppy = function() { |
| 800 setCalled = 0; |
| 801 getCalled = 0; |
| 802 assertEquals(42, this[x]); |
| 803 assertEquals(1, getCalled); |
| 804 assertEquals(0, setCalled); |
| 805 |
| 806 getCalled = 0; |
| 807 setCalled = 0; |
| 808 this[x] = 43; |
| 809 assertEquals(0, getCalled); |
| 810 assertEquals(1, setCalled); |
| 811 |
| 812 getCalled = 0; |
| 813 setCalled = 0; |
| 814 super[x] = 15; |
| 815 assertEquals(0, setCalled); |
| 816 assertEquals(0, getCalled); |
| 817 |
| 818 assertEquals(15, this[x]); |
| 819 assertEquals(0, getCalled); |
| 820 assertEquals(0, setCalled); |
| 821 |
| 822 }.toMethod(Derived.prototype); |
| 823 |
| 824 Derived.prototype.mStrict = function() { |
| 825 'use strict'; |
| 826 setCalled = 0; |
| 827 getCalled = 0; |
| 828 assertEquals(42, this[x]); |
| 829 assertEquals(1, getCalled); |
| 830 assertEquals(0, setCalled); |
| 831 |
| 832 getCalled = 0; |
| 833 setCalled = 0; |
| 834 this[x] = 43; |
| 835 assertEquals(0, getCalled); |
| 836 assertEquals(1, setCalled); |
| 837 |
| 838 getCalled = 0; |
| 839 setCalled = 0; |
| 840 super[x] = 15; |
| 841 assertEquals(0, setCalled); |
| 842 assertEquals(0, getCalled); |
| 843 |
| 844 assertEquals(15, this[x]); |
| 845 assertEquals(0, getCalled); |
| 846 assertEquals(0, setCalled); |
| 847 |
| 848 }.toMethod(Derived.prototype); |
| 849 |
| 850 new Derived().mSloppy(); |
| 851 new Derived().mStrict(); |
| 852 }()); |
| 853 |
| 854 |
495 (function TestSetterDoesNotReconfigure() { | 855 (function TestSetterDoesNotReconfigure() { |
496 function Base() {} | 856 function Base() {} |
497 function Derived() {} | 857 function Derived() {} |
498 | 858 |
499 Derived.prototype.mStrict = function (){ | 859 Derived.prototype.mStrict = function (){ |
500 'use strict'; | 860 'use strict'; |
501 super.nonEnumConfig = 5; | 861 super.nonEnumConfig = 5; |
502 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumConfig'); | 862 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumConfig'); |
503 assertEquals(5, d1.value); | 863 assertEquals(5, d1.value); |
504 assertTrue(d1.configurable); | 864 assertTrue(d1.configurable); |
(...skipping 23 matching lines...) Expand all Loading... |
528 var d = new Derived(); | 888 var d = new Derived(); |
529 Object.defineProperty(d, 'nonEnumConfig', | 889 Object.defineProperty(d, 'nonEnumConfig', |
530 { value : 0, enumerable : false, configurable : true, writable : true }); | 890 { value : 0, enumerable : false, configurable : true, writable : true }); |
531 Object.defineProperty(d, 'nonEnumNonConfig', | 891 Object.defineProperty(d, 'nonEnumNonConfig', |
532 { value : 0, enumerable : false, configurable : false, writable : true }); | 892 { value : 0, enumerable : false, configurable : false, writable : true }); |
533 d.mStrict(); | 893 d.mStrict(); |
534 d.mSloppy(); | 894 d.mSloppy(); |
535 }()); | 895 }()); |
536 | 896 |
537 | 897 |
| 898 (function TestKeyedSetterDoesNotReconfigure() { |
| 899 var nonEnumConfig = 'nonEnumConfig'; |
| 900 var nonEnumNonConfig = 'nonEnumNonConfig'; |
| 901 function Base() {} |
| 902 function Derived() {} |
| 903 |
| 904 Derived.prototype.mStrict = function (){ |
| 905 'use strict'; |
| 906 super[nonEnumConfig] = 5; |
| 907 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumConfig'); |
| 908 assertEquals(5, d1.value); |
| 909 assertTrue(d1.configurable); |
| 910 assertFalse(d1.enumerable); |
| 911 |
| 912 super[nonEnumNonConfig] = 5; |
| 913 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumNonConfig'); |
| 914 assertEquals(5, d1.value); |
| 915 assertFalse(d1.configurable); |
| 916 assertFalse(d1.enumerable); |
| 917 }.toMethod(Derived.prototype); |
| 918 |
| 919 Derived.prototype.mSloppy = function (){ |
| 920 super[nonEnumConfig] = 42; |
| 921 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumConfig'); |
| 922 assertEquals(42, d1.value); |
| 923 assertTrue(d1.configurable); |
| 924 assertFalse(d1.enumerable); |
| 925 |
| 926 super[nonEnumNonConfig] = 42; |
| 927 var d1 = Object.getOwnPropertyDescriptor(this, 'nonEnumNonConfig'); |
| 928 assertEquals(42, d1.value); |
| 929 assertFalse(d1.configurable); |
| 930 assertFalse(d1.enumerable); |
| 931 }.toMethod(Derived.prototype); |
| 932 |
| 933 var d = new Derived(); |
| 934 Object.defineProperty(d, 'nonEnumConfig', |
| 935 { value : 0, enumerable : false, configurable : true, writable : true }); |
| 936 Object.defineProperty(d, 'nonEnumNonConfig', |
| 937 { value : 0, enumerable : false, configurable : false, writable : true }); |
| 938 d.mStrict(); |
| 939 d.mSloppy(); |
| 940 }()); |
| 941 |
| 942 |
538 (function TestCountOperations() { | 943 (function TestCountOperations() { |
539 function Base() {} | 944 function Base() {} |
540 Base.prototype = { | 945 Base.prototype = { |
541 constructor: Base, | 946 constructor: Base, |
542 get x() { | 947 get x() { |
543 return this._x; | 948 return this._x; |
544 }, | 949 }, |
545 set x(v) { | 950 set x(v) { |
546 this._x = v; | 951 this._x = v; |
547 }, | 952 }, |
(...skipping 28 matching lines...) Expand all Loading... |
576 assertEquals(4, super.x--); | 981 assertEquals(4, super.x--); |
577 assertEquals(3, super.x); | 982 assertEquals(3, super.x); |
578 assertEquals(2, --super.x); | 983 assertEquals(2, --super.x); |
579 assertEquals(2, super.x); | 984 assertEquals(2, super.x); |
580 assertEquals(2, this._x); | 985 assertEquals(2, this._x); |
581 }.toMethod(Derived.prototype); | 986 }.toMethod(Derived.prototype); |
582 new Derived().testCounts(); | 987 new Derived().testCounts(); |
583 }()); | 988 }()); |
584 | 989 |
585 | 990 |
| 991 (function TestKeyedCountOperations() { |
| 992 var x = 'x'; |
| 993 function Base() {} |
| 994 Base.prototype = { |
| 995 constructor: Base, |
| 996 get x() { |
| 997 return this._x; |
| 998 }, |
| 999 set x(v) { |
| 1000 this._x = v; |
| 1001 }, |
| 1002 _x: 1 |
| 1003 }; |
| 1004 |
| 1005 function Derived() {} |
| 1006 Derived.__proto__ = Base; |
| 1007 Derived.prototype = { |
| 1008 __proto__: Base.prototype, |
| 1009 constructor: Derived, |
| 1010 _x: 2 |
| 1011 }; |
| 1012 |
| 1013 Derived.prototype.testCounts = function() { |
| 1014 assertEquals(2, this._x); |
| 1015 assertEquals(2, super[x]); |
| 1016 super[x]++; |
| 1017 assertEquals(3, super[x]); |
| 1018 ++super[x]; |
| 1019 assertEquals(4, super[x]); |
| 1020 assertEquals(4, super[x]++); |
| 1021 assertEquals(5, super[x]); |
| 1022 assertEquals(6, ++super[x]); |
| 1023 assertEquals(6, super[x]); |
| 1024 assertEquals(6, this._x); |
| 1025 |
| 1026 super[x]--; |
| 1027 assertEquals(5, super[x]); |
| 1028 --super[x]; |
| 1029 assertEquals(4, super[x]); |
| 1030 assertEquals(4, super[x]--); |
| 1031 assertEquals(3, super[x]); |
| 1032 assertEquals(2, --super[x]); |
| 1033 assertEquals(2, super[x]); |
| 1034 assertEquals(2, this._x); |
| 1035 }.toMethod(Derived.prototype); |
| 1036 new Derived().testCounts(); |
| 1037 }()); |
| 1038 |
| 1039 |
586 (function TestSuperCall() { | 1040 (function TestSuperCall() { |
587 function Subclass(base, constructor) { | 1041 function Subclass(base, constructor) { |
588 var homeObject = { __proto__ : base.prototype }; | 1042 var homeObject = { __proto__ : base.prototype }; |
589 var result = constructor.toMethod(homeObject); | 1043 var result = constructor.toMethod(homeObject); |
590 homeObject.constructor = result; | 1044 homeObject.constructor = result; |
591 result.prototype = homeObject; | 1045 result.prototype = homeObject; |
592 return result; | 1046 return result; |
593 } | 1047 } |
594 | 1048 |
595 var baseCalled = 0; | 1049 var baseCalled = 0; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 }()); | 1095 }()); |
642 | 1096 |
643 | 1097 |
644 (function TestUnsupportedCases() { | 1098 (function TestUnsupportedCases() { |
645 function f1(x) { return super[x]; } | 1099 function f1(x) { return super[x]; } |
646 function f2(x) { super[x] = 5; } | 1100 function f2(x) { super[x] = 5; } |
647 var o = {}; | 1101 var o = {}; |
648 assertThrows(function(){f1.toMethod(o)(15);}, ReferenceError); | 1102 assertThrows(function(){f1.toMethod(o)(15);}, ReferenceError); |
649 assertThrows(function(){f2.toMethod(o)(15);}, ReferenceError); | 1103 assertThrows(function(){f2.toMethod(o)(15);}, ReferenceError); |
650 }()); | 1104 }()); |
OLD | NEW |