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

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

Issue 214883002: Two-threaded parser (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: . Created 6 years, 8 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 | Annotate | Revision Log
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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 CcTest::i_isolate()->stack_guard()->SetStackLimit( 145 CcTest::i_isolate()->stack_guard()->SetStackLimit(
146 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); 146 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
147 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 147 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
148 for (int i = 0; tests[i]; i++) { 148 for (int i = 0; tests[i]; i++) {
149 const i::byte* source = 149 const i::byte* source =
150 reinterpret_cast<const i::byte*>(tests[i]); 150 reinterpret_cast<const i::byte*>(tests[i]);
151 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(tests[i])); 151 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(tests[i]));
152 i::CompleteParserRecorder log; 152 i::CompleteParserRecorder log;
153 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 153 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
154 scanner.Initialize(&stream); 154 scanner.Initialize(&stream);
155 i::PreParser preparser(&scanner, &log, stack_limit); 155 i::PreParser preparser(&scanner, &log, stack_limit, NULL);
156 preparser.set_allow_lazy(true); 156 preparser.set_allow_lazy(true);
157 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 157 i::PreParser::PreParseResult result = preparser.PreParseProgram();
158 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 158 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
159 i::ScriptData data(log.ExtractData()); 159 i::ScriptData data(log.ExtractData());
160 CHECK(!data.has_error()); 160 CHECK(!data.has_error());
161 } 161 }
162 162
163 for (int i = 0; fail_tests[i]; i++) { 163 for (int i = 0; fail_tests[i]; i++) {
164 const i::byte* source = 164 const i::byte* source =
165 reinterpret_cast<const i::byte*>(fail_tests[i]); 165 reinterpret_cast<const i::byte*>(fail_tests[i]);
166 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i])); 166 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i]));
167 i::CompleteParserRecorder log; 167 i::CompleteParserRecorder log;
168 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 168 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
169 scanner.Initialize(&stream); 169 scanner.Initialize(&stream);
170 i::PreParser preparser(&scanner, &log, stack_limit); 170 i::PreParser preparser(&scanner, &log, stack_limit, NULL);
171 preparser.set_allow_lazy(true); 171 preparser.set_allow_lazy(true);
172 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 172 i::PreParser::PreParseResult result = preparser.PreParseProgram();
173 // Even in the case of a syntax error, kPreParseSuccess is returned. 173 // Even in the case of a syntax error, kPreParseSuccess is returned.
174 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 174 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
175 i::ScriptData data(log.ExtractData()); 175 i::ScriptData data(log.ExtractData());
176 CHECK(data.has_error()); 176 CHECK(data.has_error());
177 } 177 }
178 } 178 }
179 179
180 180
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 346 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
347 for (int i = 0; programs[i]; i++) { 347 for (int i = 0; programs[i]; i++) {
348 const char* program = programs[i]; 348 const char* program = programs[i];
349 i::Utf8ToUtf16CharacterStream stream( 349 i::Utf8ToUtf16CharacterStream stream(
350 reinterpret_cast<const i::byte*>(program), 350 reinterpret_cast<const i::byte*>(program),
351 static_cast<unsigned>(strlen(program))); 351 static_cast<unsigned>(strlen(program)));
352 i::CompleteParserRecorder log; 352 i::CompleteParserRecorder log;
353 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 353 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
354 scanner.Initialize(&stream); 354 scanner.Initialize(&stream);
355 355
356 i::PreParser preparser(&scanner, &log, stack_limit); 356 i::PreParser preparser(&scanner, &log, stack_limit, NULL);
357 preparser.set_allow_lazy(true); 357 preparser.set_allow_lazy(true);
358 preparser.set_allow_natives_syntax(true); 358 preparser.set_allow_natives_syntax(true);
359 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 359 i::PreParser::PreParseResult result = preparser.PreParseProgram();
360 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 360 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
361 i::ScriptData data(log.ExtractData()); 361 i::ScriptData data(log.ExtractData());
362 CHECK(!data.has_error()); 362 CHECK(!data.has_error());
363 } 363 }
364 } 364 }
365 365
366 366
(...skipping 14 matching lines...) Expand all
381 for (int i = 0; programs[i]; i++) { 381 for (int i = 0; programs[i]; i++) {
382 const char* program = programs[i]; 382 const char* program = programs[i];
383 i::Utf8ToUtf16CharacterStream stream( 383 i::Utf8ToUtf16CharacterStream stream(
384 reinterpret_cast<const i::byte*>(program), 384 reinterpret_cast<const i::byte*>(program),
385 static_cast<unsigned>(strlen(program))); 385 static_cast<unsigned>(strlen(program)));
386 i::CompleteParserRecorder log; 386 i::CompleteParserRecorder log;
387 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 387 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
388 scanner.Initialize(&stream); 388 scanner.Initialize(&stream);
389 389
390 // Preparser defaults to disallowing natives syntax. 390 // Preparser defaults to disallowing natives syntax.
391 i::PreParser preparser(&scanner, &log, stack_limit); 391 i::PreParser preparser(&scanner, &log, stack_limit, NULL);
392 preparser.set_allow_lazy(true); 392 preparser.set_allow_lazy(true);
393 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 393 i::PreParser::PreParseResult result = preparser.PreParseProgram();
394 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 394 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
395 i::ScriptData data(log.ExtractData()); 395 i::ScriptData data(log.ExtractData());
396 // Data contains syntax error. 396 // Data contains syntax error.
397 CHECK(data.has_error()); 397 CHECK(data.has_error());
398 } 398 }
399 } 399 }
400 400
401 401
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), 497 // Before fix, didn't check *ok after Expect(Token::Identifier, ok),
498 // and then used the invalid currently scanned literal. This always 498 // and then used the invalid currently scanned literal. This always
499 // failed in debug mode, and sometimes crashed in release mode. 499 // failed in debug mode, and sometimes crashed in release mode.
500 500
501 i::Utf8ToUtf16CharacterStream stream( 501 i::Utf8ToUtf16CharacterStream stream(
502 reinterpret_cast<const i::byte*>(program), 502 reinterpret_cast<const i::byte*>(program),
503 static_cast<unsigned>(strlen(program))); 503 static_cast<unsigned>(strlen(program)));
504 i::CompleteParserRecorder log; 504 i::CompleteParserRecorder log;
505 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 505 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
506 scanner.Initialize(&stream); 506 scanner.Initialize(&stream);
507 i::PreParser preparser(&scanner, &log, 507 i::PreParser preparser(
508 CcTest::i_isolate()->stack_guard()->real_climit()); 508 &scanner, &log, CcTest::i_isolate()->stack_guard()->real_climit(), NULL);
509 preparser.set_allow_lazy(true); 509 preparser.set_allow_lazy(true);
510 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 510 i::PreParser::PreParseResult result = preparser.PreParseProgram();
511 // Even in the case of a syntax error, kPreParseSuccess is returned. 511 // Even in the case of a syntax error, kPreParseSuccess is returned.
512 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 512 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
513 i::ScriptData data(log.ExtractData()); 513 i::ScriptData data(log.ExtractData());
514 CHECK(data.has_error()); 514 CHECK(data.has_error());
515 } 515 }
516 516
517 517
518 TEST(Regress928) { 518 TEST(Regress928) {
(...skipping 13 matching lines...) Expand all
532 "try { } catch (e) { var foo = function () { /* first */ } }" 532 "try { } catch (e) { var foo = function () { /* first */ } }"
533 "var bar = function () { /* second */ }"; 533 "var bar = function () { /* second */ }";
534 534
535 v8::HandleScope handles(CcTest::isolate()); 535 v8::HandleScope handles(CcTest::isolate());
536 i::Handle<i::String> source( 536 i::Handle<i::String> source(
537 factory->NewStringFromAscii(i::CStrVector(program))); 537 factory->NewStringFromAscii(i::CStrVector(program)));
538 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); 538 i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
539 i::CompleteParserRecorder log; 539 i::CompleteParserRecorder log;
540 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 540 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
541 scanner.Initialize(&stream); 541 scanner.Initialize(&stream);
542 i::PreParser preparser(&scanner, &log, 542 i::PreParser preparser(
543 CcTest::i_isolate()->stack_guard()->real_climit()); 543 &scanner, &log, CcTest::i_isolate()->stack_guard()->real_climit(), NULL);
544 preparser.set_allow_lazy(true); 544 preparser.set_allow_lazy(true);
545 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 545 i::PreParser::PreParseResult result = preparser.PreParseProgram();
546 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 546 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
547 i::ScriptData data(log.ExtractData()); 547 i::ScriptData data(log.ExtractData());
548 CHECK(!data.has_error()); 548 CHECK(!data.has_error());
549 data.Initialize(); 549 data.Initialize();
550 550
551 int first_function = 551 int first_function =
552 static_cast<int>(strstr(program, "function") - program); 552 static_cast<int>(strstr(program, "function") - program);
553 int first_lbrace = first_function + i::StrLength("function () "); 553 int first_lbrace = first_function + i::StrLength("function () ");
(...skipping 26 matching lines...) Expand all
580 580
581 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); 581 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit();
582 582
583 i::Utf8ToUtf16CharacterStream stream( 583 i::Utf8ToUtf16CharacterStream stream(
584 reinterpret_cast<const i::byte*>(program.get()), 584 reinterpret_cast<const i::byte*>(program.get()),
585 static_cast<unsigned>(kProgramSize)); 585 static_cast<unsigned>(kProgramSize));
586 i::CompleteParserRecorder log; 586 i::CompleteParserRecorder log;
587 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 587 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
588 scanner.Initialize(&stream); 588 scanner.Initialize(&stream);
589 589
590 i::PreParser preparser(&scanner, &log, stack_limit); 590 i::PreParser preparser(&scanner, &log, stack_limit, NULL);
591 preparser.set_allow_lazy(true); 591 preparser.set_allow_lazy(true);
592 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 592 i::PreParser::PreParseResult result = preparser.PreParseProgram();
593 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); 593 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result);
594 } 594 }
595 595
596 596
597 class TestExternalResource: public v8::String::ExternalStringResource { 597 class TestExternalResource: public v8::String::ExternalStringResource {
598 public: 598 public:
599 explicit TestExternalResource(uint16_t* data, int length) 599 explicit TestExternalResource(uint16_t* data, int length)
600 : data_(data), length_(static_cast<size_t>(length)) { } 600 : data_(data), length_(static_cast<size_t>(length)) { }
(...skipping 29 matching lines...) Expand all
630 uc16_buffer[i] = static_cast<i::uc16>(ascii_source[i]); 630 uc16_buffer[i] = static_cast<i::uc16>(ascii_source[i]);
631 } 631 }
632 i::Vector<const char> ascii_vector(ascii_source, static_cast<int>(length)); 632 i::Vector<const char> ascii_vector(ascii_source, static_cast<int>(length));
633 i::Handle<i::String> ascii_string( 633 i::Handle<i::String> ascii_string(
634 factory->NewStringFromAscii(ascii_vector)); 634 factory->NewStringFromAscii(ascii_vector));
635 TestExternalResource resource(uc16_buffer.get(), length); 635 TestExternalResource resource(uc16_buffer.get(), length);
636 i::Handle<i::String> uc16_string( 636 i::Handle<i::String> uc16_string(
637 factory->NewExternalStringFromTwoByte(&resource).ToHandleChecked()); 637 factory->NewExternalStringFromTwoByte(&resource).ToHandleChecked());
638 638
639 i::ExternalTwoByteStringUtf16CharacterStream uc16_stream( 639 i::ExternalTwoByteStringUtf16CharacterStream uc16_stream(
640 i::Handle<i::ExternalTwoByteString>::cast(uc16_string), start, end); 640 i::Handle<i::ExternalTwoByteString>::cast(uc16_string)->GetTwoByteData(0),
641 start, end);
641 i::GenericStringUtf16CharacterStream string_stream(ascii_string, start, end); 642 i::GenericStringUtf16CharacterStream string_stream(ascii_string, start, end);
642 i::Utf8ToUtf16CharacterStream utf8_stream( 643 i::Utf8ToUtf16CharacterStream utf8_stream(
643 reinterpret_cast<const i::byte*>(ascii_source), end); 644 reinterpret_cast<const i::byte*>(ascii_source), end);
644 utf8_stream.SeekForward(start); 645 utf8_stream.SeekForward(start);
645 646
646 unsigned i = start; 647 unsigned i = start;
647 while (i < end) { 648 while (i < end) {
648 // Read streams one char at a time 649 // Read streams one char at a time
649 CHECK_EQU(i, uc16_stream.pos()); 650 CHECK_EQU(i, uc16_stream.pos());
650 CHECK_EQU(i, string_stream.pos()); 651 CHECK_EQU(i, string_stream.pos());
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
1306 i::Isolate* isolate = CcTest::i_isolate(); 1307 i::Isolate* isolate = CcTest::i_isolate();
1307 i::Factory* factory = isolate->factory(); 1308 i::Factory* factory = isolate->factory();
1308 1309
1309 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); 1310 uintptr_t stack_limit = isolate->stack_guard()->real_climit();
1310 1311
1311 // Preparse the data. 1312 // Preparse the data.
1312 i::CompleteParserRecorder log; 1313 i::CompleteParserRecorder log;
1313 { 1314 {
1314 i::Scanner scanner(isolate->unicode_cache()); 1315 i::Scanner scanner(isolate->unicode_cache());
1315 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); 1316 i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
1316 i::PreParser preparser(&scanner, &log, stack_limit); 1317 i::PreParser preparser(&scanner, &log, stack_limit, NULL);
1317 SetParserFlags(&preparser, flags); 1318 SetParserFlags(&preparser, flags);
1318 scanner.Initialize(&stream); 1319 scanner.Initialize(&stream);
1319 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 1320 i::PreParser::PreParseResult result = preparser.PreParseProgram();
1320 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 1321 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
1321 } 1322 }
1322 i::ScriptData data(log.ExtractData()); 1323 i::ScriptData data(log.ExtractData());
1323 1324
1324 // Parse the data 1325 // Parse the data
1325 i::FunctionLiteral* function; 1326 i::FunctionLiteral* function;
1326 { 1327 {
(...skipping 1240 matching lines...) Expand 10 before | Expand all | Expand 10 after
2567 RunParserSyncTest(assignment_context_data, bad_statement_data_common, kError); 2568 RunParserSyncTest(assignment_context_data, bad_statement_data_common, kError);
2568 RunParserSyncTest(assignment_context_data, bad_statement_data_for_assignment, 2569 RunParserSyncTest(assignment_context_data, bad_statement_data_for_assignment,
2569 kError); 2570 kError);
2570 2571
2571 RunParserSyncTest(prefix_context_data, good_statement_data, kSuccess); 2572 RunParserSyncTest(prefix_context_data, good_statement_data, kSuccess);
2572 RunParserSyncTest(prefix_context_data, bad_statement_data_common, kError); 2573 RunParserSyncTest(prefix_context_data, bad_statement_data_common, kError);
2573 2574
2574 RunParserSyncTest(postfix_context_data, good_statement_data, kSuccess); 2575 RunParserSyncTest(postfix_context_data, good_statement_data, kSuccess);
2575 RunParserSyncTest(postfix_context_data, bad_statement_data_common, kError); 2576 RunParserSyncTest(postfix_context_data, bad_statement_data_common, kError);
2576 } 2577 }
2578
2579
2580 TEST(ParallelParsing) {
2581 // Make lazy parsing and parallel parsing work for short scripts.
2582 i::FLAG_min_preparse_length = 0;
2583 i::FLAG_min_parallel_parse_length = 0;
2584
2585 v8::Isolate* isolate = CcTest::isolate();
2586 v8::HandleScope handles(isolate);
2587 v8::Local<v8::Context> context = v8::Context::New(isolate);
2588 v8::Context::Scope context_scope(context);
2589 int marker;
2590 CcTest::i_isolate()->stack_guard()->SetStackLimit(
2591 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
2592
2593 const char* code =
2594 "var outside_var = 8;\n"
2595 "function this_is_lazy() { return 5 + outside_var; }\n"
2596 "(function not_lazy() { return this_is_lazy(); })()";
2597 v8::ScriptCompiler::Source source(v8::String::NewExternal(
2598 isolate, new ScriptResource(code, i::StrLength(code))));
2599 v8::TryCatch try_catch;
2600 v8::Handle<v8::Script> script = v8::ScriptCompiler::Compile(
2601 isolate, &source, v8::ScriptCompiler::kProduceDataToCache);
2602 CHECK(!script.IsEmpty());
2603 CHECK(!try_catch.HasCaught());
2604 v8::Local<v8::Value> result = script->Run();
2605 CHECK(result->IsInt32());
2606 CHECK_EQ(13, result->Int32Value());
2607 }
2608
2609
2610 TEST(ParallelParsingErrorInLazyFunction) {
2611 // Make lazy parsing and parallel parsing work for short scripts.
2612 i::FLAG_min_preparse_length = 0;
2613 i::FLAG_min_parallel_parse_length = 0;
2614
2615 v8::Isolate* isolate = CcTest::isolate();
2616 v8::HandleScope handles(isolate);
2617 v8::Local<v8::Context> context = v8::Context::New(isolate);
2618 v8::Context::Scope context_scope(context);
2619 int marker;
2620 CcTest::i_isolate()->stack_guard()->SetStackLimit(
2621 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
2622
2623 // Compile code which has error inside a lazy function. Check that we get an
2624 // error.
2625 const char* code =
2626 "function this_is_lazy() { 1 2 3 error }";
2627 v8::ScriptCompiler::Source source(v8::String::NewExternal(
2628 isolate, new ScriptResource(code, i::StrLength(code))));
2629 v8::TryCatch try_catch;
2630 v8::Handle<v8::Script> script = v8::ScriptCompiler::Compile(
2631 isolate, &source, v8::ScriptCompiler::kProduceDataToCache);
2632 CHECK(try_catch.HasCaught());
2633 v8::String::Utf8Value exception(try_catch.Exception());
2634 CHECK_EQ("SyntaxError: Unexpected number", *exception);
2635 CHECK(script.IsEmpty());
2636 }
OLDNEW
« src/preparse-data.h ('K') | « src/scanner-character-streams.cc ('k') | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698