| 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 150 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
| 151 i::GetCurrentStackPosition() - 128 * 1024); | 151 i::GetCurrentStackPosition() - 128 * 1024); |
| 152 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); | 152 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); |
| 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::PreParser preparser(CcTest::i_isolate(), &scanner, &log, stack_limit); | 160 i::Zone zone; |
| 161 i::AstValueFactory ast_value_factory( |
| 162 &zone, CcTest::i_isolate()->heap()->HashSeed()); |
| 163 i::PreParser preparser(CcTest::i_isolate(), &zone, &scanner, |
| 164 &ast_value_factory, &log, stack_limit); |
| 161 preparser.set_allow_lazy(true); | 165 preparser.set_allow_lazy(true); |
| 162 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 166 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 163 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 167 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 164 CHECK(!log.HasError()); | 168 CHECK(!log.HasError()); |
| 165 } | 169 } |
| 166 | 170 |
| 167 for (int i = 0; fail_tests[i]; i++) { | 171 for (int i = 0; fail_tests[i]; i++) { |
| 168 const i::byte* source = | 172 const i::byte* source = |
| 169 reinterpret_cast<const i::byte*>(fail_tests[i]); | 173 reinterpret_cast<const i::byte*>(fail_tests[i]); |
| 170 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i])); | 174 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i])); |
| 171 i::CompleteParserRecorder log; | 175 i::CompleteParserRecorder log; |
| 172 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 176 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 173 scanner.Initialize(&stream); | 177 scanner.Initialize(&stream); |
| 174 i::PreParser preparser(CcTest::i_isolate(), &scanner, &log, stack_limit); | 178 i::Zone zone; |
| 179 i::AstValueFactory ast_value_factory( |
| 180 &zone, CcTest::i_isolate()->heap()->HashSeed()); |
| 181 i::PreParser preparser(CcTest::i_isolate(), &zone, &scanner, |
| 182 &ast_value_factory, &log, stack_limit); |
| 175 preparser.set_allow_lazy(true); | 183 preparser.set_allow_lazy(true); |
| 176 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 184 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 177 // Even in the case of a syntax error, kPreParseSuccess is returned. | 185 // Even in the case of a syntax error, kPreParseSuccess is returned. |
| 178 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 186 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 179 CHECK(log.HasError()); | 187 CHECK(log.HasError()); |
| 180 } | 188 } |
| 181 } | 189 } |
| 182 | 190 |
| 183 | 191 |
| 184 class ScriptResource : public v8::String::ExternalOneByteStringResource { | 192 class ScriptResource : public v8::String::ExternalOneByteStringResource { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); | 318 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); |
| 311 for (int i = 0; programs[i]; i++) { | 319 for (int i = 0; programs[i]; i++) { |
| 312 const char* program = programs[i]; | 320 const char* program = programs[i]; |
| 313 i::Utf8ToUtf16CharacterStream stream( | 321 i::Utf8ToUtf16CharacterStream stream( |
| 314 reinterpret_cast<const i::byte*>(program), | 322 reinterpret_cast<const i::byte*>(program), |
| 315 static_cast<unsigned>(strlen(program))); | 323 static_cast<unsigned>(strlen(program))); |
| 316 i::CompleteParserRecorder log; | 324 i::CompleteParserRecorder log; |
| 317 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 325 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 318 scanner.Initialize(&stream); | 326 scanner.Initialize(&stream); |
| 319 | 327 |
| 320 i::PreParser preparser(CcTest::i_isolate(), &scanner, &log, stack_limit); | 328 i::Zone zone; |
| 329 i::AstValueFactory ast_value_factory( |
| 330 &zone, CcTest::i_isolate()->heap()->HashSeed()); |
| 331 i::PreParser preparser(CcTest::i_isolate(), &zone, &scanner, |
| 332 &ast_value_factory, &log, stack_limit); |
| 321 preparser.set_allow_lazy(true); | 333 preparser.set_allow_lazy(true); |
| 322 preparser.set_allow_natives(true); | 334 preparser.set_allow_natives(true); |
| 323 preparser.set_allow_harmony_arrow_functions(true); | 335 preparser.set_allow_harmony_arrow_functions(true); |
| 324 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 336 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 325 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 337 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 326 CHECK(!log.HasError()); | 338 CHECK(!log.HasError()); |
| 327 } | 339 } |
| 328 } | 340 } |
| 329 | 341 |
| 330 | 342 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 344 for (int i = 0; programs[i]; i++) { | 356 for (int i = 0; programs[i]; i++) { |
| 345 const char* program = programs[i]; | 357 const char* program = programs[i]; |
| 346 i::Utf8ToUtf16CharacterStream stream( | 358 i::Utf8ToUtf16CharacterStream stream( |
| 347 reinterpret_cast<const i::byte*>(program), | 359 reinterpret_cast<const i::byte*>(program), |
| 348 static_cast<unsigned>(strlen(program))); | 360 static_cast<unsigned>(strlen(program))); |
| 349 i::CompleteParserRecorder log; | 361 i::CompleteParserRecorder log; |
| 350 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 362 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 351 scanner.Initialize(&stream); | 363 scanner.Initialize(&stream); |
| 352 | 364 |
| 353 // Preparser defaults to disallowing natives syntax. | 365 // Preparser defaults to disallowing natives syntax. |
| 354 i::PreParser preparser(CcTest::i_isolate(), &scanner, &log, stack_limit); | 366 i::Zone zone; |
| 367 i::AstValueFactory ast_value_factory( |
| 368 &zone, CcTest::i_isolate()->heap()->HashSeed()); |
| 369 i::PreParser preparser(CcTest::i_isolate(), &zone, &scanner, |
| 370 &ast_value_factory, &log, stack_limit); |
| 355 preparser.set_allow_lazy(true); | 371 preparser.set_allow_lazy(true); |
| 356 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 372 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 357 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 373 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 358 CHECK(log.HasError()); | 374 CHECK(log.HasError()); |
| 359 } | 375 } |
| 360 } | 376 } |
| 361 | 377 |
| 362 | 378 |
| 363 TEST(PreparsingObjectLiterals) { | 379 TEST(PreparsingObjectLiterals) { |
| 364 // 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), | 425 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), |
| 410 // and then used the invalid currently scanned literal. This always | 426 // and then used the invalid currently scanned literal. This always |
| 411 // failed in debug mode, and sometimes crashed in release mode. | 427 // failed in debug mode, and sometimes crashed in release mode. |
| 412 | 428 |
| 413 i::Utf8ToUtf16CharacterStream stream( | 429 i::Utf8ToUtf16CharacterStream stream( |
| 414 reinterpret_cast<const i::byte*>(program), | 430 reinterpret_cast<const i::byte*>(program), |
| 415 static_cast<unsigned>(strlen(program))); | 431 static_cast<unsigned>(strlen(program))); |
| 416 i::CompleteParserRecorder log; | 432 i::CompleteParserRecorder log; |
| 417 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 433 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 418 scanner.Initialize(&stream); | 434 scanner.Initialize(&stream); |
| 419 i::PreParser preparser(CcTest::i_isolate(), &scanner, &log, | 435 i::Zone zone; |
| 436 i::AstValueFactory ast_value_factory(&zone, |
| 437 CcTest::i_isolate()->heap()->HashSeed()); |
| 438 i::PreParser preparser(CcTest::i_isolate(), &zone, &scanner, |
| 439 &ast_value_factory, &log, |
| 420 CcTest::i_isolate()->stack_guard()->real_climit()); | 440 CcTest::i_isolate()->stack_guard()->real_climit()); |
| 421 preparser.set_allow_lazy(true); | 441 preparser.set_allow_lazy(true); |
| 422 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 442 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 423 // Even in the case of a syntax error, kPreParseSuccess is returned. | 443 // Even in the case of a syntax error, kPreParseSuccess is returned. |
| 424 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 444 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 425 CHECK(log.HasError()); | 445 CHECK(log.HasError()); |
| 426 } | 446 } |
| 427 | 447 |
| 428 | 448 |
| 429 TEST(Regress928) { | 449 TEST(Regress928) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 441 const char* program = | 461 const char* program = |
| 442 "try { } catch (e) { var foo = function () { /* first */ } }" | 462 "try { } catch (e) { var foo = function () { /* first */ } }" |
| 443 "var bar = function () { /* second */ }"; | 463 "var bar = function () { /* second */ }"; |
| 444 | 464 |
| 445 v8::HandleScope handles(CcTest::isolate()); | 465 v8::HandleScope handles(CcTest::isolate()); |
| 446 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(program); | 466 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(program); |
| 447 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 467 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
| 448 i::CompleteParserRecorder log; | 468 i::CompleteParserRecorder log; |
| 449 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 469 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 450 scanner.Initialize(&stream); | 470 scanner.Initialize(&stream); |
| 451 i::PreParser preparser(CcTest::i_isolate(), &scanner, &log, | 471 i::Zone zone; |
| 472 i::AstValueFactory ast_value_factory(&zone, |
| 473 CcTest::i_isolate()->heap()->HashSeed()); |
| 474 i::PreParser preparser(CcTest::i_isolate(), &zone, &scanner, |
| 475 &ast_value_factory, &log, |
| 452 CcTest::i_isolate()->stack_guard()->real_climit()); | 476 CcTest::i_isolate()->stack_guard()->real_climit()); |
| 453 preparser.set_allow_lazy(true); | 477 preparser.set_allow_lazy(true); |
| 454 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 478 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 455 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 479 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 456 i::ScriptData* sd = log.GetScriptData(); | 480 i::ScriptData* sd = log.GetScriptData(); |
| 457 i::ParseData* pd = i::ParseData::FromCachedData(sd); | 481 i::ParseData* pd = i::ParseData::FromCachedData(sd); |
| 458 pd->Initialize(); | 482 pd->Initialize(); |
| 459 | 483 |
| 460 int first_function = | 484 int first_function = |
| 461 static_cast<int>(strstr(program, "function") - program); | 485 static_cast<int>(strstr(program, "function") - program); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 490 | 514 |
| 491 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); | 515 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); |
| 492 | 516 |
| 493 i::Utf8ToUtf16CharacterStream stream( | 517 i::Utf8ToUtf16CharacterStream stream( |
| 494 reinterpret_cast<const i::byte*>(program.get()), | 518 reinterpret_cast<const i::byte*>(program.get()), |
| 495 static_cast<unsigned>(kProgramSize)); | 519 static_cast<unsigned>(kProgramSize)); |
| 496 i::CompleteParserRecorder log; | 520 i::CompleteParserRecorder log; |
| 497 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); | 521 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 498 scanner.Initialize(&stream); | 522 scanner.Initialize(&stream); |
| 499 | 523 |
| 500 i::PreParser preparser(CcTest::i_isolate(), &scanner, &log, stack_limit); | 524 i::Zone zone; |
| 525 i::AstValueFactory ast_value_factory(&zone, |
| 526 CcTest::i_isolate()->heap()->HashSeed()); |
| 527 i::PreParser preparser(CcTest::i_isolate(), &zone, &scanner, |
| 528 &ast_value_factory, &log, stack_limit); |
| 501 preparser.set_allow_lazy(true); | 529 preparser.set_allow_lazy(true); |
| 502 preparser.set_allow_harmony_arrow_functions(true); | 530 preparser.set_allow_harmony_arrow_functions(true); |
| 503 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 531 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 504 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); | 532 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); |
| 505 } | 533 } |
| 506 | 534 |
| 507 | 535 |
| 508 class TestExternalResource: public v8::String::ExternalStringResource { | 536 class TestExternalResource: public v8::String::ExternalStringResource { |
| 509 public: | 537 public: |
| 510 explicit TestExternalResource(uint16_t* data, int length) | 538 explicit TestExternalResource(uint16_t* data, int length) |
| (...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1402 | 1430 |
| 1403 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); | 1431 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); |
| 1404 int preparser_materialized_literals = -1; | 1432 int preparser_materialized_literals = -1; |
| 1405 int parser_materialized_literals = -2; | 1433 int parser_materialized_literals = -2; |
| 1406 | 1434 |
| 1407 // Preparse the data. | 1435 // Preparse the data. |
| 1408 i::CompleteParserRecorder log; | 1436 i::CompleteParserRecorder log; |
| 1409 { | 1437 { |
| 1410 i::Scanner scanner(isolate->unicode_cache()); | 1438 i::Scanner scanner(isolate->unicode_cache()); |
| 1411 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 1439 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
| 1412 i::PreParser preparser(CcTest::i_isolate(), &scanner, &log, stack_limit); | 1440 i::Zone zone; |
| 1441 i::AstValueFactory ast_value_factory( |
| 1442 &zone, CcTest::i_isolate()->heap()->HashSeed()); |
| 1443 i::PreParser preparser(CcTest::i_isolate(), &zone, &scanner, |
| 1444 &ast_value_factory, &log, stack_limit); |
| 1413 SetParserFlags(&preparser, flags); | 1445 SetParserFlags(&preparser, flags); |
| 1414 scanner.Initialize(&stream); | 1446 scanner.Initialize(&stream); |
| 1415 i::PreParser::PreParseResult result = preparser.PreParseProgram( | 1447 i::PreParser::PreParseResult result = preparser.PreParseProgram( |
| 1416 &preparser_materialized_literals); | 1448 &preparser_materialized_literals); |
| 1417 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 1449 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 1418 } | 1450 } |
| 1419 | 1451 |
| 1420 bool preparse_error = log.HasError(); | 1452 bool preparse_error = log.HasError(); |
| 1421 | 1453 |
| 1422 // Parse the data | 1454 // Parse the data |
| (...skipping 3554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4977 "const x = 1;", | 5009 "const x = 1;", |
| 4978 "class C {}", | 5010 "class C {}", |
| 4979 NULL}; | 5011 NULL}; |
| 4980 | 5012 |
| 4981 static const ParserFlag always_flags[] = { | 5013 static const ParserFlag always_flags[] = { |
| 4982 kAllowHarmonyClasses, kAllowHarmonyScoping | 5014 kAllowHarmonyClasses, kAllowHarmonyScoping |
| 4983 }; | 5015 }; |
| 4984 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, | 5016 RunParserSyncTest(context_data, statement_data, kError, NULL, 0, |
| 4985 always_flags, arraysize(always_flags)); | 5017 always_flags, arraysize(always_flags)); |
| 4986 } | 5018 } |
| OLD | NEW |