| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1057 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), | 1055 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), |
| 1058 isolate->heap()->HashSeed(), | 1056 isolate->heap()->HashSeed(), |
| 1059 isolate->unicode_cache()}; | 1057 isolate->unicode_cache()}; |
| 1060 i::Parser parser(&info, &parse_info); | 1058 i::Parser parser(&info, &parse_info); |
| 1061 parser.set_allow_harmony_arrow_functions(true); | 1059 parser.set_allow_harmony_arrow_functions(true); |
| 1062 parser.set_allow_harmony_classes(true); | 1060 parser.set_allow_harmony_classes(true); |
| 1063 parser.set_allow_harmony_object_literals(true); | 1061 parser.set_allow_harmony_object_literals(true); |
| 1064 parser.set_allow_harmony_scoping(true); | 1062 parser.set_allow_harmony_scoping(true); |
| 1065 parser.set_allow_harmony_sloppy(true); | 1063 parser.set_allow_harmony_sloppy(true); |
| 1066 info.MarkAsGlobal(); | 1064 info.MarkAsGlobal(); |
| 1067 CHECK(parser.Parse()); | 1065 CHECK(parser.Parse(&info)); |
| 1068 CHECK(i::Rewriter::Rewrite(&info)); | 1066 CHECK(i::Rewriter::Rewrite(&info)); |
| 1069 CHECK(i::Scope::Analyze(&info)); | 1067 CHECK(i::Scope::Analyze(&info)); |
| 1070 CHECK(info.function() != NULL); | 1068 CHECK(info.function() != NULL); |
| 1071 | 1069 |
| 1072 i::Scope* script_scope = info.function()->scope(); | 1070 i::Scope* script_scope = info.function()->scope(); |
| 1073 CHECK(script_scope->is_script_scope()); | 1071 CHECK(script_scope->is_script_scope()); |
| 1074 CHECK_EQ(1, script_scope->inner_scopes()->length()); | 1072 CHECK_EQ(1, script_scope->inner_scopes()->length()); |
| 1075 | 1073 |
| 1076 i::Scope* scope = script_scope->inner_scopes()->at(0); | 1074 i::Scope* scope = script_scope->inner_scopes()->at(0); |
| 1077 // Adjust for constructor scope. | 1075 // Adjust for constructor scope. |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1314 i::CompilationInfoWithZone info(script); | 1312 i::CompilationInfoWithZone info(script); |
| 1315 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), | 1313 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), |
| 1316 isolate->heap()->HashSeed(), | 1314 isolate->heap()->HashSeed(), |
| 1317 isolate->unicode_cache()}; | 1315 isolate->unicode_cache()}; |
| 1318 i::Parser parser(&info, &parse_info); | 1316 i::Parser parser(&info, &parse_info); |
| 1319 parser.set_allow_lazy(true); | 1317 parser.set_allow_lazy(true); |
| 1320 parser.set_allow_harmony_scoping(true); | 1318 parser.set_allow_harmony_scoping(true); |
| 1321 parser.set_allow_harmony_arrow_functions(true); | 1319 parser.set_allow_harmony_arrow_functions(true); |
| 1322 info.MarkAsGlobal(); | 1320 info.MarkAsGlobal(); |
| 1323 info.SetLanguageMode(source_data[i].language_mode); | 1321 info.SetLanguageMode(source_data[i].language_mode); |
| 1324 parser.Parse(); | 1322 parser.Parse(&info); |
| 1325 CHECK(info.function() != NULL); | 1323 CHECK(info.function() != NULL); |
| 1326 | 1324 |
| 1327 // Check scope types and positions. | 1325 // Check scope types and positions. |
| 1328 i::Scope* scope = info.function()->scope(); | 1326 i::Scope* scope = info.function()->scope(); |
| 1329 CHECK(scope->is_script_scope()); | 1327 CHECK(scope->is_script_scope()); |
| 1330 CHECK_EQ(scope->start_position(), 0); | 1328 CHECK_EQ(scope->start_position(), 0); |
| 1331 CHECK_EQ(scope->end_position(), kProgramSize); | 1329 CHECK_EQ(scope->end_position(), kProgramSize); |
| 1332 CHECK_EQ(scope->inner_scopes()->length(), 1); | 1330 CHECK_EQ(scope->inner_scopes()->length(), 1); |
| 1333 | 1331 |
| 1334 i::Scope* inner_scope = scope->inner_scopes()->at(0); | 1332 i::Scope* inner_scope = scope->inner_scopes()->at(0); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1450 int parser_materialized_literals = -2; | 1448 int parser_materialized_literals = -2; |
| 1451 | 1449 |
| 1452 // Preparse the data. | 1450 // Preparse the data. |
| 1453 i::CompleteParserRecorder log; | 1451 i::CompleteParserRecorder log; |
| 1454 { | 1452 { |
| 1455 i::Scanner scanner(isolate->unicode_cache()); | 1453 i::Scanner scanner(isolate->unicode_cache()); |
| 1456 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 1454 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
| 1457 i::Zone zone; | 1455 i::Zone zone; |
| 1458 i::AstValueFactory ast_value_factory( | 1456 i::AstValueFactory ast_value_factory( |
| 1459 &zone, CcTest::i_isolate()->heap()->HashSeed()); | 1457 &zone, CcTest::i_isolate()->heap()->HashSeed()); |
| 1460 i::PreParser preparser(CcTest::i_isolate(), &zone, &scanner, | 1458 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, |
| 1461 &ast_value_factory, &log, stack_limit); | 1459 stack_limit); |
| 1462 SetParserFlags(&preparser, flags); | 1460 SetParserFlags(&preparser, flags); |
| 1463 scanner.Initialize(&stream); | 1461 scanner.Initialize(&stream); |
| 1464 i::PreParser::PreParseResult result = preparser.PreParseProgram( | 1462 i::PreParser::PreParseResult result = preparser.PreParseProgram( |
| 1465 &preparser_materialized_literals); | 1463 &preparser_materialized_literals); |
| 1466 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 1464 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 1467 } | 1465 } |
| 1468 | 1466 |
| 1469 bool preparse_error = log.HasError(); | 1467 bool preparse_error = log.HasError(); |
| 1470 | 1468 |
| 1471 // Parse the data | 1469 // Parse the data |
| 1472 i::FunctionLiteral* function; | 1470 i::FunctionLiteral* function; |
| 1473 { | 1471 { |
| 1474 i::Handle<i::Script> script = factory->NewScript(source); | 1472 i::Handle<i::Script> script = factory->NewScript(source); |
| 1475 i::CompilationInfoWithZone info(script); | 1473 i::CompilationInfoWithZone info(script); |
| 1476 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), | 1474 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), |
| 1477 isolate->heap()->HashSeed(), | 1475 isolate->heap()->HashSeed(), |
| 1478 isolate->unicode_cache()}; | 1476 isolate->unicode_cache()}; |
| 1479 i::Parser parser(&info, &parse_info); | 1477 i::Parser parser(&info, &parse_info); |
| 1480 SetParserFlags(&parser, flags); | 1478 SetParserFlags(&parser, flags); |
| 1481 info.MarkAsGlobal(); | 1479 info.MarkAsGlobal(); |
| 1482 parser.Parse(); | 1480 parser.Parse(&info); |
| 1483 function = info.function(); | 1481 function = info.function(); |
| 1484 if (function) { | 1482 if (function) { |
| 1485 parser_materialized_literals = function->materialized_literal_count(); | 1483 parser_materialized_literals = function->materialized_literal_count(); |
| 1486 } | 1484 } |
| 1487 } | 1485 } |
| 1488 | 1486 |
| 1489 // Check that preparsing fails iff parsing fails. | 1487 // Check that preparsing fails iff parsing fails. |
| 1490 if (function == NULL) { | 1488 if (function == NULL) { |
| 1491 // Extract exception from the parser. | 1489 // Extract exception from the parser. |
| 1492 CHECK(isolate->has_pending_exception()); | 1490 CHECK(isolate->has_pending_exception()); |
| (...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2557 | 2555 |
| 2558 for (int i = 0; test_cases[i].program; i++) { | 2556 for (int i = 0; test_cases[i].program; i++) { |
| 2559 const char* program = test_cases[i].program; | 2557 const char* program = test_cases[i].program; |
| 2560 i::Factory* factory = CcTest::i_isolate()->factory(); | 2558 i::Factory* factory = CcTest::i_isolate()->factory(); |
| 2561 i::Handle<i::String> source = | 2559 i::Handle<i::String> source = |
| 2562 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); | 2560 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); |
| 2563 i::Handle<i::Script> script = factory->NewScript(source); | 2561 i::Handle<i::Script> script = factory->NewScript(source); |
| 2564 i::CompilationInfoWithZone info(script); | 2562 i::CompilationInfoWithZone info(script); |
| 2565 i::ScriptData* sd = NULL; | 2563 i::ScriptData* sd = NULL; |
| 2566 info.SetCachedData(&sd, v8::ScriptCompiler::kProduceParserCache); | 2564 info.SetCachedData(&sd, v8::ScriptCompiler::kProduceParserCache); |
| 2567 i::Parser::Parse(&info, true); | 2565 i::Parser::ParseStatic(&info, true); |
| 2568 i::ParseData* pd = i::ParseData::FromCachedData(sd); | 2566 i::ParseData* pd = i::ParseData::FromCachedData(sd); |
| 2569 | 2567 |
| 2570 if (pd->FunctionCount() != test_cases[i].functions) { | 2568 if (pd->FunctionCount() != test_cases[i].functions) { |
| 2571 v8::base::OS::Print( | 2569 v8::base::OS::Print( |
| 2572 "Expected preparse data for program:\n" | 2570 "Expected preparse data for program:\n" |
| 2573 "\t%s\n" | 2571 "\t%s\n" |
| 2574 "to contain %d functions, however, received %d functions.\n", | 2572 "to contain %d functions, however, received %d functions.\n", |
| 2575 program, test_cases[i].functions, pd->FunctionCount()); | 2573 program, test_cases[i].functions, pd->FunctionCount()); |
| 2576 CHECK(false); | 2574 CHECK(false); |
| 2577 } | 2575 } |
| (...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3437 source->PrintOn(stdout); | 3435 source->PrintOn(stdout); |
| 3438 printf("\n"); | 3436 printf("\n"); |
| 3439 | 3437 |
| 3440 i::Handle<i::Script> script = factory->NewScript(source); | 3438 i::Handle<i::Script> script = factory->NewScript(source); |
| 3441 i::CompilationInfoWithZone info(script); | 3439 i::CompilationInfoWithZone info(script); |
| 3442 i::Parser::ParseInfo parse_info = { | 3440 i::Parser::ParseInfo parse_info = { |
| 3443 isolate->stack_guard()->real_climit(), | 3441 isolate->stack_guard()->real_climit(), |
| 3444 isolate->heap()->HashSeed(), isolate->unicode_cache()}; | 3442 isolate->heap()->HashSeed(), isolate->unicode_cache()}; |
| 3445 i::Parser parser(&info, &parse_info); | 3443 i::Parser parser(&info, &parse_info); |
| 3446 parser.set_allow_harmony_scoping(true); | 3444 parser.set_allow_harmony_scoping(true); |
| 3447 CHECK(parser.Parse()); | 3445 CHECK(parser.Parse(&info)); |
| 3448 CHECK(i::Compiler::Analyze(&info)); | 3446 CHECK(i::Compiler::Analyze(&info)); |
| 3449 CHECK(info.function() != NULL); | 3447 CHECK(info.function() != NULL); |
| 3450 | 3448 |
| 3451 i::Scope* scope = info.function()->scope(); | 3449 i::Scope* scope = info.function()->scope(); |
| 3452 CHECK_EQ(scope->inner_scopes()->length(), 1); | 3450 CHECK_EQ(scope->inner_scopes()->length(), 1); |
| 3453 i::Scope* inner_scope = scope->inner_scopes()->at(0); | 3451 i::Scope* inner_scope = scope->inner_scopes()->at(0); |
| 3454 const i::AstRawString* var_name = | 3452 const i::AstRawString* var_name = |
| 3455 info.ast_value_factory()->GetOneByteString("x"); | 3453 info.ast_value_factory()->GetOneByteString("x"); |
| 3456 i::Variable* var = inner_scope->Lookup(var_name); | 3454 i::Variable* var = inner_scope->Lookup(var_name); |
| 3457 bool expected = outers[i].assigned || inners[j].assigned; | 3455 bool expected = outers[i].assigned || inners[j].assigned; |
| (...skipping 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5053 i::Handle<i::Script> script = factory->NewScript(source); | 5051 i::Handle<i::Script> script = factory->NewScript(source); |
| 5054 i::CompilationInfoWithZone info(script); | 5052 i::CompilationInfoWithZone info(script); |
| 5055 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), | 5053 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), |
| 5056 isolate->heap()->HashSeed(), | 5054 isolate->heap()->HashSeed(), |
| 5057 isolate->unicode_cache()}; | 5055 isolate->unicode_cache()}; |
| 5058 i::Parser parser(&info, &parse_info); | 5056 i::Parser parser(&info, &parse_info); |
| 5059 parser.set_allow_harmony_classes(true); | 5057 parser.set_allow_harmony_classes(true); |
| 5060 parser.set_allow_harmony_modules(true); | 5058 parser.set_allow_harmony_modules(true); |
| 5061 parser.set_allow_harmony_scoping(true); | 5059 parser.set_allow_harmony_scoping(true); |
| 5062 info.MarkAsModule(); | 5060 info.MarkAsModule(); |
| 5063 if (!parser.Parse()) { | 5061 if (!parser.Parse(&info)) { |
| 5064 i::Handle<i::JSObject> exception_handle( | 5062 i::Handle<i::JSObject> exception_handle( |
| 5065 i::JSObject::cast(isolate->pending_exception())); | 5063 i::JSObject::cast(isolate->pending_exception())); |
| 5066 i::Handle<i::String> message_string = | 5064 i::Handle<i::String> message_string = |
| 5067 i::Handle<i::String>::cast(i::Object::GetProperty( | 5065 i::Handle<i::String>::cast(i::Object::GetProperty( |
| 5068 isolate, exception_handle, "message").ToHandleChecked()); | 5066 isolate, exception_handle, "message").ToHandleChecked()); |
| 5069 | 5067 |
| 5070 v8::base::OS::Print( | 5068 v8::base::OS::Print( |
| 5071 "Parser failed on:\n" | 5069 "Parser failed on:\n" |
| 5072 "\t%s\n" | 5070 "\t%s\n" |
| 5073 "with error:\n" | 5071 "with error:\n" |
| 5074 "\t%s\n" | 5072 "\t%s\n" |
| 5075 "However, we expected no error.", | 5073 "However, we expected no error.", |
| 5076 source->ToCString().get(), message_string->ToCString().get()); | 5074 source->ToCString().get(), message_string->ToCString().get()); |
| 5077 CHECK(false); | 5075 CHECK(false); |
| 5078 } | 5076 } |
| 5079 } | 5077 } |
| 5080 | 5078 |
| 5081 // And that parsing a script does not. | 5079 // And that parsing a script does not. |
| 5082 { | 5080 { |
| 5083 i::Handle<i::Script> script = factory->NewScript(source); | 5081 i::Handle<i::Script> script = factory->NewScript(source); |
| 5084 i::CompilationInfoWithZone info(script); | 5082 i::CompilationInfoWithZone info(script); |
| 5085 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), | 5083 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), |
| 5086 isolate->heap()->HashSeed(), | 5084 isolate->heap()->HashSeed(), |
| 5087 isolate->unicode_cache()}; | 5085 isolate->unicode_cache()}; |
| 5088 i::Parser parser(&info, &parse_info); | 5086 i::Parser parser(&info, &parse_info); |
| 5089 parser.set_allow_harmony_classes(true); | 5087 parser.set_allow_harmony_classes(true); |
| 5090 parser.set_allow_harmony_modules(true); | 5088 parser.set_allow_harmony_modules(true); |
| 5091 parser.set_allow_harmony_scoping(true); | 5089 parser.set_allow_harmony_scoping(true); |
| 5092 info.MarkAsGlobal(); | 5090 info.MarkAsGlobal(); |
| 5093 CHECK(!parser.Parse()); | 5091 CHECK(!parser.Parse(&info)); |
| 5094 } | 5092 } |
| 5095 } | 5093 } |
| 5096 } | 5094 } |
| 5097 | 5095 |
| 5098 | 5096 |
| 5099 TEST(ImportExportParsingErrors) { | 5097 TEST(ImportExportParsingErrors) { |
| 5100 const char* kErrorSources[] = { | 5098 const char* kErrorSources[] = { |
| 5101 "export {", | 5099 "export {", |
| 5102 "var a; export { a", | 5100 "var a; export { a", |
| 5103 "var a; export { a,", | 5101 "var a; export { a,", |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5175 i::Handle<i::Script> script = factory->NewScript(source); | 5173 i::Handle<i::Script> script = factory->NewScript(source); |
| 5176 i::CompilationInfoWithZone info(script); | 5174 i::CompilationInfoWithZone info(script); |
| 5177 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), | 5175 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), |
| 5178 isolate->heap()->HashSeed(), | 5176 isolate->heap()->HashSeed(), |
| 5179 isolate->unicode_cache()}; | 5177 isolate->unicode_cache()}; |
| 5180 i::Parser parser(&info, &parse_info); | 5178 i::Parser parser(&info, &parse_info); |
| 5181 parser.set_allow_harmony_classes(true); | 5179 parser.set_allow_harmony_classes(true); |
| 5182 parser.set_allow_harmony_modules(true); | 5180 parser.set_allow_harmony_modules(true); |
| 5183 parser.set_allow_harmony_scoping(true); | 5181 parser.set_allow_harmony_scoping(true); |
| 5184 info.MarkAsModule(); | 5182 info.MarkAsModule(); |
| 5185 CHECK(!parser.Parse()); | 5183 CHECK(!parser.Parse(&info)); |
| 5186 } | 5184 } |
| 5187 } | 5185 } |
| 5188 | 5186 |
| 5189 | 5187 |
| 5190 TEST(DuplicateProtoError) { | 5188 TEST(DuplicateProtoError) { |
| 5191 const char* context_data[][2] = { | 5189 const char* context_data[][2] = { |
| 5192 {"({", "});"}, | 5190 {"({", "});"}, |
| 5193 {"'use strict'; ({", "});"}, | 5191 {"'use strict'; ({", "});"}, |
| 5194 {NULL, NULL} | 5192 {NULL, NULL} |
| 5195 }; | 5193 }; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5269 | 5267 |
| 5270 i::Handle<i::Script> script = | 5268 i::Handle<i::Script> script = |
| 5271 factory->NewScript(factory->NewStringFromAsciiChecked(source)); | 5269 factory->NewScript(factory->NewStringFromAsciiChecked(source)); |
| 5272 i::CompilationInfoWithZone info(script); | 5270 i::CompilationInfoWithZone info(script); |
| 5273 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), | 5271 i::Parser::ParseInfo parse_info = {isolate->stack_guard()->real_climit(), |
| 5274 isolate->heap()->HashSeed(), | 5272 isolate->heap()->HashSeed(), |
| 5275 isolate->unicode_cache()}; | 5273 isolate->unicode_cache()}; |
| 5276 i::Parser parser(&info, &parse_info); | 5274 i::Parser parser(&info, &parse_info); |
| 5277 parser.set_allow_strong_mode(true); | 5275 parser.set_allow_strong_mode(true); |
| 5278 info.MarkAsGlobal(); | 5276 info.MarkAsGlobal(); |
| 5279 parser.Parse(); | 5277 parser.Parse(&info); |
| 5280 CHECK(info.function() != NULL); | 5278 CHECK(info.function() != NULL); |
| 5281 CHECK_EQ(expected_language_mode, info.function()->language_mode()); | 5279 CHECK_EQ(expected_language_mode, info.function()->language_mode()); |
| 5282 } | 5280 } |
| 5283 | 5281 |
| 5284 | 5282 |
| 5285 TEST(LanguageModeDirectives) { | 5283 TEST(LanguageModeDirectives) { |
| 5286 TestLanguageMode("\"use nothing\"", i::SLOPPY); | 5284 TestLanguageMode("\"use nothing\"", i::SLOPPY); |
| 5287 TestLanguageMode("\"use strict\"", i::STRICT); | 5285 TestLanguageMode("\"use strict\"", i::STRICT); |
| 5288 TestLanguageMode("\"use strong\"", i::STRONG); | 5286 TestLanguageMode("\"use strong\"", i::STRONG); |
| 5289 | 5287 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5336 "class C {static set arguments(_) {}}", | 5334 "class C {static set arguments(_) {}}", |
| 5337 | 5335 |
| 5338 NULL}; | 5336 NULL}; |
| 5339 | 5337 |
| 5340 static const ParserFlag always_flags[] = { | 5338 static const ParserFlag always_flags[] = { |
| 5341 kAllowHarmonyClasses, kAllowHarmonyObjectLiterals, kAllowHarmonyScoping, | 5339 kAllowHarmonyClasses, kAllowHarmonyObjectLiterals, kAllowHarmonyScoping, |
| 5342 kAllowStrongMode}; | 5340 kAllowStrongMode}; |
| 5343 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 5341 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
| 5344 always_flags, arraysize(always_flags)); | 5342 always_flags, arraysize(always_flags)); |
| 5345 } | 5343 } |
| OLD | NEW |