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

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

Issue 2421833002: Remove "is function lazy" logic from Preparser + tiny error reporting refactoring. (Closed)
Patch Set: kill unused var Created 4 years, 2 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 | « src/parsing/preparser.cc ('k') | no next file » | 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 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 CcTest::i_isolate()->stack_guard()->real_climit()); 454 CcTest::i_isolate()->stack_guard()->real_climit());
455 preparser.set_allow_lazy(true); 455 preparser.set_allow_lazy(true);
456 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 456 i::PreParser::PreParseResult result = preparser.PreParseProgram();
457 // Even in the case of a syntax error, kPreParseSuccess is returned. 457 // Even in the case of a syntax error, kPreParseSuccess is returned.
458 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 458 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
459 CHECK(log.HasError()); 459 CHECK(log.HasError());
460 } 460 }
461 461
462 462
463 TEST(Regress928) { 463 TEST(Regress928) {
464 v8::V8::Initialize(); 464 // Test only applies when lazy parsing.
465 i::Isolate* isolate = CcTest::i_isolate(); 465 if (!i::FLAG_lazy || (i::FLAG_ignition && i::FLAG_ignition_eager)) return;
466 i::FLAG_min_preparse_length = 0;
466 467
467 // Preparsing didn't consider the catch clause of a try statement 468 // Tests that the first non-toplevel function is not included in the preparse
468 // as with-content, which made it assume that a function inside 469 // data.
469 // the block could be lazily compiled, and an extra, unexpected,
470 // entry was added to the data.
471 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() -
472 128 * 1024);
473
474 const char* program = 470 const char* program =
475 "try { } catch (e) { var foo = function () { /* first */ } }" 471 "try { } catch (e) { var foo = function () { /* first */ } }"
476 "var bar = function () { /* second */ }"; 472 "var bar = function () { /* second */ }";
477 473
478 v8::HandleScope handles(CcTest::isolate()); 474 v8::Isolate* isolate = CcTest::isolate();
479 auto stream = i::ScannerStream::ForTesting(program); 475 v8::HandleScope handles(isolate);
480 i::CompleteParserRecorder log; 476 v8::Local<v8::Context> context = v8::Context::New(isolate);
481 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 477 v8::Context::Scope context_scope(context);
482 scanner.Initialize(stream.get()); 478 v8::ScriptCompiler::Source script_source(v8_str(program));
483 i::Zone zone(CcTest::i_isolate()->allocator()); 479 v8::ScriptCompiler::Compile(context, &script_source,
484 i::AstValueFactory ast_value_factory(&zone, 480 v8::ScriptCompiler::kProduceParserCache)
485 CcTest::i_isolate()->heap()->HashSeed()); 481 .ToLocalChecked();
486 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, 482
487 CcTest::i_isolate()->stack_guard()->real_climit()); 483 const v8::ScriptCompiler::CachedData* cached_data =
488 preparser.set_allow_lazy(true); 484 script_source.GetCachedData();
489 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 485 i::ScriptData script_data(cached_data->data, cached_data->length);
490 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 486 std::unique_ptr<i::ParseData> pd(i::ParseData::FromCachedData(&script_data));
491 i::ScriptData* sd = log.GetScriptData();
492 i::ParseData* pd = i::ParseData::FromCachedData(sd);
493 pd->Initialize(); 487 pd->Initialize();
494 488
495 int first_function = 489 int first_function =
496 static_cast<int>(strstr(program, "function") - program); 490 static_cast<int>(strstr(program, "function") - program);
497 int first_lbrace = first_function + i::StrLength("function () "); 491 int first_lbrace = first_function + i::StrLength("function () ");
498 CHECK_EQ('{', program[first_lbrace]); 492 CHECK_EQ('{', program[first_lbrace]);
499 i::FunctionEntry entry1 = pd->GetFunctionEntry(first_lbrace); 493 i::FunctionEntry entry1 = pd->GetFunctionEntry(first_lbrace);
500 CHECK(!entry1.is_valid()); 494 CHECK(!entry1.is_valid());
501 495
502 int second_function = 496 int second_function =
503 static_cast<int>(strstr(program + first_lbrace, "function") - program); 497 static_cast<int>(strstr(program + first_lbrace, "function") - program);
504 int second_lbrace = 498 int second_lbrace =
505 second_function + i::StrLength("function () "); 499 second_function + i::StrLength("function () ");
506 CHECK_EQ('{', program[second_lbrace]); 500 CHECK_EQ('{', program[second_lbrace]);
507 i::FunctionEntry entry2 = pd->GetFunctionEntry(second_lbrace); 501 i::FunctionEntry entry2 = pd->GetFunctionEntry(second_lbrace);
508 CHECK(entry2.is_valid()); 502 CHECK(entry2.is_valid());
509 CHECK_EQ('}', program[entry2.end_pos() - 1]); 503 CHECK_EQ('}', program[entry2.end_pos() - 1]);
510 delete sd;
511 delete pd;
512 } 504 }
513 505
514 506
515 TEST(PreParseOverflow) { 507 TEST(PreParseOverflow) {
516 v8::V8::Initialize(); 508 v8::V8::Initialize();
517 509
518 CcTest::i_isolate()->stack_guard()->SetStackLimit( 510 CcTest::i_isolate()->stack_guard()->SetStackLimit(
519 i::GetCurrentStackPosition() - 128 * 1024); 511 i::GetCurrentStackPosition() - 128 * 1024);
520 512
521 size_t kProgramSize = 1024 * 1024; 513 size_t kProgramSize = 1024 * 1024;
(...skipping 7804 matching lines...) Expand 10 before | Expand all | Expand 10 after
8326 const char* data[] = { 8318 const char* data[] = {
8327 "const arguments = 1", 8319 "const arguments = 1",
8328 "let arguments", 8320 "let arguments",
8329 "var arguments", 8321 "var arguments",
8330 NULL 8322 NULL
8331 }; 8323 };
8332 // clang-format on 8324 // clang-format on
8333 RunParserSyncTest(context_data, data, kSuccess); 8325 RunParserSyncTest(context_data, data, kSuccess);
8334 } 8326 }
8335 } 8327 }
OLDNEW
« no previous file with comments | « src/parsing/preparser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698