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

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

Issue 2513563002: Remove FLAG_min_preparse_length. (Closed)
Patch Set: test262 expectations Created 4 years, 1 month 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/test-api.cc ('k') | test/cctest/test-serialize.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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 " set setter(v) { this.value = v; }};" 244 " set setter(v) { this.value = v; }};"
245 "var f = a => function (b) { return a + b; };" 245 "var f = a => function (b) { return a + b; };"
246 "var g = a => b => a + b;"; 246 "var g = a => b => a + b;";
247 int source_length = i::StrLength(source); 247 int source_length = i::StrLength(source);
248 248
249 // ScriptResource will be deleted when the corresponding String is GCd. 249 // ScriptResource will be deleted when the corresponding String is GCd.
250 v8::ScriptCompiler::Source script_source( 250 v8::ScriptCompiler::Source script_source(
251 v8::String::NewExternalOneByte(isolate, 251 v8::String::NewExternalOneByte(isolate,
252 new ScriptResource(source, source_length)) 252 new ScriptResource(source, source_length))
253 .ToLocalChecked()); 253 .ToLocalChecked());
254 i::FLAG_min_preparse_length = 0;
255 v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &script_source, 254 v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &script_source,
256 v8::ScriptCompiler::kProduceParserCache) 255 v8::ScriptCompiler::kProduceParserCache)
257 .ToLocalChecked(); 256 .ToLocalChecked();
258 CHECK(script_source.GetCachedData()); 257 CHECK(script_source.GetCachedData());
259 258
260 // Compile the script again, using the cached data. 259 // Compile the script again, using the cached data.
261 bool lazy_flag = i::FLAG_lazy; 260 bool lazy_flag = i::FLAG_lazy;
262 i::FLAG_lazy = true; 261 i::FLAG_lazy = true;
263 v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &script_source, 262 v8::ScriptCompiler::Compile(isolate->GetCurrentContext(), &script_source,
264 v8::ScriptCompiler::kConsumeParserCache) 263 v8::ScriptCompiler::kConsumeParserCache)
265 .ToLocalChecked(); 264 .ToLocalChecked();
266 i::FLAG_lazy = false; 265 i::FLAG_lazy = false;
267 v8::ScriptCompiler::CompileUnboundScript( 266 v8::ScriptCompiler::CompileUnboundScript(
268 isolate, &script_source, v8::ScriptCompiler::kConsumeParserCache) 267 isolate, &script_source, v8::ScriptCompiler::kConsumeParserCache)
269 .ToLocalChecked(); 268 .ToLocalChecked();
270 i::FLAG_lazy = lazy_flag; 269 i::FLAG_lazy = lazy_flag;
271 } 270 }
272 271
273 272
274 TEST(PreparseFunctionDataIsUsed) { 273 TEST(PreparseFunctionDataIsUsed) {
275 // Producing cached parser data while parsing eagerly is not supported. 274 // Producing cached parser data while parsing eagerly is not supported.
276 if (!i::FLAG_lazy) return; 275 if (!i::FLAG_lazy) return;
277 276
278 // This tests that we actually do use the function data generated by the 277 // This tests that we actually do use the function data generated by the
279 // preparser. 278 // preparser.
280 279
281 // Make preparsing work for short scripts.
282 i::FLAG_min_preparse_length = 0;
283
284 v8::Isolate* isolate = CcTest::isolate(); 280 v8::Isolate* isolate = CcTest::isolate();
285 v8::HandleScope handles(isolate); 281 v8::HandleScope handles(isolate);
286 v8::Local<v8::Context> context = v8::Context::New(isolate); 282 v8::Local<v8::Context> context = v8::Context::New(isolate);
287 v8::Context::Scope context_scope(context); 283 v8::Context::Scope context_scope(context);
288 CcTest::i_isolate()->stack_guard()->SetStackLimit( 284 CcTest::i_isolate()->stack_guard()->SetStackLimit(
289 i::GetCurrentStackPosition() - 128 * 1024); 285 i::GetCurrentStackPosition() - 128 * 1024);
290 286
291 const char* good_code[] = { 287 const char* good_code[] = {
292 "function z() { var a; } function f() { return 25; } f();", 288 "function z() { var a; } function f() { return 25; } f();",
293 "var z = function () { var a; }; function f() { return 25; } f();", 289 "var z = function () { var a; }; function f() { return 25; } f();",
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 473 i::PreParser::PreParseResult result = preparser.PreParseProgram();
478 // Even in the case of a syntax error, kPreParseSuccess is returned. 474 // Even in the case of a syntax error, kPreParseSuccess is returned.
479 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 475 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
480 CHECK(pending_error_handler.has_pending_error()); 476 CHECK(pending_error_handler.has_pending_error());
481 } 477 }
482 478
483 479
484 TEST(Regress928) { 480 TEST(Regress928) {
485 // Test only applies when lazy parsing. 481 // Test only applies when lazy parsing.
486 if (!i::FLAG_lazy) return; 482 if (!i::FLAG_lazy) return;
487 i::FLAG_min_preparse_length = 0;
488 483
489 // Tests that the first non-toplevel function is not included in the preparse 484 // Tests that the first non-toplevel function is not included in the preparse
490 // data. 485 // data.
491 const char* program = 486 const char* program =
492 "try { } catch (e) { var foo = function () { /* first */ } }" 487 "try { } catch (e) { var foo = function () { /* first */ } }"
493 "var bar = function () { /* second */ }"; 488 "var bar = function () { /* second */ }";
494 489
495 v8::Isolate* isolate = CcTest::isolate(); 490 v8::Isolate* isolate = CcTest::isolate();
496 v8::HandleScope handles(isolate); 491 v8::HandleScope handles(isolate);
497 v8::Local<v8::Context> context = v8::Context::New(isolate); 492 v8::Local<v8::Context> context = v8::Context::New(isolate);
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 i::StrLength(source_data[i].body); 810 i::StrLength(source_data[i].body);
816 i::ScopedVector<char> program(kProgramByteSize + 1); 811 i::ScopedVector<char> program(kProgramByteSize + 1);
817 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix, 812 i::SNPrintF(program, "%s%s%s", surroundings[j].prefix,
818 source_data[i].body, surroundings[j].suffix); 813 source_data[i].body, surroundings[j].suffix);
819 i::Handle<i::String> source = 814 i::Handle<i::String> source =
820 factory->NewStringFromUtf8(i::CStrVector(program.start())) 815 factory->NewStringFromUtf8(i::CStrVector(program.start()))
821 .ToHandleChecked(); 816 .ToHandleChecked();
822 i::Handle<i::Script> script = factory->NewScript(source); 817 i::Handle<i::Script> script = factory->NewScript(source);
823 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 818 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
824 i::ParseInfo info(&zone, script); 819 i::ParseInfo info(&zone, script);
820 // The information we're checking is only produced when eager parsing.
821 info.set_allow_lazy_parsing(false);
825 i::Parser parser(&info); 822 i::Parser parser(&info);
826 CHECK(parser.Parse(&info)); 823 CHECK(parser.Parse(&info));
827 CHECK(i::Rewriter::Rewrite(&info)); 824 CHECK(i::Rewriter::Rewrite(&info));
828 i::DeclarationScope::Analyze(&info, i::AnalyzeMode::kRegular); 825 i::DeclarationScope::Analyze(&info, i::AnalyzeMode::kRegular);
829 CHECK(info.literal() != NULL); 826 CHECK(info.literal() != NULL);
830 827
831 i::DeclarationScope* script_scope = info.literal()->scope(); 828 i::DeclarationScope* script_scope = info.literal()->scope();
832 CHECK(script_scope->is_script_scope()); 829 CHECK(script_scope->is_script_scope());
833 830
834 i::Scope* scope = script_scope->inner_scope(); 831 i::Scope* scope = script_scope->inner_scope();
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 1168
1172 // Parse program source. 1169 // Parse program source.
1173 i::Handle<i::String> source = factory->NewStringFromUtf8( 1170 i::Handle<i::String> source = factory->NewStringFromUtf8(
1174 i::CStrVector(program.start())).ToHandleChecked(); 1171 i::CStrVector(program.start())).ToHandleChecked();
1175 CHECK_EQ(source->length(), kProgramSize); 1172 CHECK_EQ(source->length(), kProgramSize);
1176 i::Handle<i::Script> script = factory->NewScript(source); 1173 i::Handle<i::Script> script = factory->NewScript(source);
1177 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 1174 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
1178 i::ParseInfo info(&zone, script); 1175 i::ParseInfo info(&zone, script);
1179 i::Parser parser(&info); 1176 i::Parser parser(&info);
1180 info.set_language_mode(source_data[i].language_mode); 1177 info.set_language_mode(source_data[i].language_mode);
1181 info.set_allow_lazy_parsing();
1182 parser.Parse(&info); 1178 parser.Parse(&info);
1183 CHECK_NOT_NULL(info.literal()); 1179 CHECK_NOT_NULL(info.literal());
1184 1180
1185 // Check scope types and positions. 1181 // Check scope types and positions.
1186 i::Scope* scope = info.literal()->scope(); 1182 i::Scope* scope = info.literal()->scope();
1187 CHECK(scope->is_script_scope()); 1183 CHECK(scope->is_script_scope());
1188 CHECK_EQ(scope->start_position(), 0); 1184 CHECK_EQ(scope->start_position(), 0);
1189 CHECK_EQ(scope->end_position(), kProgramSize); 1185 CHECK_EQ(scope->end_position(), kProgramSize);
1190 1186
1191 i::Scope* inner_scope = scope->inner_scope(); 1187 i::Scope* inner_scope = scope->inner_scope();
(...skipping 26 matching lines...) Expand all
1218 v8::HandleScope handles(CcTest::isolate()); 1214 v8::HandleScope handles(CcTest::isolate());
1219 i::FunctionLiteral* function; 1215 i::FunctionLiteral* function;
1220 1216
1221 for (int i = 0; discard_sources[i]; i++) { 1217 for (int i = 0; discard_sources[i]; i++) {
1222 const char* source = discard_sources[i]; 1218 const char* source = discard_sources[i];
1223 i::Handle<i::String> source_code = 1219 i::Handle<i::String> source_code =
1224 factory->NewStringFromUtf8(i::CStrVector(source)).ToHandleChecked(); 1220 factory->NewStringFromUtf8(i::CStrVector(source)).ToHandleChecked();
1225 i::Handle<i::Script> script = factory->NewScript(source_code); 1221 i::Handle<i::Script> script = factory->NewScript(source_code);
1226 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 1222 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
1227 i::ParseInfo info(&zone, script); 1223 i::ParseInfo info(&zone, script);
1228 info.set_allow_lazy_parsing();
1229 i::Parser parser(&info); 1224 i::Parser parser(&info);
1230 parser.Parse(&info); 1225 parser.Parse(&info);
1231 function = info.literal(); 1226 function = info.literal();
1232 CHECK_NOT_NULL(function); 1227 CHECK_NOT_NULL(function);
1233 CHECK_NOT_NULL(function->body()); 1228 CHECK_NOT_NULL(function->body());
1234 CHECK_EQ(1, function->body()->length()); 1229 CHECK_EQ(1, function->body()->length());
1235 i::FunctionLiteral* inner = 1230 i::FunctionLiteral* inner =
1236 function->body()->first()->AsExpressionStatement()->expression()-> 1231 function->body()->first()->AsExpressionStatement()->expression()->
1237 AsCall()->expression()->AsFunctionLiteral(); 1232 AsCall()->expression()->AsFunctionLiteral();
1238 i::Scope* inner_scope = inner->scope(); 1233 i::Scope* inner_scope = inner->scope();
(...skipping 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after
2475 const char* program = test_cases[i].program; 2470 const char* program = test_cases[i].program;
2476 i::Factory* factory = CcTest::i_isolate()->factory(); 2471 i::Factory* factory = CcTest::i_isolate()->factory();
2477 i::Handle<i::String> source = 2472 i::Handle<i::String> source =
2478 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); 2473 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked();
2479 i::Handle<i::Script> script = factory->NewScript(source); 2474 i::Handle<i::Script> script = factory->NewScript(source);
2480 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME); 2475 i::Zone zone(CcTest::i_isolate()->allocator(), ZONE_NAME);
2481 i::ParseInfo info(&zone, script); 2476 i::ParseInfo info(&zone, script);
2482 i::ScriptData* sd = NULL; 2477 i::ScriptData* sd = NULL;
2483 info.set_cached_data(&sd); 2478 info.set_cached_data(&sd);
2484 info.set_compile_options(v8::ScriptCompiler::kProduceParserCache); 2479 info.set_compile_options(v8::ScriptCompiler::kProduceParserCache);
2485 info.set_allow_lazy_parsing();
2486 i::Parser::ParseStatic(&info); 2480 i::Parser::ParseStatic(&info);
2487 i::ParseData* pd = i::ParseData::FromCachedData(sd); 2481 i::ParseData* pd = i::ParseData::FromCachedData(sd);
2488 2482
2489 if (pd->FunctionCount() != test_cases[i].functions) { 2483 if (pd->FunctionCount() != test_cases[i].functions) {
2490 v8::base::OS::Print( 2484 v8::base::OS::Print(
2491 "Expected preparse data for program:\n" 2485 "Expected preparse data for program:\n"
2492 "\t%s\n" 2486 "\t%s\n"
2493 "to contain %d functions, however, received %d functions.\n", 2487 "to contain %d functions, however, received %d functions.\n",
2494 program, test_cases[i].functions, pd->FunctionCount()); 2488 program, test_cases[i].functions, pd->FunctionCount());
2495 CHECK(false); 2489 CHECK(false);
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
3141 if (!i::FLAG_lazy) return; 3135 if (!i::FLAG_lazy) return;
3142 3136
3143 // The bug occurred when a lazy function had an error which requires a 3137 // The bug occurred when a lazy function had an error which requires a
3144 // parameter (such as "unknown label" here). The error message was processed 3138 // parameter (such as "unknown label" here). The error message was processed
3145 // before the AstValueFactory containing the error message string was 3139 // before the AstValueFactory containing the error message string was
3146 // internalized. 3140 // internalized.
3147 v8::Isolate* isolate = CcTest::isolate(); 3141 v8::Isolate* isolate = CcTest::isolate();
3148 v8::HandleScope scope(isolate); 3142 v8::HandleScope scope(isolate);
3149 LocalContext env; 3143 LocalContext env;
3150 i::FLAG_lazy = true; 3144 i::FLAG_lazy = true;
3151 i::FLAG_min_preparse_length = 0;
3152 CompileRun("function this_is_lazy() {\n" 3145 CompileRun("function this_is_lazy() {\n"
3153 " break p;\n" 3146 " break p;\n"
3154 "}\n" 3147 "}\n"
3155 "this_is_lazy();\n"); 3148 "this_is_lazy();\n");
3156 } 3149 }
3157 3150
3158 3151
3159 TEST(SerializationOfMaybeAssignmentFlag) { 3152 TEST(SerializationOfMaybeAssignmentFlag) {
3160 i::Isolate* isolate = CcTest::i_isolate(); 3153 i::Isolate* isolate = CcTest::i_isolate();
3161 i::Factory* factory = isolate->factory(); 3154 i::Factory* factory = isolate->factory();
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
3370 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o); 3363 i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o);
3371 i::Handle<i::SharedFunctionInfo> shared = i::handle(f->shared()); 3364 i::Handle<i::SharedFunctionInfo> shared = i::handle(f->shared());
3372 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, shared)); 3365 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, shared));
3373 } else { 3366 } else {
3374 i::Handle<i::String> source = 3367 i::Handle<i::String> source =
3375 factory->InternalizeUtf8String(program.start()); 3368 factory->InternalizeUtf8String(program.start());
3376 source->PrintOn(stdout); 3369 source->PrintOn(stdout);
3377 printf("\n"); 3370 printf("\n");
3378 i::Handle<i::Script> script = factory->NewScript(source); 3371 i::Handle<i::Script> script = factory->NewScript(source);
3379 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, script)); 3372 info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(&zone, script));
3373 info->set_allow_lazy_parsing(false);
3380 } 3374 }
3381 i::Parser parser(info.get()); 3375 i::Parser parser(info.get());
3382 CHECK(parser.Parse(info.get())); 3376 CHECK(parser.Parse(info.get()));
3383 CHECK(i::Compiler::Analyze(info.get())); 3377 CHECK(i::Compiler::Analyze(info.get()));
3384 CHECK(info->literal() != NULL); 3378 CHECK(info->literal() != NULL);
3385 3379
3386 i::Scope* scope = info->literal()->scope(); 3380 i::Scope* scope = info->literal()->scope();
3387 if (!lazy) { 3381 if (!lazy) {
3388 scope = scope->inner_scope(); 3382 scope = scope->inner_scope();
3389 } 3383 }
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
3545 CHECK_EQ(0, use_counts[v8::Isolate::kSloppyMode]); 3539 CHECK_EQ(0, use_counts[v8::Isolate::kSloppyMode]);
3546 } 3540 }
3547 3541
3548 3542
3549 TEST(SloppyModeUseCount) { 3543 TEST(SloppyModeUseCount) {
3550 i::Isolate* isolate = CcTest::i_isolate(); 3544 i::Isolate* isolate = CcTest::i_isolate();
3551 i::HandleScope scope(isolate); 3545 i::HandleScope scope(isolate);
3552 LocalContext env; 3546 LocalContext env;
3553 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; 3547 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {};
3554 global_use_counts = use_counts; 3548 global_use_counts = use_counts;
3549 // Force eager parsing (preparser doesn't update use counts).
3550 i::FLAG_lazy = false;
3555 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); 3551 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback);
3556 CompileRun("function bar() { var baz = 1; }"); 3552 CompileRun("function bar() { var baz = 1; }");
3557 CHECK_LT(0, use_counts[v8::Isolate::kSloppyMode]); 3553 CHECK_LT(0, use_counts[v8::Isolate::kSloppyMode]);
3558 CHECK_EQ(0, use_counts[v8::Isolate::kStrictMode]); 3554 CHECK_EQ(0, use_counts[v8::Isolate::kStrictMode]);
3559 } 3555 }
3560 3556
3561 3557
3562 TEST(BothModesUseCount) { 3558 TEST(BothModesUseCount) {
3563 i::Isolate* isolate = CcTest::i_isolate(); 3559 i::Isolate* isolate = CcTest::i_isolate();
3564 i::HandleScope scope(isolate); 3560 i::HandleScope scope(isolate);
3565 LocalContext env; 3561 LocalContext env;
3566 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {}; 3562 int use_counts[v8::Isolate::kUseCounterFeatureCount] = {};
3567 global_use_counts = use_counts; 3563 global_use_counts = use_counts;
3564 // Force eager parsing (preparser doesn't update use counts).
3565 i::FLAG_lazy = false;
3568 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback); 3566 CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback);
3569 CompileRun("function bar() { 'use strict'; var baz = 1; }"); 3567 CompileRun("function bar() { 'use strict'; var baz = 1; }");
3570 CHECK_LT(0, use_counts[v8::Isolate::kSloppyMode]); 3568 CHECK_LT(0, use_counts[v8::Isolate::kSloppyMode]);
3571 CHECK_LT(0, use_counts[v8::Isolate::kStrictMode]); 3569 CHECK_LT(0, use_counts[v8::Isolate::kStrictMode]);
3572 } 3570 }
3573 3571
3574 3572
3575 TEST(ErrorsArrowFormalParameters) { 3573 TEST(ErrorsArrowFormalParameters) {
3576 const char* context_data[][2] = { 3574 const char* context_data[][2] = {
3577 { "()", "=>{}" }, 3575 { "()", "=>{}" },
(...skipping 4822 matching lines...) Expand 10 before | Expand all | Expand 10 after
8400 const char* data[] = { 8398 const char* data[] = {
8401 "const arguments = 1", 8399 "const arguments = 1",
8402 "let arguments", 8400 "let arguments",
8403 "var arguments", 8401 "var arguments",
8404 NULL 8402 NULL
8405 }; 8403 };
8406 // clang-format on 8404 // clang-format on
8407 RunParserSyncTest(context_data, data, kSuccess); 8405 RunParserSyncTest(context_data, data, kSuccess);
8408 } 8406 }
8409 } 8407 }
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | test/cctest/test-serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698