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

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

Issue 1002673002: Remove funky 2-stage initialization of ParserInfo and an adventurous memset. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Removed TODOs Created 5 years, 9 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/compiler/test-loop-assignment-analysis.cc ('k') | tools/parser-shell.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 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 i::StrLength(surroundings[j].suffix) + 1039 i::StrLength(surroundings[j].suffix) +
1040 i::StrLength(source_data[i].body); 1040 i::StrLength(source_data[i].body);
1041 i::ScopedVector<char> program(kProgramByteSize + 1); 1041 i::ScopedVector<char> program(kProgramByteSize + 1);
1042 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix, 1042 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix,
1043 source_data[i].body, surroundings[j].suffix); 1043 source_data[i].body, surroundings[j].suffix);
1044 i::Handle<i::String> source = 1044 i::Handle<i::String> source =
1045 factory->NewStringFromUtf8(i::CStrVector(program.start())) 1045 factory->NewStringFromUtf8(i::CStrVector(program.start()))
1046 .ToHandleChecked(); 1046 .ToHandleChecked();
1047 i::Handle<i::Script> script = factory->NewScript(source); 1047 i::Handle<i::Script> script = factory->NewScript(source);
1048 i::Zone zone; 1048 i::Zone zone;
1049 i::ParseInfo info(&zone); 1049 i::ParseInfo info(&zone, script);
1050 info.InitializeFromScript(script);
1051 i::Parser parser(&info); 1050 i::Parser parser(&info);
1052 parser.set_allow_harmony_arrow_functions(true); 1051 parser.set_allow_harmony_arrow_functions(true);
1053 parser.set_allow_harmony_classes(true); 1052 parser.set_allow_harmony_classes(true);
1054 parser.set_allow_harmony_object_literals(true); 1053 parser.set_allow_harmony_object_literals(true);
1055 parser.set_allow_harmony_scoping(true); 1054 parser.set_allow_harmony_scoping(true);
1056 parser.set_allow_harmony_sloppy(true); 1055 parser.set_allow_harmony_sloppy(true);
1057 info.set_global(); 1056 info.set_global();
1058 CHECK(parser.Parse(&info)); 1057 CHECK(parser.Parse(&info));
1059 CHECK(i::Rewriter::Rewrite(&info)); 1058 CHECK(i::Rewriter::Rewrite(&info));
1060 CHECK(i::Scope::Analyze(&info)); 1059 CHECK(i::Scope::Analyze(&info));
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 source_data[i].outer_prefix, 1291 source_data[i].outer_prefix,
1293 source_data[i].inner_source, 1292 source_data[i].inner_source,
1294 source_data[i].outer_suffix); 1293 source_data[i].outer_suffix);
1295 1294
1296 // Parse program source. 1295 // Parse program source.
1297 i::Handle<i::String> source = factory->NewStringFromUtf8( 1296 i::Handle<i::String> source = factory->NewStringFromUtf8(
1298 i::CStrVector(program.start())).ToHandleChecked(); 1297 i::CStrVector(program.start())).ToHandleChecked();
1299 CHECK_EQ(source->length(), kProgramSize); 1298 CHECK_EQ(source->length(), kProgramSize);
1300 i::Handle<i::Script> script = factory->NewScript(source); 1299 i::Handle<i::Script> script = factory->NewScript(source);
1301 i::Zone zone; 1300 i::Zone zone;
1302 i::ParseInfo info(&zone); 1301 i::ParseInfo info(&zone, script);
1303 info.InitializeFromScript(script);
1304 i::Parser parser(&info); 1302 i::Parser parser(&info);
1305 parser.set_allow_lazy(true); 1303 parser.set_allow_lazy(true);
1306 parser.set_allow_harmony_scoping(true); 1304 parser.set_allow_harmony_scoping(true);
1307 parser.set_allow_harmony_arrow_functions(true); 1305 parser.set_allow_harmony_arrow_functions(true);
1308 info.set_global(); 1306 info.set_global();
1309 info.set_language_mode(source_data[i].language_mode); 1307 info.set_language_mode(source_data[i].language_mode);
1310 parser.Parse(&info); 1308 parser.Parse(&info);
1311 CHECK(info.function() != NULL); 1309 CHECK(info.function() != NULL);
1312 1310
1313 // Check scope types and positions. 1311 // Check scope types and positions.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 1450 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
1453 } 1451 }
1454 1452
1455 bool preparse_error = log.HasError(); 1453 bool preparse_error = log.HasError();
1456 1454
1457 // Parse the data 1455 // Parse the data
1458 i::FunctionLiteral* function; 1456 i::FunctionLiteral* function;
1459 { 1457 {
1460 i::Handle<i::Script> script = factory->NewScript(source); 1458 i::Handle<i::Script> script = factory->NewScript(source);
1461 i::Zone zone; 1459 i::Zone zone;
1462 i::ParseInfo info(&zone); 1460 i::ParseInfo info(&zone, script);
1463 info.InitializeFromScript(script);
1464 i::Parser parser(&info); 1461 i::Parser parser(&info);
1465 SetParserFlags(&parser, flags); 1462 SetParserFlags(&parser, flags);
1466 info.set_global(); 1463 info.set_global();
1467 parser.Parse(&info); 1464 parser.Parse(&info);
1468 function = info.function(); 1465 function = info.function();
1469 if (function) { 1466 if (function) {
1470 parser_materialized_literals = function->materialized_literal_count(); 1467 parser_materialized_literals = function->materialized_literal_count();
1471 } 1468 }
1472 } 1469 }
1473 1470
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after
2541 {NULL, 0} 2538 {NULL, 0}
2542 }; 2539 };
2543 2540
2544 for (int i = 0; test_cases[i].program; i++) { 2541 for (int i = 0; test_cases[i].program; i++) {
2545 const char* program = test_cases[i].program; 2542 const char* program = test_cases[i].program;
2546 i::Factory* factory = CcTest::i_isolate()->factory(); 2543 i::Factory* factory = CcTest::i_isolate()->factory();
2547 i::Handle<i::String> source = 2544 i::Handle<i::String> source =
2548 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); 2545 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked();
2549 i::Handle<i::Script> script = factory->NewScript(source); 2546 i::Handle<i::Script> script = factory->NewScript(source);
2550 i::Zone zone; 2547 i::Zone zone;
2551 i::ParseInfo info(&zone); 2548 i::ParseInfo info(&zone, script);
2552 info.InitializeFromScript(script);
2553 i::ScriptData* sd = NULL; 2549 i::ScriptData* sd = NULL;
2554 info.set_cached_data(&sd); 2550 info.set_cached_data(&sd);
2555 info.set_compile_options(v8::ScriptCompiler::kProduceParserCache); 2551 info.set_compile_options(v8::ScriptCompiler::kProduceParserCache);
2556 info.set_allow_lazy_parsing(); 2552 info.set_allow_lazy_parsing();
2557 i::Parser::ParseStatic(&info); 2553 i::Parser::ParseStatic(&info);
2558 i::ParseData* pd = i::ParseData::FromCachedData(sd); 2554 i::ParseData* pd = i::ParseData::FromCachedData(sd);
2559 2555
2560 if (pd->FunctionCount() != test_cases[i].functions) { 2556 if (pd->FunctionCount() != test_cases[i].functions) {
2561 v8::base::OS::Print( 2557 v8::base::OS::Print(
2562 "Expected preparse data for program:\n" 2558 "Expected preparse data for program:\n"
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after
3368 3364
3369 i::SNPrintF(program, "%s%s%s%s%s%s%s", prefix, outer_comment, outer, 3365 i::SNPrintF(program, "%s%s%s%s%s%s%s", prefix, outer_comment, outer,
3370 midfix, inner_comment, inner, suffix); 3366 midfix, inner_comment, inner, suffix);
3371 i::Handle<i::String> source = 3367 i::Handle<i::String> source =
3372 factory->InternalizeUtf8String(program.start()); 3368 factory->InternalizeUtf8String(program.start());
3373 source->PrintOn(stdout); 3369 source->PrintOn(stdout);
3374 printf("\n"); 3370 printf("\n");
3375 3371
3376 i::Handle<i::Script> script = factory->NewScript(source); 3372 i::Handle<i::Script> script = factory->NewScript(source);
3377 i::Zone zone; 3373 i::Zone zone;
3378 i::ParseInfo info(&zone); 3374 i::ParseInfo info(&zone, script);
3379 info.InitializeFromScript(script);
3380 i::Parser parser(&info); 3375 i::Parser parser(&info);
3381 parser.set_allow_harmony_scoping(true); 3376 parser.set_allow_harmony_scoping(true);
3382 CHECK(parser.Parse(&info)); 3377 CHECK(parser.Parse(&info));
3383 CHECK(i::Compiler::Analyze(&info)); 3378 CHECK(i::Compiler::Analyze(&info));
3384 CHECK(info.function() != NULL); 3379 CHECK(info.function() != NULL);
3385 3380
3386 i::Scope* scope = info.function()->scope(); 3381 i::Scope* scope = info.function()->scope();
3387 CHECK_EQ(scope->inner_scopes()->length(), 1); 3382 CHECK_EQ(scope->inner_scopes()->length(), 1);
3388 i::Scope* inner_scope = scope->inner_scopes()->at(0); 3383 i::Scope* inner_scope = scope->inner_scopes()->at(0);
3389 const i::AstRawString* var_name = 3384 const i::AstRawString* var_name =
(...skipping 1689 matching lines...) Expand 10 before | Expand all | Expand 10 after
5079 128 * 1024); 5074 128 * 1024);
5080 5075
5081 for (unsigned i = 0; i < arraysize(kSources); ++i) { 5076 for (unsigned i = 0; i < arraysize(kSources); ++i) {
5082 i::Handle<i::String> source = 5077 i::Handle<i::String> source =
5083 factory->NewStringFromAsciiChecked(kSources[i]); 5078 factory->NewStringFromAsciiChecked(kSources[i]);
5084 5079
5085 // Show that parsing as a module works 5080 // Show that parsing as a module works
5086 { 5081 {
5087 i::Handle<i::Script> script = factory->NewScript(source); 5082 i::Handle<i::Script> script = factory->NewScript(source);
5088 i::Zone zone; 5083 i::Zone zone;
5089 i::ParseInfo info(&zone); 5084 i::ParseInfo info(&zone, script);
5090 info.InitializeFromScript(script);
5091 i::Parser parser(&info); 5085 i::Parser parser(&info);
5092 parser.set_allow_harmony_classes(true); 5086 parser.set_allow_harmony_classes(true);
5093 parser.set_allow_harmony_modules(true); 5087 parser.set_allow_harmony_modules(true);
5094 parser.set_allow_harmony_scoping(true); 5088 parser.set_allow_harmony_scoping(true);
5095 info.set_module(); 5089 info.set_module();
5096 if (!parser.Parse(&info)) { 5090 if (!parser.Parse(&info)) {
5097 i::Handle<i::JSObject> exception_handle( 5091 i::Handle<i::JSObject> exception_handle(
5098 i::JSObject::cast(isolate->pending_exception())); 5092 i::JSObject::cast(isolate->pending_exception()));
5099 i::Handle<i::String> message_string = 5093 i::Handle<i::String> message_string =
5100 i::Handle<i::String>::cast(i::Object::GetProperty( 5094 i::Handle<i::String>::cast(i::Object::GetProperty(
5101 isolate, exception_handle, "message").ToHandleChecked()); 5095 isolate, exception_handle, "message").ToHandleChecked());
5102 5096
5103 v8::base::OS::Print( 5097 v8::base::OS::Print(
5104 "Parser failed on:\n" 5098 "Parser failed on:\n"
5105 "\t%s\n" 5099 "\t%s\n"
5106 "with error:\n" 5100 "with error:\n"
5107 "\t%s\n" 5101 "\t%s\n"
5108 "However, we expected no error.", 5102 "However, we expected no error.",
5109 source->ToCString().get(), message_string->ToCString().get()); 5103 source->ToCString().get(), message_string->ToCString().get());
5110 CHECK(false); 5104 CHECK(false);
5111 } 5105 }
5112 } 5106 }
5113 5107
5114 // And that parsing a script does not. 5108 // And that parsing a script does not.
5115 { 5109 {
5116 i::Handle<i::Script> script = factory->NewScript(source); 5110 i::Handle<i::Script> script = factory->NewScript(source);
5117 i::Zone zone; 5111 i::Zone zone;
5118 i::ParseInfo info(&zone); 5112 i::ParseInfo info(&zone, script);
5119 info.InitializeFromScript(script);
5120 i::Parser parser(&info); 5113 i::Parser parser(&info);
5121 parser.set_allow_harmony_classes(true); 5114 parser.set_allow_harmony_classes(true);
5122 parser.set_allow_harmony_modules(true); 5115 parser.set_allow_harmony_modules(true);
5123 parser.set_allow_harmony_scoping(true); 5116 parser.set_allow_harmony_scoping(true);
5124 info.set_global(); 5117 info.set_global();
5125 CHECK(!parser.Parse(&info)); 5118 CHECK(!parser.Parse(&info));
5126 } 5119 }
5127 } 5120 }
5128 } 5121 }
5129 5122
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
5200 5193
5201 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 5194 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5202 128 * 1024); 5195 128 * 1024);
5203 5196
5204 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) { 5197 for (unsigned i = 0; i < arraysize(kErrorSources); ++i) {
5205 i::Handle<i::String> source = 5198 i::Handle<i::String> source =
5206 factory->NewStringFromAsciiChecked(kErrorSources[i]); 5199 factory->NewStringFromAsciiChecked(kErrorSources[i]);
5207 5200
5208 i::Handle<i::Script> script = factory->NewScript(source); 5201 i::Handle<i::Script> script = factory->NewScript(source);
5209 i::Zone zone; 5202 i::Zone zone;
5210 i::ParseInfo info(&zone); 5203 i::ParseInfo info(&zone, script);
5211 info.InitializeFromScript(script);
5212 i::Parser parser(&info); 5204 i::Parser parser(&info);
5213 parser.set_allow_harmony_classes(true); 5205 parser.set_allow_harmony_classes(true);
5214 parser.set_allow_harmony_modules(true); 5206 parser.set_allow_harmony_modules(true);
5215 parser.set_allow_harmony_scoping(true); 5207 parser.set_allow_harmony_scoping(true);
5216 info.set_module(); 5208 info.set_module();
5217 CHECK(!parser.Parse(&info)); 5209 CHECK(!parser.Parse(&info));
5218 } 5210 }
5219 } 5211 }
5220 5212
5221 5213
5222 TEST(ModuleParsingInternals) { 5214 TEST(ModuleParsingInternals) {
5223 i::FLAG_harmony_modules = true; 5215 i::FLAG_harmony_modules = true;
5224 5216
5225 i::Isolate* isolate = CcTest::i_isolate(); 5217 i::Isolate* isolate = CcTest::i_isolate();
5226 i::Factory* factory = isolate->factory(); 5218 i::Factory* factory = isolate->factory();
5227 v8::HandleScope handles(CcTest::isolate()); 5219 v8::HandleScope handles(CcTest::isolate());
5228 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 5220 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
5229 v8::Context::Scope context_scope(context); 5221 v8::Context::Scope context_scope(context);
5230 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 5222 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5231 128 * 1024); 5223 128 * 1024);
5232 5224
5233 static const char kSource[] = 5225 static const char kSource[] =
5234 "let x = 5;" 5226 "let x = 5;"
5235 "export { x as y };" 5227 "export { x as y };"
5236 "import { q as z } from 'm.js';" 5228 "import { q as z } from 'm.js';"
5237 "import n from 'n.js'"; 5229 "import n from 'n.js'";
5238 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource); 5230 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource);
5239 i::Handle<i::Script> script = factory->NewScript(source); 5231 i::Handle<i::Script> script = factory->NewScript(source);
5240 i::Zone zone; 5232 i::Zone zone;
5241 i::ParseInfo info(&zone); 5233 i::ParseInfo info(&zone, script);
5242 info.InitializeFromScript(script);
5243 i::AstValueFactory avf(&zone, isolate->heap()->HashSeed()); 5234 i::AstValueFactory avf(&zone, isolate->heap()->HashSeed());
5244 i::Parser parser(&info); 5235 i::Parser parser(&info);
5245 parser.set_allow_harmony_modules(true); 5236 parser.set_allow_harmony_modules(true);
5246 parser.set_allow_harmony_scoping(true); 5237 parser.set_allow_harmony_scoping(true);
5247 info.set_module(); 5238 info.set_module();
5248 CHECK(parser.Parse(&info)); 5239 CHECK(parser.Parse(&info));
5249 CHECK(i::Compiler::Analyze(&info)); 5240 CHECK(i::Compiler::Analyze(&info));
5250 5241
5251 i::FunctionLiteral* func = info.function(); 5242 i::FunctionLiteral* func = info.function();
5252 i::Scope* module_scope = func->scope(); 5243 i::Scope* module_scope = func->scope();
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
5357 i::Factory* factory = isolate->factory(); 5348 i::Factory* factory = isolate->factory();
5358 v8::HandleScope handles(CcTest::isolate()); 5349 v8::HandleScope handles(CcTest::isolate());
5359 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate()); 5350 v8::Handle<v8::Context> context = v8::Context::New(CcTest::isolate());
5360 v8::Context::Scope context_scope(context); 5351 v8::Context::Scope context_scope(context);
5361 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - 5352 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
5362 128 * 1024); 5353 128 * 1024);
5363 5354
5364 i::Handle<i::Script> script = 5355 i::Handle<i::Script> script =
5365 factory->NewScript(factory->NewStringFromAsciiChecked(source)); 5356 factory->NewScript(factory->NewStringFromAsciiChecked(source));
5366 i::Zone zone; 5357 i::Zone zone;
5367 i::ParseInfo info(&zone); 5358 i::ParseInfo info(&zone, script);
5368 info.InitializeFromScript(script);
5369 i::Parser parser(&info); 5359 i::Parser parser(&info);
5370 parser.set_allow_strong_mode(true); 5360 parser.set_allow_strong_mode(true);
5371 info.set_global(); 5361 info.set_global();
5372 parser.Parse(&info); 5362 parser.Parse(&info);
5373 CHECK(info.function() != NULL); 5363 CHECK(info.function() != NULL);
5374 CHECK_EQ(expected_language_mode, info.function()->language_mode()); 5364 CHECK_EQ(expected_language_mode, info.function()->language_mode());
5375 } 5365 }
5376 5366
5377 5367
5378 TEST(LanguageModeDirectives) { 5368 TEST(LanguageModeDirectives) {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
5587 "(a/*\n*/=> a)(1)", 5577 "(a/*\n*/=> a)(1)",
5588 "((a)\n=> a)(1)", 5578 "((a)\n=> a)(1)",
5589 "((a)/*\n*/=> a)(1)", 5579 "((a)/*\n*/=> a)(1)",
5590 "((a, b)\n=> a + b)(1, 2)", 5580 "((a, b)\n=> a + b)(1, 2)",
5591 "((a, b)/*\n*/=> a + b)(1, 2)", 5581 "((a, b)/*\n*/=> a + b)(1, 2)",
5592 NULL}; 5582 NULL};
5593 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions}; 5583 static const ParserFlag always_flags[] = {kAllowHarmonyArrowFunctions};
5594 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 5584 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
5595 arraysize(always_flags)); 5585 arraysize(always_flags));
5596 } 5586 }
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-loop-assignment-analysis.cc ('k') | tools/parser-shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698