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 1629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1640 | 1640 |
1641 // Check that preparsing fails iff parsing fails. | 1641 // Check that preparsing fails iff parsing fails. |
1642 if (function == NULL) { | 1642 if (function == NULL) { |
1643 // Extract exception from the parser. | 1643 // Extract exception from the parser. |
1644 CHECK(isolate->has_pending_exception()); | 1644 CHECK(isolate->has_pending_exception()); |
1645 i::Handle<i::JSObject> exception_handle( | 1645 i::Handle<i::JSObject> exception_handle( |
1646 i::JSObject::cast(isolate->pending_exception())); | 1646 i::JSObject::cast(isolate->pending_exception())); |
1647 i::Handle<i::String> message_string = i::Handle<i::String>::cast( | 1647 i::Handle<i::String> message_string = i::Handle<i::String>::cast( |
1648 i::JSReceiver::GetProperty(isolate, exception_handle, "message") | 1648 i::JSReceiver::GetProperty(isolate, exception_handle, "message") |
1649 .ToHandleChecked()); | 1649 .ToHandleChecked()); |
| 1650 isolate->clear_pending_exception(); |
1650 | 1651 |
1651 if (result == kSuccess) { | 1652 if (result == kSuccess) { |
1652 v8::base::OS::Print( | 1653 v8::base::OS::Print( |
1653 "Parser failed on:\n" | 1654 "Parser failed on:\n" |
1654 "\t%s\n" | 1655 "\t%s\n" |
1655 "with error:\n" | 1656 "with error:\n" |
1656 "\t%s\n" | 1657 "\t%s\n" |
1657 "However, we expected no error.", | 1658 "However, we expected no error.", |
1658 source->ToCString().get(), message_string->ToCString().get()); | 1659 source->ToCString().get(), message_string->ToCString().get()); |
1659 CHECK(false); | 1660 CHECK(false); |
(...skipping 3948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5608 i::Zone zone(CcTest::i_isolate()->allocator()); | 5609 i::Zone zone(CcTest::i_isolate()->allocator()); |
5609 i::ParseInfo info(&zone, script); | 5610 i::ParseInfo info(&zone, script); |
5610 i::Parser parser(&info); | 5611 i::Parser parser(&info); |
5611 info.set_module(); | 5612 info.set_module(); |
5612 if (!parser.Parse(&info)) { | 5613 if (!parser.Parse(&info)) { |
5613 i::Handle<i::JSObject> exception_handle( | 5614 i::Handle<i::JSObject> exception_handle( |
5614 i::JSObject::cast(isolate->pending_exception())); | 5615 i::JSObject::cast(isolate->pending_exception())); |
5615 i::Handle<i::String> message_string = i::Handle<i::String>::cast( | 5616 i::Handle<i::String> message_string = i::Handle<i::String>::cast( |
5616 i::JSReceiver::GetProperty(isolate, exception_handle, "message") | 5617 i::JSReceiver::GetProperty(isolate, exception_handle, "message") |
5617 .ToHandleChecked()); | 5618 .ToHandleChecked()); |
| 5619 isolate->clear_pending_exception(); |
5618 | 5620 |
5619 v8::base::OS::Print( | 5621 v8::base::OS::Print( |
5620 "Parser failed on:\n" | 5622 "Parser failed on:\n" |
5621 "\t%s\n" | 5623 "\t%s\n" |
5622 "with error:\n" | 5624 "with error:\n" |
5623 "\t%s\n" | 5625 "\t%s\n" |
5624 "However, we expected no error.", | 5626 "However, we expected no error.", |
5625 source->ToCString().get(), message_string->ToCString().get()); | 5627 source->ToCString().get(), message_string->ToCString().get()); |
5626 CHECK(false); | 5628 CHECK(false); |
5627 } | 5629 } |
5628 } | 5630 } |
5629 | 5631 |
5630 // And that parsing a script does not. | 5632 // And that parsing a script does not. |
5631 { | 5633 { |
5632 i::Handle<i::Script> script = factory->NewScript(source); | 5634 i::Handle<i::Script> script = factory->NewScript(source); |
5633 i::Zone zone(CcTest::i_isolate()->allocator()); | 5635 i::Zone zone(CcTest::i_isolate()->allocator()); |
5634 i::ParseInfo info(&zone, script); | 5636 i::ParseInfo info(&zone, script); |
5635 i::Parser parser(&info); | 5637 i::Parser parser(&info); |
5636 info.set_global(); | 5638 info.set_global(); |
5637 CHECK(!parser.Parse(&info)); | 5639 CHECK(!parser.Parse(&info)); |
| 5640 isolate->clear_pending_exception(); |
5638 } | 5641 } |
5639 } | 5642 } |
5640 } | 5643 } |
5641 | 5644 |
5642 | 5645 |
5643 TEST(ImportExportParsingErrors) { | 5646 TEST(ImportExportParsingErrors) { |
5644 // clang-format off | 5647 // clang-format off |
5645 const char* kErrorSources[] = { | 5648 const char* kErrorSources[] = { |
5646 "export {", | 5649 "export {", |
5647 "var a; export { a", | 5650 "var a; export { a", |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5720 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { | 5723 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { |
5721 i::Handle<i::String> source = | 5724 i::Handle<i::String> source = |
5722 factory->NewStringFromAsciiChecked(kErrorSources[i]); | 5725 factory->NewStringFromAsciiChecked(kErrorSources[i]); |
5723 | 5726 |
5724 i::Handle<i::Script> script = factory->NewScript(source); | 5727 i::Handle<i::Script> script = factory->NewScript(source); |
5725 i::Zone zone(CcTest::i_isolate()->allocator()); | 5728 i::Zone zone(CcTest::i_isolate()->allocator()); |
5726 i::ParseInfo info(&zone, script); | 5729 i::ParseInfo info(&zone, script); |
5727 i::Parser parser(&info); | 5730 i::Parser parser(&info); |
5728 info.set_module(); | 5731 info.set_module(); |
5729 CHECK(!parser.Parse(&info)); | 5732 CHECK(!parser.Parse(&info)); |
| 5733 isolate->clear_pending_exception(); |
5730 } | 5734 } |
5731 } | 5735 } |
5732 | 5736 |
5733 TEST(ModuleTopLevelFunctionDecl) { | 5737 TEST(ModuleTopLevelFunctionDecl) { |
5734 // clang-format off | 5738 // clang-format off |
5735 const char* kErrorSources[] = { | 5739 const char* kErrorSources[] = { |
5736 "function f() {} function f() {}", | 5740 "function f() {} function f() {}", |
5737 "var f; function f() {}", | 5741 "var f; function f() {}", |
5738 "function f() {} var f;", | 5742 "function f() {} var f;", |
5739 "function* f() {} function* f() {}", | 5743 "function* f() {} function* f() {}", |
(...skipping 17 matching lines...) Expand all Loading... |
5757 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { | 5761 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { |
5758 i::Handle<i::String> source = | 5762 i::Handle<i::String> source = |
5759 factory->NewStringFromAsciiChecked(kErrorSources[i]); | 5763 factory->NewStringFromAsciiChecked(kErrorSources[i]); |
5760 | 5764 |
5761 i::Handle<i::Script> script = factory->NewScript(source); | 5765 i::Handle<i::Script> script = factory->NewScript(source); |
5762 i::Zone zone(CcTest::i_isolate()->allocator()); | 5766 i::Zone zone(CcTest::i_isolate()->allocator()); |
5763 i::ParseInfo info(&zone, script); | 5767 i::ParseInfo info(&zone, script); |
5764 i::Parser parser(&info); | 5768 i::Parser parser(&info); |
5765 info.set_module(); | 5769 info.set_module(); |
5766 CHECK(!parser.Parse(&info)); | 5770 CHECK(!parser.Parse(&info)); |
| 5771 isolate->clear_pending_exception(); |
5767 } | 5772 } |
5768 } | 5773 } |
5769 | 5774 |
5770 TEST(ModuleAwaitReserved) { | 5775 TEST(ModuleAwaitReserved) { |
5771 // clang-format off | 5776 // clang-format off |
5772 const char* kErrorSources[] = { | 5777 const char* kErrorSources[] = { |
5773 "await;", | 5778 "await;", |
5774 "await: ;", | 5779 "await: ;", |
5775 "var await;", | 5780 "var await;", |
5776 "var [await] = [];", | 5781 "var [await] = [];", |
(...skipping 2200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7977 "(a,);", | 7982 "(a,);", |
7978 "(a,b,c,);", | 7983 "(a,b,c,);", |
7979 NULL | 7984 NULL |
7980 }; | 7985 }; |
7981 // clang-format on | 7986 // clang-format on |
7982 | 7987 |
7983 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; | 7988 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; |
7984 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, | 7989 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
7985 arraysize(always_flags)); | 7990 arraysize(always_flags)); |
7986 } | 7991 } |
OLD | NEW |