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

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

Issue 2534393002: Split parsing of functions and top-level code into two separate methods (Closed)
Patch Set: updates Created 4 years 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 | « test/cctest/compiler/test-loop-assignment-analysis.cc ('k') | test/fuzzer/parser.cc » ('j') | 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 25 matching lines...) Expand all
36 #include "src/ast/ast-numbering.h" 36 #include "src/ast/ast-numbering.h"
37 #include "src/ast/ast-value-factory.h" 37 #include "src/ast/ast-value-factory.h"
38 #include "src/ast/ast.h" 38 #include "src/ast/ast.h"
39 #include "src/compiler.h" 39 #include "src/compiler.h"
40 #include "src/execution.h" 40 #include "src/execution.h"
41 #include "src/flags.h" 41 #include "src/flags.h"
42 #include "src/isolate.h" 42 #include "src/isolate.h"
43 #include "src/objects.h" 43 #include "src/objects.h"
44 #include "src/parsing/parse-info.h" 44 #include "src/parsing/parse-info.h"
45 #include "src/parsing/parser.h" 45 #include "src/parsing/parser.h"
46 #include "src/parsing/parsing.h"
46 #include "src/parsing/preparser.h" 47 #include "src/parsing/preparser.h"
47 #include "src/parsing/rewriter.h" 48 #include "src/parsing/rewriter.h"
48 #include "src/parsing/scanner-character-streams.h" 49 #include "src/parsing/scanner-character-streams.h"
49 #include "src/parsing/token.h" 50 #include "src/parsing/token.h"
50 #include "src/utils.h" 51 #include "src/utils.h"
51 52
52 #include "test/cctest/cctest.h" 53 #include "test/cctest/cctest.h"
53 54
54 TEST(ScanKeywords) { 55 TEST(ScanKeywords) {
55 struct KeywordToken { 56 struct KeywordToken {
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix, 813 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix,
813 source_data[i].body, surroundings[j].suffix); 814 source_data[i].body, surroundings[j].suffix);
814 i::Handle<i::String> source = 815 i::Handle<i::String> source =
815 factory->NewStringFromUtf8(i::CStrVector(program.start())) 816 factory->NewStringFromUtf8(i::CStrVector(program.start()))
816 .ToHandleChecked(); 817 .ToHandleChecked();
817 i::Handle<i::Script> script = factory->NewScript(source); 818 i::Handle<i::Script> script = factory->NewScript(source);
818 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 819 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
819 i::ParseInfo info(&zone, script); 820 i::ParseInfo info(&zone, script);
820 // The information we're checking is only produced when eager parsing. 821 // The information we're checking is only produced when eager parsing.
821 info.set_allow_lazy_parsing(false); 822 info.set_allow_lazy_parsing(false);
822 i::Parser parser(&info); 823 CHECK(i::parsing::ParseProgram(&info));
823 CHECK(parser.Parse(&info));
824 CHECK(i::Rewriter::Rewrite(&info)); 824 CHECK(i::Rewriter::Rewrite(&info));
825 i::DeclarationScope::Analyze(&info, i::AnalyzeMode::kRegular); 825 i::DeclarationScope::Analyze(&info, i::AnalyzeMode::kRegular);
826 CHECK(info.literal() != NULL); 826 CHECK(info.literal() != NULL);
827 827
828 i::DeclarationScope* script_scope = info.literal()->scope(); 828 i::DeclarationScope* script_scope = info.literal()->scope();
829 CHECK(script_scope->is_script_scope()); 829 CHECK(script_scope->is_script_scope());
830 830
831 i::Scope* scope = script_scope->inner_scope(); 831 i::Scope* scope = script_scope->inner_scope();
832 DCHECK_NOT_NULL(scope); 832 DCHECK_NOT_NULL(scope);
833 DCHECK_NULL(scope->sibling()); 833 DCHECK_NULL(scope->sibling());
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 source_data[i].inner_source, 1166 source_data[i].inner_source,
1167 source_data[i].outer_suffix); 1167 source_data[i].outer_suffix);
1168 1168
1169 // Parse program source. 1169 // Parse program source.
1170 i::Handle<i::String> source = factory->NewStringFromUtf8( 1170 i::Handle<i::String> source = factory->NewStringFromUtf8(
1171 i::CStrVector(program.start())).ToHandleChecked(); 1171 i::CStrVector(program.start())).ToHandleChecked();
1172 CHECK_EQ(source->length(), kProgramSize); 1172 CHECK_EQ(source->length(), kProgramSize);
1173 i::Handle<i::Script> script = factory->NewScript(source); 1173 i::Handle<i::Script> script = factory->NewScript(source);
1174 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 1174 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
1175 i::ParseInfo info(&zone, script); 1175 i::ParseInfo info(&zone, script);
1176 i::Parser parser(&info);
1177 info.set_language_mode(source_data[i].language_mode); 1176 info.set_language_mode(source_data[i].language_mode);
1178 parser.Parse(&info); 1177 i::parsing::ParseProgram(&info);
1179 CHECK_NOT_NULL(info.literal()); 1178 CHECK_NOT_NULL(info.literal());
1180 1179
1181 // Check scope types and positions. 1180 // Check scope types and positions.
1182 i::Scope* scope = info.literal()->scope(); 1181 i::Scope* scope = info.literal()->scope();
1183 CHECK(scope->is_script_scope()); 1182 CHECK(scope->is_script_scope());
1184 CHECK_EQ(scope->start_position(), 0); 1183 CHECK_EQ(scope->start_position(), 0);
1185 CHECK_EQ(scope->end_position(), kProgramSize); 1184 CHECK_EQ(scope->end_position(), kProgramSize);
1186 1185
1187 i::Scope* inner_scope = scope->inner_scope(); 1186 i::Scope* inner_scope = scope->inner_scope();
1188 DCHECK_NOT_NULL(inner_scope); 1187 DCHECK_NOT_NULL(inner_scope);
(...skipping 25 matching lines...) Expand all
1214 v8::HandleScope handles(CcTest::isolate()); 1213 v8::HandleScope handles(CcTest::isolate());
1215 i::FunctionLiteral* function; 1214 i::FunctionLiteral* function;
1216 1215
1217 for (int i = 0; discard_sources[i]; i++) { 1216 for (int i = 0; discard_sources[i]; i++) {
1218 const char* source = discard_sources[i]; 1217 const char* source = discard_sources[i];
1219 i::Handle<i::String> source_code = 1218 i::Handle<i::String> source_code =
1220 factory->NewStringFromUtf8(i::CStrVector(source)).ToHandleChecked(); 1219 factory->NewStringFromUtf8(i::CStrVector(source)).ToHandleChecked();
1221 i::Handle<i::Script> script = factory->NewScript(source_code); 1220 i::Handle<i::Script> script = factory->NewScript(source_code);
1222 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 1221 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
1223 i::ParseInfo info(&zone, script); 1222 i::ParseInfo info(&zone, script);
1224 i::Parser parser(&info); 1223 i::parsing::ParseProgram(&info);
1225 parser.Parse(&info);
1226 function = info.literal(); 1224 function = info.literal();
1227 CHECK_NOT_NULL(function); 1225 CHECK_NOT_NULL(function);
1228 CHECK_NOT_NULL(function->body()); 1226 CHECK_NOT_NULL(function->body());
1229 CHECK_EQ(1, function->body()->length()); 1227 CHECK_EQ(1, function->body()->length());
1230 i::FunctionLiteral* inner = 1228 i::FunctionLiteral* inner =
1231 function->body()->first()->AsExpressionStatement()->expression()-> 1229 function->body()->first()->AsExpressionStatement()->expression()->
1232 AsCall()->expression()->AsFunctionLiteral(); 1230 AsCall()->expression()->AsFunctionLiteral();
1233 i::Scope* inner_scope = inner->scope(); 1231 i::Scope* inner_scope = inner->scope();
1234 i::FunctionLiteral* fun = nullptr; 1232 i::FunctionLiteral* fun = nullptr;
1235 if (!inner_scope->declarations()->is_empty()) { 1233 if (!inner_scope->declarations()->is_empty()) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 kAllowHarmonyTrailingCommas, 1278 kAllowHarmonyTrailingCommas,
1281 kAllowHarmonyClassFields, 1279 kAllowHarmonyClassFields,
1282 }; 1280 };
1283 1281
1284 enum ParserSyncTestResult { 1282 enum ParserSyncTestResult {
1285 kSuccessOrError, 1283 kSuccessOrError,
1286 kSuccess, 1284 kSuccess,
1287 kError 1285 kError
1288 }; 1286 };
1289 1287
1290 template <typename Traits> 1288 void SetGlobalFlags(i::EnumSet<ParserFlag> flags) {
1291 void SetParserFlags(i::ParserBase<Traits>* parser, 1289 i::FLAG_allow_natives_syntax = flags.Contains(kAllowNatives);
1292 i::EnumSet<ParserFlag> flags) { 1290 i::FLAG_harmony_function_sent = flags.Contains(kAllowHarmonyFunctionSent);
1291 i::FLAG_harmony_async_await = flags.Contains(kAllowHarmonyAsyncAwait);
1292 i::FLAG_harmony_restrictive_generators =
1293 flags.Contains(kAllowHarmonyRestrictiveGenerators);
1294 i::FLAG_harmony_trailing_commas = flags.Contains(kAllowHarmonyTrailingCommas);
1295 i::FLAG_harmony_class_fields = flags.Contains(kAllowHarmonyClassFields);
1296 }
1297
1298 void SetParserFlags(i::PreParser* parser, i::EnumSet<ParserFlag> flags) {
1293 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1299 parser->set_allow_natives(flags.Contains(kAllowNatives));
1294 parser->set_allow_harmony_function_sent( 1300 parser->set_allow_harmony_function_sent(
1295 flags.Contains(kAllowHarmonyFunctionSent)); 1301 flags.Contains(kAllowHarmonyFunctionSent));
1296 parser->set_allow_harmony_async_await( 1302 parser->set_allow_harmony_async_await(
1297 flags.Contains(kAllowHarmonyAsyncAwait)); 1303 flags.Contains(kAllowHarmonyAsyncAwait));
1298 parser->set_allow_harmony_restrictive_generators( 1304 parser->set_allow_harmony_restrictive_generators(
1299 flags.Contains(kAllowHarmonyRestrictiveGenerators)); 1305 flags.Contains(kAllowHarmonyRestrictiveGenerators));
1300 parser->set_allow_harmony_trailing_commas( 1306 parser->set_allow_harmony_trailing_commas(
1301 flags.Contains(kAllowHarmonyTrailingCommas)); 1307 flags.Contains(kAllowHarmonyTrailingCommas));
1302 parser->set_allow_harmony_class_fields( 1308 parser->set_allow_harmony_class_fields(
1303 flags.Contains(kAllowHarmonyClassFields)); 1309 flags.Contains(kAllowHarmonyClassFields));
1304 } 1310 }
1305 1311
1306
1307 void TestParserSyncWithFlags(i::Handle<i::String> source, 1312 void TestParserSyncWithFlags(i::Handle<i::String> source,
1308 i::EnumSet<ParserFlag> flags, 1313 i::EnumSet<ParserFlag> flags,
1309 ParserSyncTestResult result, 1314 ParserSyncTestResult result,
1310 bool is_module = false, 1315 bool is_module = false,
1311 bool test_preparser = true) { 1316 bool test_preparser = true) {
1312 i::Isolate* isolate = CcTest::i_isolate(); 1317 i::Isolate* isolate = CcTest::i_isolate();
1313 i::Factory* factory = isolate->factory(); 1318 i::Factory* factory = isolate->factory();
1314 1319
1315 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); 1320 uintptr_t stack_limit = isolate->stack_guard()->real_climit();
1316 int preparser_materialized_literals = -1; 1321 int preparser_materialized_literals = -1;
(...skipping 18 matching lines...) Expand all
1335 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 1340 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
1336 } 1341 }
1337 1342
1338 // Parse the data 1343 // Parse the data
1339 i::FunctionLiteral* function; 1344 i::FunctionLiteral* function;
1340 { 1345 {
1341 i::Handle<i::Script> script = factory->NewScript(source); 1346 i::Handle<i::Script> script = factory->NewScript(source);
1342 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 1347 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
1343 i::ParseInfo info(&zone, script); 1348 i::ParseInfo info(&zone, script);
1344 info.set_allow_lazy_parsing(flags.Contains(kAllowLazy)); 1349 info.set_allow_lazy_parsing(flags.Contains(kAllowLazy));
1345 i::Parser parser(&info); 1350 SetGlobalFlags(flags);
1346 SetParserFlags(&parser, flags);
1347 if (is_module) info.set_module(); 1351 if (is_module) info.set_module();
1348 parser.Parse(&info); 1352 i::parsing::ParseProgram(&info);
1349 function = info.literal(); 1353 function = info.literal();
1350 if (function) { 1354 if (function) {
1351 parser_materialized_literals = function->materialized_literal_count(); 1355 parser_materialized_literals = function->materialized_literal_count();
1352 } 1356 }
1353 } 1357 }
1354 1358
1355 // Check that preparsing fails iff parsing fails. 1359 // Check that preparsing fails iff parsing fails.
1356 if (function == NULL) { 1360 if (function == NULL) {
1357 // Extract exception from the parser. 1361 // Extract exception from the parser.
1358 CHECK(isolate->has_pending_exception()); 1362 CHECK(isolate->has_pending_exception());
(...skipping 1111 matching lines...) Expand 10 before | Expand all | Expand 10 after
2470 const char* program = test_cases[i].program; 2474 const char* program = test_cases[i].program;
2471 i::Factory* factory = CcTest::i_isolate()->factory(); 2475 i::Factory* factory = CcTest::i_isolate()->factory();
2472 i::Handle<i::String> source = 2476 i::Handle<i::String> source =
2473 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); 2477 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked();
2474 i::Handle<i::Script> script = factory->NewScript(source); 2478 i::Handle<i::Script> script = factory->NewScript(source);
2475 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 2479 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
2476 i::ParseInfo info(&zone, script); 2480 i::ParseInfo info(&zone, script);
2477 i::ScriptData* sd = NULL; 2481 i::ScriptData* sd = NULL;
2478 info.set_cached_data(&sd); 2482 info.set_cached_data(&sd);
2479 info.set_compile_options(v8::ScriptCompiler::kProduceParserCache); 2483 info.set_compile_options(v8::ScriptCompiler::kProduceParserCache);
2480 i::Parser::ParseStatic(&info); 2484 i::parsing::ParseProgram(&info);
2481 i::ParseData* pd = i::ParseData::FromCachedData(sd); 2485 i::ParseData* pd = i::ParseData::FromCachedData(sd);
2482 2486
2483 if (pd->FunctionCount() != test_cases[i].functions) { 2487 if (pd->FunctionCount() != test_cases[i].functions) {
2484 v8::base::OS::Print( 2488 v8::base::OS::Print(
2485 "Expected preparse data for program:\n" 2489 "Expected preparse data for program:\n"
2486 "\t%s\n" 2490 "\t%s\n"
2487 "to contain %d functions, however, received %d functions.\n", 2491 "to contain %d functions, however, received %d functions.\n",
2488 program, test_cases[i].functions, pd->FunctionCount()); 2492 program, test_cases[i].functions, pd->FunctionCount());
2489 CHECK(false); 2493 CHECK(false);
2490 } 2494 }
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
3356 3360
3357 i::Zone zone(isolate->allocator(), ZONE_NAME); 3361 i::Zone zone(isolate->allocator(), ZONE_NAME);
3358 std::unique_ptr<i::ParseInfo> info; 3362 std::unique_ptr<i::ParseInfo> info;
3359 if (lazy) { 3363 if (lazy) {
3360 printf("%s\n", program.start()); 3364 printf("%s\n", program.start());
3361 v8::Local<v8::Value> v = CompileRun(program.start()); 3365 v8::Local<v8::Value> v = CompileRun(program.start());
3362 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); 3366 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v);
3363 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); 3367 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o);
3364 i::Handle<i::SharedFunctionInfo> shared = i::handle(f->shared()); 3368 i::Handle<i::SharedFunctionInfo> shared = i::handle(f->shared());
3365 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, shared)); 3369 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, shared));
3370 CHECK(i::parsing::ParseFunction(info.get()));
3366 } else { 3371 } else {
3367 i::Handle<i::String> source = 3372 i::Handle<i::String> source =
3368 factory->InternalizeUtf8String(program.start()); 3373 factory->InternalizeUtf8String(program.start());
3369 source->PrintOn(stdout); 3374 source->PrintOn(stdout);
3370 printf("\n"); 3375 printf("\n");
3371 i::Handle<i::Script> script = factory->NewScript(source); 3376 i::Handle<i::Script> script = factory->NewScript(source);
3372 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, script)); 3377 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, script));
3373 info->set_allow_lazy_parsing(false); 3378 info->set_allow_lazy_parsing(false);
3379 CHECK(i::parsing::ParseProgram(info.get()));
3374 } 3380 }
3375 i::Parser parser(info.get());
3376 CHECK(parser.Parse(info.get()));
3377 CHECK(i::Compiler::Analyze(info.get())); 3381 CHECK(i::Compiler::Analyze(info.get()));
3378 CHECK(info->literal() != NULL); 3382 CHECK(info->literal() != NULL);
3379 3383
3380 i::Scope* scope = info->literal()->scope(); 3384 i::Scope* scope = info->literal()->scope();
3381 if (!lazy) { 3385 if (!lazy) {
3382 scope = scope->inner_scope(); 3386 scope = scope->inner_scope();
3383 } 3387 }
3384 DCHECK_NOT_NULL(scope); 3388 DCHECK_NOT_NULL(scope);
3385 DCHECK_NULL(scope->sibling()); 3389 DCHECK_NULL(scope->sibling());
3386 DCHECK(scope->is_function_scope()); 3390 DCHECK(scope->is_function_scope());
(...skipping 2342 matching lines...) Expand 10 before | Expand all | Expand 10 after
5729 5733
5730 for (unsigned i = 0; i < arraysize(kSources); ++i) { 5734 for (unsigned i = 0; i < arraysize(kSources); ++i) {
5731 i::Handle<i::String> source = 5735 i::Handle<i::String> source =
5732 factory->NewStringFromAsciiChecked(kSources[i]); 5736 factory->NewStringFromAsciiChecked(kSources[i]);
5733 5737
5734 // Show that parsing as a module works 5738 // Show that parsing as a module works
5735 { 5739 {
5736 i::Handle<i::Script> script = factory->NewScript(source); 5740 i::Handle<i::Script> script = factory->NewScript(source);
5737 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 5741 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
5738 i::ParseInfo info(&zone, script); 5742 i::ParseInfo info(&zone, script);
5739 i::Parser parser(&info);
5740 info.set_module(); 5743 info.set_module();
5741 if (!parser.Parse(&info)) { 5744 if (!i::parsing::ParseProgram(&info)) {
5742 i::Handle<i::JSObject> exception_handle( 5745 i::Handle<i::JSObject> exception_handle(
5743 i::JSObject::cast(isolate->pending_exception())); 5746 i::JSObject::cast(isolate->pending_exception()));
5744 i::Handle<i::String> message_string = i::Handle<i::String>::cast( 5747 i::Handle<i::String> message_string = i::Handle<i::String>::cast(
5745 i::JSReceiver::GetProperty(isolate, exception_handle, "message") 5748 i::JSReceiver::GetProperty(isolate, exception_handle, "message")
5746 .ToHandleChecked()); 5749 .ToHandleChecked());
5747 isolate->clear_pending_exception(); 5750 isolate->clear_pending_exception();
5748 5751
5749 v8::base::OS::Print( 5752 v8::base::OS::Print(
5750 "Parser failed on:\n" 5753 "Parser failed on:\n"
5751 "\t%s\n" 5754 "\t%s\n"
5752 "with error:\n" 5755 "with error:\n"
5753 "\t%s\n" 5756 "\t%s\n"
5754 "However, we expected no error.", 5757 "However, we expected no error.",
5755 source->ToCString().get(), message_string->ToCString().get()); 5758 source->ToCString().get(), message_string->ToCString().get());
5756 CHECK(false); 5759 CHECK(false);
5757 } 5760 }
5758 } 5761 }
5759 5762
5760 // And that parsing a script does not. 5763 // And that parsing a script does not.
5761 { 5764 {
5762 i::Handle<i::Script> script = factory->NewScript(source); 5765 i::Handle<i::Script> script = factory->NewScript(source);
5763 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 5766 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
5764 i::ParseInfo info(&zone, script); 5767 i::ParseInfo info(&zone, script);
5765 i::Parser parser(&info); 5768 CHECK(!i::parsing::ParseProgram(&info));
5766 CHECK(!parser.Parse(&info));
5767 isolate->clear_pending_exception(); 5769 isolate->clear_pending_exception();
5768 } 5770 }
5769 } 5771 }
5770 } 5772 }
5771 5773
5772 5774
5773 TEST(ImportExportParsingErrors) { 5775 TEST(ImportExportParsingErrors) {
5774 // clang-format off 5776 // clang-format off
5775 const char* kErrorSources[] = { 5777 const char* kErrorSources[] = {
5776 "export {", 5778 "export {",
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
5847 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 5849 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5848 128 * 1024); 5850 128 * 1024);
5849 5851
5850 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { 5852 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) {
5851 i::Handle<i::String> source = 5853 i::Handle<i::String> source =
5852 factory->NewStringFromAsciiChecked(kErrorSources[i]); 5854 factory->NewStringFromAsciiChecked(kErrorSources[i]);
5853 5855
5854 i::Handle<i::Script> script = factory->NewScript(source); 5856 i::Handle<i::Script> script = factory->NewScript(source);
5855 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 5857 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
5856 i::ParseInfo info(&zone, script); 5858 i::ParseInfo info(&zone, script);
5857 i::Parser parser(&info);
5858 info.set_module(); 5859 info.set_module();
5859 CHECK(!parser.Parse(&info)); 5860 CHECK(!i::parsing::ParseProgram(&info));
5860 isolate->clear_pending_exception(); 5861 isolate->clear_pending_exception();
5861 } 5862 }
5862 } 5863 }
5863 5864
5864 TEST(ModuleTopLevelFunctionDecl) { 5865 TEST(ModuleTopLevelFunctionDecl) {
5865 // clang-format off 5866 // clang-format off
5866 const char* kErrorSources[] = { 5867 const char* kErrorSources[] = {
5867 "function f() {} function f() {}", 5868 "function f() {} function f() {}",
5868 "var f; function f() {}", 5869 "var f; function f() {}",
5869 "function f() {} var f;", 5870 "function f() {} var f;",
(...skipping 15 matching lines...) Expand all
5885 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 5886 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5886 128 * 1024); 5887 128 * 1024);
5887 5888
5888 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { 5889 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) {
5889 i::Handle<i::String> source = 5890 i::Handle<i::String> source =
5890 factory->NewStringFromAsciiChecked(kErrorSources[i]); 5891 factory->NewStringFromAsciiChecked(kErrorSources[i]);
5891 5892
5892 i::Handle<i::Script> script = factory->NewScript(source); 5893 i::Handle<i::Script> script = factory->NewScript(source);
5893 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 5894 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
5894 i::ParseInfo info(&zone, script); 5895 i::ParseInfo info(&zone, script);
5895 i::Parser parser(&info);
5896 info.set_module(); 5896 info.set_module();
5897 CHECK(!parser.Parse(&info)); 5897 CHECK(!i::parsing::ParseProgram(&info));
5898 isolate->clear_pending_exception(); 5898 isolate->clear_pending_exception();
5899 } 5899 }
5900 } 5900 }
5901 5901
5902 TEST(ModuleAwaitReserved) { 5902 TEST(ModuleAwaitReserved) {
5903 // clang-format off 5903 // clang-format off
5904 const char* kErrorSources[] = { 5904 const char* kErrorSources[] = {
5905 "await;", 5905 "await;",
5906 "await: ;", 5906 "await: ;",
5907 "var await;", 5907 "var await;",
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
6084 "import {m as mm} from 'm.js';" 6084 "import {m as mm} from 'm.js';"
6085 "import {aa} from 'm.js';" 6085 "import {aa} from 'm.js';"
6086 "export {aa as bb, x};" 6086 "export {aa as bb, x};"
6087 "import * as loo from 'bar.js';" 6087 "import * as loo from 'bar.js';"
6088 "import * as foob from 'bar.js';" 6088 "import * as foob from 'bar.js';"
6089 "export {foob};"; 6089 "export {foob};";
6090 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource); 6090 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource);
6091 i::Handle<i::Script> script = factory->NewScript(source); 6091 i::Handle<i::Script> script = factory->NewScript(source);
6092 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 6092 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
6093 i::ParseInfo info(&zone, script); 6093 i::ParseInfo info(&zone, script);
6094 i::Parser parser(&info);
6095 info.set_module(); 6094 info.set_module();
6096 CHECK(parser.Parse(&info)); 6095 CHECK(i::parsing::ParseProgram(&info));
6097 CHECK(i::Compiler::Analyze(&info)); 6096 CHECK(i::Compiler::Analyze(&info));
6098 i::FunctionLiteral* func = info.literal(); 6097 i::FunctionLiteral* func = info.literal();
6099 i::ModuleScope* module_scope = func->scope()->AsModuleScope(); 6098 i::ModuleScope* module_scope = func->scope()->AsModuleScope();
6100 i::Scope* outer_scope = module_scope->outer_scope(); 6099 i::Scope* outer_scope = module_scope->outer_scope();
6101 CHECK(outer_scope->is_script_scope()); 6100 CHECK(outer_scope->is_script_scope());
6102 CHECK_NULL(outer_scope->outer_scope()); 6101 CHECK_NULL(outer_scope->outer_scope());
6103 CHECK(module_scope->is_module_scope()); 6102 CHECK(module_scope->is_module_scope());
6104 const i::ModuleDescriptor::Entry* entry; 6103 const i::ModuleDescriptor::Entry* entry;
6105 i::Declaration::List* declarations = module_scope->declarations(); 6104 i::Declaration::List* declarations = module_scope->declarations();
6106 CHECK_EQ(13, declarations->LengthForTest()); 6105 CHECK_EQ(13, declarations->LengthForTest());
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
6345 v8::HandleScope handles(CcTest::isolate()); 6344 v8::HandleScope handles(CcTest::isolate());
6346 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); 6345 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
6347 v8::Context::Scope context_scope(context); 6346 v8::Context::Scope context_scope(context);
6348 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 6347 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
6349 128 * 1024); 6348 128 * 1024);
6350 6349
6351 i::Handle<i::Script> script = 6350 i::Handle<i::Script> script =
6352 factory->NewScript(factory->NewStringFromAsciiChecked(source)); 6351 factory->NewScript(factory->NewStringFromAsciiChecked(source));
6353 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 6352 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
6354 i::ParseInfo info(&zone, script); 6353 i::ParseInfo info(&zone, script);
6355 i::Parser parser(&info); 6354 i::parsing::ParseProgram(&info);
6356 parser.Parse(&info);
6357 CHECK(info.literal() != NULL); 6355 CHECK(info.literal() != NULL);
6358 CHECK_EQ(expected_language_mode, info.literal()->language_mode()); 6356 CHECK_EQ(expected_language_mode, info.literal()->language_mode());
6359 } 6357 }
6360 6358
6361 6359
6362 TEST(LanguageModeDirectives) { 6360 TEST(LanguageModeDirectives) {
6363 TestLanguageMode("\"use nothing\"", i::SLOPPY); 6361 TestLanguageMode("\"use nothing\"", i::SLOPPY);
6364 TestLanguageMode("\"use strict\"", i::STRICT); 6362 TestLanguageMode("\"use strict\"", i::STRICT);
6365 6363
6366 TestLanguageMode("var x = 1; \"use strict\"", i::SLOPPY); 6364 TestLanguageMode("var x = 1; \"use strict\"", i::SLOPPY);
(...skipping 2031 matching lines...) Expand 10 before | Expand all | Expand 10 after
8398 const char* data[] = { 8396 const char* data[] = {
8399 "const arguments = 1", 8397 "const arguments = 1",
8400 "let arguments", 8398 "let arguments",
8401 "var arguments", 8399 "var arguments",
8402 NULL 8400 NULL
8403 }; 8401 };
8404 // clang-format on 8402 // clang-format on
8405 RunParserSyncTest(context_data, data, kSuccess); 8403 RunParserSyncTest(context_data, data, kSuccess);
8406 } 8404 }
8407 } 8405 }
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-loop-assignment-analysis.cc ('k') | test/fuzzer/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698