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

Side by Side Diff: test/cctest/test-parsing.cc

Issue 1024063002: [strong] checking of this & super in constructors (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Typo Created 5 years, 9 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
« no previous file with comments | « src/preparser.cc ('k') | test/mjsunit/strong/classes.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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}};
5583 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}};
5584 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}};
5585
5586 const char* data[] = {
5587 "class C extends Object { constructor() { this; } }",
5588 "class C extends Object { constructor() { this.a; } }",
5589 "class C extends Object { constructor() { this['a']; } }",
5590 "class C extends Object { constructor() { this.a = 0; } }",
5591 "class C extends Object { constructor() { (this); } }",
marja 2015/03/23 10:20:07 I'm not sure if this test is testing what it looks
rossberg 2015/04/20 17:21:11 Oops, yes, this test wasn't supposed to test missi
5592 "class C extends Object { constructor() { this(); } }",
5593 // TODO(rossberg): arrow functions not handled yet.
5594 // "class C extends Object { constructor() { () => this; } }",
5595 "class C extends Object { constructor() { this.a = 0, 0; } }",
5596 "class C extends Object { constructor() { (this.a = 0); } }",
5597 // "class C extends Object { constructor() { (() => this.a = 0)(); } }",
5598 "class C extends Object { constructor() { { this.a = 0; } } }",
5599 "class C extends Object { constructor() { if (1) this.a = 0; } }",
5600 "class C extends Object { constructor() { label: this.a = 0; } }",
5601 NULL};
5602
5603 static const ParserFlag always_flags[] = {
5604 kAllowStrongMode, kAllowHarmonyClasses, kAllowHarmonyObjectLiterals,
5605 kAllowHarmonyArrowFunctions
5606 };
5607 RunParserSyncTest(sloppy_context_data, data, kError, NULL, 0, always_flags,
5608 arraysize(always_flags));
5609 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags,
5610 arraysize(always_flags));
5611 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags,
5612 arraysize(always_flags));
5613 }
5614
5615
5616 TEST(StrongConstructorSuper) {
5582 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}}; 5617 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}};
5583 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}}; 5618 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}};
5584 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}}; 5619 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}};
5585 5620
5586 const char* data[] = { 5621 const char* data[] = {
5587 "class C extends Object { constructor() {} }", 5622 "class C extends Object { constructor() {} }",
5623 "class C extends Object { constructor() { super.a; } }",
5624 "class C extends Object { constructor() { super['a']; } }",
5625 "class C extends Object { constructor() { super.a = 0; } }",
5626 "class C extends Object { constructor() { (super.a); } }",
5627 // TODO(rossberg): arrow functions do not handle super yet.
5628 // "class C extends Object { constructor() { () => super.a; } }",
5629 "class C extends Object { constructor() { super(), 0; } }",
5588 "class C extends Object { constructor() { (super()); } }", 5630 "class C extends Object { constructor() { (super()); } }",
5589 "class C extends Object { constructor() { (() => super())(); } }", 5631 // "class C extends Object { constructor() { (() => super())(); } }",
5590 "class C extends Object { constructor() { { super(); } } }", 5632 "class C extends Object { constructor() { { super(); } } }",
5591 "class C extends Object { constructor() { if (1) super(); } }", 5633 "class C extends Object { constructor() { if (1) super(); } }",
5634 "class C extends Object { constructor() { label: super(); } }",
5592 "class C extends Object { constructor() { super(), super(); } }", 5635 "class C extends Object { constructor() { super(), super(); } }",
5593 "class C extends Object { constructor() { super(); super(); } }", 5636 "class C extends Object { constructor() { super(); super(); } }",
5594 "class C extends Object { constructor() { super(); (super()); } }", 5637 "class C extends Object { constructor() { super(); (super()); } }",
5595 "class C extends Object { constructor() { super(); { super() } } }", 5638 "class C extends Object { constructor() { super(); { super() } } }",
5639 "class C extends Object { constructor() { this.a = 0, super(); } }",
5640 "class C extends Object { constructor() { this.a = 0; super(); } }",
5641 "class C extends Object { constructor() { super(this.a = 0); } }",
5596 NULL}; 5642 NULL};
5597 5643
5598 static const ParserFlag always_flags[] = { 5644 static const ParserFlag always_flags[] = {
5599 kAllowStrongMode, kAllowHarmonyClasses, kAllowHarmonyObjectLiterals, 5645 kAllowStrongMode, kAllowHarmonyClasses, kAllowHarmonyObjectLiterals,
5600 kAllowHarmonyArrowFunctions 5646 kAllowHarmonyArrowFunctions
5601 }; 5647 };
5602 RunParserSyncTest(sloppy_context_data, data, kError, NULL, 0, always_flags, 5648 RunParserSyncTest(sloppy_context_data, data, kError, NULL, 0, always_flags,
5603 arraysize(always_flags)); 5649 arraysize(always_flags));
5604 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, 5650 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags,
5605 arraysize(always_flags)); 5651 arraysize(always_flags));
5606 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, 5652 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags,
5607 arraysize(always_flags)); 5653 arraysize(always_flags));
5608 } 5654 }
5609 5655
5610 5656
5611 TEST(StrongConstructorReturns) { 5657 TEST(StrongConstructorReturns) {
5612 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}}; 5658 const char* sloppy_context_data[][2] = {{"", ""}, {NULL}};
5613 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}}; 5659 const char* strict_context_data[][2] = {{"'use strict';", ""}, {NULL}};
5614 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}}; 5660 const char* strong_context_data[][2] = {{"'use strong';", ""}, {NULL}};
5615 5661
5616 const char* data[] = { 5662 const char* data[] = {
5617 "class C extends Object { constructor() { super(); return {}; } }", 5663 "class C extends Object { constructor() { super(); return {}; } }",
5618 "class C extends Object { constructor() { super(); { return {}; } } }", 5664 "class C extends Object { constructor() { super(); { return {}; } } }",
5619 "class C extends Object { constructor() { super(); if (1) return {}; } }", 5665 "class C extends Object { constructor() { super(); if (1) return {}; } }",
5620 "class C extends Object { constructor() { return; super(); } }", 5666 "class C extends Object { constructor() { return; super(); } }",
5621 "class C extends Object { constructor() { { return; } super(); } }", 5667 "class C extends Object { constructor() { { return; } super(); } }",
5622 "class C extends Object { constructor() { if (0) return; super(); } }", 5668 "class C extends Object { constructor() { if (0) return; super(); } }",
5669 "class C extends Object { constructor() { return; this.a = 0; } }",
5670 "class C extends Object { constructor() { { return; } this.a = 0; } }",
5671 "class C extends Object { constructor() { if (0) return; this.a = 0; } }",
5623 NULL}; 5672 NULL};
5624 5673
5625 static const ParserFlag always_flags[] = { 5674 static const ParserFlag always_flags[] = {
5626 kAllowStrongMode, kAllowHarmonyClasses, kAllowHarmonyObjectLiterals 5675 kAllowStrongMode, kAllowHarmonyClasses, kAllowHarmonyObjectLiterals
5627 }; 5676 };
5628 RunParserSyncTest(sloppy_context_data, data, kError, NULL, 0, always_flags, 5677 RunParserSyncTest(sloppy_context_data, data, kError, NULL, 0, always_flags,
5629 arraysize(always_flags)); 5678 arraysize(always_flags));
5630 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags, 5679 RunParserSyncTest(strict_context_data, data, kSuccess, NULL, 0, always_flags,
5631 arraysize(always_flags)); 5680 arraysize(always_flags));
5632 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags, 5681 RunParserSyncTest(strong_context_data, data, kError, NULL, 0, always_flags,
(...skipping 10 matching lines...) Expand all
5643 "(a/*\n*/=> a)(1)", 5692 "(a/*\n*/=> a)(1)",
5644 "((a)\n=> a)(1)", 5693 "((a)\n=> a)(1)",
5645 "((a)/*\n*/=> a)(1)", 5694 "((a)/*\n*/=> a)(1)",
5646 "((a, b)\n=> a + b)(1, 2)", 5695 "((a, b)\n=> a + b)(1, 2)",
5647 "((a, b)/*\n*/=> a + b)(1, 2)", 5696 "((a, b)/*\n*/=> a + b)(1, 2)",
5648 NULL}; 5697 NULL};
5649 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions}; 5698 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions};
5650 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 5699 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
5651 arraysize(always_flags)); 5700 arraysize(always_flags));
5652 } 5701 }
OLDNEW
« no previous file with comments | « src/preparser.cc ('k') | test/mjsunit/strong/classes.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698