| 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 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 i::Handle<i::Script> script = factory->NewScript(source); | 1053 i::Handle<i::Script> script = factory->NewScript(source); |
| 1056 i::CompilationInfoWithZone info(script); | 1054 i::CompilationInfoWithZone info(script); |
| 1057 i::Parser parser(&info, isolate->stack_guard()->real_climit(), | 1055 i::Parser parser(&info, isolate->stack_guard()->real_climit(), |
| 1058 isolate->heap()->HashSeed(), isolate->unicode_cache()); | 1056 isolate->heap()->HashSeed(), isolate->unicode_cache()); |
| 1059 parser.set_allow_harmony_arrow_functions(true); | 1057 parser.set_allow_harmony_arrow_functions(true); |
| 1060 parser.set_allow_harmony_classes(true); | 1058 parser.set_allow_harmony_classes(true); |
| 1061 parser.set_allow_harmony_object_literals(true); | 1059 parser.set_allow_harmony_object_literals(true); |
| 1062 parser.set_allow_harmony_scoping(true); | 1060 parser.set_allow_harmony_scoping(true); |
| 1063 parser.set_allow_harmony_sloppy(true); | 1061 parser.set_allow_harmony_sloppy(true); |
| 1064 info.MarkAsGlobal(); | 1062 info.MarkAsGlobal(); |
| 1065 CHECK(parser.Parse()); | 1063 CHECK(parser.Parse(&info)); |
| 1066 CHECK(i::Rewriter::Rewrite(&info)); | 1064 CHECK(i::Rewriter::Rewrite(&info)); |
| 1067 CHECK(i::Scope::Analyze(&info)); | 1065 CHECK(i::Scope::Analyze(&info)); |
| 1068 CHECK(info.function() != NULL); | 1066 CHECK(info.function() != NULL); |
| 1069 | 1067 |
| 1070 i::Scope* script_scope = info.function()->scope(); | 1068 i::Scope* script_scope = info.function()->scope(); |
| 1071 CHECK(script_scope->is_script_scope()); | 1069 CHECK(script_scope->is_script_scope()); |
| 1072 CHECK_EQ(1, script_scope->inner_scopes()->length()); | 1070 CHECK_EQ(1, script_scope->inner_scopes()->length()); |
| 1073 | 1071 |
| 1074 i::Scope* scope = script_scope->inner_scopes()->at(0); | 1072 i::Scope* scope = script_scope->inner_scopes()->at(0); |
| 1075 // Adjust for constructor scope. | 1073 // Adjust for constructor scope. |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1310 CHECK_EQ(source->length(), kProgramSize); | 1308 CHECK_EQ(source->length(), kProgramSize); |
| 1311 i::Handle<i::Script> script = factory->NewScript(source); | 1309 i::Handle<i::Script> script = factory->NewScript(source); |
| 1312 i::CompilationInfoWithZone info(script); | 1310 i::CompilationInfoWithZone info(script); |
| 1313 i::Parser parser(&info, isolate->stack_guard()->real_climit(), | 1311 i::Parser parser(&info, isolate->stack_guard()->real_climit(), |
| 1314 isolate->heap()->HashSeed(), isolate->unicode_cache()); | 1312 isolate->heap()->HashSeed(), isolate->unicode_cache()); |
| 1315 parser.set_allow_lazy(true); | 1313 parser.set_allow_lazy(true); |
| 1316 parser.set_allow_harmony_scoping(true); | 1314 parser.set_allow_harmony_scoping(true); |
| 1317 parser.set_allow_harmony_arrow_functions(true); | 1315 parser.set_allow_harmony_arrow_functions(true); |
| 1318 info.MarkAsGlobal(); | 1316 info.MarkAsGlobal(); |
| 1319 info.SetLanguageMode(source_data[i].language_mode); | 1317 info.SetLanguageMode(source_data[i].language_mode); |
| 1320 parser.Parse(); | 1318 parser.Parse(&info); |
| 1321 CHECK(info.function() != NULL); | 1319 CHECK(info.function() != NULL); |
| 1322 | 1320 |
| 1323 // Check scope types and positions. | 1321 // Check scope types and positions. |
| 1324 i::Scope* scope = info.function()->scope(); | 1322 i::Scope* scope = info.function()->scope(); |
| 1325 CHECK(scope->is_script_scope()); | 1323 CHECK(scope->is_script_scope()); |
| 1326 CHECK_EQ(scope->start_position(), 0); | 1324 CHECK_EQ(scope->start_position(), 0); |
| 1327 CHECK_EQ(scope->end_position(), kProgramSize); | 1325 CHECK_EQ(scope->end_position(), kProgramSize); |
| 1328 CHECK_EQ(scope->inner_scopes()->length(), 1); | 1326 CHECK_EQ(scope->inner_scopes()->length(), 1); |
| 1329 | 1327 |
| 1330 i::Scope* inner_scope = scope->inner_scopes()->at(0); | 1328 i::Scope* inner_scope = scope->inner_scopes()->at(0); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1446 int parser_materialized_literals = -2; | 1444 int parser_materialized_literals = -2; |
| 1447 | 1445 |
| 1448 // Preparse the data. | 1446 // Preparse the data. |
| 1449 i::CompleteParserRecorder log; | 1447 i::CompleteParserRecorder log; |
| 1450 { | 1448 { |
| 1451 i::Scanner scanner(isolate->unicode_cache()); | 1449 i::Scanner scanner(isolate->unicode_cache()); |
| 1452 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 1450 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
| 1453 i::Zone zone; | 1451 i::Zone zone; |
| 1454 i::AstValueFactory ast_value_factory( | 1452 i::AstValueFactory ast_value_factory( |
| 1455 &zone, CcTest::i_isolate()->heap()->HashSeed()); | 1453 &zone, CcTest::i_isolate()->heap()->HashSeed()); |
| 1456 i::PreParser preparser(CcTest::i_isolate(), &zone, &scanner, | 1454 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, |
| 1457 &ast_value_factory, &log, stack_limit); | 1455 stack_limit); |
| 1458 SetParserFlags(&preparser, flags); | 1456 SetParserFlags(&preparser, flags); |
| 1459 scanner.Initialize(&stream); | 1457 scanner.Initialize(&stream); |
| 1460 i::PreParser::PreParseResult result = preparser.PreParseProgram( | 1458 i::PreParser::PreParseResult result = preparser.PreParseProgram( |
| 1461 &preparser_materialized_literals); | 1459 &preparser_materialized_literals); |
| 1462 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 1460 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 1463 } | 1461 } |
| 1464 | 1462 |
| 1465 bool preparse_error = log.HasError(); | 1463 bool preparse_error = log.HasError(); |
| 1466 | 1464 |
| 1467 // Parse the data | 1465 // Parse the data |
| 1468 i::FunctionLiteral* function; | 1466 i::FunctionLiteral* function; |
| 1469 { | 1467 { |
| 1470 i::Handle<i::Script> script = factory->NewScript(source); | 1468 i::Handle<i::Script> script = factory->NewScript(source); |
| 1471 i::CompilationInfoWithZone info(script); | 1469 i::CompilationInfoWithZone info(script); |
| 1472 i::Parser parser(&info, isolate->stack_guard()->real_climit(), | 1470 i::Parser parser(&info, isolate->stack_guard()->real_climit(), |
| 1473 isolate->heap()->HashSeed(), isolate->unicode_cache()); | 1471 isolate->heap()->HashSeed(), isolate->unicode_cache()); |
| 1474 SetParserFlags(&parser, flags); | 1472 SetParserFlags(&parser, flags); |
| 1475 info.MarkAsGlobal(); | 1473 info.MarkAsGlobal(); |
| 1476 parser.Parse(); | 1474 parser.Parse(&info); |
| 1477 function = info.function(); | 1475 function = info.function(); |
| 1478 if (function) { | 1476 if (function) { |
| 1479 parser_materialized_literals = function->materialized_literal_count(); | 1477 parser_materialized_literals = function->materialized_literal_count(); |
| 1480 } | 1478 } |
| 1481 } | 1479 } |
| 1482 | 1480 |
| 1483 // Check that preparsing fails iff parsing fails. | 1481 // Check that preparsing fails iff parsing fails. |
| 1484 if (function == NULL) { | 1482 if (function == NULL) { |
| 1485 // Extract exception from the parser. | 1483 // Extract exception from the parser. |
| 1486 CHECK(isolate->has_pending_exception()); | 1484 CHECK(isolate->has_pending_exception()); |
| (...skipping 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2551 | 2549 |
| 2552 for (int i = 0; test_cases[i].program; i++) { | 2550 for (int i = 0; test_cases[i].program; i++) { |
| 2553 const char* program = test_cases[i].program; | 2551 const char* program = test_cases[i].program; |
| 2554 i::Factory* factory = CcTest::i_isolate()->factory(); | 2552 i::Factory* factory = CcTest::i_isolate()->factory(); |
| 2555 i::Handle<i::String> source = | 2553 i::Handle<i::String> source = |
| 2556 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); | 2554 factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked(); |
| 2557 i::Handle<i::Script> script = factory->NewScript(source); | 2555 i::Handle<i::Script> script = factory->NewScript(source); |
| 2558 i::CompilationInfoWithZone info(script); | 2556 i::CompilationInfoWithZone info(script); |
| 2559 i::ScriptData* sd = NULL; | 2557 i::ScriptData* sd = NULL; |
| 2560 info.SetCachedData(&sd, v8::ScriptCompiler::kProduceParserCache); | 2558 info.SetCachedData(&sd, v8::ScriptCompiler::kProduceParserCache); |
| 2561 i::Parser::Parse(&info, true); | 2559 i::Parser::ParseStatic(&info, true); |
| 2562 i::ParseData* pd = i::ParseData::FromCachedData(sd); | 2560 i::ParseData* pd = i::ParseData::FromCachedData(sd); |
| 2563 | 2561 |
| 2564 if (pd->FunctionCount() != test_cases[i].functions) { | 2562 if (pd->FunctionCount() != test_cases[i].functions) { |
| 2565 v8::base::OS::Print( | 2563 v8::base::OS::Print( |
| 2566 "Expected preparse data for program:\n" | 2564 "Expected preparse data for program:\n" |
| 2567 "\t%s\n" | 2565 "\t%s\n" |
| 2568 "to contain %d functions, however, received %d functions.\n", | 2566 "to contain %d functions, however, received %d functions.\n", |
| 2569 program, test_cases[i].functions, pd->FunctionCount()); | 2567 program, test_cases[i].functions, pd->FunctionCount()); |
| 2570 CHECK(false); | 2568 CHECK(false); |
| 2571 } | 2569 } |
| (...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3430 factory->InternalizeUtf8String(program.start()); | 3428 factory->InternalizeUtf8String(program.start()); |
| 3431 source->PrintOn(stdout); | 3429 source->PrintOn(stdout); |
| 3432 printf("\n"); | 3430 printf("\n"); |
| 3433 | 3431 |
| 3434 i::Handle<i::Script> script = factory->NewScript(source); | 3432 i::Handle<i::Script> script = factory->NewScript(source); |
| 3435 i::CompilationInfoWithZone info(script); | 3433 i::CompilationInfoWithZone info(script); |
| 3436 i::Parser parser(&info, isolate->stack_guard()->real_climit(), | 3434 i::Parser parser(&info, isolate->stack_guard()->real_climit(), |
| 3437 isolate->heap()->HashSeed(), | 3435 isolate->heap()->HashSeed(), |
| 3438 isolate->unicode_cache()); | 3436 isolate->unicode_cache()); |
| 3439 parser.set_allow_harmony_scoping(true); | 3437 parser.set_allow_harmony_scoping(true); |
| 3440 CHECK(parser.Parse()); | 3438 CHECK(parser.Parse(&info)); |
| 3441 CHECK(i::Compiler::Analyze(&info)); | 3439 CHECK(i::Compiler::Analyze(&info)); |
| 3442 CHECK(info.function() != NULL); | 3440 CHECK(info.function() != NULL); |
| 3443 | 3441 |
| 3444 i::Scope* scope = info.function()->scope(); | 3442 i::Scope* scope = info.function()->scope(); |
| 3445 CHECK_EQ(scope->inner_scopes()->length(), 1); | 3443 CHECK_EQ(scope->inner_scopes()->length(), 1); |
| 3446 i::Scope* inner_scope = scope->inner_scopes()->at(0); | 3444 i::Scope* inner_scope = scope->inner_scopes()->at(0); |
| 3447 const i::AstRawString* var_name = | 3445 const i::AstRawString* var_name = |
| 3448 info.ast_value_factory()->GetOneByteString("x"); | 3446 info.ast_value_factory()->GetOneByteString("x"); |
| 3449 i::Variable* var = inner_scope->Lookup(var_name); | 3447 i::Variable* var = inner_scope->Lookup(var_name); |
| 3450 bool expected = outers[i].assigned || inners[j].assigned; | 3448 bool expected = outers[i].assigned || inners[j].assigned; |
| (...skipping 1593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5044 // Show that parsing as a module works | 5042 // Show that parsing as a module works |
| 5045 { | 5043 { |
| 5046 i::Handle<i::Script> script = factory->NewScript(source); | 5044 i::Handle<i::Script> script = factory->NewScript(source); |
| 5047 i::CompilationInfoWithZone info(script); | 5045 i::CompilationInfoWithZone info(script); |
| 5048 i::Parser parser(&info, isolate->stack_guard()->real_climit(), | 5046 i::Parser parser(&info, isolate->stack_guard()->real_climit(), |
| 5049 isolate->heap()->HashSeed(), isolate->unicode_cache()); | 5047 isolate->heap()->HashSeed(), isolate->unicode_cache()); |
| 5050 parser.set_allow_harmony_classes(true); | 5048 parser.set_allow_harmony_classes(true); |
| 5051 parser.set_allow_harmony_modules(true); | 5049 parser.set_allow_harmony_modules(true); |
| 5052 parser.set_allow_harmony_scoping(true); | 5050 parser.set_allow_harmony_scoping(true); |
| 5053 info.MarkAsModule(); | 5051 info.MarkAsModule(); |
| 5054 if (!parser.Parse()) { | 5052 if (!parser.Parse(&info)) { |
| 5055 i::Handle<i::JSObject> exception_handle( | 5053 i::Handle<i::JSObject> exception_handle( |
| 5056 i::JSObject::cast(isolate->pending_exception())); | 5054 i::JSObject::cast(isolate->pending_exception())); |
| 5057 i::Handle<i::String> message_string = | 5055 i::Handle<i::String> message_string = |
| 5058 i::Handle<i::String>::cast(i::Object::GetProperty( | 5056 i::Handle<i::String>::cast(i::Object::GetProperty( |
| 5059 isolate, exception_handle, "message").ToHandleChecked()); | 5057 isolate, exception_handle, "message").ToHandleChecked()); |
| 5060 | 5058 |
| 5061 v8::base::OS::Print( | 5059 v8::base::OS::Print( |
| 5062 "Parser failed on:\n" | 5060 "Parser failed on:\n" |
| 5063 "\t%s\n" | 5061 "\t%s\n" |
| 5064 "with error:\n" | 5062 "with error:\n" |
| 5065 "\t%s\n" | 5063 "\t%s\n" |
| 5066 "However, we expected no error.", | 5064 "However, we expected no error.", |
| 5067 source->ToCString().get(), message_string->ToCString().get()); | 5065 source->ToCString().get(), message_string->ToCString().get()); |
| 5068 CHECK(false); | 5066 CHECK(false); |
| 5069 } | 5067 } |
| 5070 } | 5068 } |
| 5071 | 5069 |
| 5072 // And that parsing a script does not. | 5070 // And that parsing a script does not. |
| 5073 { | 5071 { |
| 5074 i::Handle<i::Script> script = factory->NewScript(source); | 5072 i::Handle<i::Script> script = factory->NewScript(source); |
| 5075 i::CompilationInfoWithZone info(script); | 5073 i::CompilationInfoWithZone info(script); |
| 5076 i::Parser parser(&info, isolate->stack_guard()->real_climit(), | 5074 i::Parser parser(&info, isolate->stack_guard()->real_climit(), |
| 5077 isolate->heap()->HashSeed(), isolate->unicode_cache()); | 5075 isolate->heap()->HashSeed(), isolate->unicode_cache()); |
| 5078 parser.set_allow_harmony_classes(true); | 5076 parser.set_allow_harmony_classes(true); |
| 5079 parser.set_allow_harmony_modules(true); | 5077 parser.set_allow_harmony_modules(true); |
| 5080 parser.set_allow_harmony_scoping(true); | 5078 parser.set_allow_harmony_scoping(true); |
| 5081 info.MarkAsGlobal(); | 5079 info.MarkAsGlobal(); |
| 5082 CHECK(!parser.Parse()); | 5080 CHECK(!parser.Parse(&info)); |
| 5083 } | 5081 } |
| 5084 } | 5082 } |
| 5085 } | 5083 } |
| 5086 | 5084 |
| 5087 | 5085 |
| 5088 TEST(ImportExportParsingErrors) { | 5086 TEST(ImportExportParsingErrors) { |
| 5089 const char* kErrorSources[] = { | 5087 const char* kErrorSources[] = { |
| 5090 "export {", | 5088 "export {", |
| 5091 "var a; export { a", | 5089 "var a; export { a", |
| 5092 "var a; export { a,", | 5090 "var a; export { a,", |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5162 .ToHandleChecked(); | 5160 .ToHandleChecked(); |
| 5163 | 5161 |
| 5164 i::Handle<i::Script> script = factory->NewScript(source); | 5162 i::Handle<i::Script> script = factory->NewScript(source); |
| 5165 i::CompilationInfoWithZone info(script); | 5163 i::CompilationInfoWithZone info(script); |
| 5166 i::Parser parser(&info, isolate->stack_guard()->real_climit(), | 5164 i::Parser parser(&info, isolate->stack_guard()->real_climit(), |
| 5167 isolate->heap()->HashSeed(), isolate->unicode_cache()); | 5165 isolate->heap()->HashSeed(), isolate->unicode_cache()); |
| 5168 parser.set_allow_harmony_classes(true); | 5166 parser.set_allow_harmony_classes(true); |
| 5169 parser.set_allow_harmony_modules(true); | 5167 parser.set_allow_harmony_modules(true); |
| 5170 parser.set_allow_harmony_scoping(true); | 5168 parser.set_allow_harmony_scoping(true); |
| 5171 info.MarkAsModule(); | 5169 info.MarkAsModule(); |
| 5172 CHECK(!parser.Parse()); | 5170 CHECK(!parser.Parse(&info)); |
| 5173 } | 5171 } |
| 5174 } | 5172 } |
| 5175 | 5173 |
| 5176 | 5174 |
| 5177 TEST(DuplicateProtoError) { | 5175 TEST(DuplicateProtoError) { |
| 5178 const char* context_data[][2] = { | 5176 const char* context_data[][2] = { |
| 5179 {"({", "});"}, | 5177 {"({", "});"}, |
| 5180 {"'use strict'; ({", "});"}, | 5178 {"'use strict'; ({", "});"}, |
| 5181 {NULL, NULL} | 5179 {NULL, NULL} |
| 5182 }; | 5180 }; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5254 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - | 5252 isolate->stack_guard()->SetStackLimit(i::GetCurrentStackPosition() - |
| 5255 128 * 1024); | 5253 128 * 1024); |
| 5256 | 5254 |
| 5257 i::Handle<i::Script> script = | 5255 i::Handle<i::Script> script = |
| 5258 factory->NewScript(factory->NewStringFromAsciiChecked(source)); | 5256 factory->NewScript(factory->NewStringFromAsciiChecked(source)); |
| 5259 i::CompilationInfoWithZone info(script); | 5257 i::CompilationInfoWithZone info(script); |
| 5260 i::Parser parser(&info, isolate->stack_guard()->real_climit(), | 5258 i::Parser parser(&info, isolate->stack_guard()->real_climit(), |
| 5261 isolate->heap()->HashSeed(), isolate->unicode_cache()); | 5259 isolate->heap()->HashSeed(), isolate->unicode_cache()); |
| 5262 parser.set_allow_strong_mode(true); | 5260 parser.set_allow_strong_mode(true); |
| 5263 info.MarkAsGlobal(); | 5261 info.MarkAsGlobal(); |
| 5264 parser.Parse(); | 5262 parser.Parse(&info); |
| 5265 CHECK(info.function() != NULL); | 5263 CHECK(info.function() != NULL); |
| 5266 CHECK_EQ(expected_language_mode, info.function()->language_mode()); | 5264 CHECK_EQ(expected_language_mode, info.function()->language_mode()); |
| 5267 } | 5265 } |
| 5268 | 5266 |
| 5269 | 5267 |
| 5270 TEST(LanguageModeDirectives) { | 5268 TEST(LanguageModeDirectives) { |
| 5271 TestLanguageMode("\"use nothing\"", i::SLOPPY); | 5269 TestLanguageMode("\"use nothing\"", i::SLOPPY); |
| 5272 TestLanguageMode("\"use strict\"", i::STRICT); | 5270 TestLanguageMode("\"use strict\"", i::STRICT); |
| 5273 TestLanguageMode("\"use strong\"", i::STRONG); | 5271 TestLanguageMode("\"use strong\"", i::STRONG); |
| 5274 | 5272 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5321 "class C {static set arguments(_) {}}", | 5319 "class C {static set arguments(_) {}}", |
| 5322 | 5320 |
| 5323 NULL}; | 5321 NULL}; |
| 5324 | 5322 |
| 5325 static const ParserFlag always_flags[] = { | 5323 static const ParserFlag always_flags[] = { |
| 5326 kAllowHarmonyClasses, kAllowHarmonyObjectLiterals, kAllowHarmonyScoping, | 5324 kAllowHarmonyClasses, kAllowHarmonyObjectLiterals, kAllowHarmonyScoping, |
| 5327 kAllowStrongMode}; | 5325 kAllowStrongMode}; |
| 5328 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, | 5326 RunParserSyncTest(context_data, statement_data, kSuccess, NULL, 0, |
| 5329 always_flags, arraysize(always_flags)); | 5327 always_flags, arraysize(always_flags)); |
| 5330 } | 5328 } |
| OLD | NEW |