Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 5560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5571 }; | 5571 }; |
| 5572 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags, | 5572 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, always_flags, |
| 5573 arraysize(always_flags)); | 5573 arraysize(always_flags)); |
| 5574 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, | 5574 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, |
| 5575 arraysize(always_flags)); | 5575 arraysize(always_flags)); |
| 5576 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, | 5576 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, |
| 5577 arraysize(always_flags)); | 5577 arraysize(always_flags)); |
| 5578 } | 5578 } |
| 5579 | 5579 |
| 5580 | 5580 |
| 5581 TEST(StrongSuperCalls) { | 5581 TEST(StrongConstructorThis) { |
| 5582 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}}; | 5582 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}}; |
| 5583 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}}; | 5583 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}}; |
| 5584 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}}; | 5584 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}}; |
| 5585 | 5585 |
| 5586 const char* data[] = { | 5586 const char* error_data[] = { |
| 5587 "class C extends Object { constructor() {} }", | 5587 "class C { constructor() { this; } }", |
| 5588 "class C extends Object { constructor() { (super()); } }", | 5588 "class C { constructor() { this.a; } }", |
| 5589 "class C extends Object { constructor() { (() => super())(); } }", | 5589 "class C { constructor() { this['a']; } }", |
| 5590 "class C extends Object { constructor() { { super(); } } }", | 5590 "class C { constructor() { (this); } }", |
| 5591 "class C extends Object { constructor() { if (1) super(); } }", | 5591 "class C { constructor() { this(); } }", |
| 5592 "class C extends Object { constructor() { super(), super(); } }", | 5592 // TODO(rossberg): arrow functions not handled yet. |
| 5593 "class C extends Object { constructor() { super(); super(); } }", | 5593 // "class C { constructor() { () => this; } }", |
| 5594 "class C extends Object { constructor() { super(); (super()); } }", | 5594 "class C { constructor() { this.a = 0, 0; } }", |
| 5595 "class C extends Object { constructor() { super(); { super() } } }", | 5595 "class C { constructor() { (this.a = 0); } }", |
| 5596 // "class C { constructor() { (() => this.a = 0)(); } }", | |
| 5597 "class C { constructor() { { this.a = 0; } } }", | |
| 5598 "class C { constructor() { if (1) this.a = 0; } }", | |
| 5599 "class C { constructor() { label: this.a = 0; } }", | |
| 5600 NULL}; | |
|
marja
2015/04/21 09:01:37
These cases would be relevant to add:
this.a = th
rossberg
2015/04/21 09:47:47
Done.
| |
| 5601 | |
| 5602 const char* success_data[] = { | |
| 5603 "class C { constructor() { this.a = 0; } }", | |
| 5604 "class C { constructor() { label: 0; this.a = 0; this.b = 6; } }", | |
| 5596 NULL}; | 5605 NULL}; |
| 5597 | 5606 |
| 5598 static const ParserFlag always_flags[] = { | 5607 static const ParserFlag always_flags[] = { |
| 5599 kAllowStrongMode, kAllowHarmonyClasses, kAllowHarmonyObjectLiterals, | 5608 kAllowStrongMode, kAllowHarmonyClasses, kAllowHarmonyObjectLiterals, |
| 5600 kAllowHarmonyArrowFunctions | 5609 kAllowHarmonyArrowFunctions |
| 5601 }; | 5610 }; |
| 5602 RunParserSyncTest(sloppy_context_data, data, kError, NULL, 0, always_flags, | 5611 RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0, |
| 5603 arraysize(always_flags)); | 5612 always_flags, arraysize(always_flags)); |
| 5604 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, | 5613 RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0, |
| 5605 arraysize(always_flags)); | 5614 always_flags, arraysize(always_flags)); |
| 5606 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, | 5615 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0, |
| 5607 arraysize(always_flags)); | 5616 always_flags, arraysize(always_flags)); |
| 5617 | |
| 5618 RunParserSyncTest(sloppy_context_data, success_data, kError, NULL, 0, | |
| 5619 always_flags, arraysize(always_flags)); | |
| 5620 RunParserSyncTest(strict_context_data, success_data, kSuccess, NULL, 0, | |
| 5621 always_flags, arraysize(always_flags)); | |
| 5622 RunParserSyncTest(strong_context_data, success_data, kSuccess, NULL, 0, | |
| 5623 always_flags, arraysize(always_flags)); | |
| 5608 } | 5624 } |
| 5609 | 5625 |
| 5610 | 5626 |
| 5627 TEST(StrongConstructorSuper) { | |
| 5628 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}}; | |
| 5629 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}}; | |
| 5630 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}}; | |
| 5631 | |
| 5632 const char* error_data[] = { | |
| 5633 "class C extends Object { constructor() {} }", | |
| 5634 "class C extends Object { constructor() { super.a; } }", | |
| 5635 "class C extends Object { constructor() { super['a']; } }", | |
| 5636 "class C extends Object { constructor() { super.a = 0; } }", | |
| 5637 "class C extends Object { constructor() { (super.a); } }", | |
| 5638 // TODO(rossberg): arrow functions do not handle super yet. | |
| 5639 // "class C extends Object { constructor() { () => super.a; } }", | |
| 5640 "class C extends Object { constructor() { super(), 0; } }", | |
| 5641 "class C extends Object { constructor() { (super()); } }", | |
| 5642 // "class C extends Object { constructor() { (() => super())(); } }", | |
| 5643 "class C extends Object { constructor() { { super(); } } }", | |
| 5644 "class C extends Object { constructor() { if (1) super(); } }", | |
| 5645 "class C extends Object { constructor() { label: super(); } }", | |
| 5646 "class C extends Object { constructor() { super(), super(); } }", | |
| 5647 "class C extends Object { constructor() { super(); super(); } }", | |
|
marja
2015/04/21 09:01:37
Nit: these 2 lines are the same.
rossberg
2015/04/21 09:47:47
No, "," vs ";" ;)
| |
| 5648 "class C extends Object { constructor() { super(); (super()); } }", | |
| 5649 "class C extends Object { constructor() { super(); { super() } } }", | |
| 5650 "class C extends Object { constructor() { this.a = 0, super(); } }", | |
| 5651 "class C extends Object { constructor() { this.a = 0; super(); } }", | |
| 5652 "class C extends Object { constructor() { super(this.a = 0); } }", | |
|
marja
2015/04/21 09:01:37
How about
super().foo; ?
rossberg
2015/04/21 09:47:47
Done.
| |
| 5653 NULL}; | |
| 5654 | |
| 5655 const char* success_data[] = { | |
| 5656 "class C extends Object { constructor() { super(); } }", | |
| 5657 "class C extends Object { constructor() { l: 66; super(); } }", | |
|
marja
2015/04/21 09:01:37
Hmm, why is label: super(); forbidden but label: 6
rossberg
2015/04/21 09:47:47
Because the former nests the super call into a lab
| |
| 5658 "class C extends Object { constructor() { super(3); this.x = 0; } }", | |
| 5659 "class C extends Object { constructor() { 3; super(3); this.x = 0; } }", | |
| 5660 NULL}; | |
| 5661 | |
| 5662 static const ParserFlag always_flags[] = { | |
| 5663 kAllowStrongMode, kAllowHarmonyClasses, kAllowHarmonyObjectLiterals, | |
| 5664 kAllowHarmonyArrowFunctions | |
| 5665 }; | |
| 5666 RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0, | |
| 5667 always_flags, arraysize(always_flags)); | |
| 5668 RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0, | |
| 5669 always_flags, arraysize(always_flags)); | |
| 5670 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0, | |
| 5671 always_flags, arraysize(always_flags)); | |
| 5672 | |
| 5673 RunParserSyncTest(sloppy_context_data, success_data, kError, NULL, 0, | |
| 5674 always_flags, arraysize(always_flags)); | |
| 5675 RunParserSyncTest(strict_context_data, success_data, kSuccess, NULL, 0, | |
| 5676 always_flags, arraysize(always_flags)); | |
| 5677 RunParserSyncTest(strong_context_data, success_data, kSuccess, NULL, 0, | |
| 5678 always_flags, arraysize(always_flags)); | |
| 5679 } | |
| 5680 | |
| 5681 | |
| 5611 TEST(StrongConstructorReturns) { | 5682 TEST(StrongConstructorReturns) { |
| 5612 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}}; | 5683 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}}; |
| 5613 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}}; | 5684 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}}; |
| 5614 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}}; | 5685 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}}; |
| 5615 | 5686 |
| 5616 const char* data[] = { | 5687 const char* error_data[] = { |
| 5617 "class C extends Object { constructor() { super(); return {}; } }", | 5688 "class C extends Object { constructor() { super(); return {}; } }", |
| 5618 "class C extends Object { constructor() { super(); { return {}; } } }", | 5689 "class C extends Object { constructor() { super(); { return {}; } } }", |
| 5619 "class C extends Object { constructor() { super(); if (1) return {}; } }", | 5690 "class C extends Object { constructor() { super(); if (1) return {}; } }", |
| 5620 "class C extends Object { constructor() { return; super(); } }", | 5691 "class C extends Object { constructor() { return; super(); } }", |
| 5621 "class C extends Object { constructor() { { return; } super(); } }", | 5692 "class C extends Object { constructor() { { return; } super(); } }", |
| 5622 "class C extends Object { constructor() { if (0) return; super(); } }", | 5693 "class C extends Object { constructor() { if (0) return; super(); } }", |
| 5694 "class C { constructor() { return; this.a = 0; } }", | |
| 5695 "class C { constructor() { { return; } this.a = 0; } }", | |
| 5696 "class C { constructor() { if (0) return; this.a = 0; } }", | |
| 5697 "class C { constructor() { this.a = 0; if (0) return; this.b = 0; } }", | |
| 5698 NULL}; | |
| 5699 | |
| 5700 const char* success_data[] = { | |
| 5701 "class C extends Object { constructor() { super(); return; } }", | |
| 5702 "class C extends Object { constructor() { super(); { return } } }", | |
| 5703 "class C extends Object { constructor() { super(); if (1) return; } }", | |
| 5704 "class C { constructor() { this.a = 0; return; } }", | |
| 5705 "class C { constructor() { this.a = 0; { return; } } }", | |
| 5706 "class C { constructor() { this.a = 0; if (0) return; 65; } }", | |
| 5707 "class C extends Array { constructor() { super(); this.a = 9; return } }", | |
| 5623 NULL}; | 5708 NULL}; |
| 5624 | 5709 |
| 5625 static const ParserFlag always_flags[] = { | 5710 static const ParserFlag always_flags[] = { |
| 5626 kAllowStrongMode, kAllowHarmonyClasses, kAllowHarmonyObjectLiterals | 5711 kAllowStrongMode, kAllowHarmonyClasses, kAllowHarmonyObjectLiterals |
| 5627 }; | 5712 }; |
| 5628 RunParserSyncTest(sloppy_context_data, data, kError, NULL, 0, always_flags, | 5713 RunParserSyncTest(sloppy_context_data, error_data, kError, NULL, 0, |
| 5629 arraysize(always_flags)); | 5714 always_flags, arraysize(always_flags)); |
| 5630 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, | 5715 RunParserSyncTest(strict_context_data, error_data, kSuccess, NULL, 0, |
| 5631 arraysize(always_flags)); | 5716 always_flags, arraysize(always_flags)); |
| 5632 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, | 5717 RunParserSyncTest(strong_context_data, error_data, kError, NULL, 0, |
| 5633 arraysize(always_flags)); | 5718 always_flags, arraysize(always_flags)); |
| 5719 | |
| 5720 RunParserSyncTest(sloppy_context_data, success_data, kError, NULL, 0, | |
| 5721 always_flags, arraysize(always_flags)); | |
| 5722 RunParserSyncTest(strict_context_data, success_data, kSuccess, NULL, 0, | |
| 5723 always_flags, arraysize(always_flags)); | |
| 5724 RunParserSyncTest(strong_context_data, success_data, kSuccess, NULL, 0, | |
| 5725 always_flags, arraysize(always_flags)); | |
| 5634 } | 5726 } |
| 5635 | 5727 |
| 5636 | 5728 |
| 5637 TEST(ArrowFunctionASIErrors) { | 5729 TEST(ArrowFunctionASIErrors) { |
| 5638 const char* context_data[][2] = {{"'use strict';", ""}, {"", ""}, | 5730 const char* context_data[][2] = {{"'use strict';", ""}, {"", ""}, |
| 5639 {NULL, NULL}}; | 5731 {NULL, NULL}}; |
| 5640 | 5732 |
| 5641 const char* data[] = { | 5733 const char* data[] = { |
| 5642 "(a\n=> a)(1)", | 5734 "(a\n=> a)(1)", |
| 5643 "(a/*\n*/=> a)(1)", | 5735 "(a/*\n*/=> a)(1)", |
| 5644 "((a)\n=> a)(1)", | 5736 "((a)\n=> a)(1)", |
| 5645 "((a)/*\n*/=> a)(1)", | 5737 "((a)/*\n*/=> a)(1)", |
| 5646 "((a, b)\n=> a + b)(1, 2)", | 5738 "((a, b)\n=> a + b)(1, 2)", |
| 5647 "((a, b)/*\n*/=> a + b)(1, 2)", | 5739 "((a, b)/*\n*/=> a + b)(1, 2)", |
| 5648 NULL}; | 5740 NULL}; |
| 5649 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions}; | 5741 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions}; |
| 5650 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | 5742 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
| 5651 arraysize(always_flags)); | 5743 arraysize(always_flags)); |
| 5652 } | 5744 } |
| OLD | NEW |