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

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

Issue 1723313002: [parser] Enforce module-specific identifier restriction (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Remove references to variable that has recently been deleted Created 4 years, 8 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/token.h ('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 1531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 void TestParserSyncWithFlags(i::Handle<i::String> source, 1542 void TestParserSyncWithFlags(i::Handle<i::String> source,
1543 i::EnumSet<ParserFlag> flags, 1543 i::EnumSet<ParserFlag> flags,
1544 ParserSyncTestResult result, 1544 ParserSyncTestResult result,
1545 bool is_module = false) { 1545 bool is_module = false) {
1546 i::Isolate* isolate = CcTest::i_isolate(); 1546 i::Isolate* isolate = CcTest::i_isolate();
1547 i::Factory* factory = isolate->factory(); 1547 i::Factory* factory = isolate->factory();
1548 1548
1549 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); 1549 uintptr_t stack_limit = isolate->stack_guard()->real_climit();
1550 int preparser_materialized_literals = -1; 1550 int preparser_materialized_literals = -1;
1551 int parser_materialized_literals = -2; 1551 int parser_materialized_literals = -2;
1552 bool test_preparser = !is_module;
1553 1552
1554 // Preparse the data. 1553 // Preparse the data.
1555 i::CompleteParserRecorder log; 1554 i::CompleteParserRecorder log;
1556 if (test_preparser) { 1555 {
adamk 2016/04/04 22:33:46 Does this test still pass after you remove these i
mike3 2016/04/13 20:06:16 After applying this patch, all tests in test-parsi
1557 i::Scanner scanner(isolate->unicode_cache()); 1556 i::Scanner scanner(isolate->unicode_cache());
1558 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); 1557 i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
1559 i::Zone zone; 1558 i::Zone zone;
1560 i::AstValueFactory ast_value_factory( 1559 i::AstValueFactory ast_value_factory(
1561 &zone, CcTest::i_isolate()->heap()->HashSeed()); 1560 &zone, CcTest::i_isolate()->heap()->HashSeed());
1562 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, 1561 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
1563 stack_limit); 1562 stack_limit);
1564 SetParserFlags(&preparser, flags); 1563 SetParserFlags(&preparser, flags);
1565 scanner.Initialize(&stream); 1564 scanner.Initialize(&stream);
1566 i::PreParser::PreParseResult result = preparser.PreParseProgram( 1565 i::PreParser::PreParseResult result =
1567 &preparser_materialized_literals); 1566 preparser.PreParseProgram(&preparser_materialized_literals, is_module);
1568 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 1567 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
1569 } 1568 }
1570 bool preparse_error = log.HasError(); 1569 bool preparse_error = log.HasError();
1571 1570
1572 // Parse the data 1571 // Parse the data
1573 i::FunctionLiteral* function; 1572 i::FunctionLiteral* function;
1574 { 1573 {
1575 i::Handle<i::Script> script = factory->NewScript(source); 1574 i::Handle<i::Script> script = factory->NewScript(source);
1576 i::Zone zone; 1575 i::Zone zone;
1577 i::ParseInfo info(&zone, script); 1576 i::ParseInfo info(&zone, script);
(...skipping 25 matching lines...) Expand all
1603 v8::base::OS::Print( 1602 v8::base::OS::Print(
1604 "Parser failed on:\n" 1603 "Parser failed on:\n"
1605 "\t%s\n" 1604 "\t%s\n"
1606 "with error:\n" 1605 "with error:\n"
1607 "\t%s\n" 1606 "\t%s\n"
1608 "However, we expected no error.", 1607 "However, we expected no error.",
1609 source->ToCString().get(), message_string->ToCString().get()); 1608 source->ToCString().get(), message_string->ToCString().get());
1610 CHECK(false); 1609 CHECK(false);
1611 } 1610 }
1612 1611
1613 if (test_preparser && !preparse_error) { 1612 if (!preparse_error) {
1614 v8::base::OS::Print( 1613 v8::base::OS::Print(
1615 "Parser failed on:\n" 1614 "Parser failed on:\n"
1616 "\t%s\n" 1615 "\t%s\n"
1617 "with error:\n" 1616 "with error:\n"
1618 "\t%s\n" 1617 "\t%s\n"
1619 "However, the preparser succeeded", 1618 "However, the preparser succeeded",
1620 source->ToCString().get(), message_string->ToCString().get()); 1619 source->ToCString().get(), message_string->ToCString().get());
1621 CHECK(false); 1620 CHECK(false);
1622 } 1621 }
1623 // Check that preparser and parser produce the same error. 1622 // Check that preparser and parser produce the same error.
1624 if (test_preparser) { 1623 {
1625 i::Handle<i::String> preparser_message = 1624 i::Handle<i::String> preparser_message =
1626 FormatMessage(log.ErrorMessageData()); 1625 FormatMessage(log.ErrorMessageData());
1627 if (!i::String::Equals(message_string, preparser_message)) { 1626 if (!i::String::Equals(message_string, preparser_message)) {
1628 v8::base::OS::Print( 1627 v8::base::OS::Print(
1629 "Expected parser and preparser to produce the same error on:\n" 1628 "Expected parser and preparser to produce the same error on:\n"
1630 "\t%s\n" 1629 "\t%s\n"
1631 "However, found the following error messages\n" 1630 "However, found the following error messages\n"
1632 "\tparser: %s\n" 1631 "\tparser: %s\n"
1633 "\tpreparser: %s\n", 1632 "\tpreparser: %s\n",
1634 source->ToCString().get(), message_string->ToCString().get(), 1633 source->ToCString().get(), message_string->ToCString().get(),
1635 preparser_message->ToCString().get()); 1634 preparser_message->ToCString().get());
1636 CHECK(false); 1635 CHECK(false);
1637 } 1636 }
1638 } 1637 }
1639 } else if (test_preparser && preparse_error) { 1638 } else if (preparse_error) {
1640 v8::base::OS::Print( 1639 v8::base::OS::Print(
1641 "Preparser failed on:\n" 1640 "Preparser failed on:\n"
1642 "\t%s\n" 1641 "\t%s\n"
1643 "with error:\n" 1642 "with error:\n"
1644 "\t%s\n" 1643 "\t%s\n"
1645 "However, the parser succeeded", 1644 "However, the parser succeeded",
1646 source->ToCString().get(), 1645 source->ToCString().get(),
1647 FormatMessage(log.ErrorMessageData())->ToCString().get()); 1646 FormatMessage(log.ErrorMessageData())->ToCString().get());
1648 CHECK(false); 1647 CHECK(false);
1649 } else if (result == kError) { 1648 } else if (result == kError) {
1650 v8::base::OS::Print( 1649 v8::base::OS::Print(
1651 "Expected error on:\n" 1650 "Expected error on:\n"
1652 "\t%s\n" 1651 "\t%s\n"
1653 "However, parser and preparser succeeded", 1652 "However, parser and preparser succeeded",
1654 source->ToCString().get()); 1653 source->ToCString().get());
1655 CHECK(false); 1654 CHECK(false);
1656 } else if (test_preparser && 1655 } else if (preparser_materialized_literals != parser_materialized_literals) {
1657 preparser_materialized_literals != parser_materialized_literals) {
1658 v8::base::OS::Print( 1656 v8::base::OS::Print(
1659 "Preparser materialized literals (%d) differ from Parser materialized " 1657 "Preparser materialized literals (%d) differ from Parser materialized "
1660 "literals (%d) on:\n" 1658 "literals (%d) on:\n"
1661 "\t%s\n" 1659 "\t%s\n"
1662 "However, parser and preparser succeeded", 1660 "However, parser and preparser succeeded",
1663 preparser_materialized_literals, parser_materialized_literals, 1661 preparser_materialized_literals, parser_materialized_literals,
1664 source->ToCString().get()); 1662 source->ToCString().get());
1665 CHECK(false); 1663 CHECK(false);
1666 } 1664 }
1667 } 1665 }
(...skipping 3918 matching lines...) Expand 10 before | Expand all | Expand 10 after
5586 "var x; export default x = 7", 5584 "var x; export default x = 7",
5587 "export { Q } from 'somemodule.js';", 5585 "export { Q } from 'somemodule.js';",
5588 "export * from 'somemodule.js';", 5586 "export * from 'somemodule.js';",
5589 "var foo; export { foo as for };", 5587 "var foo; export { foo as for };",
5590 "export { arguments } from 'm.js';", 5588 "export { arguments } from 'm.js';",
5591 "export { for } from 'm.js';", 5589 "export { for } from 'm.js';",
5592 "export { yield } from 'm.js'", 5590 "export { yield } from 'm.js'",
5593 "export { static } from 'm.js'", 5591 "export { static } from 'm.js'",
5594 "export { let } from 'm.js'", 5592 "export { let } from 'm.js'",
5595 "var a; export { a as b, a as c };", 5593 "var a; export { a as b, a as c };",
5594 "var a; export { a as await };",
5595 "var a; export { a as enum };",
5596 5596
5597 "import 'somemodule.js';", 5597 "import 'somemodule.js';",
5598 "import { } from 'm.js';", 5598 "import { } from 'm.js';",
5599 "import { a } from 'm.js';", 5599 "import { a } from 'm.js';",
5600 "import { a, b as d, c, } from 'm.js';", 5600 "import { a, b as d, c, } from 'm.js';",
5601 "import * as thing from 'm.js';", 5601 "import * as thing from 'm.js';",
5602 "import thing from 'm.js';", 5602 "import thing from 'm.js';",
5603 "import thing, * as rest from 'm.js';", 5603 "import thing, * as rest from 'm.js';",
5604 "import thing, { a, b, c } from 'm.js';", 5604 "import thing, { a, b, c } from 'm.js';",
5605 "import { arguments as a } from 'm.js';", 5605 "import { arguments as a } from 'm.js';",
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
5711 "import a { b, c } from 'm.js';", 5711 "import a { b, c } from 'm.js';",
5712 "import arguments from 'm.js';", 5712 "import arguments from 'm.js';",
5713 "import eval from 'm.js';", 5713 "import eval from 'm.js';",
5714 "import { arguments } from 'm.js';", 5714 "import { arguments } from 'm.js';",
5715 "import { eval } from 'm.js';", 5715 "import { eval } from 'm.js';",
5716 "import { a as arguments } from 'm.js';", 5716 "import { a as arguments } from 'm.js';",
5717 "import { for } from 'm.js';", 5717 "import { for } from 'm.js';",
5718 "import { y as yield } from 'm.js'", 5718 "import { y as yield } from 'm.js'",
5719 "import { s as static } from 'm.js'", 5719 "import { s as static } from 'm.js'",
5720 "import { l as let } from 'm.js'", 5720 "import { l as let } from 'm.js'",
5721 "import { a as await } from 'm.js';",
5722 "import { a as enum } from 'm.js';",
5721 "import { x }, def from 'm.js';", 5723 "import { x }, def from 'm.js';",
5722 "import def, def2 from 'm.js';", 5724 "import def, def2 from 'm.js';",
5723 "import * as x, def from 'm.js';", 5725 "import * as x, def from 'm.js';",
5724 "import * as x, * as y from 'm.js';", 5726 "import * as x, * as y from 'm.js';",
5725 "import {x}, {y} from 'm.js';", 5727 "import {x}, {y} from 'm.js';",
5726 "import * as x, {y} from 'm.js';", 5728 "import * as x, {y} from 'm.js';",
5727 }; 5729 };
5728 // clang-format on 5730 // clang-format on
5729 5731
5730 i::Isolate* isolate = CcTest::i_isolate(); 5732 i::Isolate* isolate = CcTest::i_isolate();
(...skipping 12 matching lines...) Expand all
5743 5745
5744 i::Handle<i::Script> script = factory->NewScript(source); 5746 i::Handle<i::Script> script = factory->NewScript(source);
5745 i::Zone zone; 5747 i::Zone zone;
5746 i::ParseInfo info(&zone, script); 5748 i::ParseInfo info(&zone, script);
5747 i::Parser parser(&info); 5749 i::Parser parser(&info);
5748 info.set_module(); 5750 info.set_module();
5749 CHECK(!parser.Parse(&info)); 5751 CHECK(!parser.Parse(&info));
5750 } 5752 }
5751 } 5753 }
5752 5754
5755 TEST(ModuleAwaitReserved) {
5756 // clang-format off
5757 const char* kErrorSources[] = {
5758 "await;",
5759 "await: ;",
5760 "var await;",
5761 "var [await] = [];",
5762 "var { await } = {};",
5763 "var { x: await } = {};",
5764 "{ var await; }",
5765 "let await;",
5766 "let [await] = [];",
5767 "let { await } = {};",
5768 "let { x: await } = {};",
5769 "{ let await; }",
5770 "const await = null;",
5771 "const [await] = [];",
5772 "const { await } = {};",
5773 "const { x: await } = {};",
5774 "{ const await = null; }",
5775 "function await() {}",
5776 "function f(await) {}",
5777 "function* await() {}",
5778 "function* g(await) {}",
5779 "(function await() {});",
5780 "(function (await) {});",
5781 "(function* await() {});",
5782 "(function* (await) {});",
5783 "(await) => {};",
5784 "await => {};",
5785 "class await {}",
5786 "class C { constructor(await) {} }",
5787 "class C { m(await) {} }",
5788 "class C { static m(await) {} }",
5789 "class C { *m(await) {} }",
5790 "class C { static *m(await) {} }",
5791 "(class await {})",
5792 "(class { constructor(await) {} });",
5793 "(class { m(await) {} });",
5794 "(class { static m(await) {} });",
5795 "(class { *m(await) {} });",
5796 "(class { static *m(await) {} });",
5797 "({ m(await) {} });",
5798 "({ *m(await) {} });",
5799 "({ set p(await) {} });",
5800 "try {} catch (await) {}",
5801 "try {} catch (await) {} finally {}"
5802 };
adamk 2016/04/04 22:33:46 Please add a "// clang-format on" after this line.
mike3 2016/04/13 20:06:16 Sure thing! I omitted it in another test, so I'll
5803
5804 i::Isolate* isolate = CcTest::i_isolate();
5805 i::Factory* factory = isolate->factory();
5806
5807 v8::HandleScope handles(CcTest::isolate());
5808 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
5809 v8::Context::Scope context_scope(context);
5810
5811 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5812 128 * 1024);
5813
5814 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) {
5815 i::Handle<i::String> source =
5816 factory->NewStringFromAsciiChecked(kErrorSources[i]);
5817
5818 i::Handle<i::Script> script = factory->NewScript(source);
5819 i::Zone zone;
5820 i::ParseInfo info(&zone, script);
5821 i::Parser parser(&info);
5822 info.set_module();
5823 CHECK(!parser.Parse(&info));
5824 }
5825 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) {
5826 i::Handle<i::String> source =
5827 factory->NewStringFromAsciiChecked(kErrorSources[i]);
5828
5829 i::Handle<i::Script> script = factory->NewScript(source);
5830 i::Zone zone;
5831 i::ParseInfo info(&zone, script);
5832 i::Parser parser(&info);
5833 CHECK(parser.Parse(&info));
5834 }
5835 }
5836
5837
5838 TEST(ModuleAwaitReservedPreParse) {
5839 const char* context_data[][2] = {
5840 {"", ""},
5841 {NULL, NULL}
5842 };
5843 const char* error_data[] = {
5844 "function f() { var await = 0; }",
5845 NULL
5846 };
5847
5848 RunModuleParserSyncTest(context_data, error_data, kError, NULL, 0, NULL, 0);
5849 }
5850
5851
5852 TEST(ModuleAwaitPermitted) {
5853 // clang-format off
5854 const char* kErrorSources[] = {
5855 "({}).await;",
5856 "({ await: null });",
5857 "({ await() {} });",
5858 "({ get await() {} });",
5859 "({ set await(x) {} });",
5860 "(class { await() {} });",
5861 "(class { static await() {} });",
5862 "(class { *await() {} });",
5863 "(class { static *await() {} });"
5864 };
5865 // clang-format on
5866
5867 i::Isolate* isolate = CcTest::i_isolate();
5868 i::Factory* factory = isolate->factory();
5869
5870 v8::HandleScope handles(CcTest::isolate());
5871 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
5872 v8::Context::Scope context_scope(context);
5873
5874 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5875 128 * 1024);
5876
5877 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) {
5878 i::Handle<i::String> source =
5879 factory->NewStringFromAsciiChecked(kErrorSources[i]);
5880
5881 i::Handle<i::Script> script = factory->NewScript(source);
5882 i::Zone zone;
5883 i::ParseInfo info(&zone, script);
5884 i::Parser parser(&info);
5885 info.set_module();
5886 CHECK(parser.Parse(&info));
5887 }
5888 }
5889
5890 TEST(EnumReserved) {
5891 // clang-format off
5892 const char* kErrorSources[] = {
5893 "enum;",
5894 "enum: ;",
5895 "var enum;",
5896 "var [enum] = [];",
5897 "var { enum } = {};",
5898 "var { x: enum } = {};",
5899 "{ var enum; }",
5900 "let enum;",
5901 "let [enum] = [];",
5902 "let { enum } = {};",
5903 "let { x: enum } = {};",
5904 "{ let enum; }",
5905 "const enum = null;",
5906 "const [enum] = [];",
5907 "const { enum } = {};",
5908 "const { x: enum } = {};",
5909 "{ const enum = null; }",
5910 "function enum() {}",
5911 "function f(enum) {}",
5912 "function* enum() {}",
5913 "function* g(enum) {}",
5914 "(function enum() {});",
5915 "(function (enum) {});",
5916 "(function* enum() {});",
5917 "(function* (enum) {});",
5918 "(enum) => {};",
5919 "enum => {};",
5920 "class enum {}",
5921 "class C { constructor(enum) {} }",
5922 "class C { m(enum) {} }",
5923 "class C { static m(enum) {} }",
5924 "class C { *m(enum) {} }",
5925 "class C { static *m(enum) {} }",
5926 "(class enum {})",
5927 "(class { constructor(enum) {} });",
5928 "(class { m(enum) {} });",
5929 "(class { static m(enum) {} });",
5930 "(class { *m(enum) {} });",
5931 "(class { static *m(enum) {} });",
5932 "({ m(enum) {} });",
5933 "({ *m(enum) {} });",
5934 "({ set p(enum) {} });",
5935 "try {} catch (enum) {}",
5936 "try {} catch (enum) {} finally {}"
5937 };
5938
5939 i::Isolate* isolate = CcTest::i_isolate();
5940 i::Factory* factory = isolate->factory();
5941
5942 v8::HandleScope handles(CcTest::isolate());
5943 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
5944 v8::Context::Scope context_scope(context);
5945
5946 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5947 128 * 1024);
5948
5949 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) {
5950 i::Handle<i::String> source =
5951 factory->NewStringFromAsciiChecked(kErrorSources[i]);
5952
5953 i::Handle<i::Script> script = factory->NewScript(source);
5954 i::Zone zone;
5955 i::ParseInfo info(&zone, script);
5956 i::Parser parser(&info);
5957 info.set_module();
5958 CHECK(!parser.Parse(&info));
5959 }
5960 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) {
5961 i::Handle<i::String> source =
5962 factory->NewStringFromAsciiChecked(kErrorSources[i]);
5963
5964 i::Handle<i::Script> script = factory->NewScript(source);
5965 i::Zone zone;
5966 i::ParseInfo info(&zone, script);
5967 i::Parser parser(&info);
5968 CHECK(!parser.Parse(&info));
5969 }
5970 }
5971
5753 5972
5754 TEST(ModuleParsingInternals) { 5973 TEST(ModuleParsingInternals) {
5755 i::Isolate* isolate = CcTest::i_isolate(); 5974 i::Isolate* isolate = CcTest::i_isolate();
5756 i::Factory* factory = isolate->factory(); 5975 i::Factory* factory = isolate->factory();
5757 v8::HandleScope handles(CcTest::isolate()); 5976 v8::HandleScope handles(CcTest::isolate());
5758 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); 5977 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
5759 v8::Context::Scope context_scope(context); 5978 v8::Context::Scope context_scope(context);
5760 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 5979 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5761 128 * 1024); 5980 128 * 1024);
5762 5981
(...skipping 1617 matching lines...) Expand 10 before | Expand all | Expand 10 after
7380 // "Array() **= 10", 7599 // "Array() **= 10",
7381 NULL 7600 NULL
7382 }; 7601 };
7383 // clang-format on 7602 // clang-format on
7384 7603
7385 static const ParserFlag always_flags[] = { 7604 static const ParserFlag always_flags[] = {
7386 kAllowHarmonyExponentiationOperator}; 7605 kAllowHarmonyExponentiationOperator};
7387 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, 7606 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
7388 arraysize(always_flags)); 7607 arraysize(always_flags));
7389 } 7608 }
OLDNEW
« no previous file with comments | « src/parsing/token.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698