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

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

Issue 908173003: Parsing: Make Parser not know about Isolate during background parsing. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 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
« src/parser.cc ('K') | « src/preparser.h ('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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 for (int i = 0; tests[i]; i++) { 153 for (int i = 0; tests[i]; i++) {
154 const i::byte* source = 154 const i::byte* source =
155 reinterpret_cast<const i::byte*>(tests[i]); 155 reinterpret_cast<const i::byte*>(tests[i]);
156 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(tests[i])); 156 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(tests[i]));
157 i::CompleteParserRecorder log; 157 i::CompleteParserRecorder log;
158 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 158 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
159 scanner.Initialize(&stream); 159 scanner.Initialize(&stream);
160 i::Zone zone; 160 i::Zone zone;
161 i::AstValueFactory ast_value_factory( 161 i::AstValueFactory ast_value_factory(
162 &zone, CcTest::i_isolate()->heap()->HashSeed()); 162 &zone, CcTest::i_isolate()->heap()->HashSeed());
163 i::PreParser preparser(CcTest::i_isolate(), &zone, &scanner, 163 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
164 &ast_value_factory, &log, stack_limit); 164 stack_limit);
165 preparser.set_allow_lazy(true); 165 preparser.set_allow_lazy(true);
166 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 166 i::PreParser::PreParseResult result = preparser.PreParseProgram();
167 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 167 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
168 CHECK(!log.HasError()); 168 CHECK(!log.HasError());
169 } 169 }
170 170
171 for (int i = 0; fail_tests[i]; i++) { 171 for (int i = 0; fail_tests[i]; i++) {
172 const i::byte* source = 172 const i::byte* source =
173 reinterpret_cast<const i::byte*>(fail_tests[i]); 173 reinterpret_cast<const i::byte*>(fail_tests[i]);
174 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i])); 174 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i]));
175 i::CompleteParserRecorder log; 175 i::CompleteParserRecorder log;
176 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 176 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
177 scanner.Initialize(&stream); 177 scanner.Initialize(&stream);
178 i::Zone zone; 178 i::Zone zone;
179 i::AstValueFactory ast_value_factory( 179 i::AstValueFactory ast_value_factory(
180 &zone, CcTest::i_isolate()->heap()->HashSeed()); 180 &zone, CcTest::i_isolate()->heap()->HashSeed());
181 i::PreParser preparser(CcTest::i_isolate(), &zone, &scanner, 181 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
182 &ast_value_factory, &log, stack_limit); 182 stack_limit);
183 preparser.set_allow_lazy(true); 183 preparser.set_allow_lazy(true);
184 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 184 i::PreParser::PreParseResult result = preparser.PreParseProgram();
185 // Even in the case of a syntax error, kPreParseSuccess is returned. 185 // Even in the case of a syntax error, kPreParseSuccess is returned.
186 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 186 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
187 CHECK(log.HasError()); 187 CHECK(log.HasError());
188 } 188 }
189 } 189 }
190 190
191 191
192 class ScriptResource : public v8::String::ExternalOneByteStringResource { 192 class ScriptResource : public v8::String::ExternalOneByteStringResource {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 i::Utf8ToUtf16CharacterStream stream( 321 i::Utf8ToUtf16CharacterStream stream(
322 reinterpret_cast<const i::byte*>(program), 322 reinterpret_cast<const i::byte*>(program),
323 static_cast<unsigned>(strlen(program))); 323 static_cast<unsigned>(strlen(program)));
324 i::CompleteParserRecorder log; 324 i::CompleteParserRecorder log;
325 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 325 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
326 scanner.Initialize(&stream); 326 scanner.Initialize(&stream);
327 327
328 i::Zone zone; 328 i::Zone zone;
329 i::AstValueFactory ast_value_factory( 329 i::AstValueFactory ast_value_factory(
330 &zone, CcTest::i_isolate()->heap()->HashSeed()); 330 &zone, CcTest::i_isolate()->heap()->HashSeed());
331 i::PreParser preparser(CcTest::i_isolate(), &zone, &scanner, 331 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
332 &ast_value_factory, &log, stack_limit); 332 stack_limit);
333 preparser.set_allow_lazy(true); 333 preparser.set_allow_lazy(true);
334 preparser.set_allow_natives(true); 334 preparser.set_allow_natives(true);
335 preparser.set_allow_harmony_arrow_functions(true); 335 preparser.set_allow_harmony_arrow_functions(true);
336 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 336 i::PreParser::PreParseResult result = preparser.PreParseProgram();
337 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 337 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
338 CHECK(!log.HasError()); 338 CHECK(!log.HasError());
339 } 339 }
340 } 340 }
341 341
342 342
(...skipping 16 matching lines...) Expand all
359 reinterpret_cast<const i::byte*>(program), 359 reinterpret_cast<const i::byte*>(program),
360 static_cast<unsigned>(strlen(program))); 360 static_cast<unsigned>(strlen(program)));
361 i::CompleteParserRecorder log; 361 i::CompleteParserRecorder log;
362 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 362 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
363 scanner.Initialize(&stream); 363 scanner.Initialize(&stream);
364 364
365 // Preparser defaults to disallowing natives syntax. 365 // Preparser defaults to disallowing natives syntax.
366 i::Zone zone; 366 i::Zone zone;
367 i::AstValueFactory ast_value_factory( 367 i::AstValueFactory ast_value_factory(
368 &zone, CcTest::i_isolate()->heap()->HashSeed()); 368 &zone, CcTest::i_isolate()->heap()->HashSeed());
369 i::PreParser preparser(CcTest::i_isolate(), &zone, &scanner, 369 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
370 &ast_value_factory, &log, stack_limit); 370 stack_limit);
371 preparser.set_allow_lazy(true); 371 preparser.set_allow_lazy(true);
372 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 372 i::PreParser::PreParseResult result = preparser.PreParseProgram();
373 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 373 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
374 CHECK(log.HasError()); 374 CHECK(log.HasError());
375 } 375 }
376 } 376 }
377 377
378 378
379 TEST(PreparsingObjectLiterals) { 379 TEST(PreparsingObjectLiterals) {
380 // Regression test for a bug where the symbol stream produced by PreParser 380 // Regression test for a bug where the symbol stream produced by PreParser
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 428
429 i::Utf8ToUtf16CharacterStream stream( 429 i::Utf8ToUtf16CharacterStream stream(
430 reinterpret_cast<const i::byte*>(program), 430 reinterpret_cast<const i::byte*>(program),
431 static_cast<unsigned>(strlen(program))); 431 static_cast<unsigned>(strlen(program)));
432 i::CompleteParserRecorder log; 432 i::CompleteParserRecorder log;
433 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 433 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
434 scanner.Initialize(&stream); 434 scanner.Initialize(&stream);
435 i::Zone zone; 435 i::Zone zone;
436 i::AstValueFactory ast_value_factory(&zone, 436 i::AstValueFactory ast_value_factory(&zone,
437 CcTest::i_isolate()->heap()->HashSeed()); 437 CcTest::i_isolate()->heap()->HashSeed());
438 i::PreParser preparser(CcTest::i_isolate(), &zone, &scanner, 438 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
439 &ast_value_factory, &log,
440 CcTest::i_isolate()->stack_guard()->real_climit()); 439 CcTest::i_isolate()->stack_guard()->real_climit());
441 preparser.set_allow_lazy(true); 440 preparser.set_allow_lazy(true);
442 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 441 i::PreParser::PreParseResult result = preparser.PreParseProgram();
443 // Even in the case of a syntax error, kPreParseSuccess is returned. 442 // Even in the case of a syntax error, kPreParseSuccess is returned.
444 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 443 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
445 CHECK(log.HasError()); 444 CHECK(log.HasError());
446 } 445 }
447 446
448 447
449 TEST(Regress928) { 448 TEST(Regress928) {
(...skipping 14 matching lines...) Expand all
464 463
465 v8::HandleScope handles(CcTest::isolate()); 464 v8::HandleScope handles(CcTest::isolate());
466 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(program); 465 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(program);
467 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); 466 i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
468 i::CompleteParserRecorder log; 467 i::CompleteParserRecorder log;
469 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 468 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
470 scanner.Initialize(&stream); 469 scanner.Initialize(&stream);
471 i::Zone zone; 470 i::Zone zone;
472 i::AstValueFactory ast_value_factory(&zone, 471 i::AstValueFactory ast_value_factory(&zone,
473 CcTest::i_isolate()->heap()->HashSeed()); 472 CcTest::i_isolate()->heap()->HashSeed());
474 i::PreParser preparser(CcTest::i_isolate(), &zone, &scanner, 473 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
475 &ast_value_factory, &log,
476 CcTest::i_isolate()->stack_guard()->real_climit()); 474 CcTest::i_isolate()->stack_guard()->real_climit());
477 preparser.set_allow_lazy(true); 475 preparser.set_allow_lazy(true);
478 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 476 i::PreParser::PreParseResult result = preparser.PreParseProgram();
479 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 477 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
480 i::ScriptData* sd = log.GetScriptData(); 478 i::ScriptData* sd = log.GetScriptData();
481 i::ParseData* pd = i::ParseData::FromCachedData(sd); 479 i::ParseData* pd = i::ParseData::FromCachedData(sd);
482 pd->Initialize(); 480 pd->Initialize();
483 481
484 int first_function = 482 int first_function =
485 static_cast<int>(strstr(program, "function") - program); 483 static_cast<int>(strstr(program, "function") - program);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 i::Utf8ToUtf16CharacterStream stream( 515 i::Utf8ToUtf16CharacterStream stream(
518 reinterpret_cast<const i::byte*>(program.get()), 516 reinterpret_cast<const i::byte*>(program.get()),
519 static_cast<unsigned>(kProgramSize)); 517 static_cast<unsigned>(kProgramSize));
520 i::CompleteParserRecorder log; 518 i::CompleteParserRecorder log;
521 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); 519 i::Scanner scanner(CcTest::i_isolate()->unicode_cache());
522 scanner.Initialize(&stream); 520 scanner.Initialize(&stream);
523 521
524 i::Zone zone; 522 i::Zone zone;
525 i::AstValueFactory ast_value_factory(&zone, 523 i::AstValueFactory ast_value_factory(&zone,
526 CcTest::i_isolate()->heap()->HashSeed()); 524 CcTest::i_isolate()->heap()->HashSeed());
527 i::PreParser preparser(CcTest::i_isolate(), &zone, &scanner, 525 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
528 &ast_value_factory, &log, stack_limit); 526 stack_limit);
529 preparser.set_allow_lazy(true); 527 preparser.set_allow_lazy(true);
530 preparser.set_allow_harmony_arrow_functions(true); 528 preparser.set_allow_harmony_arrow_functions(true);
531 i::PreParser::PreParseResult result = preparser.PreParseProgram(); 529 i::PreParser::PreParseResult result = preparser.PreParseProgram();
532 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); 530 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result);
533 } 531 }
534 532
535 533
536 class TestExternalResource: public v8::String::ExternalStringResource { 534 class TestExternalResource: public v8::String::ExternalStringResource {
537 public: 535 public:
538 explicit TestExternalResource(uint16_t* data, int length) 536 explicit TestExternalResource(uint16_t* data, int length)
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 i::Handle<i::Script> script = factory->NewScript(source); 1045 i::Handle<i::Script> script = factory->NewScript(source);
1048 i::CompilationInfoWithZone info(script); 1046 i::CompilationInfoWithZone info(script);
1049 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), 1047 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(),
1050 isolate->heap()->HashSeed(), 1048 isolate->heap()->HashSeed(),
1051 isolate->unicode_cache()}; 1049 isolate->unicode_cache()};
1052 i::Parser parser(&info, &parse_info); 1050 i::Parser parser(&info, &parse_info);
1053 parser.set_allow_harmony_arrow_functions(true); 1051 parser.set_allow_harmony_arrow_functions(true);
1054 parser.set_allow_harmony_classes(true); 1052 parser.set_allow_harmony_classes(true);
1055 parser.set_allow_harmony_scoping(true); 1053 parser.set_allow_harmony_scoping(true);
1056 info.MarkAsGlobal(); 1054 info.MarkAsGlobal();
1057 parser.Parse(); 1055 parser.Parse(&info);
1058 CHECK(i::Rewriter::Rewrite(&info)); 1056 CHECK(i::Rewriter::Rewrite(&info));
1059 CHECK(i::Scope::Analyze(&info)); 1057 CHECK(i::Scope::Analyze(&info));
1060 CHECK(info.function() != NULL); 1058 CHECK(info.function() != NULL);
1061 1059
1062 i::Scope* script_scope = info.function()->scope(); 1060 i::Scope* script_scope = info.function()->scope();
1063 CHECK(script_scope->is_script_scope()); 1061 CHECK(script_scope->is_script_scope());
1064 CHECK_EQ(1, script_scope->inner_scopes()->length()); 1062 CHECK_EQ(1, script_scope->inner_scopes()->length());
1065 1063
1066 i::Scope* scope = script_scope->inner_scopes()->at(0); 1064 i::Scope* scope = script_scope->inner_scopes()->at(0);
1067 CHECK_EQ((source_data[i].expected & ARGUMENTS) != 0, 1065 CHECK_EQ((source_data[i].expected & ARGUMENTS) != 0,
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 i::CompilationInfoWithZone info(script); 1297 i::CompilationInfoWithZone info(script);
1300 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), 1298 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(),
1301 isolate->heap()->HashSeed(), 1299 isolate->heap()->HashSeed(),
1302 isolate->unicode_cache()}; 1300 isolate->unicode_cache()};
1303 i::Parser parser(&info, &parse_info); 1301 i::Parser parser(&info, &parse_info);
1304 parser.set_allow_lazy(true); 1302 parser.set_allow_lazy(true);
1305 parser.set_allow_harmony_scoping(true); 1303 parser.set_allow_harmony_scoping(true);
1306 parser.set_allow_harmony_arrow_functions(true); 1304 parser.set_allow_harmony_arrow_functions(true);
1307 info.MarkAsGlobal(); 1305 info.MarkAsGlobal();
1308 info.SetLanguageMode(source_data[i].language_mode); 1306 info.SetLanguageMode(source_data[i].language_mode);
1309 parser.Parse(); 1307 parser.Parse(&info);
1310 CHECK(info.function() != NULL); 1308 CHECK(info.function() != NULL);
1311 1309
1312 // Check scope types and positions. 1310 // Check scope types and positions.
1313 i::Scope* scope = info.function()->scope(); 1311 i::Scope* scope = info.function()->scope();
1314 CHECK(scope->is_script_scope()); 1312 CHECK(scope->is_script_scope());
1315 CHECK_EQ(scope->start_position(), 0); 1313 CHECK_EQ(scope->start_position(), 0);
1316 CHECK_EQ(scope->end_position(), kProgramSize); 1314 CHECK_EQ(scope->end_position(), kProgramSize);
1317 CHECK_EQ(scope->inner_scopes()->length(), 1); 1315 CHECK_EQ(scope->inner_scopes()->length(), 1);
1318 1316
1319 i::Scope* inner_scope = scope->inner_scopes()->at(0); 1317 i::Scope* inner_scope = scope->inner_scopes()->at(0);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1435 int parser_materialized_literals = -2; 1433 int parser_materialized_literals = -2;
1436 1434
1437 // Preparse the data. 1435 // Preparse the data.
1438 i::CompleteParserRecorder log; 1436 i::CompleteParserRecorder log;
1439 { 1437 {
1440 i::Scanner scanner(isolate->unicode_cache()); 1438 i::Scanner scanner(isolate->unicode_cache());
1441 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); 1439 i::GenericStringUtf16CharacterStream stream(source, 0, source->length());
1442 i::Zone zone; 1440 i::Zone zone;
1443 i::AstValueFactory ast_value_factory( 1441 i::AstValueFactory ast_value_factory(
1444 &zone, CcTest::i_isolate()->heap()->HashSeed()); 1442 &zone, CcTest::i_isolate()->heap()->HashSeed());
1445 i::PreParser preparser(CcTest::i_isolate(), &zone, &scanner, 1443 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log,
1446 &ast_value_factory, &log, stack_limit); 1444 stack_limit);
1447 SetParserFlags(&preparser, flags); 1445 SetParserFlags(&preparser, flags);
1448 scanner.Initialize(&stream); 1446 scanner.Initialize(&stream);
1449 i::PreParser::PreParseResult result = preparser.PreParseProgram( 1447 i::PreParser::PreParseResult result = preparser.PreParseProgram(
1450 &preparser_materialized_literals); 1448 &preparser_materialized_literals);
1451 CHECK_EQ(i::PreParser::kPreParseSuccess, result); 1449 CHECK_EQ(i::PreParser::kPreParseSuccess, result);
1452 } 1450 }
1453 1451
1454 bool preparse_error = log.HasError(); 1452 bool preparse_error = log.HasError();
1455 1453
1456 // Parse the data 1454 // Parse the data
1457 i::FunctionLiteral* function; 1455 i::FunctionLiteral* function;
1458 { 1456 {
1459 i::Handle<i::Script> script = factory->NewScript(source); 1457 i::Handle<i::Script> script = factory->NewScript(source);
1460 i::CompilationInfoWithZone info(script); 1458 i::CompilationInfoWithZone info(script);
1461 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), 1459 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(),
1462 isolate->heap()->HashSeed(), 1460 isolate->heap()->HashSeed(),
1463 isolate->unicode_cache()}; 1461 isolate->unicode_cache()};
1464 i::Parser parser(&info, &parse_info); 1462 i::Parser parser(&info, &parse_info);
1465 SetParserFlags(&parser, flags); 1463 SetParserFlags(&parser, flags);
1466 info.MarkAsGlobal(); 1464 info.MarkAsGlobal();
1467 parser.Parse(); 1465 parser.Parse(&info);
1468 function = info.function(); 1466 function = info.function();
1469 if (function) { 1467 if (function) {
1470 parser_materialized_literals = function->materialized_literal_count(); 1468 parser_materialized_literals = function->materialized_literal_count();
1471 } 1469 }
1472 } 1470 }
1473 1471
1474 // Check that preparsing fails iff parsing fails. 1472 // Check that preparsing fails iff parsing fails.
1475 if (function == NULL) { 1473 if (function == NULL) {
1476 // Extract exception from the parser. 1474 // Extract exception from the parser.
1477 CHECK(isolate->has_pending_exception()); 1475 CHECK(isolate->has_pending_exception());
(...skipping 1944 matching lines...) Expand 10 before | Expand all | Expand 10 after
3422 source->PrintOn(stdout); 3420 source->PrintOn(stdout);
3423 printf("\n"); 3421 printf("\n");
3424 3422
3425 i::Handle<i::Script> script = factory->NewScript(source); 3423 i::Handle<i::Script> script = factory->NewScript(source);
3426 i::CompilationInfoWithZone info(script); 3424 i::CompilationInfoWithZone info(script);
3427 i::Parser::ParseInfo parse_info = { 3425 i::Parser::ParseInfo parse_info = {
3428 isolate->stack_guard()->real_climit(), 3426 isolate->stack_guard()->real_climit(),
3429 isolate->heap()->HashSeed(), isolate->unicode_cache()}; 3427 isolate->heap()->HashSeed(), isolate->unicode_cache()};
3430 i::Parser parser(&info, &parse_info); 3428 i::Parser parser(&info, &parse_info);
3431 parser.set_allow_harmony_scoping(true); 3429 parser.set_allow_harmony_scoping(true);
3432 CHECK(parser.Parse()); 3430 CHECK(parser.Parse(&info));
3433 CHECK(i::Compiler::Analyze(&info)); 3431 CHECK(i::Compiler::Analyze(&info));
3434 CHECK(info.function() != NULL); 3432 CHECK(info.function() != NULL);
3435 3433
3436 i::Scope* scope = info.function()->scope(); 3434 i::Scope* scope = info.function()->scope();
3437 CHECK_EQ(scope->inner_scopes()->length(), 1); 3435 CHECK_EQ(scope->inner_scopes()->length(), 1);
3438 i::Scope* inner_scope = scope->inner_scopes()->at(0); 3436 i::Scope* inner_scope = scope->inner_scopes()->at(0);
3439 const i::AstRawString* var_name = 3437 const i::AstRawString* var_name =
3440 info.ast_value_factory()->GetOneByteString("x"); 3438 info.ast_value_factory()->GetOneByteString("x");
3441 i::Variable* var = inner_scope->Lookup(var_name); 3439 i::Variable* var = inner_scope->Lookup(var_name);
3442 bool expected = outers[i].assigned || inners[j].assigned; 3440 bool expected = outers[i].assigned || inners[j].assigned;
(...skipping 1416 matching lines...) Expand 10 before | Expand all | Expand 10 after
4859 i::Handle<i::Script> script = factory->NewScript(source); 4857 i::Handle<i::Script> script = factory->NewScript(source);
4860 i::CompilationInfoWithZone info(script); 4858 i::CompilationInfoWithZone info(script);
4861 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), 4859 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(),
4862 isolate->heap()->HashSeed(), 4860 isolate->heap()->HashSeed(),
4863 isolate->unicode_cache()}; 4861 isolate->unicode_cache()};
4864 i::Parser parser(&info, &parse_info); 4862 i::Parser parser(&info, &parse_info);
4865 parser.set_allow_harmony_classes(true); 4863 parser.set_allow_harmony_classes(true);
4866 parser.set_allow_harmony_modules(true); 4864 parser.set_allow_harmony_modules(true);
4867 parser.set_allow_harmony_scoping(true); 4865 parser.set_allow_harmony_scoping(true);
4868 info.MarkAsModule(); 4866 info.MarkAsModule();
4869 if (!parser.Parse()) { 4867 if (!parser.Parse(&info)) {
4870 i::Handle<i::JSObject> exception_handle( 4868 i::Handle<i::JSObject> exception_handle(
4871 i::JSObject::cast(isolate->pending_exception())); 4869 i::JSObject::cast(isolate->pending_exception()));
4872 i::Handle<i::String> message_string = 4870 i::Handle<i::String> message_string =
4873 i::Handle<i::String>::cast(i::Object::GetProperty( 4871 i::Handle<i::String>::cast(i::Object::GetProperty(
4874 isolate, exception_handle, "message").ToHandleChecked()); 4872 isolate, exception_handle, "message").ToHandleChecked());
4875 4873
4876 v8::base::OS::Print( 4874 v8::base::OS::Print(
4877 "Parser failed on:\n" 4875 "Parser failed on:\n"
4878 "\t%s\n" 4876 "\t%s\n"
4879 "with error:\n" 4877 "with error:\n"
4880 "\t%s\n" 4878 "\t%s\n"
4881 "However, we expected no error.", 4879 "However, we expected no error.",
4882 source->ToCString().get(), message_string->ToCString().get()); 4880 source->ToCString().get(), message_string->ToCString().get());
4883 CHECK(false); 4881 CHECK(false);
4884 } 4882 }
4885 } 4883 }
4886 4884
4887 // And that parsing a script does not. 4885 // And that parsing a script does not.
4888 { 4886 {
4889 i::Handle<i::Script> script = factory->NewScript(source); 4887 i::Handle<i::Script> script = factory->NewScript(source);
4890 i::CompilationInfoWithZone info(script); 4888 i::CompilationInfoWithZone info(script);
4891 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), 4889 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(),
4892 isolate->heap()->HashSeed(), 4890 isolate->heap()->HashSeed(),
4893 isolate->unicode_cache()}; 4891 isolate->unicode_cache()};
4894 i::Parser parser(&info, &parse_info); 4892 i::Parser parser(&info, &parse_info);
4895 parser.set_allow_harmony_classes(true); 4893 parser.set_allow_harmony_classes(true);
4896 parser.set_allow_harmony_modules(true); 4894 parser.set_allow_harmony_modules(true);
4897 parser.set_allow_harmony_scoping(true); 4895 parser.set_allow_harmony_scoping(true);
4898 info.MarkAsGlobal(); 4896 info.MarkAsGlobal();
4899 CHECK(!parser.Parse()); 4897 CHECK(!parser.Parse(&info));
4900 } 4898 }
4901 } 4899 }
4902 } 4900 }
4903 4901
4904 4902
4905 TEST(ImportExportParsingErrors) { 4903 TEST(ImportExportParsingErrors) {
4906 const char* kErrorSources[] = { 4904 const char* kErrorSources[] = {
4907 "export {", 4905 "export {",
4908 "var a; export { a", 4906 "var a; export { a",
4909 "var a; export { a,", 4907 "var a; export { a,",
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
4981 i::Handle<i::Script> script = factory->NewScript(source); 4979 i::Handle<i::Script> script = factory->NewScript(source);
4982 i::CompilationInfoWithZone info(script); 4980 i::CompilationInfoWithZone info(script);
4983 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), 4981 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(),
4984 isolate->heap()->HashSeed(), 4982 isolate->heap()->HashSeed(),
4985 isolate->unicode_cache()}; 4983 isolate->unicode_cache()};
4986 i::Parser parser(&info, &parse_info); 4984 i::Parser parser(&info, &parse_info);
4987 parser.set_allow_harmony_classes(true); 4985 parser.set_allow_harmony_classes(true);
4988 parser.set_allow_harmony_modules(true); 4986 parser.set_allow_harmony_modules(true);
4989 parser.set_allow_harmony_scoping(true); 4987 parser.set_allow_harmony_scoping(true);
4990 info.MarkAsModule(); 4988 info.MarkAsModule();
4991 CHECK(!parser.Parse()); 4989 CHECK(!parser.Parse(&info));
4992 } 4990 }
4993 } 4991 }
4994 4992
4995 4993
4996 TEST(DuplicateProtoError) { 4994 TEST(DuplicateProtoError) {
4997 const char* context_data[][2] = { 4995 const char* context_data[][2] = {
4998 {"({", "});"}, 4996 {"({", "});"},
4999 {"'use strict'; ({", "});"}, 4997 {"'use strict'; ({", "});"},
5000 {NULL, NULL} 4998 {NULL, NULL}
5001 }; 4999 };
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
5075 5073
5076 i::Handle<i::Script> script = 5074 i::Handle<i::Script> script =
5077 factory->NewScript(factory->NewStringFromAsciiChecked(source)); 5075 factory->NewScript(factory->NewStringFromAsciiChecked(source));
5078 i::CompilationInfoWithZone info(script); 5076 i::CompilationInfoWithZone info(script);
5079 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), 5077 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(),
5080 isolate->heap()->HashSeed(), 5078 isolate->heap()->HashSeed(),
5081 isolate->unicode_cache()}; 5079 isolate->unicode_cache()};
5082 i::Parser parser(&info, &parse_info); 5080 i::Parser parser(&info, &parse_info);
5083 parser.set_allow_strong_mode(true); 5081 parser.set_allow_strong_mode(true);
5084 info.MarkAsGlobal(); 5082 info.MarkAsGlobal();
5085 parser.Parse(); 5083 parser.Parse(&info);
5086 CHECK(info.function() != NULL); 5084 CHECK(info.function() != NULL);
5087 CHECK_EQ(expected_language_mode, info.function()->language_mode()); 5085 CHECK_EQ(expected_language_mode, info.function()->language_mode());
5088 } 5086 }
5089 5087
5090 5088
5091 TEST(LanguageModeDirectives) { 5089 TEST(LanguageModeDirectives) {
5092 TestLanguageMode("\"use nothing\"", i::SLOPPY); 5090 TestLanguageMode("\"use nothing\"", i::SLOPPY);
5093 TestLanguageMode("\"use strict\"", i::STRICT); 5091 TestLanguageMode("\"use strict\"", i::STRICT);
5094 TestLanguageMode("\"use strong\"", i::STRONG); 5092 TestLanguageMode("\"use strong\"", i::STRONG);
5095 5093
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
5142 "class C {static set arguments(_) {}}", 5140 "class C {static set arguments(_) {}}",
5143 5141
5144 NULL}; 5142 NULL};
5145 5143
5146 static const ParserFlag always_flags[] = { 5144 static const ParserFlag always_flags[] = {
5147 kAllowHarmonyClasses, kAllowHarmonyObjectLiterals, kAllowHarmonyScoping, 5145 kAllowHarmonyClasses, kAllowHarmonyObjectLiterals, kAllowHarmonyScoping,
5148 kAllowStrongMode}; 5146 kAllowStrongMode};
5149 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, 5147 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0,
5150 always_flags, arraysize(always_flags)); 5148 always_flags, arraysize(always_flags));
5151 } 5149 }
OLDNEW
« src/parser.cc ('K') | « src/preparser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698