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

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: Relax assertion criteria Created 4 years, 7 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 1524 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 void TestParserSyncWithFlags(i::Handle<i::String> source, 1535 void TestParserSyncWithFlags(i::Handle<i::String> source,
1536 i::EnumSet<ParserFlag> flags, 1536 i::EnumSet<ParserFlag> flags,
1537 ParserSyncTestResult result, 1537 ParserSyncTestResult result,
1538 bool is_module = false) { 1538 bool is_module = false) {
1539 i::Isolate* isolate = CcTest::i_isolate(); 1539 i::Isolate* isolate = CcTest::i_isolate();
1540 i::Factory* factory = isolate->factory(); 1540 i::Factory* factory = isolate->factory();
1541 1541
1542 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); 1542 uintptr_t stack_limit = isolate->stack_guard()->real_climit();
1543 int preparser_materialized_literals = -1; 1543 int preparser_materialized_literals = -1;
1544 int parser_materialized_literals = -2; 1544 int parser_materialized_literals = -2;
1545 bool test_preparser = !is_module;
1546 1545
1547 // Preparse the data. 1546 // Preparse the data.
1548 i::CompleteParserRecorder log; 1547 i::CompleteParserRecorder log;
1549 if (test_preparser) { 1548 {
nickie 2016/05/03 17:07:52 If I understand it right, this change requires the
1550 i::Scanner scanner(isolate->unicode_cache()); 1549 i::Scanner scanner(isolate->unicode_cache());
1551 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); 1550 i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
1552 i::Zone zone(CcTest::i_isolate()->allocator()); 1551 i::Zone zone(CcTest::i_isolate()->allocator());
1553 i::AstValueFactory ast_value_factory( 1552 i::AstValueFactory ast_value_factory(
1554 &zone, CcTest::i_isolate()->heap()->HashSeed()); 1553 &zone, CcTest::i_isolate()->heap()->HashSeed());
1555 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, 1554 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
1556 stack_limit); 1555 stack_limit);
1557 SetParserFlags(&preparser, flags); 1556 SetParserFlags(&preparser, flags);
1558 scanner.Initialize(&stream); 1557 scanner.Initialize(&stream);
1559 i::PreParser::PreParseResult result = 1558 i::PreParser::PreParseResult result =
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1596 v8::base::OS::Print( 1595 v8::base::OS::Print(
1597 "Parser failed on:\n" 1596 "Parser failed on:\n"
1598 "\t%s\n" 1597 "\t%s\n"
1599 "with error:\n" 1598 "with error:\n"
1600 "\t%s\n" 1599 "\t%s\n"
1601 "However, we expected no error.", 1600 "However, we expected no error.",
1602 source->ToCString().get(), message_string->ToCString().get()); 1601 source->ToCString().get(), message_string->ToCString().get());
1603 CHECK(false); 1602 CHECK(false);
1604 } 1603 }
1605 1604
1606 if (test_preparser && !preparse_error) { 1605 if (!preparse_error) {
1607 v8::base::OS::Print( 1606 v8::base::OS::Print(
1608 "Parser failed on:\n" 1607 "Parser failed on:\n"
1609 "\t%s\n" 1608 "\t%s\n"
1610 "with error:\n" 1609 "with error:\n"
1611 "\t%s\n" 1610 "\t%s\n"
1612 "However, the preparser succeeded", 1611 "However, the preparser succeeded",
1613 source->ToCString().get(), message_string->ToCString().get()); 1612 source->ToCString().get(), message_string->ToCString().get());
1614 CHECK(false); 1613 CHECK(false);
1615 } 1614 }
1616 // Check that preparser and parser produce the same error. 1615 // Check that preparser and parser produce the same error.
1617 if (test_preparser) { 1616 {
1618 i::Handle<i::String> preparser_message = 1617 i::Handle<i::String> preparser_message =
1619 FormatMessage(log.ErrorMessageData()); 1618 FormatMessage(log.ErrorMessageData());
1620 if (!i::String::Equals(message_string, preparser_message)) { 1619 if (!i::String::Equals(message_string, preparser_message)) {
1621 v8::base::OS::Print( 1620 v8::base::OS::Print(
1622 "Expected parser and preparser to produce the same error on:\n" 1621 "Expected parser and preparser to produce the same error on:\n"
1623 "\t%s\n" 1622 "\t%s\n"
1624 "However, found the following error messages\n" 1623 "However, found the following error messages\n"
1625 "\tparser: %s\n" 1624 "\tparser: %s\n"
1626 "\tpreparser: %s\n", 1625 "\tpreparser: %s\n",
1627 source->ToCString().get(), message_string->ToCString().get(), 1626 source->ToCString().get(), message_string->ToCString().get(),
1628 preparser_message->ToCString().get()); 1627 preparser_message->ToCString().get());
1629 CHECK(false); 1628 CHECK(false);
1630 } 1629 }
1631 } 1630 }
1632 } else if (test_preparser && preparse_error) { 1631 } else if (preparse_error) {
1633 v8::base::OS::Print( 1632 v8::base::OS::Print(
1634 "Preparser failed on:\n" 1633 "Preparser failed on:\n"
1635 "\t%s\n" 1634 "\t%s\n"
1636 "with error:\n" 1635 "with error:\n"
1637 "\t%s\n" 1636 "\t%s\n"
1638 "However, the parser succeeded", 1637 "However, the parser succeeded",
1639 source->ToCString().get(), 1638 source->ToCString().get(),
1640 FormatMessage(log.ErrorMessageData())->ToCString().get()); 1639 FormatMessage(log.ErrorMessageData())->ToCString().get());
1641 CHECK(false); 1640 CHECK(false);
1642 } else if (result == kError) { 1641 } else if (result == kError) {
1643 v8::base::OS::Print( 1642 v8::base::OS::Print(
1644 "Expected error on:\n" 1643 "Expected error on:\n"
1645 "\t%s\n" 1644 "\t%s\n"
1646 "However, parser and preparser succeeded", 1645 "However, parser and preparser succeeded",
1647 source->ToCString().get()); 1646 source->ToCString().get());
1648 CHECK(false); 1647 CHECK(false);
1649 } else if (test_preparser && 1648 } else if (preparser_materialized_literals != parser_materialized_literals) {
1650 preparser_materialized_literals != parser_materialized_literals) {
1651 v8::base::OS::Print( 1649 v8::base::OS::Print(
1652 "Preparser materialized literals (%d) differ from Parser materialized " 1650 "Preparser materialized literals (%d) differ from Parser materialized "
1653 "literals (%d) on:\n" 1651 "literals (%d) on:\n"
1654 "\t%s\n" 1652 "\t%s\n"
1655 "However, parser and preparser succeeded", 1653 "However, parser and preparser succeeded",
1656 preparser_materialized_literals, parser_materialized_literals, 1654 preparser_materialized_literals, parser_materialized_literals,
1657 source->ToCString().get()); 1655 source->ToCString().get());
1658 CHECK(false); 1656 CHECK(false);
1659 } 1657 }
1660 } 1658 }
(...skipping 3808 matching lines...) Expand 10 before | Expand all | Expand 10 after
5469 "var x; export default x = 7", 5467 "var x; export default x = 7",
5470 "export { Q } from 'somemodule.js';", 5468 "export { Q } from 'somemodule.js';",
5471 "export * from 'somemodule.js';", 5469 "export * from 'somemodule.js';",
5472 "var foo; export { foo as for };", 5470 "var foo; export { foo as for };",
5473 "export { arguments } from 'm.js';", 5471 "export { arguments } from 'm.js';",
5474 "export { for } from 'm.js';", 5472 "export { for } from 'm.js';",
5475 "export { yield } from 'm.js'", 5473 "export { yield } from 'm.js'",
5476 "export { static } from 'm.js'", 5474 "export { static } from 'm.js'",
5477 "export { let } from 'm.js'", 5475 "export { let } from 'm.js'",
5478 "var a; export { a as b, a as c };", 5476 "var a; export { a as b, a as c };",
5477 "var a; export { a as await };",
5478 "var a; export { a as enum };",
5479 5479
5480 "import 'somemodule.js';", 5480 "import 'somemodule.js';",
5481 "import { } from 'm.js';", 5481 "import { } from 'm.js';",
5482 "import { a } from 'm.js';", 5482 "import { a } from 'm.js';",
5483 "import { a, b as d, c, } from 'm.js';", 5483 "import { a, b as d, c, } from 'm.js';",
5484 "import * as thing from 'm.js';", 5484 "import * as thing from 'm.js';",
5485 "import thing from 'm.js';", 5485 "import thing from 'm.js';",
5486 "import thing, * as rest from 'm.js';", 5486 "import thing, * as rest from 'm.js';",
5487 "import thing, { a, b, c } from 'm.js';", 5487 "import thing, { a, b, c } from 'm.js';",
5488 "import { arguments as a } from 'm.js';", 5488 "import { arguments as a } from 'm.js';",
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
5594 "import a { b, c } from 'm.js';", 5594 "import a { b, c } from 'm.js';",
5595 "import arguments from 'm.js';", 5595 "import arguments from 'm.js';",
5596 "import eval from 'm.js';", 5596 "import eval from 'm.js';",
5597 "import { arguments } from 'm.js';", 5597 "import { arguments } from 'm.js';",
5598 "import { eval } from 'm.js';", 5598 "import { eval } from 'm.js';",
5599 "import { a as arguments } from 'm.js';", 5599 "import { a as arguments } from 'm.js';",
5600 "import { for } from 'm.js';", 5600 "import { for } from 'm.js';",
5601 "import { y as yield } from 'm.js'", 5601 "import { y as yield } from 'm.js'",
5602 "import { s as static } from 'm.js'", 5602 "import { s as static } from 'm.js'",
5603 "import { l as let } from 'm.js'", 5603 "import { l as let } from 'm.js'",
5604 "import { a as await } from 'm.js';",
5605 "import { a as enum } from 'm.js';",
5604 "import { x }, def from 'm.js';", 5606 "import { x }, def from 'm.js';",
5605 "import def, def2 from 'm.js';", 5607 "import def, def2 from 'm.js';",
5606 "import * as x, def from 'm.js';", 5608 "import * as x, def from 'm.js';",
5607 "import * as x, * as y from 'm.js';", 5609 "import * as x, * as y from 'm.js';",
5608 "import {x}, {y} from 'm.js';", 5610 "import {x}, {y} from 'm.js';",
5609 "import * as x, {y} from 'm.js';", 5611 "import * as x, {y} from 'm.js';",
5610 }; 5612 };
5611 // clang-format on 5613 // clang-format on
5612 5614
5613 i::Isolate* isolate = CcTest::i_isolate(); 5615 i::Isolate* isolate = CcTest::i_isolate();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
5663 5665
5664 i::Handle<i::Script> script = factory->NewScript(source); 5666 i::Handle<i::Script> script = factory->NewScript(source);
5665 i::Zone zone(CcTest::i_isolate()->allocator()); 5667 i::Zone zone(CcTest::i_isolate()->allocator());
5666 i::ParseInfo info(&zone, script); 5668 i::ParseInfo info(&zone, script);
5667 i::Parser parser(&info); 5669 i::Parser parser(&info);
5668 info.set_module(); 5670 info.set_module();
5669 CHECK(!parser.Parse(&info)); 5671 CHECK(!parser.Parse(&info));
5670 } 5672 }
5671 } 5673 }
5672 5674
5675 TEST(ModuleAwaitReserved) {
5676 // clang-format off
5677 const char* kErrorSources[] = {
5678 "await;",
5679 "await: ;",
5680 "var await;",
5681 "var [await] = [];",
5682 "var { await } = {};",
5683 "var { x: await } = {};",
5684 "{ var await; }",
5685 "let await;",
5686 "let [await] = [];",
5687 "let { await } = {};",
5688 "let { x: await } = {};",
5689 "{ let await; }",
5690 "const await = null;",
5691 "const [await] = [];",
5692 "const { await } = {};",
5693 "const { x: await } = {};",
5694 "{ const await = null; }",
5695 "function await() {}",
5696 "function f(await) {}",
5697 "function* await() {}",
5698 "function* g(await) {}",
5699 "(function await() {});",
5700 "(function (await) {});",
5701 "(function* await() {});",
5702 "(function* (await) {});",
5703 "(await) => {};",
5704 "await => {};",
5705 "class await {}",
5706 "class C { constructor(await) {} }",
5707 "class C { m(await) {} }",
5708 "class C { static m(await) {} }",
5709 "class C { *m(await) {} }",
5710 "class C { static *m(await) {} }",
5711 "(class await {})",
5712 "(class { constructor(await) {} });",
5713 "(class { m(await) {} });",
5714 "(class { static m(await) {} });",
5715 "(class { *m(await) {} });",
5716 "(class { static *m(await) {} });",
5717 "({ m(await) {} });",
5718 "({ *m(await) {} });",
5719 "({ set p(await) {} });",
5720 "try {} catch (await) {}",
5721 "try {} catch (await) {} finally {}",
5722 NULL
5723 };
5724 // clang-format on
5725 const char* context_data[][2] = {{"", ""}, {NULL, NULL}};
5726
5727 RunModuleParserSyncTest(context_data, kErrorSources, kError);
5728 }
5729
5730 TEST(ModuleAwaitReservedPreParse) {
5731 const char* context_data[][2] = {{"", ""}, {NULL, NULL}};
5732 const char* error_data[] = {"function f() { var await = 0; }", NULL};
5733
5734 RunModuleParserSyncTest(context_data, error_data, kError);
5735 }
5736
5737 TEST(ModuleAwaitPermitted) {
5738 // clang-format off
5739 const char* kValidSources[] = {
5740 "({}).await;",
5741 "({ await: null });",
5742 "({ await() {} });",
5743 "({ get await() {} });",
5744 "({ set await(x) {} });",
5745 "(class { await() {} });",
5746 "(class { static await() {} });",
5747 "(class { *await() {} });",
5748 "(class { static *await() {} });",
5749 NULL
5750 };
5751 // clang-format on
5752 const char* context_data[][2] = {{"", ""}, {NULL, NULL}};
5753
5754 RunModuleParserSyncTest(context_data, kValidSources, kSuccess);
5755 }
5756
5757 TEST(EnumReserved) {
5758 // clang-format off
5759 const char* kErrorSources[] = {
5760 "enum;",
5761 "enum: ;",
5762 "var enum;",
5763 "var [enum] = [];",
5764 "var { enum } = {};",
5765 "var { x: enum } = {};",
5766 "{ var enum; }",
5767 "let enum;",
5768 "let [enum] = [];",
5769 "let { enum } = {};",
5770 "let { x: enum } = {};",
5771 "{ let enum; }",
5772 "const enum = null;",
5773 "const [enum] = [];",
5774 "const { enum } = {};",
5775 "const { x: enum } = {};",
5776 "{ const enum = null; }",
5777 "function enum() {}",
5778 "function f(enum) {}",
5779 "function* enum() {}",
5780 "function* g(enum) {}",
5781 "(function enum() {});",
5782 "(function (enum) {});",
5783 "(function* enum() {});",
5784 "(function* (enum) {});",
5785 "(enum) => {};",
5786 "enum => {};",
5787 "class enum {}",
5788 "class C { constructor(enum) {} }",
5789 "class C { m(enum) {} }",
5790 "class C { static m(enum) {} }",
5791 "class C { *m(enum) {} }",
5792 "class C { static *m(enum) {} }",
5793 "(class enum {})",
5794 "(class { constructor(enum) {} });",
5795 "(class { m(enum) {} });",
5796 "(class { static m(enum) {} });",
5797 "(class { *m(enum) {} });",
5798 "(class { static *m(enum) {} });",
5799 "({ m(enum) {} });",
5800 "({ *m(enum) {} });",
5801 "({ set p(enum) {} });",
5802 "try {} catch (enum) {}",
5803 "try {} catch (enum) {} finally {}",
5804 NULL
5805 };
5806 // clang-format on
5807 const char* context_data[][2] = {{"", ""}, {NULL, NULL}};
5808
5809 RunModuleParserSyncTest(context_data, kErrorSources, kError);
5810 }
5673 5811
5674 TEST(ModuleParsingInternals) { 5812 TEST(ModuleParsingInternals) {
5675 i::Isolate* isolate = CcTest::i_isolate(); 5813 i::Isolate* isolate = CcTest::i_isolate();
5676 i::Factory* factory = isolate->factory(); 5814 i::Factory* factory = isolate->factory();
5677 v8::HandleScope handles(CcTest::isolate()); 5815 v8::HandleScope handles(CcTest::isolate());
5678 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); 5816 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
5679 v8::Context::Scope context_scope(context); 5817 v8::Context::Scope context_scope(context);
5680 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 5818 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5681 128 * 1024); 5819 128 * 1024);
5682 5820
(...skipping 1609 matching lines...) Expand 10 before | Expand all | Expand 10 after
7292 "for (const x = 0 in {});", 7430 "for (const x = 0 in {});",
7293 "for (let x = 0 in {});", 7431 "for (let x = 0 in {});",
7294 NULL 7432 NULL
7295 }; 7433 };
7296 // clang-format on 7434 // clang-format on
7297 7435
7298 static const ParserFlag always_flags[] = {kAllowHarmonyForIn}; 7436 static const ParserFlag always_flags[] = {kAllowHarmonyForIn};
7299 RunParserSyncTest(context_data, error_data, kError, nullptr, 0, always_flags, 7437 RunParserSyncTest(context_data, error_data, kError, nullptr, 0, always_flags,
7300 arraysize(always_flags)); 7438 arraysize(always_flags));
7301 } 7439 }
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