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

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

Issue 2683733002: Revert of Reland: [Parse] ParseInfo owns the parsing Zone. (Closed)
Patch Set: Created 3 years, 10 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 | « test/cctest/parsing/test-preparser.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 786 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 int kProgramByteSize = i::StrLength(surroundings[j].prefix) + 797 int kProgramByteSize = i::StrLength(surroundings[j].prefix) +
798 i::StrLength(surroundings[j].suffix) + 798 i::StrLength(surroundings[j].suffix) +
799 i::StrLength(source_data[i].body); 799 i::StrLength(source_data[i].body);
800 i::ScopedVector<char> program(kProgramByteSize + 1); 800 i::ScopedVector<char> program(kProgramByteSize + 1);
801 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix, 801 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix,
802 source_data[i].body, surroundings[j].suffix); 802 source_data[i].body, surroundings[j].suffix);
803 i::Handle<i::String> source = 803 i::Handle<i::String> source =
804 factory->NewStringFromUtf8(i::CStrVector(program.start())) 804 factory->NewStringFromUtf8(i::CStrVector(program.start()))
805 .ToHandleChecked(); 805 .ToHandleChecked();
806 i::Handle<i::Script> script = factory->NewScript(source); 806 i::Handle<i::Script> script = factory->NewScript(source);
807 i::ParseInfo info(script); 807 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
808 i::ParseInfo info(&zone, script);
808 // The information we're checking is only produced when eager parsing. 809 // The information we're checking is only produced when eager parsing.
809 info.set_allow_lazy_parsing(false); 810 info.set_allow_lazy_parsing(false);
810 CHECK(i::parsing::ParseProgram(&info)); 811 CHECK(i::parsing::ParseProgram(&info));
811 CHECK(i::Rewriter::Rewrite(&info)); 812 CHECK(i::Rewriter::Rewrite(&info));
812 i::DeclarationScope::Analyze(&info, i::AnalyzeMode::kRegular); 813 i::DeclarationScope::Analyze(&info, i::AnalyzeMode::kRegular);
813 CHECK(info.literal() != NULL); 814 CHECK(info.literal() != NULL);
814 815
815 i::DeclarationScope* script_scope = info.literal()->scope(); 816 i::DeclarationScope* script_scope = info.literal()->scope();
816 CHECK(script_scope->is_script_scope()); 817 CHECK(script_scope->is_script_scope());
817 818
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 std::string full_source = "function f() { return "; 854 std::string full_source = "function f() { return ";
854 full_source += source; 855 full_source += source;
855 full_source += "; }"; 856 full_source += "; }";
856 857
857 i::Handle<i::String> source_code = 858 i::Handle<i::String> source_code =
858 factory->NewStringFromUtf8(i::CStrVector(full_source.c_str())) 859 factory->NewStringFromUtf8(i::CStrVector(full_source.c_str()))
859 .ToHandleChecked(); 860 .ToHandleChecked();
860 861
861 i::Handle<i::Script> script = factory->NewScript(source_code); 862 i::Handle<i::Script> script = factory->NewScript(source_code);
862 863
863 i::ParseInfo info(script); 864 i::ParseInfo info(handles.main_zone(), script);
864 i::Parser parser(&info); 865 i::Parser parser(&info);
865 info.set_allow_lazy_parsing(false); 866 info.set_allow_lazy_parsing(false);
866 info.set_toplevel(true); 867 info.set_toplevel(true);
867 868
868 CHECK(i::Compiler::ParseAndAnalyze(&info)); 869 CHECK(i::Compiler::ParseAndAnalyze(&info));
869 870
870 CHECK_EQ(1, info.scope()->declarations()->LengthForTest()); 871 CHECK_EQ(1, info.scope()->declarations()->LengthForTest());
871 i::Declaration* decl = info.scope()->declarations()->AtForTest(0); 872 i::Declaration* decl = info.scope()->declarations()->AtForTest(0);
872 i::FunctionLiteral* fun = decl->AsFunctionDeclaration()->fun(); 873 i::FunctionLiteral* fun = decl->AsFunctionDeclaration()->fun();
873 CHECK(fun->body()->length() == 1); 874 CHECK(fun->body()->length() == 1);
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 i::SNPrintF(program, "%s%s%s", 1152 i::SNPrintF(program, "%s%s%s",
1152 source_data[i].outer_prefix, 1153 source_data[i].outer_prefix,
1153 source_data[i].inner_source, 1154 source_data[i].inner_source,
1154 source_data[i].outer_suffix); 1155 source_data[i].outer_suffix);
1155 1156
1156 // Parse program source. 1157 // Parse program source.
1157 i::Handle<i::String> source = factory->NewStringFromUtf8( 1158 i::Handle<i::String> source = factory->NewStringFromUtf8(
1158 i::CStrVector(program.start())).ToHandleChecked(); 1159 i::CStrVector(program.start())).ToHandleChecked();
1159 CHECK_EQ(source->length(), kProgramSize); 1160 CHECK_EQ(source->length(), kProgramSize);
1160 i::Handle<i::Script> script = factory->NewScript(source); 1161 i::Handle<i::Script> script = factory->NewScript(source);
1161 i::ParseInfo info(script); 1162 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
1163 i::ParseInfo info(&zone, script);
1162 info.set_language_mode(source_data[i].language_mode); 1164 info.set_language_mode(source_data[i].language_mode);
1163 i::parsing::ParseProgram(&info); 1165 i::parsing::ParseProgram(&info);
1164 CHECK_NOT_NULL(info.literal()); 1166 CHECK_NOT_NULL(info.literal());
1165 1167
1166 // Check scope types and positions. 1168 // Check scope types and positions.
1167 i::Scope* scope = info.literal()->scope(); 1169 i::Scope* scope = info.literal()->scope();
1168 CHECK(scope->is_script_scope()); 1170 CHECK(scope->is_script_scope());
1169 CHECK_EQ(scope->start_position(), 0); 1171 CHECK_EQ(scope->start_position(), 0);
1170 CHECK_EQ(scope->end_position(), kProgramSize); 1172 CHECK_EQ(scope->end_position(), kProgramSize);
1171 1173
(...skipping 25 matching lines...) Expand all
1197 i::Isolate* isolate = CcTest::i_isolate(); 1199 i::Isolate* isolate = CcTest::i_isolate();
1198 i::Factory* factory = isolate->factory(); 1200 i::Factory* factory = isolate->factory();
1199 v8::HandleScope handles(CcTest::isolate()); 1201 v8::HandleScope handles(CcTest::isolate());
1200 i::FunctionLiteral* function; 1202 i::FunctionLiteral* function;
1201 1203
1202 for (int i = 0; discard_sources[i]; i++) { 1204 for (int i = 0; discard_sources[i]; i++) {
1203 const char* source = discard_sources[i]; 1205 const char* source = discard_sources[i];
1204 i::Handle<i::String> source_code = 1206 i::Handle<i::String> source_code =
1205 factory->NewStringFromUtf8(i::CStrVector(source)).ToHandleChecked(); 1207 factory->NewStringFromUtf8(i::CStrVector(source)).ToHandleChecked();
1206 i::Handle<i::Script> script = factory->NewScript(source_code); 1208 i::Handle<i::Script> script = factory->NewScript(source_code);
1207 i::ParseInfo info(script); 1209 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
1210 i::ParseInfo info(&zone, script);
1208 i::parsing::ParseProgram(&info); 1211 i::parsing::ParseProgram(&info);
1209 function = info.literal(); 1212 function = info.literal();
1210 CHECK_NOT_NULL(function); 1213 CHECK_NOT_NULL(function);
1211 CHECK_NOT_NULL(function->body()); 1214 CHECK_NOT_NULL(function->body());
1212 CHECK_EQ(1, function->body()->length()); 1215 CHECK_EQ(1, function->body()->length());
1213 i::FunctionLiteral* inner = 1216 i::FunctionLiteral* inner =
1214 function->body()->first()->AsExpressionStatement()->expression()-> 1217 function->body()->first()->AsExpressionStatement()->expression()->
1215 AsCall()->expression()->AsFunctionLiteral(); 1218 AsCall()->expression()->AsFunctionLiteral();
1216 i::Scope* inner_scope = inner->scope(); 1219 i::Scope* inner_scope = inner->scope();
1217 i::FunctionLiteral* fun = nullptr; 1220 i::FunctionLiteral* fun = nullptr;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 scanner.Initialize(stream.get()); 1330 scanner.Initialize(stream.get());
1328 i::PreParser::PreParseResult result = 1331 i::PreParser::PreParseResult result =
1329 preparser.PreParseProgram(&preparser_materialized_literals, is_module); 1332 preparser.PreParseProgram(&preparser_materialized_literals, is_module);
1330 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 1333 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
1331 } 1334 }
1332 1335
1333 // Parse the data 1336 // Parse the data
1334 i::FunctionLiteral* function; 1337 i::FunctionLiteral* function;
1335 { 1338 {
1336 i::Handle<i::Script> script = factory->NewScript(source); 1339 i::Handle<i::Script> script = factory->NewScript(source);
1337 i::ParseInfo info(script); 1340 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
1341 i::ParseInfo info(&zone, script);
1338 info.set_allow_lazy_parsing(flags.Contains(kAllowLazy)); 1342 info.set_allow_lazy_parsing(flags.Contains(kAllowLazy));
1339 SetGlobalFlags(flags); 1343 SetGlobalFlags(flags);
1340 if (is_module) info.set_module(); 1344 if (is_module) info.set_module();
1341 i::parsing::ParseProgram(&info); 1345 i::parsing::ParseProgram(&info);
1342 function = info.literal(); 1346 function = info.literal();
1343 if (function) { 1347 if (function) {
1344 parser_materialized_literals = function->materialized_literal_count(); 1348 parser_materialized_literals = function->materialized_literal_count();
1345 } 1349 }
1346 } 1350 }
1347 1351
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after
2454 {"function lazy() { var x = {get foo(){} } }", 1}, 2458 {"function lazy() { var x = {get foo(){} } }", 1},
2455 {NULL, 0} 2459 {NULL, 0}
2456 }; 2460 };
2457 2461
2458 for (int i = 0; test_cases[i].program; i++) { 2462 for (int i = 0; test_cases[i].program; i++) {
2459 const char* program = test_cases[i].program; 2463 const char* program = test_cases[i].program;
2460 i::Factory* factory = CcTest::i_isolate()->factory(); 2464 i::Factory* factory = CcTest::i_isolate()->factory();
2461 i::Handle<i::String> source = 2465 i::Handle<i::String> source =
2462 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); 2466 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked();
2463 i::Handle<i::Script> script = factory->NewScript(source); 2467 i::Handle<i::Script> script = factory->NewScript(source);
2464 i::ParseInfo info(script); 2468 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
2469 i::ParseInfo info(&zone, script);
2465 i::ScriptData* sd = NULL; 2470 i::ScriptData* sd = NULL;
2466 info.set_cached_data(&sd); 2471 info.set_cached_data(&sd);
2467 info.set_compile_options(v8::ScriptCompiler::kProduceParserCache); 2472 info.set_compile_options(v8::ScriptCompiler::kProduceParserCache);
2468 i::parsing::ParseProgram(&info); 2473 i::parsing::ParseProgram(&info);
2469 i::ParseData* pd = i::ParseData::FromCachedData(sd); 2474 i::ParseData* pd = i::ParseData::FromCachedData(sd);
2470 2475
2471 if (pd->FunctionCount() != test_cases[i].functions) { 2476 if (pd->FunctionCount() != test_cases[i].functions) {
2472 v8::base::OS::Print( 2477 v8::base::OS::Print(
2473 "Expected preparse data for program:\n" 2478 "Expected preparse data for program:\n"
2474 "\t%s\n" 2479 "\t%s\n"
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
3341 if (outers[i].strict && inners[j].with) continue; 3346 if (outers[i].strict && inners[j].with) continue;
3342 const char* inner = inners[j].source; 3347 const char* inner = inners[j].source;
3343 int inner_len = Utf8LengthHelper(inner); 3348 int inner_len = Utf8LengthHelper(inner);
3344 3349
3345 int len = prefix_len + outer_len + midfix_len + inner_len + suffix_len; 3350 int len = prefix_len + outer_len + midfix_len + inner_len + suffix_len;
3346 i::ScopedVector<char> program(len + 1); 3351 i::ScopedVector<char> program(len + 1);
3347 3352
3348 i::SNPrintF(program, "%s%s%s%s%s", prefix, outer, midfix, inner, 3353 i::SNPrintF(program, "%s%s%s%s%s", prefix, outer, midfix, inner,
3349 suffix); 3354 suffix);
3350 3355
3356 i::Zone zone(isolate->allocator(), ZONE_NAME);
3351 std::unique_ptr<i::ParseInfo> info; 3357 std::unique_ptr<i::ParseInfo> info;
3352 if (lazy) { 3358 if (lazy) {
3353 printf("%s\n", program.start()); 3359 printf("%s\n", program.start());
3354 v8::Local<v8::Value> v = CompileRun(program.start()); 3360 v8::Local<v8::Value> v = CompileRun(program.start());
3355 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); 3361 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v);
3356 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); 3362 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o);
3357 i::Handle<i::SharedFunctionInfo> shared = i::handle(f->shared()); 3363 i::Handle<i::SharedFunctionInfo> shared = i::handle(f->shared());
3358 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(shared)); 3364 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, shared));
3359 CHECK(i::parsing::ParseFunction(info.get())); 3365 CHECK(i::parsing::ParseFunction(info.get()));
3360 } else { 3366 } else {
3361 i::Handle<i::String> source = 3367 i::Handle<i::String> source =
3362 factory->InternalizeUtf8String(program.start()); 3368 factory->InternalizeUtf8String(program.start());
3363 source->PrintOn(stdout); 3369 source->PrintOn(stdout);
3364 printf("\n"); 3370 printf("\n");
3365 i::Handle<i::Script> script = factory->NewScript(source); 3371 i::Handle<i::Script> script = factory->NewScript(source);
3366 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(script)); 3372 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, script));
3367 info->set_allow_lazy_parsing(false); 3373 info->set_allow_lazy_parsing(false);
3368 CHECK(i::parsing::ParseProgram(info.get())); 3374 CHECK(i::parsing::ParseProgram(info.get()));
3369 } 3375 }
3370 CHECK(i::Compiler::Analyze(info.get())); 3376 CHECK(i::Compiler::Analyze(info.get()));
3371 CHECK(info->literal() != NULL); 3377 CHECK(info->literal() != NULL);
3372 3378
3373 i::Scope* scope = info->literal()->scope(); 3379 i::Scope* scope = info->literal()->scope();
3374 if (!lazy) { 3380 if (!lazy) {
3375 scope = scope->inner_scope(); 3381 scope = scope->inner_scope();
3376 } 3382 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
3455 3461
3456 const char* suffix = "; f"; 3462 const char* suffix = "; f";
3457 3463
3458 for (unsigned i = 0; i < arraysize(tests); ++i) { 3464 for (unsigned i = 0; i < arraysize(tests); ++i) {
3459 bool assigned = tests[i].arg_assigned; 3465 bool assigned = tests[i].arg_assigned;
3460 const char* source = tests[i].source; 3466 const char* source = tests[i].source;
3461 for (unsigned allow_lazy = 0; allow_lazy < 2; ++allow_lazy) { 3467 for (unsigned allow_lazy = 0; allow_lazy < 2; ++allow_lazy) {
3462 i::ScopedVector<char> program(Utf8LengthHelper(source) + 3468 i::ScopedVector<char> program(Utf8LengthHelper(source) +
3463 Utf8LengthHelper(suffix) + 1); 3469 Utf8LengthHelper(suffix) + 1);
3464 i::SNPrintF(program, "%s%s", source, suffix); 3470 i::SNPrintF(program, "%s%s", source, suffix);
3471 i::Zone zone(isolate->allocator(), ZONE_NAME);
3465 std::unique_ptr<i::ParseInfo> info; 3472 std::unique_ptr<i::ParseInfo> info;
3466 printf("%s\n", program.start()); 3473 printf("%s\n", program.start());
3467 v8::Local<v8::Value> v = CompileRun(program.start()); 3474 v8::Local<v8::Value> v = CompileRun(program.start());
3468 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v); 3475 i::Handle<i::Object> o = v8::Utils::OpenHandle(*v);
3469 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); 3476 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o);
3470 i::Handle<i::SharedFunctionInfo> shared = i::handle(f->shared()); 3477 i::Handle<i::SharedFunctionInfo> shared = i::handle(f->shared());
3471 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(shared)); 3478 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, shared));
3472 info->set_allow_lazy_parsing(allow_lazy); 3479 info->set_allow_lazy_parsing(allow_lazy);
3473 CHECK(i::parsing::ParseFunction(info.get())); 3480 CHECK(i::parsing::ParseFunction(info.get()));
3474 CHECK(i::Compiler::Analyze(info.get())); 3481 CHECK(i::Compiler::Analyze(info.get()));
3475 CHECK_NOT_NULL(info->literal()); 3482 CHECK_NOT_NULL(info->literal());
3476 3483
3477 i::Scope* scope = info->literal()->scope(); 3484 i::Scope* scope = info->literal()->scope();
3478 CHECK(!scope->AsDeclarationScope()->was_lazily_parsed()); 3485 CHECK(!scope->AsDeclarationScope()->was_lazily_parsed());
3479 CHECK_NULL(scope->sibling()); 3486 CHECK_NULL(scope->sibling());
3480 CHECK(scope->is_function_scope()); 3487 CHECK(scope->is_function_scope());
3481 const i::AstRawString* var_name = 3488 const i::AstRawString* var_name =
3482 info->ast_value_factory()->GetOneByteString("arg"); 3489 info->ast_value_factory()->GetOneByteString("arg");
3483 i::Variable* var = scope->Lookup(var_name); 3490 i::Variable* var = scope->Lookup(var_name);
3484 CHECK(var->is_used() || !assigned); 3491 CHECK(var->is_used() || !assigned);
3485 bool is_maybe_assigned = var->maybe_assigned() == i::kMaybeAssigned; 3492 bool is_maybe_assigned = var->maybe_assigned() == i::kMaybeAssigned;
3486 CHECK_EQ(is_maybe_assigned, assigned); 3493 CHECK_EQ(is_maybe_assigned, assigned);
3487 } 3494 }
3488 } 3495 }
3489 } 3496 }
3490 3497
3491 struct Input { 3498 struct Input {
3492 bool assigned; 3499 bool assigned;
3493 std::string source; 3500 std::string source;
3494 std::vector<unsigned> location; // "Directions" to the relevant scope. 3501 std::vector<unsigned> location; // "Directions" to the relevant scope.
3495 }; 3502 };
3496 3503
3497 static void TestMaybeAssigned(Input input, const char* variable, bool module, 3504 static void TestMaybeAssigned(i::Zone* zone, Input input, const char* variable,
3498 bool allow_lazy_parsing) { 3505 bool module, bool allow_lazy_parsing) {
3499 i::Factory* factory = CcTest::i_isolate()->factory(); 3506 i::Factory* factory = CcTest::i_isolate()->factory();
3500 i::Handle<i::String> string = 3507 i::Handle<i::String> string =
3501 factory->InternalizeUtf8String(input.source.c_str()); 3508 factory->InternalizeUtf8String(input.source.c_str());
3502 string->PrintOn(stdout); 3509 string->PrintOn(stdout);
3503 printf("\n"); 3510 printf("\n");
3504 i::Handle<i::Script> script = factory->NewScript(string); 3511 i::Handle<i::Script> script = factory->NewScript(string);
3505 3512
3506 std::unique_ptr<i::ParseInfo> info; 3513 std::unique_ptr<i::ParseInfo> info;
3507 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(script)); 3514 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(zone, script));
3508 info->set_module(module); 3515 info->set_module(module);
3509 info->set_allow_lazy_parsing(allow_lazy_parsing); 3516 info->set_allow_lazy_parsing(allow_lazy_parsing);
3510 3517
3511 CHECK(i::parsing::ParseProgram(info.get())); 3518 CHECK(i::parsing::ParseProgram(info.get()));
3512 CHECK(i::Compiler::Analyze(info.get())); 3519 CHECK(i::Compiler::Analyze(info.get()));
3513 3520
3514 CHECK_NOT_NULL(info->literal()); 3521 CHECK_NOT_NULL(info->literal());
3515 i::Scope* scope = info->literal()->scope(); 3522 i::Scope* scope = info->literal()->scope();
3516 CHECK(!scope->AsDeclarationScope()->was_lazily_parsed()); 3523 CHECK(!scope->AsDeclarationScope()->was_lazily_parsed());
3517 CHECK_NULL(scope->sibling()); 3524 CHECK_NULL(scope->sibling());
(...skipping 28 matching lines...) Expand all
3546 for (auto n : input.location) { 3553 for (auto n : input.location) {
3547 result.location.push_back(n); 3554 result.location.push_back(n);
3548 } 3555 }
3549 return result; 3556 return result;
3550 } 3557 }
3551 3558
3552 TEST(MaybeAssignedInsideLoop) { 3559 TEST(MaybeAssignedInsideLoop) {
3553 i::Isolate* isolate = CcTest::i_isolate(); 3560 i::Isolate* isolate = CcTest::i_isolate();
3554 i::HandleScope scope(isolate); 3561 i::HandleScope scope(isolate);
3555 LocalContext env; 3562 LocalContext env;
3563 i::Zone zone(isolate->allocator(), ZONE_NAME);
3556 3564
3557 std::vector<unsigned> top; // Can't use {} in initializers below. 3565 std::vector<unsigned> top; // Can't use {} in initializers below.
3558 3566
3559 Input module_and_script_tests[] = { 3567 Input module_and_script_tests[] = {
3560 {1, "for (j=x; j<10; ++j) { foo = j }", top}, 3568 {1, "for (j=x; j<10; ++j) { foo = j }", top},
3561 {1, "for (j=x; j<10; ++j) { [foo] = [j] }", top}, 3569 {1, "for (j=x; j<10; ++j) { [foo] = [j] }", top},
3562 {1, "for (j=x; j<10; ++j) { var foo = j }", top}, 3570 {1, "for (j=x; j<10; ++j) { var foo = j }", top},
3563 {1, "for (j=x; j<10; ++j) { var [foo] = [j] }", top}, 3571 {1, "for (j=x; j<10; ++j) { var [foo] = [j] }", top},
3564 {0, "for (j=x; j<10; ++j) { let foo = j }", {0}}, 3572 {0, "for (j=x; j<10; ++j) { let foo = j }", {0}},
3565 {0, "for (j=x; j<10; ++j) { let [foo] = [j] }", {0}}, 3573 {0, "for (j=x; j<10; ++j) { let [foo] = [j] }", {0}},
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
3823 {1, "for (const {j} in x) { function foo() {return j} }", top}, 3831 {1, "for (const {j} in x) { function foo() {return j} }", top},
3824 {1, "while (j) { function foo() {return j} }", top}, 3832 {1, "while (j) { function foo() {return j} }", top},
3825 {1, "do { function foo() {return j} } while (j)", top}, 3833 {1, "do { function foo() {return j} } while (j)", top},
3826 }; 3834 };
3827 3835
3828 for (unsigned i = 0; i < arraysize(module_and_script_tests); ++i) { 3836 for (unsigned i = 0; i < arraysize(module_and_script_tests); ++i) {
3829 Input input = module_and_script_tests[i]; 3837 Input input = module_and_script_tests[i];
3830 for (unsigned module = 0; module <= 1; ++module) { 3838 for (unsigned module = 0; module <= 1; ++module) {
3831 for (unsigned allow_lazy_parsing = 0; allow_lazy_parsing <= 1; 3839 for (unsigned allow_lazy_parsing = 0; allow_lazy_parsing <= 1;
3832 ++allow_lazy_parsing) { 3840 ++allow_lazy_parsing) {
3833 TestMaybeAssigned(input, "foo", module, allow_lazy_parsing); 3841 TestMaybeAssigned(&zone, input, "foo", module, allow_lazy_parsing);
3834 } 3842 }
3835 TestMaybeAssigned(wrap(input), "foo", module, false); 3843 TestMaybeAssigned(&zone, wrap(input), "foo", module, false);
3836 } 3844 }
3837 } 3845 }
3838 3846
3839 for (unsigned i = 0; i < arraysize(script_only_tests); ++i) { 3847 for (unsigned i = 0; i < arraysize(script_only_tests); ++i) {
3840 Input input = script_only_tests[i]; 3848 Input input = script_only_tests[i];
3841 for (unsigned allow_lazy_parsing = 0; allow_lazy_parsing <= 1; 3849 for (unsigned allow_lazy_parsing = 0; allow_lazy_parsing <= 1;
3842 ++allow_lazy_parsing) { 3850 ++allow_lazy_parsing) {
3843 TestMaybeAssigned(input, "foo", false, allow_lazy_parsing); 3851 TestMaybeAssigned(&zone, input, "foo", false, allow_lazy_parsing);
3844 } 3852 }
3845 TestMaybeAssigned(wrap(input), "foo", false, false); 3853 TestMaybeAssigned(&zone, wrap(input), "foo", false, false);
3846 } 3854 }
3847 } 3855 }
3848 3856
3849 TEST(MaybeAssignedTopLevel) { 3857 TEST(MaybeAssignedTopLevel) {
3850 i::Isolate* isolate = CcTest::i_isolate(); 3858 i::Isolate* isolate = CcTest::i_isolate();
3851 i::HandleScope scope(isolate); 3859 i::HandleScope scope(isolate);
3852 LocalContext env; 3860 LocalContext env;
3853 i::Factory* factory = isolate->factory(); 3861 i::Factory* factory = isolate->factory();
3854 3862
3855 const char* prefixes[] = { 3863 const char* prefixes[] = {
(...skipping 11 matching lines...) Expand all
3867 "function* bar() {eval(ext)}; ext(bar); ext(foo)", 3875 "function* bar() {eval(ext)}; ext(bar); ext(foo)",
3868 }; 3876 };
3869 3877
3870 for (unsigned i = 0; i < arraysize(prefixes); ++i) { 3878 for (unsigned i = 0; i < arraysize(prefixes); ++i) {
3871 const char* prefix = prefixes[i]; 3879 const char* prefix = prefixes[i];
3872 for (unsigned j = 0; j < arraysize(sources); ++j) { 3880 for (unsigned j = 0; j < arraysize(sources); ++j) {
3873 const char* source = sources[j]; 3881 const char* source = sources[j];
3874 i::ScopedVector<char> program(Utf8LengthHelper(prefix) + 3882 i::ScopedVector<char> program(Utf8LengthHelper(prefix) +
3875 Utf8LengthHelper(source) + 1); 3883 Utf8LengthHelper(source) + 1);
3876 i::SNPrintF(program, "%s%s", prefix, source); 3884 i::SNPrintF(program, "%s%s", prefix, source);
3885 i::Zone zone(isolate->allocator(), ZONE_NAME);
3877 3886
3878 i::Handle<i::String> string = 3887 i::Handle<i::String> string =
3879 factory->InternalizeUtf8String(program.start()); 3888 factory->InternalizeUtf8String(program.start());
3880 string->PrintOn(stdout); 3889 string->PrintOn(stdout);
3881 printf("\n"); 3890 printf("\n");
3882 i::Handle<i::Script> script = factory->NewScript(string); 3891 i::Handle<i::Script> script = factory->NewScript(string);
3883 3892
3884 for (unsigned allow_lazy = 0; allow_lazy < 2; ++allow_lazy) { 3893 for (unsigned allow_lazy = 0; allow_lazy < 2; ++allow_lazy) {
3885 for (unsigned module = 0; module < 2; ++module) { 3894 for (unsigned module = 0; module < 2; ++module) {
3886 std::unique_ptr<i::ParseInfo> info; 3895 std::unique_ptr<i::ParseInfo> info;
3887 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(script)); 3896 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, script));
3888 info->set_module(module); 3897 info->set_module(module);
3889 info->set_allow_lazy_parsing(allow_lazy); 3898 info->set_allow_lazy_parsing(allow_lazy);
3890 3899
3891 CHECK(i::parsing::ParseProgram(info.get())); 3900 CHECK(i::parsing::ParseProgram(info.get()));
3892 CHECK(i::Compiler::Analyze(info.get())); 3901 CHECK(i::Compiler::Analyze(info.get()));
3893 3902
3894 CHECK_NOT_NULL(info->literal()); 3903 CHECK_NOT_NULL(info->literal());
3895 i::Scope* scope = info->literal()->scope(); 3904 i::Scope* scope = info->literal()->scope();
3896 CHECK(!scope->AsDeclarationScope()->was_lazily_parsed()); 3905 CHECK(!scope->AsDeclarationScope()->was_lazily_parsed());
3897 CHECK_NULL(scope->sibling()); 3906 CHECK_NULL(scope->sibling());
(...skipping 2432 matching lines...) Expand 10 before | Expand all | Expand 10 after
6330 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 6339 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
6331 128 * 1024); 6340 128 * 1024);
6332 6341
6333 for (unsigned i = 0; i < arraysize(kSources); ++i) { 6342 for (unsigned i = 0; i < arraysize(kSources); ++i) {
6334 i::Handle<i::String> source = 6343 i::Handle<i::String> source =
6335 factory->NewStringFromAsciiChecked(kSources[i]); 6344 factory->NewStringFromAsciiChecked(kSources[i]);
6336 6345
6337 // Show that parsing as a module works 6346 // Show that parsing as a module works
6338 { 6347 {
6339 i::Handle<i::Script> script = factory->NewScript(source); 6348 i::Handle<i::Script> script = factory->NewScript(source);
6340 i::ParseInfo info(script); 6349 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
6350 i::ParseInfo info(&zone, script);
6341 info.set_module(); 6351 info.set_module();
6342 if (!i::parsing::ParseProgram(&info)) { 6352 if (!i::parsing::ParseProgram(&info)) {
6343 i::Handle<i::JSObject> exception_handle( 6353 i::Handle<i::JSObject> exception_handle(
6344 i::JSObject::cast(isolate->pending_exception())); 6354 i::JSObject::cast(isolate->pending_exception()));
6345 i::Handle<i::String> message_string = i::Handle<i::String>::cast( 6355 i::Handle<i::String> message_string = i::Handle<i::String>::cast(
6346 i::JSReceiver::GetProperty(isolate, exception_handle, "message") 6356 i::JSReceiver::GetProperty(isolate, exception_handle, "message")
6347 .ToHandleChecked()); 6357 .ToHandleChecked());
6348 isolate->clear_pending_exception(); 6358 isolate->clear_pending_exception();
6349 6359
6350 v8::base::OS::Print( 6360 v8::base::OS::Print(
6351 "Parser failed on:\n" 6361 "Parser failed on:\n"
6352 "\t%s\n" 6362 "\t%s\n"
6353 "with error:\n" 6363 "with error:\n"
6354 "\t%s\n" 6364 "\t%s\n"
6355 "However, we expected no error.", 6365 "However, we expected no error.",
6356 source->ToCString().get(), message_string->ToCString().get()); 6366 source->ToCString().get(), message_string->ToCString().get());
6357 CHECK(false); 6367 CHECK(false);
6358 } 6368 }
6359 } 6369 }
6360 6370
6361 // And that parsing a script does not. 6371 // And that parsing a script does not.
6362 { 6372 {
6363 i::Handle<i::Script> script = factory->NewScript(source); 6373 i::Handle<i::Script> script = factory->NewScript(source);
6364 i::ParseInfo info(script); 6374 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
6375 i::ParseInfo info(&zone, script);
6365 CHECK(!i::parsing::ParseProgram(&info)); 6376 CHECK(!i::parsing::ParseProgram(&info));
6366 isolate->clear_pending_exception(); 6377 isolate->clear_pending_exception();
6367 } 6378 }
6368 } 6379 }
6369 } 6380 }
6370 6381
6371 6382
6372 TEST(ImportExportParsingErrors) { 6383 TEST(ImportExportParsingErrors) {
6373 // clang-format off 6384 // clang-format off
6374 const char* kErrorSources[] = { 6385 const char* kErrorSources[] = {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
6444 v8::Context::Scope context_scope(context); 6455 v8::Context::Scope context_scope(context);
6445 6456
6446 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 6457 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
6447 128 * 1024); 6458 128 * 1024);
6448 6459
6449 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { 6460 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) {
6450 i::Handle<i::String> source = 6461 i::Handle<i::String> source =
6451 factory->NewStringFromAsciiChecked(kErrorSources[i]); 6462 factory->NewStringFromAsciiChecked(kErrorSources[i]);
6452 6463
6453 i::Handle<i::Script> script = factory->NewScript(source); 6464 i::Handle<i::Script> script = factory->NewScript(source);
6454 i::ParseInfo info(script); 6465 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
6466 i::ParseInfo info(&zone, script);
6455 info.set_module(); 6467 info.set_module();
6456 CHECK(!i::parsing::ParseProgram(&info)); 6468 CHECK(!i::parsing::ParseProgram(&info));
6457 isolate->clear_pending_exception(); 6469 isolate->clear_pending_exception();
6458 } 6470 }
6459 } 6471 }
6460 6472
6461 TEST(ModuleTopLevelFunctionDecl) { 6473 TEST(ModuleTopLevelFunctionDecl) {
6462 // clang-format off 6474 // clang-format off
6463 const char* kErrorSources[] = { 6475 const char* kErrorSources[] = {
6464 "function f() {} function f() {}", 6476 "function f() {} function f() {}",
(...skipping 15 matching lines...) Expand all
6480 v8::Context::Scope context_scope(context); 6492 v8::Context::Scope context_scope(context);
6481 6493
6482 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 6494 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
6483 128 * 1024); 6495 128 * 1024);
6484 6496
6485 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { 6497 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) {
6486 i::Handle<i::String> source = 6498 i::Handle<i::String> source =
6487 factory->NewStringFromAsciiChecked(kErrorSources[i]); 6499 factory->NewStringFromAsciiChecked(kErrorSources[i]);
6488 6500
6489 i::Handle<i::Script> script = factory->NewScript(source); 6501 i::Handle<i::Script> script = factory->NewScript(source);
6490 i::ParseInfo info(script); 6502 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
6503 i::ParseInfo info(&zone, script);
6491 info.set_module(); 6504 info.set_module();
6492 CHECK(!i::parsing::ParseProgram(&info)); 6505 CHECK(!i::parsing::ParseProgram(&info));
6493 isolate->clear_pending_exception(); 6506 isolate->clear_pending_exception();
6494 } 6507 }
6495 } 6508 }
6496 6509
6497 TEST(ModuleAwaitReserved) { 6510 TEST(ModuleAwaitReserved) {
6498 // clang-format off 6511 // clang-format off
6499 const char* kErrorSources[] = { 6512 const char* kErrorSources[] = {
6500 "await;", 6513 "await;",
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
6677 "import 'q.js';" 6690 "import 'q.js';"
6678 "let nonexport = 42;" 6691 "let nonexport = 42;"
6679 "import {m as mm} from 'm.js';" 6692 "import {m as mm} from 'm.js';"
6680 "import {aa} from 'm.js';" 6693 "import {aa} from 'm.js';"
6681 "export {aa as bb, x};" 6694 "export {aa as bb, x};"
6682 "import * as loo from 'bar.js';" 6695 "import * as loo from 'bar.js';"
6683 "import * as foob from 'bar.js';" 6696 "import * as foob from 'bar.js';"
6684 "export {foob};"; 6697 "export {foob};";
6685 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource); 6698 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource);
6686 i::Handle<i::Script> script = factory->NewScript(source); 6699 i::Handle<i::Script> script = factory->NewScript(source);
6687 i::ParseInfo info(script); 6700 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
6701 i::ParseInfo info(&zone, script);
6688 info.set_module(); 6702 info.set_module();
6689 CHECK(i::parsing::ParseProgram(&info)); 6703 CHECK(i::parsing::ParseProgram(&info));
6690 CHECK(i::Compiler::Analyze(&info)); 6704 CHECK(i::Compiler::Analyze(&info));
6691 i::FunctionLiteral* func = info.literal(); 6705 i::FunctionLiteral* func = info.literal();
6692 i::ModuleScope* module_scope = func->scope()->AsModuleScope(); 6706 i::ModuleScope* module_scope = func->scope()->AsModuleScope();
6693 i::Scope* outer_scope = module_scope->outer_scope(); 6707 i::Scope* outer_scope = module_scope->outer_scope();
6694 CHECK(outer_scope->is_script_scope()); 6708 CHECK(outer_scope->is_script_scope());
6695 CHECK_NULL(outer_scope->outer_scope()); 6709 CHECK_NULL(outer_scope->outer_scope());
6696 CHECK(module_scope->is_module_scope()); 6710 CHECK(module_scope->is_module_scope());
6697 const i::ModuleDescriptor::Entry* entry; 6711 const i::ModuleDescriptor::Entry* entry;
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
6936 i::Isolate* isolate = CcTest::i_isolate(); 6950 i::Isolate* isolate = CcTest::i_isolate();
6937 i::Factory* factory = isolate->factory(); 6951 i::Factory* factory = isolate->factory();
6938 v8::HandleScope handles(CcTest::isolate()); 6952 v8::HandleScope handles(CcTest::isolate());
6939 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate()); 6953 v8::Local<v8::Context> context = v8::Context::New(CcTest::isolate());
6940 v8::Context::Scope context_scope(context); 6954 v8::Context::Scope context_scope(context);
6941 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 6955 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
6942 128 * 1024); 6956 128 * 1024);
6943 6957
6944 i::Handle<i::Script> script = 6958 i::Handle<i::Script> script =
6945 factory->NewScript(factory->NewStringFromAsciiChecked(source)); 6959 factory->NewScript(factory->NewStringFromAsciiChecked(source));
6946 i::ParseInfo info(script); 6960 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
6961 i::ParseInfo info(&zone, script);
6947 i::parsing::ParseProgram(&info); 6962 i::parsing::ParseProgram(&info);
6948 CHECK(info.literal() != NULL); 6963 CHECK(info.literal() != NULL);
6949 CHECK_EQ(expected_language_mode, info.literal()->language_mode()); 6964 CHECK_EQ(expected_language_mode, info.literal()->language_mode());
6950 } 6965 }
6951 6966
6952 6967
6953 TEST(LanguageModeDirectives) { 6968 TEST(LanguageModeDirectives) {
6954 TestLanguageMode("\"use nothing\"", i::SLOPPY); 6969 TestLanguageMode("\"use nothing\"", i::SLOPPY);
6955 TestLanguageMode("\"use strict\"", i::STRICT); 6970 TestLanguageMode("\"use strict\"", i::STRICT);
6956 6971
(...skipping 2453 matching lines...) Expand 10 before | Expand all | Expand 10 after
9410 i::SNPrintF( 9425 i::SNPrintF(
9411 program + prefix_len + inner_function_len + params_len + source_len, 9426 program + prefix_len + inner_function_len + params_len + source_len,
9412 "%s", suffix); 9427 "%s", suffix);
9413 9428
9414 i::Handle<i::String> source = 9429 i::Handle<i::String> source =
9415 factory->InternalizeUtf8String(program.start()); 9430 factory->InternalizeUtf8String(program.start());
9416 source->PrintOn(stdout); 9431 source->PrintOn(stdout);
9417 printf("\n"); 9432 printf("\n");
9418 9433
9419 i::Handle<i::Script> script = factory->NewScript(source); 9434 i::Handle<i::Script> script = factory->NewScript(source);
9420 i::ParseInfo info(script); 9435 i::Zone zone(isolate->allocator(), ZONE_NAME);
9436 i::ParseInfo info(&zone, script);
9421 9437
9422 CHECK(i::parsing::ParseProgram(&info)); 9438 CHECK(i::parsing::ParseProgram(&info));
9423 CHECK(i::Compiler::Analyze(&info)); 9439 CHECK(i::Compiler::Analyze(&info));
9424 CHECK(info.literal() != NULL); 9440 CHECK(info.literal() != NULL);
9425 9441
9426 i::Scope* scope = info.literal()->scope()->inner_scope(); 9442 i::Scope* scope = info.literal()->scope()->inner_scope();
9427 DCHECK_NOT_NULL(scope); 9443 DCHECK_NOT_NULL(scope);
9428 DCHECK_NULL(scope->sibling()); 9444 DCHECK_NULL(scope->sibling());
9429 DCHECK(scope->is_function_scope()); 9445 DCHECK(scope->is_function_scope());
9430 const i::AstRawString* var_name = 9446 const i::AstRawString* var_name =
9431 info.ast_value_factory()->GetOneByteString("my_var"); 9447 info.ast_value_factory()->GetOneByteString("my_var");
9432 i::Variable* var = scope->Lookup(var_name); 9448 i::Variable* var = scope->Lookup(var_name);
9433 CHECK_EQ(inners[i].ctxt_allocate, 9449 CHECK_EQ(inners[i].ctxt_allocate,
9434 i::ScopeTestHelper::MustAllocateInContext(var)); 9450 i::ScopeTestHelper::MustAllocateInContext(var));
9435 } 9451 }
9436 } 9452 }
9437 } 9453 }
OLDNEW
« no previous file with comments | « test/cctest/parsing/test-preparser.cc ('k') | test/fuzzer/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698