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

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

Issue 1602013007: Fix handling of escaped "let" and "static" tokens (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 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/parsing/scanner.cc ('k') | no next file » | 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 4408 matching lines...) Expand 10 before | Expand all | Expand 10 after
4419 "class name extends (F, G) {}", 4419 "class name extends (F, G) {}",
4420 "class name extends class {} {}", 4420 "class name extends class {} {}",
4421 "class name extends class base {} {}", 4421 "class name extends class base {} {}",
4422 NULL}; 4422 NULL};
4423 4423
4424 RunParserSyncTest(context_data, statement_data, kSuccess); 4424 RunParserSyncTest(context_data, statement_data, kSuccess);
4425 } 4425 }
4426 4426
4427 4427
4428 TEST(ClassBodyNoErrors) { 4428 TEST(ClassBodyNoErrors) {
4429 // clang-format off
4429 // Tests that parser and preparser accept valid class syntax. 4430 // Tests that parser and preparser accept valid class syntax.
4430 const char* context_data[][2] = {{"(class {", "});"}, 4431 const char* context_data[][2] = {{"(class {", "});"},
4431 {"(class extends Base {", "});"}, 4432 {"(class extends Base {", "});"},
4432 {"class C {", "}"}, 4433 {"class C {", "}"},
4433 {"class C extends Base {", "}"}, 4434 {"class C extends Base {", "}"},
4434 {NULL, NULL}}; 4435 {NULL, NULL}};
4435 const char* class_body_data[] = { 4436 const char* class_body_data[] = {
4436 ";", 4437 ";",
4437 ";;", 4438 ";;",
4438 "m() {}", 4439 "m() {}",
4439 "m() {};", 4440 "m() {};",
4440 "; m() {}", 4441 "; m() {}",
4441 "m() {}; n(x) {}", 4442 "m() {}; n(x) {}",
4442 "get x() {}", 4443 "get x() {}",
4443 "set x(v) {}", 4444 "set x(v) {}",
4444 "get() {}", 4445 "get() {}",
4445 "set() {}", 4446 "set() {}",
4446 "*g() {}", 4447 "*g() {}",
4447 "*g() {};", 4448 "*g() {};",
4448 "; *g() {}", 4449 "; *g() {}",
4449 "*g() {}; *h(x) {}", 4450 "*g() {}; *h(x) {}",
4450 "static() {}", 4451 "static() {}",
4452 "get static() {}",
4453 "set static(v) {}",
4451 "static m() {}", 4454 "static m() {}",
4452 "static get x() {}", 4455 "static get x() {}",
4453 "static set x(v) {}", 4456 "static set x(v) {}",
4454 "static get() {}", 4457 "static get() {}",
4455 "static set() {}", 4458 "static set() {}",
4456 "static static() {}", 4459 "static static() {}",
4457 "static get static() {}", 4460 "static get static() {}",
4458 "static set static(v) {}", 4461 "static set static(v) {}",
4459 "*static() {}", 4462 "*static() {}",
4463 "static *static() {}",
4460 "*get() {}", 4464 "*get() {}",
4461 "*set() {}", 4465 "*set() {}",
4462 "static *g() {}", 4466 "static *g() {}",
4467
4468 // Escaped 'static' should be allowed anywhere
caitp (gmail) 2016/01/19 21:17:03 missing a `st\u{61}tic foo() {}` error case, since
adamk 2016/01/19 21:21:34 That's already tested down in EscapedKeywords.
4469 // static-as-PropertyName is.
4470 "st\\u0061tic() {}",
4471 "get st\\u0061tic() {}",
4472 "set st\\u0061tic(v) {}",
4473 "static st\\u0061tic() {}",
4474 "static get st\\u0061tic() {}",
4475 "static set st\\u0061tic(v) {}",
4476 "*st\\u0061tic() {}",
4477 "static *st\\u0061tic() {}",
4463 NULL}; 4478 NULL};
4479 // clang-format on
4464 4480
4465 static const ParserFlag always_flags[] = { 4481 static const ParserFlag always_flags[] = {
4466 kAllowHarmonySloppy 4482 kAllowHarmonySloppy
4467 }; 4483 };
4468 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0, 4484 RunParserSyncTest(context_data, class_body_data, kSuccess, NULL, 0,
4469 always_flags, arraysize(always_flags)); 4485 always_flags, arraysize(always_flags));
4470 } 4486 }
4471 4487
4472 4488
4473 TEST(ClassPropertyNameNoErrors) { 4489 TEST(ClassPropertyNameNoErrors) {
(...skipping 3197 matching lines...) Expand 10 before | Expand all | Expand 10 after
7671 "for (const let in {}) {}", 7687 "for (const let in {}) {}",
7672 "for (const let of []) {}", 7688 "for (const let of []) {}",
7673 "let [let] = 1", 7689 "let [let] = 1",
7674 "for (let [let] = 1; let < 1; let++) {}", 7690 "for (let [let] = 1; let < 1; let++) {}",
7675 "for (let [let] in {}) {}", 7691 "for (let [let] in {}) {}",
7676 "for (let [let] of []) {}", 7692 "for (let [let] of []) {}",
7677 "const [let] = 1", 7693 "const [let] = 1",
7678 "for (const [let] = 1; let < 1; let++) {}", 7694 "for (const [let] = 1; let < 1; let++) {}",
7679 "for (const [let] in {}) {}", 7695 "for (const [let] in {}) {}",
7680 "for (const [let] of []) {}", 7696 "for (const [let] of []) {}",
7697
7698 // Sprinkle in the escaped version too.
7699 "let l\\u0065t = 1",
7700 "const l\\u0065t = 1",
7701 "let [l\\u0065t] = 1",
7702 "const [l\\u0065t] = 1",
7703 "for (let l\\u0065t in {}) {}",
7681 NULL 7704 NULL
7682 }; 7705 };
7683 // clang-format on 7706 // clang-format on
7684 7707
7685 static const ParserFlag fail_flags[] = { 7708 static const ParserFlag fail_flags[] = {
7686 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst, 7709 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kNoLegacyConst,
7687 kAllowHarmonyDestructuring}; 7710 kAllowHarmonyDestructuring};
7688 RunParserSyncTest(context_data, fail_data, kError, NULL, 0, fail_flags, 7711 RunParserSyncTest(context_data, fail_data, kError, NULL, 0, fail_flags,
7689 arraysize(fail_flags)); 7712 arraysize(fail_flags));
7690 } 7713 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
7729 "th\\u0069s.a = 1;", 7752 "th\\u0069s.a = 1;",
7730 "thr\\u006fw 'boo';", 7753 "thr\\u006fw 'boo';",
7731 "t\\u0072y { true } catch (e) {}", 7754 "t\\u0072y { true } catch (e) {}",
7732 "var x = typ\\u0065of 'blah'", 7755 "var x = typ\\u0065of 'blah'",
7733 "v\\u0061r a = true", 7756 "v\\u0061r a = true",
7734 "var v\\u0061r = true", 7757 "var v\\u0061r = true",
7735 "(function() { return v\\u006fid 0; })()", 7758 "(function() { return v\\u006fid 0; })()",
7736 "wh\\u0069le (true) { }", 7759 "wh\\u0069le (true) { }",
7737 "w\\u0069th (this.scope) { }", 7760 "w\\u0069th (this.scope) { }",
7738 "(function*() { y\\u0069eld 1; })()", 7761 "(function*() { y\\u0069eld 1; })()",
7762 "(function*() { var y\\u0069eld = 1; })()",
7739 7763
7740 "var \\u0065num = 1;", 7764 "var \\u0065num = 1;",
7741 "var { \\u0065num } = {}", 7765 "var { \\u0065num } = {}",
7742 "(\\u0065num = 1);", 7766 "(\\u0065num = 1);",
7743 7767
7744 // Null / Boolean literals 7768 // Null / Boolean literals
7745 "(x === n\\u0075ll);", 7769 "(x === n\\u0075ll);",
7746 "var x = n\\u0075ll;", 7770 "var x = n\\u0075ll;",
7747 "var n\\u0075ll = 1;", 7771 "var n\\u0075ll = 1;",
7748 "var { n\\u0075ll } = { 1 };", 7772 "var { n\\u0075ll } = { 1 };",
(...skipping 17 matching lines...) Expand all
7766 "class C \\u0065xtends function B() {} {}", 7790 "class C \\u0065xtends function B() {} {}",
7767 "for (var a i\\u006e this) {}", 7791 "for (var a i\\u006e this) {}",
7768 "if ('foo' \\u0069n this) {}", 7792 "if ('foo' \\u0069n this) {}",
7769 "if (this \\u0069nstanceof Array) {}", 7793 "if (this \\u0069nstanceof Array) {}",
7770 "(n\\u0065w function f() {})", 7794 "(n\\u0065w function f() {})",
7771 "(typ\\u0065of 123)", 7795 "(typ\\u0065of 123)",
7772 "(v\\u006fid 0)", 7796 "(v\\u006fid 0)",
7773 "do { ; } wh\\u0069le (true) { }", 7797 "do { ; } wh\\u0069le (true) { }",
7774 "(function*() { return (n++, y\\u0069eld 1); })()", 7798 "(function*() { return (n++, y\\u0069eld 1); })()",
7775 "class C { st\\u0061tic bar() {} }", 7799 "class C { st\\u0061tic bar() {} }",
7800 "class C { st\\u0061tic *bar() {} }",
7801 "class C { st\\u0061tic get bar() {} }",
7802 "class C { st\\u0061tic set bar() {} }",
7776 7803
7804 // TODO(adamk): These should not be errors in sloppy mode.
7777 "(y\\u0069eld);", 7805 "(y\\u0069eld);",
7778 "var y\\u0069eld = 1;", 7806 "var y\\u0069eld = 1;",
7779 "var { y\\u0069eld } = {};", 7807 "var { y\\u0069eld } = {};",
7780 NULL 7808 NULL
7781 }; 7809 };
7782 // clang-format on 7810 // clang-format on
7783 7811
7784 static const ParserFlag always_flags[] = {kAllowHarmonySloppy, 7812 static const ParserFlag always_flags[] = {kAllowHarmonySloppy,
7785 kAllowHarmonyDestructuring}; 7813 kAllowHarmonyDestructuring};
7786 RunParserSyncTest(sloppy_context_data, fail_data, kError, NULL, 0, 7814 RunParserSyncTest(sloppy_context_data, fail_data, kError, NULL, 0,
7787 always_flags, arraysize(always_flags)); 7815 always_flags, arraysize(always_flags));
7788 RunParserSyncTest(strict_context_data, fail_data, kError, NULL, 0, 7816 RunParserSyncTest(strict_context_data, fail_data, kError, NULL, 0,
7789 always_flags, arraysize(always_flags)); 7817 always_flags, arraysize(always_flags));
7790 RunModuleParserSyncTest(sloppy_context_data, fail_data, kError, NULL, 0, 7818 RunModuleParserSyncTest(sloppy_context_data, fail_data, kError, NULL, 0,
7791 always_flags, arraysize(always_flags)); 7819 always_flags, arraysize(always_flags));
7792 7820
7793 // clang-format off 7821 // clang-format off
7794 const char* let_data[] = { 7822 const char* let_data[] = {
7795 "var l\\u0065t = 1;", 7823 "var l\\u0065t = 1;",
7796 "l\\u0065t = 1;", 7824 "l\\u0065t = 1;",
7797 "(l\\u0065t === 1);", 7825 "(l\\u0065t === 1);",
7798 NULL 7826 NULL
7799 }; 7827 };
7800 // clang-format on 7828 // clang-format on
7801 7829
7802 RunParserSyncTest(sloppy_context_data, let_data, kError, NULL, 0, 7830 RunParserSyncTest(sloppy_context_data, let_data, kSuccess, NULL, 0,
7803 always_flags, arraysize(always_flags)); 7831 always_flags, arraysize(always_flags));
7804 RunParserSyncTest(strict_context_data, let_data, kError, NULL, 0, 7832 RunParserSyncTest(strict_context_data, let_data, kError, NULL, 0,
7805 always_flags, arraysize(always_flags)); 7833 always_flags, arraysize(always_flags));
7806 7834
7807 static const ParserFlag sloppy_let_flags[] = { 7835 static const ParserFlag sloppy_let_flags[] = {
7808 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kAllowHarmonyDestructuring}; 7836 kAllowHarmonySloppy, kAllowHarmonySloppyLet, kAllowHarmonyDestructuring};
7809 RunParserSyncTest(sloppy_context_data, let_data, kError, NULL, 0, 7837 RunParserSyncTest(sloppy_context_data, let_data, kSuccess, NULL, 0,
7810 sloppy_let_flags, arraysize(sloppy_let_flags)); 7838 sloppy_let_flags, arraysize(sloppy_let_flags));
7811 7839
7812 // Non-errors in sloppy mode 7840 // Non-errors in sloppy mode
7813 const char* valid_data[] = {"(\\u0069mplements = 1);", 7841 const char* valid_data[] = {"(\\u0069mplements = 1);",
7814 "var impl\\u0065ments = 1;", 7842 "var impl\\u0065ments = 1;",
7815 "var { impl\\u0065ments } = {};", 7843 "var { impl\\u0065ments } = {};",
7816 "(\\u0069nterface = 1);", 7844 "(\\u0069nterface = 1);",
7817 "var int\\u0065rface = 1;", 7845 "var int\\u0065rface = 1;",
7818 "var { int\\u0065rface } = {};", 7846 "var { int\\u0065rface } = {};",
7819 "(p\\u0061ckage = 1);", 7847 "(p\\u0061ckage = 1);",
7820 "var packa\\u0067e = 1;", 7848 "var packa\\u0067e = 1;",
7821 "var { packa\\u0067e } = {};", 7849 "var { packa\\u0067e } = {};",
7822 "(p\\u0072ivate = 1);", 7850 "(p\\u0072ivate = 1);",
7823 "var p\\u0072ivate;", 7851 "var p\\u0072ivate;",
7824 "var { p\\u0072ivate } = {};", 7852 "var { p\\u0072ivate } = {};",
7825 "(prot\\u0065cted);", 7853 "(prot\\u0065cted);",
7826 "var prot\\u0065cted = 1;", 7854 "var prot\\u0065cted = 1;",
7827 "var { prot\\u0065cted } = {};", 7855 "var { prot\\u0065cted } = {};",
7828 "(publ\\u0069c);", 7856 "(publ\\u0069c);",
7829 "var publ\\u0069c = 1;", 7857 "var publ\\u0069c = 1;",
7830 "var { publ\\u0069c } = {};", 7858 "var { publ\\u0069c } = {};",
7859 "(st\\u0061tic);",
7860 "var st\\u0061tic = 1;",
7861 "var { st\\u0061tic } = {};",
7831 NULL}; 7862 NULL};
7832 RunParserSyncTest(sloppy_context_data, valid_data, kSuccess, NULL, 0, 7863 RunParserSyncTest(sloppy_context_data, valid_data, kSuccess, NULL, 0,
7833 always_flags, arraysize(always_flags)); 7864 always_flags, arraysize(always_flags));
7834 RunParserSyncTest(strict_context_data, valid_data, kError, NULL, 0, 7865 RunParserSyncTest(strict_context_data, valid_data, kError, NULL, 0,
7835 always_flags, arraysize(always_flags)); 7866 always_flags, arraysize(always_flags));
7836 RunModuleParserSyncTest(strict_context_data, valid_data, kError, NULL, 0, 7867 RunModuleParserSyncTest(strict_context_data, valid_data, kError, NULL, 0,
7837 always_flags, arraysize(always_flags)); 7868 always_flags, arraysize(always_flags));
7838 } 7869 }
7839 7870
7840 7871
7841 TEST(MiscSyntaxErrors) { 7872 TEST(MiscSyntaxErrors) {
7842 const char* context_data[][2] = { 7873 const char* context_data[][2] = {
7843 {"'use strict'", ""}, {"", ""}, {NULL, NULL}}; 7874 {"'use strict'", ""}, {"", ""}, {NULL, NULL}};
7844 const char* error_data[] = {"for (();;) {}", NULL}; 7875 const char* error_data[] = {"for (();;) {}", NULL};
7845 7876
7846 RunParserSyncTest(context_data, error_data, kError, NULL, 0, NULL, 0); 7877 RunParserSyncTest(context_data, error_data, kError, NULL, 0, NULL, 0);
7847 } 7878 }
OLDNEW
« no previous file with comments | « src/parsing/scanner.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698