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