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 225753004: Remove the PreCompile API and ScriptData. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased 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
« no previous file with comments | « test/cctest/test-api.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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
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);
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::ScriptDataImpl 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);
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::ScriptDataImpl 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
181 class ScriptResource : public v8::String::ExternalAsciiStringResource { 181 class ScriptResource : public v8::String::ExternalAsciiStringResource {
182 public: 182 public:
183 ScriptResource(const char* data, size_t length) 183 ScriptResource(const char* data, size_t length)
184 : data_(data), length_(length) { } 184 : data_(data), length_(length) { }
185 185
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
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);
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::ScriptDataImpl 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
367 TEST(StandAlonePreParserNoNatives) { 367 TEST(StandAlonePreParserNoNatives) {
368 v8::V8::Initialize(); 368 v8::V8::Initialize();
369 369
370 int marker; 370 int marker;
371 CcTest::i_isolate()->stack_guard()->SetStackLimit( 371 CcTest::i_isolate()->stack_guard()->SetStackLimit(
(...skipping 13 matching lines...) Expand all
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);
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::ScriptDataImpl 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
402 TEST(PreparsingObjectLiterals) { 402 TEST(PreparsingObjectLiterals) {
403 // Regression test for a bug where the symbol stream produced by PreParser 403 // Regression test for a bug where the symbol stream produced by PreParser
404 // didn't match what Parser wanted to consume. 404 // didn't match what Parser wanted to consume.
405 v8::Isolate* isolate = CcTest::isolate(); 405 v8::Isolate* isolate = CcTest::isolate();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 for (int i = 0; i < 18; ++i) { 461 for (int i = 0; i < 18; ++i) {
462 F::FakeWritingSymbolIdInPreParseData(&log, 1 << i); 462 F::FakeWritingSymbolIdInPreParseData(&log, 1 << i);
463 } 463 }
464 for (int i = 1; i < 18; ++i) { 464 for (int i = 1; i < 18; ++i) {
465 F::FakeWritingSymbolIdInPreParseData(&log, (1 << i) + 1); 465 F::FakeWritingSymbolIdInPreParseData(&log, (1 << i) + 1);
466 } 466 }
467 for (int i = 6; i < 18; ++i) { 467 for (int i = 6; i < 18; ++i) {
468 F::FakeWritingSymbolIdInPreParseData(&log, (3 << i) + (5 << (i - 6))); 468 F::FakeWritingSymbolIdInPreParseData(&log, (3 << i) + (5 << (i - 6)));
469 } 469 }
470 i::Vector<unsigned> store = log.ExtractData(); 470 i::Vector<unsigned> store = log.ExtractData();
471 i::ScriptDataImpl script_data(store); 471 i::ScriptData script_data(store);
472 script_data.Initialize(); 472 script_data.Initialize();
473 // Check that we get the same symbols back. 473 // Check that we get the same symbols back.
474 for (int i = 0; i < 18; ++i) { 474 for (int i = 0; i < 18; ++i) {
475 CHECK_EQ(1 << i, script_data.GetSymbolIdentifier()); 475 CHECK_EQ(1 << i, script_data.GetSymbolIdentifier());
476 } 476 }
477 for (int i = 1; i < 18; ++i) { 477 for (int i = 1; i < 18; ++i) {
478 CHECK_EQ((1 << i) + 1, script_data.GetSymbolIdentifier()); 478 CHECK_EQ((1 << i) + 1, script_data.GetSymbolIdentifier());
479 } 479 }
480 for (int i = 6; i < 18; ++i) { 480 for (int i = 6; i < 18; ++i) {
481 CHECK_EQ((3 << i) + (5 << (i - 6)), script_data.GetSymbolIdentifier()); 481 CHECK_EQ((3 << i) + (5 << (i - 6)), script_data.GetSymbolIdentifier());
(...skipping 21 matching lines...) Expand all
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(&scanner, &log,
508 CcTest::i_isolate()->stack_guard()->real_climit()); 508 CcTest::i_isolate()->stack_guard()->real_climit());
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::ScriptDataImpl 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) {
519 v8::V8::Initialize(); 519 v8::V8::Initialize();
520 i::Isolate* isolate = CcTest::i_isolate(); 520 i::Isolate* isolate = CcTest::i_isolate();
521 i::Factory* factory = isolate->factory(); 521 i::Factory* factory = isolate->factory();
522 522
523 // Preparsing didn't consider the catch clause of a try statement 523 // Preparsing didn't consider the catch clause of a try statement
(...skipping 13 matching lines...) Expand all
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(&scanner, &log,
543 CcTest::i_isolate()->stack_guard()->real_climit()); 543 CcTest::i_isolate()->stack_guard()->real_climit());
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::ScriptDataImpl 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 () ");
554 CHECK_EQ('{', program[first_lbrace]); 554 CHECK_EQ('{', program[first_lbrace]);
555 i::FunctionEntry entry1 = data.GetFunctionEntry(first_lbrace); 555 i::FunctionEntry entry1 = data.GetFunctionEntry(first_lbrace);
556 CHECK(!entry1.is_valid()); 556 CHECK(!entry1.is_valid());
557 557
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 i::Scope* inner_scope = scope->inner_scopes()->at(0); 1232 i::Scope* inner_scope = scope->inner_scopes()->at(0);
1233 CHECK_EQ(inner_scope->scope_type(), source_data[i].scope_type); 1233 CHECK_EQ(inner_scope->scope_type(), source_data[i].scope_type);
1234 CHECK_EQ(inner_scope->start_position(), kPrefixLen); 1234 CHECK_EQ(inner_scope->start_position(), kPrefixLen);
1235 // The end position of a token is one position after the last 1235 // The end position of a token is one position after the last
1236 // character belonging to that token. 1236 // character belonging to that token.
1237 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen); 1237 CHECK_EQ(inner_scope->end_position(), kPrefixLen + kInnerLen);
1238 } 1238 }
1239 } 1239 }
1240 1240
1241 1241
1242 i::Handle<i::String> FormatMessage(i::ScriptDataImpl* data) { 1242 i::Handle<i::String> FormatMessage(i::ScriptData* data) {
1243 i::Isolate* isolate = CcTest::i_isolate(); 1243 i::Isolate* isolate = CcTest::i_isolate();
1244 i::Factory* factory = isolate->factory(); 1244 i::Factory* factory = isolate->factory();
1245 const char* message = data->BuildMessage(); 1245 const char* message = data->BuildMessage();
1246 i::Handle<i::String> format = v8::Utils::OpenHandle( 1246 i::Handle<i::String> format = v8::Utils::OpenHandle(
1247 *v8::String::NewFromUtf8(CcTest::isolate(), message)); 1247 *v8::String::NewFromUtf8(CcTest::isolate(), message));
1248 i::Vector<const char*> args = data->BuildArgs(); 1248 i::Vector<const char*> args = data->BuildArgs();
1249 i::Handle<i::JSArray> args_array = factory->NewJSArray(args.length()); 1249 i::Handle<i::JSArray> args_array = factory->NewJSArray(args.length());
1250 for (int i = 0; i < args.length(); i++) { 1250 for (int i = 0; i < args.length(); i++) {
1251 i::JSArray::SetElement( 1251 i::JSArray::SetElement(
1252 args_array, i, v8::Utils::OpenHandle(*v8::String::NewFromUtf8( 1252 args_array, i, v8::Utils::OpenHandle(*v8::String::NewFromUtf8(
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 i::CompleteParserRecorder log; 1312 i::CompleteParserRecorder log;
1313 { 1313 {
1314 i::Scanner scanner(isolate->unicode_cache()); 1314 i::Scanner scanner(isolate->unicode_cache());
1315 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); 1315 i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
1316 i::PreParser preparser(&scanner, &log, stack_limit); 1316 i::PreParser preparser(&scanner, &log, stack_limit);
1317 SetParserFlags(&preparser, flags); 1317 SetParserFlags(&preparser, flags);
1318 scanner.Initialize(&stream); 1318 scanner.Initialize(&stream);
1319 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 1319 i::PreParser::PreParseResult result = preparser.PreParseProgram();
1320 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 1320 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
1321 } 1321 }
1322 i::ScriptDataImpl data(log.ExtractData()); 1322 i::ScriptData data(log.ExtractData());
1323 1323
1324 // Parse the data 1324 // Parse the data
1325 i::FunctionLiteral* function; 1325 i::FunctionLiteral* function;
1326 { 1326 {
1327 i::Handle<i::Script> script = factory->NewScript(source); 1327 i::Handle<i::Script> script = factory->NewScript(source);
1328 i::CompilationInfoWithZone info(script); 1328 i::CompilationInfoWithZone info(script);
1329 i::Parser parser(&info); 1329 i::Parser parser(&info);
1330 SetParserFlags(&parser, flags); 1330 SetParserFlags(&parser, flags);
1331 info.MarkAsGlobal(); 1331 info.MarkAsGlobal();
1332 parser.Parse(); 1332 parser.Parse();
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
2097 {NULL, 0, 0} 2097 {NULL, 0, 0}
2098 }; 2098 };
2099 2099
2100 for (int i = 0; test_cases[i].program; i++) { 2100 for (int i = 0; test_cases[i].program; i++) {
2101 const char* program = test_cases[i].program; 2101 const char* program = test_cases[i].program;
2102 i::Factory* factory = CcTest::i_isolate()->factory(); 2102 i::Factory* factory = CcTest::i_isolate()->factory();
2103 i::Handle<i::String> source( 2103 i::Handle<i::String> source(
2104 factory->NewStringFromUtf8(i::CStrVector(program))); 2104 factory->NewStringFromUtf8(i::CStrVector(program)));
2105 i::Handle<i::Script> script = factory->NewScript(source); 2105 i::Handle<i::Script> script = factory->NewScript(source);
2106 i::CompilationInfoWithZone info(script); 2106 i::CompilationInfoWithZone info(script);
2107 i::ScriptDataImpl* data = NULL; 2107 i::ScriptData* data = NULL;
2108 info.SetCachedData(&data, i::PRODUCE_CACHED_DATA); 2108 info.SetCachedData(&data, i::PRODUCE_CACHED_DATA);
2109 i::Parser::Parse(&info, true); 2109 i::Parser::Parse(&info, true);
2110 CHECK(data); 2110 CHECK(data);
2111 CHECK(!data->HasError()); 2111 CHECK(!data->HasError());
2112 2112
2113 if (data->symbol_count() != test_cases[i].symbols) { 2113 if (data->symbol_count() != test_cases[i].symbols) {
2114 i::OS::Print( 2114 i::OS::Print(
2115 "Expected preparse data for program:\n" 2115 "Expected preparse data for program:\n"
2116 "\t%s\n" 2116 "\t%s\n"
2117 "to contain %d symbols, however, received %d symbols.\n", 2117 "to contain %d symbols, however, received %d symbols.\n",
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
2567 RunParserSyncTest(assignment_context_data, bad_statement_data_common, kError); 2567 RunParserSyncTest(assignment_context_data, bad_statement_data_common, kError);
2568 RunParserSyncTest(assignment_context_data, bad_statement_data_for_assignment, 2568 RunParserSyncTest(assignment_context_data, bad_statement_data_for_assignment,
2569 kError); 2569 kError);
2570 2570
2571 RunParserSyncTest(prefix_context_data, good_statement_data, kSuccess); 2571 RunParserSyncTest(prefix_context_data, good_statement_data, kSuccess);
2572 RunParserSyncTest(prefix_context_data, bad_statement_data_common, kError); 2572 RunParserSyncTest(prefix_context_data, bad_statement_data_common, kError);
2573 2573
2574 RunParserSyncTest(postfix_context_data, good_statement_data, kSuccess); 2574 RunParserSyncTest(postfix_context_data, good_statement_data, kSuccess);
2575 RunParserSyncTest(postfix_context_data, bad_statement_data_common, kError); 2575 RunParserSyncTest(postfix_context_data, bad_statement_data_common, kError);
2576 } 2576 }
OLDNEW
« no previous file with comments | « test/cctest/test-api.cc ('k') | tools/parser-shell.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698