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 | 5 // Flags: --harmony |
6 | 6 |
7 (function TestBasics() { | 7 (function TestBasics() { |
8 var C = class C {} | 8 var C = class C {} |
9 assertEquals(typeof C, 'function'); | 9 assertEquals(typeof C, 'function'); |
10 assertEquals(C.__proto__, Function.prototype); | 10 assertEquals(C.__proto__, Function.prototype); |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 set: function() { | 432 set: function() { |
433 assertUnreachable(); | 433 assertUnreachable(); |
434 } | 434 } |
435 }); | 435 }); |
436 assertThrows(function() { | 436 assertThrows(function() { |
437 class C extends Base {} | 437 class C extends Base {} |
438 }, TypeError); | 438 }, TypeError); |
439 })(); | 439 })(); |
440 | 440 |
441 | 441 |
| 442 (function TestSuperInMethods() { |
| 443 class B { |
| 444 method() { |
| 445 return 1; |
| 446 } |
| 447 get x() { |
| 448 return 2; |
| 449 } |
| 450 } |
| 451 class C extends B { |
| 452 method() { |
| 453 assertEquals(2, super.x); |
| 454 return super.method(); |
| 455 } |
| 456 } |
| 457 assertEquals(1, new C().method()); |
| 458 })(); |
| 459 |
| 460 |
| 461 (function TestSuperInGetter() { |
| 462 class B { |
| 463 method() { |
| 464 return 1; |
| 465 } |
| 466 get x() { |
| 467 return 2; |
| 468 } |
| 469 } |
| 470 class C extends B { |
| 471 get y() { |
| 472 assertEquals(2, super.x); |
| 473 return super.method(); |
| 474 } |
| 475 } |
| 476 assertEquals(1, new C().y); |
| 477 })(); |
| 478 |
| 479 |
| 480 (function TestSuperInSetter() { |
| 481 class B { |
| 482 method() { |
| 483 return 1; |
| 484 } |
| 485 get x() { |
| 486 return 2; |
| 487 } |
| 488 } |
| 489 class C extends B { |
| 490 set y(v) { |
| 491 assertEquals(3, v); |
| 492 assertEquals(2, super.x); |
| 493 assertEquals(1, super.method()); |
| 494 } |
| 495 } |
| 496 assertEquals(3, new C().y = 3); |
| 497 })(); |
| 498 |
| 499 |
| 500 (function TestSuperInStaticMethods() { |
| 501 class B { |
| 502 static method() { |
| 503 return 1; |
| 504 } |
| 505 static get x() { |
| 506 return 2; |
| 507 } |
| 508 } |
| 509 class C extends B { |
| 510 static method() { |
| 511 assertEquals(2, super.x); |
| 512 return super.method(); |
| 513 } |
| 514 } |
| 515 assertEquals(1, C.method()); |
| 516 })(); |
| 517 |
| 518 |
| 519 (function TestSuperInStaticGetter() { |
| 520 class B { |
| 521 static method() { |
| 522 return 1; |
| 523 } |
| 524 static get x() { |
| 525 return 2; |
| 526 } |
| 527 } |
| 528 class C extends B { |
| 529 static get x() { |
| 530 assertEquals(2, super.x); |
| 531 return super.method(); |
| 532 } |
| 533 } |
| 534 assertEquals(1, C.x); |
| 535 })(); |
| 536 |
| 537 |
| 538 (function TestSuperInStaticSetter() { |
| 539 class B { |
| 540 static method() { |
| 541 return 1; |
| 542 } |
| 543 static get x() { |
| 544 return 2; |
| 545 } |
| 546 } |
| 547 class C extends B { |
| 548 static set x(v) { |
| 549 assertEquals(3, v); |
| 550 assertEquals(2, super.x); |
| 551 assertEquals(1, super.method()); |
| 552 } |
| 553 } |
| 554 assertEquals(3, C.x = 3); |
| 555 })(); |
| 556 |
| 557 |
| 558 (function TestNumericPropertyNames() { |
| 559 class B { |
| 560 1() { return 1; } |
| 561 get 2() { return 2; } |
| 562 set 3(_) {} |
| 563 |
| 564 static 4() { return 4; } |
| 565 static get 5() { return 5; } |
| 566 static set 6(_) {} |
| 567 } |
| 568 |
| 569 assertMethodDescriptor(B.prototype, '1'); |
| 570 assertGetterDescriptor(B.prototype, '2'); |
| 571 assertSetterDescriptor(B.prototype, '3'); |
| 572 |
| 573 assertMethodDescriptor(B, '4'); |
| 574 assertGetterDescriptor(B, '5'); |
| 575 assertSetterDescriptor(B, '6'); |
| 576 |
| 577 class C extends B { |
| 578 1() { return super[1](); } |
| 579 get 2() { return super[2]; } |
| 580 |
| 581 static 4() { return super[4](); } |
| 582 static get 5() { return super[5]; } |
| 583 } |
| 584 |
| 585 assertEquals(1, new C()[1]()); |
| 586 assertEquals(2, new C()[2]); |
| 587 assertEquals(4, C[4]()); |
| 588 assertEquals(5, C[5]); |
| 589 })(); |
| 590 |
| 591 |
442 /* TODO(arv): Implement | 592 /* TODO(arv): Implement |
443 (function TestNameBindingInConstructor() { | 593 (function TestNameBindingInConstructor() { |
444 class C { | 594 class C { |
445 constructor() { | 595 constructor() { |
446 assertThrows(function() { | 596 assertThrows(function() { |
447 C = 42; | 597 C = 42; |
448 }, ReferenceError); | 598 }, ReferenceError); |
449 } | 599 } |
450 } | 600 } |
451 new C(); | 601 new C(); |
452 })(); | 602 })(); |
453 */ | 603 */ |
OLD | NEW |