| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 KeywordToken key_token; | 63 KeywordToken key_token; |
| 64 i::UnicodeCache unicode_cache; | 64 i::UnicodeCache unicode_cache; |
| 65 i::byte buffer[32]; | 65 i::byte buffer[32]; |
| 66 for (int i = 0; (key_token = keywords[i]).keyword != NULL; i++) { | 66 for (int i = 0; (key_token = keywords[i]).keyword != NULL; i++) { |
| 67 const i::byte* keyword = | 67 const i::byte* keyword = |
| 68 reinterpret_cast<const i::byte*>(key_token.keyword); | 68 reinterpret_cast<const i::byte*>(key_token.keyword); |
| 69 int length = i::StrLength(key_token.keyword); | 69 int length = i::StrLength(key_token.keyword); |
| 70 CHECK(static_cast<int>(sizeof(buffer)) >= length); | 70 CHECK(static_cast<int>(sizeof(buffer)) >= length); |
| 71 { | 71 { |
| 72 i::Utf8ToUtf16CharacterStream stream(keyword, length); | 72 i::Utf8ToUtf16CharacterStream stream(keyword, length); |
| 73 i::Scanner scanner(&unicode_cache, false); | 73 i::Scanner scanner(&unicode_cache); |
| 74 scanner.Initialize(&stream); | 74 scanner.Initialize(&stream); |
| 75 CHECK_EQ(key_token.token, scanner.Next()); | 75 CHECK_EQ(key_token.token, scanner.Next()); |
| 76 CHECK_EQ(i::Token::EOS, scanner.Next()); | 76 CHECK_EQ(i::Token::EOS, scanner.Next()); |
| 77 } | 77 } |
| 78 // Removing characters will make keyword matching fail. | 78 // Removing characters will make keyword matching fail. |
| 79 { | 79 { |
| 80 i::Utf8ToUtf16CharacterStream stream(keyword, length - 1); | 80 i::Utf8ToUtf16CharacterStream stream(keyword, length - 1); |
| 81 i::Scanner scanner(&unicode_cache, false); | 81 i::Scanner scanner(&unicode_cache); |
| 82 scanner.Initialize(&stream); | 82 scanner.Initialize(&stream); |
| 83 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); | 83 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); |
| 84 CHECK_EQ(i::Token::EOS, scanner.Next()); | 84 CHECK_EQ(i::Token::EOS, scanner.Next()); |
| 85 } | 85 } |
| 86 // Adding characters will make keyword matching fail. | 86 // Adding characters will make keyword matching fail. |
| 87 static const char chars_to_append[] = { 'z', '0', '_' }; | 87 static const char chars_to_append[] = { 'z', '0', '_' }; |
| 88 for (int j = 0; j < static_cast<int>(arraysize(chars_to_append)); ++j) { | 88 for (int j = 0; j < static_cast<int>(arraysize(chars_to_append)); ++j) { |
| 89 i::MemMove(buffer, keyword, length); | 89 i::MemMove(buffer, keyword, length); |
| 90 buffer[length] = chars_to_append[j]; | 90 buffer[length] = chars_to_append[j]; |
| 91 i::Utf8ToUtf16CharacterStream stream(buffer, length + 1); | 91 i::Utf8ToUtf16CharacterStream stream(buffer, length + 1); |
| 92 i::Scanner scanner(&unicode_cache, false); | 92 i::Scanner scanner(&unicode_cache); |
| 93 scanner.Initialize(&stream); | 93 scanner.Initialize(&stream); |
| 94 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); | 94 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); |
| 95 CHECK_EQ(i::Token::EOS, scanner.Next()); | 95 CHECK_EQ(i::Token::EOS, scanner.Next()); |
| 96 } | 96 } |
| 97 // Replacing characters will make keyword matching fail. | 97 // Replacing characters will make keyword matching fail. |
| 98 { | 98 { |
| 99 i::MemMove(buffer, keyword, length); | 99 i::MemMove(buffer, keyword, length); |
| 100 buffer[length - 1] = '_'; | 100 buffer[length - 1] = '_'; |
| 101 i::Utf8ToUtf16CharacterStream stream(buffer, length); | 101 i::Utf8ToUtf16CharacterStream stream(buffer, length); |
| 102 i::Scanner scanner(&unicode_cache, false); | 102 i::Scanner scanner(&unicode_cache); |
| 103 scanner.Initialize(&stream); | 103 scanner.Initialize(&stream); |
| 104 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); | 104 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); |
| 105 CHECK_EQ(i::Token::EOS, scanner.Next()); | 105 CHECK_EQ(i::Token::EOS, scanner.Next()); |
| 106 } | 106 } |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 | 109 |
| 110 | 110 |
| 111 TEST(ScanHTMLEndComments) { | 111 TEST(ScanHTMLEndComments) { |
| 112 v8::V8::Initialize(); | 112 v8::V8::Initialize(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 144 |
| 145 // Parser/Scanner needs a stack limit. | 145 // Parser/Scanner needs a stack limit. |
| 146 CcTest::i_isolate()->stack_guard()->SetStackLimit( | 146 CcTest::i_isolate()->stack_guard()->SetStackLimit( |
| 147 i::GetCurrentStackPosition() - 128 * 1024); | 147 i::GetCurrentStackPosition() - 128 * 1024); |
| 148 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); | 148 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); |
| 149 for (int i = 0; tests[i]; i++) { | 149 for (int i = 0; tests[i]; i++) { |
| 150 const i::byte* source = | 150 const i::byte* source = |
| 151 reinterpret_cast<const i::byte*>(tests[i]); | 151 reinterpret_cast<const i::byte*>(tests[i]); |
| 152 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(tests[i])); | 152 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(tests[i])); |
| 153 i::CompleteParserRecorder log; | 153 i::CompleteParserRecorder log; |
| 154 i::Scanner scanner(CcTest::i_isolate()->unicode_cache(), false); | 154 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 155 scanner.Initialize(&stream); | 155 scanner.Initialize(&stream); |
| 156 i::Zone zone; | 156 i::Zone zone; |
| 157 i::AstValueFactory ast_value_factory( | 157 i::AstValueFactory ast_value_factory( |
| 158 &zone, CcTest::i_isolate()->heap()->HashSeed()); | 158 &zone, CcTest::i_isolate()->heap()->HashSeed()); |
| 159 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, | 159 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, |
| 160 stack_limit); | 160 stack_limit); |
| 161 preparser.set_allow_lazy(true); | 161 preparser.set_allow_lazy(true); |
| 162 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 162 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 163 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 163 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 164 CHECK(!log.HasError()); | 164 CHECK(!log.HasError()); |
| 165 } | 165 } |
| 166 | 166 |
| 167 for (int i = 0; fail_tests[i]; i++) { | 167 for (int i = 0; fail_tests[i]; i++) { |
| 168 const i::byte* source = | 168 const i::byte* source = |
| 169 reinterpret_cast<const i::byte*>(fail_tests[i]); | 169 reinterpret_cast<const i::byte*>(fail_tests[i]); |
| 170 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i])); | 170 i::Utf8ToUtf16CharacterStream stream(source, i::StrLength(fail_tests[i])); |
| 171 i::CompleteParserRecorder log; | 171 i::CompleteParserRecorder log; |
| 172 i::Scanner scanner(CcTest::i_isolate()->unicode_cache(), false); | 172 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 173 scanner.Initialize(&stream); | 173 scanner.Initialize(&stream); |
| 174 i::Zone zone; | 174 i::Zone zone; |
| 175 i::AstValueFactory ast_value_factory( | 175 i::AstValueFactory ast_value_factory( |
| 176 &zone, CcTest::i_isolate()->heap()->HashSeed()); | 176 &zone, CcTest::i_isolate()->heap()->HashSeed()); |
| 177 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, | 177 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, |
| 178 stack_limit); | 178 stack_limit); |
| 179 preparser.set_allow_lazy(true); | 179 preparser.set_allow_lazy(true); |
| 180 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 180 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 181 // Even in the case of a syntax error, kPreParseSuccess is returned. | 181 // Even in the case of a syntax error, kPreParseSuccess is returned. |
| 182 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 182 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 183 CHECK(log.HasError()); | 183 CHECK(log.HasError()); |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 | 186 |
| 187 TEST(ScanHtmlComments) { | |
| 188 const char* src = "a <!-- b --> c"; | |
| 189 i::UnicodeCache unicode_cache; | |
| 190 | |
| 191 // Skip HTML comments: | |
| 192 { | |
| 193 i::Utf8ToUtf16CharacterStream stream(reinterpret_cast<const i::byte*>(src), | |
| 194 i::StrLength(src)); | |
| 195 i::Scanner scanner(&unicode_cache, true); | |
| 196 scanner.Initialize(&stream); | |
| 197 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); | |
| 198 CHECK_EQ(i::Token::EOS, scanner.Next()); | |
| 199 } | |
| 200 | |
| 201 // Parse (don't skip) HTML comments: | |
| 202 { | |
| 203 i::Utf8ToUtf16CharacterStream stream(reinterpret_cast<const i::byte*>(src), | |
| 204 i::StrLength(src)); | |
| 205 i::Scanner scanner(&unicode_cache, false); | |
| 206 scanner.Initialize(&stream); | |
| 207 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); | |
| 208 CHECK_EQ(i::Token::LT, scanner.Next()); | |
| 209 CHECK_EQ(i::Token::NOT, scanner.Next()); | |
| 210 CHECK_EQ(i::Token::DEC, scanner.Next()); | |
| 211 } | |
| 212 } | |
| 213 | 187 |
| 214 class ScriptResource : public v8::String::ExternalOneByteStringResource { | 188 class ScriptResource : public v8::String::ExternalOneByteStringResource { |
| 215 public: | 189 public: |
| 216 ScriptResource(const char* data, size_t length) | 190 ScriptResource(const char* data, size_t length) |
| 217 : data_(data), length_(length) { } | 191 : data_(data), length_(length) { } |
| 218 | 192 |
| 219 const char* data() const { return data_; } | 193 const char* data() const { return data_; } |
| 220 size_t length() const { return length_; } | 194 size_t length() const { return length_; } |
| 221 | 195 |
| 222 private: | 196 private: |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 NULL | 316 NULL |
| 343 }; | 317 }; |
| 344 | 318 |
| 345 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); | 319 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); |
| 346 for (int i = 0; programs[i]; i++) { | 320 for (int i = 0; programs[i]; i++) { |
| 347 const char* program = programs[i]; | 321 const char* program = programs[i]; |
| 348 i::Utf8ToUtf16CharacterStream stream( | 322 i::Utf8ToUtf16CharacterStream stream( |
| 349 reinterpret_cast<const i::byte*>(program), | 323 reinterpret_cast<const i::byte*>(program), |
| 350 static_cast<unsigned>(strlen(program))); | 324 static_cast<unsigned>(strlen(program))); |
| 351 i::CompleteParserRecorder log; | 325 i::CompleteParserRecorder log; |
| 352 i::Scanner scanner(CcTest::i_isolate()->unicode_cache(), false); | 326 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 353 scanner.Initialize(&stream); | 327 scanner.Initialize(&stream); |
| 354 | 328 |
| 355 i::Zone zone; | 329 i::Zone zone; |
| 356 i::AstValueFactory ast_value_factory( | 330 i::AstValueFactory ast_value_factory( |
| 357 &zone, CcTest::i_isolate()->heap()->HashSeed()); | 331 &zone, CcTest::i_isolate()->heap()->HashSeed()); |
| 358 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, | 332 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, |
| 359 stack_limit); | 333 stack_limit); |
| 360 preparser.set_allow_lazy(true); | 334 preparser.set_allow_lazy(true); |
| 361 preparser.set_allow_natives(true); | 335 preparser.set_allow_natives(true); |
| 362 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 336 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 378 NULL | 352 NULL |
| 379 }; | 353 }; |
| 380 | 354 |
| 381 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); | 355 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); |
| 382 for (int i = 0; programs[i]; i++) { | 356 for (int i = 0; programs[i]; i++) { |
| 383 const char* program = programs[i]; | 357 const char* program = programs[i]; |
| 384 i::Utf8ToUtf16CharacterStream stream( | 358 i::Utf8ToUtf16CharacterStream stream( |
| 385 reinterpret_cast<const i::byte*>(program), | 359 reinterpret_cast<const i::byte*>(program), |
| 386 static_cast<unsigned>(strlen(program))); | 360 static_cast<unsigned>(strlen(program))); |
| 387 i::CompleteParserRecorder log; | 361 i::CompleteParserRecorder log; |
| 388 i::Scanner scanner(CcTest::i_isolate()->unicode_cache(), false); | 362 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 389 scanner.Initialize(&stream); | 363 scanner.Initialize(&stream); |
| 390 | 364 |
| 391 // Preparser defaults to disallowing natives syntax. | 365 // Preparser defaults to disallowing natives syntax. |
| 392 i::Zone zone; | 366 i::Zone zone; |
| 393 i::AstValueFactory ast_value_factory( | 367 i::AstValueFactory ast_value_factory( |
| 394 &zone, CcTest::i_isolate()->heap()->HashSeed()); | 368 &zone, CcTest::i_isolate()->heap()->HashSeed()); |
| 395 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, | 369 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, |
| 396 stack_limit); | 370 stack_limit); |
| 397 preparser.set_allow_lazy(true); | 371 preparser.set_allow_lazy(true); |
| 398 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 372 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 "escape: function() {}"; | 423 "escape: function() {}"; |
| 450 // Fails parsing expecting an identifier after "function". | 424 // Fails parsing expecting an identifier after "function". |
| 451 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), | 425 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), |
| 452 // and then used the invalid currently scanned literal. This always | 426 // and then used the invalid currently scanned literal. This always |
| 453 // failed in debug mode, and sometimes crashed in release mode. | 427 // failed in debug mode, and sometimes crashed in release mode. |
| 454 | 428 |
| 455 i::Utf8ToUtf16CharacterStream stream( | 429 i::Utf8ToUtf16CharacterStream stream( |
| 456 reinterpret_cast<const i::byte*>(program), | 430 reinterpret_cast<const i::byte*>(program), |
| 457 static_cast<unsigned>(strlen(program))); | 431 static_cast<unsigned>(strlen(program))); |
| 458 i::CompleteParserRecorder log; | 432 i::CompleteParserRecorder log; |
| 459 i::Scanner scanner(CcTest::i_isolate()->unicode_cache(), false); | 433 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 460 scanner.Initialize(&stream); | 434 scanner.Initialize(&stream); |
| 461 i::Zone zone; | 435 i::Zone zone; |
| 462 i::AstValueFactory ast_value_factory(&zone, | 436 i::AstValueFactory ast_value_factory(&zone, |
| 463 CcTest::i_isolate()->heap()->HashSeed()); | 437 CcTest::i_isolate()->heap()->HashSeed()); |
| 464 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, | 438 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, |
| 465 CcTest::i_isolate()->stack_guard()->real_climit()); | 439 CcTest::i_isolate()->stack_guard()->real_climit()); |
| 466 preparser.set_allow_lazy(true); | 440 preparser.set_allow_lazy(true); |
| 467 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 441 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 468 // Even in the case of a syntax error, kPreParseSuccess is returned. | 442 // Even in the case of a syntax error, kPreParseSuccess is returned. |
| 469 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 443 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 484 128 * 1024); | 458 128 * 1024); |
| 485 | 459 |
| 486 const char* program = | 460 const char* program = |
| 487 "try { } catch (e) { var foo = function () { /* first */ } }" | 461 "try { } catch (e) { var foo = function () { /* first */ } }" |
| 488 "var bar = function () { /* second */ }"; | 462 "var bar = function () { /* second */ }"; |
| 489 | 463 |
| 490 v8::HandleScope handles(CcTest::isolate()); | 464 v8::HandleScope handles(CcTest::isolate()); |
| 491 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(program); | 465 i::Handle<i::String> source = factory->NewStringFromAsciiChecked(program); |
| 492 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 466 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
| 493 i::CompleteParserRecorder log; | 467 i::CompleteParserRecorder log; |
| 494 i::Scanner scanner(CcTest::i_isolate()->unicode_cache(), false); | 468 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 495 scanner.Initialize(&stream); | 469 scanner.Initialize(&stream); |
| 496 i::Zone zone; | 470 i::Zone zone; |
| 497 i::AstValueFactory ast_value_factory(&zone, | 471 i::AstValueFactory ast_value_factory(&zone, |
| 498 CcTest::i_isolate()->heap()->HashSeed()); | 472 CcTest::i_isolate()->heap()->HashSeed()); |
| 499 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, | 473 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, |
| 500 CcTest::i_isolate()->stack_guard()->real_climit()); | 474 CcTest::i_isolate()->stack_guard()->real_climit()); |
| 501 preparser.set_allow_lazy(true); | 475 preparser.set_allow_lazy(true); |
| 502 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 476 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 503 CHECK_EQ(i::PreParser::kPreParseSuccess, result); | 477 CHECK_EQ(i::PreParser::kPreParseSuccess, result); |
| 504 i::ScriptData* sd = log.GetScriptData(); | 478 i::ScriptData* sd = log.GetScriptData(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 i::NewArray<char>(kProgramSize + 1)); | 510 i::NewArray<char>(kProgramSize + 1)); |
| 537 memset(program.get(), '(', kProgramSize); | 511 memset(program.get(), '(', kProgramSize); |
| 538 program[kProgramSize] = '\0'; | 512 program[kProgramSize] = '\0'; |
| 539 | 513 |
| 540 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); | 514 uintptr_t stack_limit = CcTest::i_isolate()->stack_guard()->real_climit(); |
| 541 | 515 |
| 542 i::Utf8ToUtf16CharacterStream stream( | 516 i::Utf8ToUtf16CharacterStream stream( |
| 543 reinterpret_cast<const i::byte*>(program.get()), | 517 reinterpret_cast<const i::byte*>(program.get()), |
| 544 static_cast<unsigned>(kProgramSize)); | 518 static_cast<unsigned>(kProgramSize)); |
| 545 i::CompleteParserRecorder log; | 519 i::CompleteParserRecorder log; |
| 546 i::Scanner scanner(CcTest::i_isolate()->unicode_cache(), false); | 520 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 547 scanner.Initialize(&stream); | 521 scanner.Initialize(&stream); |
| 548 | 522 |
| 549 i::Zone zone; | 523 i::Zone zone; |
| 550 i::AstValueFactory ast_value_factory(&zone, | 524 i::AstValueFactory ast_value_factory(&zone, |
| 551 CcTest::i_isolate()->heap()->HashSeed()); | 525 CcTest::i_isolate()->heap()->HashSeed()); |
| 552 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, | 526 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, |
| 553 stack_limit); | 527 stack_limit); |
| 554 preparser.set_allow_lazy(true); | 528 preparser.set_allow_lazy(true); |
| 555 i::PreParser::PreParseResult result = preparser.PreParseProgram(); | 529 i::PreParser::PreParseResult result = preparser.PreParseProgram(); |
| 556 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); | 530 CHECK_EQ(i::PreParser::kPreParseStackOverflow, result); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 CHECK_EQU(i, stream.pos()); | 740 CHECK_EQU(i, stream.pos()); |
| 767 } | 741 } |
| 768 } | 742 } |
| 769 | 743 |
| 770 #undef CHECK_EQU | 744 #undef CHECK_EQU |
| 771 | 745 |
| 772 void TestStreamScanner(i::Utf16CharacterStream* stream, | 746 void TestStreamScanner(i::Utf16CharacterStream* stream, |
| 773 i::Token::Value* expected_tokens, | 747 i::Token::Value* expected_tokens, |
| 774 int skip_pos = 0, // Zero means not skipping. | 748 int skip_pos = 0, // Zero means not skipping. |
| 775 int skip_to = 0) { | 749 int skip_to = 0) { |
| 776 i::Scanner scanner(CcTest::i_isolate()->unicode_cache(), false); | 750 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 777 scanner.Initialize(stream); | 751 scanner.Initialize(stream); |
| 778 | 752 |
| 779 int i = 0; | 753 int i = 0; |
| 780 do { | 754 do { |
| 781 i::Token::Value expected = expected_tokens[i]; | 755 i::Token::Value expected = expected_tokens[i]; |
| 782 i::Token::Value actual = scanner.Next(); | 756 i::Token::Value actual = scanner.Next(); |
| 783 CHECK_EQ(i::Token::String(expected), i::Token::String(actual)); | 757 CHECK_EQ(i::Token::String(expected), i::Token::String(actual)); |
| 784 if (scanner.location().end_pos == skip_pos) { | 758 if (scanner.location().end_pos == skip_pos) { |
| 785 scanner.SeekForward(skip_to); | 759 scanner.SeekForward(skip_to); |
| 786 } | 760 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 TestStreamScanner(&stream3, expectations3, 1, 1 + i); | 823 TestStreamScanner(&stream3, expectations3, 1, 1 + i); |
| 850 } | 824 } |
| 851 } | 825 } |
| 852 | 826 |
| 853 | 827 |
| 854 void TestScanRegExp(const char* re_source, const char* expected) { | 828 void TestScanRegExp(const char* re_source, const char* expected) { |
| 855 i::Utf8ToUtf16CharacterStream stream( | 829 i::Utf8ToUtf16CharacterStream stream( |
| 856 reinterpret_cast<const i::byte*>(re_source), | 830 reinterpret_cast<const i::byte*>(re_source), |
| 857 static_cast<unsigned>(strlen(re_source))); | 831 static_cast<unsigned>(strlen(re_source))); |
| 858 i::HandleScope scope(CcTest::i_isolate()); | 832 i::HandleScope scope(CcTest::i_isolate()); |
| 859 i::Scanner scanner(CcTest::i_isolate()->unicode_cache(), false); | 833 i::Scanner scanner(CcTest::i_isolate()->unicode_cache()); |
| 860 scanner.Initialize(&stream); | 834 scanner.Initialize(&stream); |
| 861 | 835 |
| 862 i::Token::Value start = scanner.peek(); | 836 i::Token::Value start = scanner.peek(); |
| 863 CHECK(start == i::Token::DIV || start == i::Token::ASSIGN_DIV); | 837 CHECK(start == i::Token::DIV || start == i::Token::ASSIGN_DIV); |
| 864 CHECK(scanner.ScanRegExpPattern(start == i::Token::ASSIGN_DIV)); | 838 CHECK(scanner.ScanRegExpPattern(start == i::Token::ASSIGN_DIV)); |
| 865 scanner.Next(); // Current token is now the regexp literal. | 839 scanner.Next(); // Current token is now the regexp literal. |
| 866 i::Zone zone; | 840 i::Zone zone; |
| 867 i::AstValueFactory ast_value_factory(&zone, | 841 i::AstValueFactory ast_value_factory(&zone, |
| 868 CcTest::i_isolate()->heap()->HashSeed()); | 842 CcTest::i_isolate()->heap()->HashSeed()); |
| 869 ast_value_factory.Internalize(CcTest::i_isolate()); | 843 ast_value_factory.Internalize(CcTest::i_isolate()); |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1569 i::Factory* factory = isolate->factory(); | 1543 i::Factory* factory = isolate->factory(); |
| 1570 | 1544 |
| 1571 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); | 1545 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); |
| 1572 int preparser_materialized_literals = -1; | 1546 int preparser_materialized_literals = -1; |
| 1573 int parser_materialized_literals = -2; | 1547 int parser_materialized_literals = -2; |
| 1574 bool test_preparser = !is_module; | 1548 bool test_preparser = !is_module; |
| 1575 | 1549 |
| 1576 // Preparse the data. | 1550 // Preparse the data. |
| 1577 i::CompleteParserRecorder log; | 1551 i::CompleteParserRecorder log; |
| 1578 if (test_preparser) { | 1552 if (test_preparser) { |
| 1579 i::Scanner scanner(isolate->unicode_cache(), false); | 1553 i::Scanner scanner(isolate->unicode_cache()); |
| 1580 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); | 1554 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
| 1581 i::Zone zone; | 1555 i::Zone zone; |
| 1582 i::AstValueFactory ast_value_factory( | 1556 i::AstValueFactory ast_value_factory( |
| 1583 &zone, CcTest::i_isolate()->heap()->HashSeed()); | 1557 &zone, CcTest::i_isolate()->heap()->HashSeed()); |
| 1584 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, | 1558 i::PreParser preparser(&zone, &scanner, &ast_value_factory, &log, |
| 1585 stack_limit); | 1559 stack_limit); |
| 1586 SetParserFlags(&preparser, flags); | 1560 SetParserFlags(&preparser, flags); |
| 1587 scanner.Initialize(&stream); | 1561 scanner.Initialize(&stream); |
| 1588 i::PreParser::PreParseResult result = preparser.PreParseProgram( | 1562 i::PreParser::PreParseResult result = preparser.PreParseProgram( |
| 1589 &preparser_materialized_literals); | 1563 &preparser_materialized_literals); |
| (...skipping 5846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7436 // "Array() **= 10", | 7410 // "Array() **= 10", |
| 7437 NULL | 7411 NULL |
| 7438 }; | 7412 }; |
| 7439 // clang-format on | 7413 // clang-format on |
| 7440 | 7414 |
| 7441 static const ParserFlag always_flags[] = { | 7415 static const ParserFlag always_flags[] = { |
| 7442 kAllowHarmonyExponentiationOperator}; | 7416 kAllowHarmonyExponentiationOperator}; |
| 7443 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, | 7417 RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags, |
| 7444 arraysize(always_flags)); | 7418 arraysize(always_flags)); |
| 7445 } | 7419 } |
| OLD | NEW |