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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 | 56 |
57 KeywordToken key_token; | 57 KeywordToken key_token; |
58 i::UnicodeCache unicode_cache; | 58 i::UnicodeCache unicode_cache; |
59 i::byte buffer[32]; | 59 i::byte buffer[32]; |
60 for (int i = 0; (key_token = keywords[i]).keyword != NULL; i++) { | 60 for (int i = 0; (key_token = keywords[i]).keyword != NULL; i++) { |
61 const i::byte* keyword = | 61 const i::byte* keyword = |
62 reinterpret_cast<const i::byte*>(key_token.keyword); | 62 reinterpret_cast<const i::byte*>(key_token.keyword); |
63 int length = i::StrLength(key_token.keyword); | 63 int length = i::StrLength(key_token.keyword); |
64 CHECK(static_cast<int>(sizeof(buffer)) >= length); | 64 CHECK(static_cast<int>(sizeof(buffer)) >= length); |
65 { | 65 { |
66 i::Utf8ToUC16CharacterStream stream(keyword, length); | 66 i::Utf8ToUtf16CharacterStream stream(keyword, length); |
67 i::Scanner scanner(&unicode_cache); | 67 i::Scanner scanner(&unicode_cache); |
68 // The scanner should parse Harmony keywords for this test. | 68 // The scanner should parse Harmony keywords for this test. |
69 scanner.SetHarmonyScoping(true); | 69 scanner.SetHarmonyScoping(true); |
70 scanner.SetHarmonyModules(true); | 70 scanner.SetHarmonyModules(true); |
71 scanner.Initialize(&stream); | 71 scanner.Initialize(&stream); |
72 CHECK_EQ(key_token.token, scanner.Next()); | 72 CHECK_EQ(key_token.token, scanner.Next()); |
73 CHECK_EQ(i::Token::EOS, scanner.Next()); | 73 CHECK_EQ(i::Token::EOS, scanner.Next()); |
74 } | 74 } |
75 // Removing characters will make keyword matching fail. | 75 // Removing characters will make keyword matching fail. |
76 { | 76 { |
77 i::Utf8ToUC16CharacterStream stream(keyword, length - 1); | 77 i::Utf8ToUtf16CharacterStream stream(keyword, length - 1); |
78 i::Scanner scanner(&unicode_cache); | 78 i::Scanner scanner(&unicode_cache); |
79 scanner.Initialize(&stream); | 79 scanner.Initialize(&stream); |
80 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); | 80 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); |
81 CHECK_EQ(i::Token::EOS, scanner.Next()); | 81 CHECK_EQ(i::Token::EOS, scanner.Next()); |
82 } | 82 } |
83 // Adding characters will make keyword matching fail. | 83 // Adding characters will make keyword matching fail. |
84 static const char chars_to_append[] = { 'z', '0', '_' }; | 84 static const char chars_to_append[] = { 'z', '0', '_' }; |
85 for (int j = 0; j < static_cast<int>(ARRAY_SIZE(chars_to_append)); ++j) { | 85 for (int j = 0; j < static_cast<int>(ARRAY_SIZE(chars_to_append)); ++j) { |
86 memmove(buffer, keyword, length); | 86 memmove(buffer, keyword, length); |
87 buffer[length] = chars_to_append[j]; | 87 buffer[length] = chars_to_append[j]; |
88 i::Utf8ToUC16CharacterStream stream(buffer, length + 1); | 88 i::Utf8ToUtf16CharacterStream stream(buffer, length + 1); |
89 i::Scanner scanner(&unicode_cache); | 89 i::Scanner scanner(&unicode_cache); |
90 scanner.Initialize(&stream); | 90 scanner.Initialize(&stream); |
91 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); | 91 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); |
92 CHECK_EQ(i::Token::EOS, scanner.Next()); | 92 CHECK_EQ(i::Token::EOS, scanner.Next()); |
93 } | 93 } |
94 // Replacing characters will make keyword matching fail. | 94 // Replacing characters will make keyword matching fail. |
95 { | 95 { |
96 memmove(buffer, keyword, length); | 96 memmove(buffer, keyword, length); |
97 buffer[length - 1] = '_'; | 97 buffer[length - 1] = '_'; |
98 i::Utf8ToUC16CharacterStream stream(buffer, length); | 98 i::Utf8ToUtf16CharacterStream stream(buffer, length); |
99 i::Scanner scanner(&unicode_cache); | 99 i::Scanner scanner(&unicode_cache); |
100 scanner.Initialize(&stream); | 100 scanner.Initialize(&stream); |
101 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); | 101 CHECK_EQ(i::Token::IDENTIFIER, scanner.Next()); |
102 CHECK_EQ(i::Token::EOS, scanner.Next()); | 102 CHECK_EQ(i::Token::EOS, scanner.Next()); |
103 } | 103 } |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 | 107 |
108 TEST(ScanHTMLEndComments) { | 108 TEST(ScanHTMLEndComments) { |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 "var x = 42;", | 248 "var x = 42;", |
249 "function foo(x, y) { return x + y; }", | 249 "function foo(x, y) { return x + y; }", |
250 "%ArgleBargle(glop);", | 250 "%ArgleBargle(glop);", |
251 "var x = new new Function('this.x = 42');", | 251 "var x = new new Function('this.x = 42');", |
252 NULL | 252 NULL |
253 }; | 253 }; |
254 | 254 |
255 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); | 255 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); |
256 for (int i = 0; programs[i]; i++) { | 256 for (int i = 0; programs[i]; i++) { |
257 const char* program = programs[i]; | 257 const char* program = programs[i]; |
258 i::Utf8ToUC16CharacterStream stream( | 258 i::Utf8ToUtf16CharacterStream stream( |
259 reinterpret_cast<const i::byte*>(program), | 259 reinterpret_cast<const i::byte*>(program), |
260 static_cast<unsigned>(strlen(program))); | 260 static_cast<unsigned>(strlen(program))); |
261 i::CompleteParserRecorder log; | 261 i::CompleteParserRecorder log; |
262 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); | 262 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); |
263 scanner.Initialize(&stream); | 263 scanner.Initialize(&stream); |
264 | 264 |
265 int flags = i::kAllowLazy | i::kAllowNativesSyntax; | 265 int flags = i::kAllowLazy | i::kAllowNativesSyntax; |
266 v8::preparser::PreParser::PreParseResult result = | 266 v8::preparser::PreParser::PreParseResult result = |
267 v8::preparser::PreParser::PreParseProgram(&scanner, | 267 v8::preparser::PreParser::PreParseProgram(&scanner, |
268 &log, | 268 &log, |
(...skipping 15 matching lines...) Expand all Loading... |
284 | 284 |
285 const char* programs[] = { | 285 const char* programs[] = { |
286 "%ArgleBargle(glop);", | 286 "%ArgleBargle(glop);", |
287 "var x = %_IsSmi(42);", | 287 "var x = %_IsSmi(42);", |
288 NULL | 288 NULL |
289 }; | 289 }; |
290 | 290 |
291 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); | 291 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); |
292 for (int i = 0; programs[i]; i++) { | 292 for (int i = 0; programs[i]; i++) { |
293 const char* program = programs[i]; | 293 const char* program = programs[i]; |
294 i::Utf8ToUC16CharacterStream stream( | 294 i::Utf8ToUtf16CharacterStream stream( |
295 reinterpret_cast<const i::byte*>(program), | 295 reinterpret_cast<const i::byte*>(program), |
296 static_cast<unsigned>(strlen(program))); | 296 static_cast<unsigned>(strlen(program))); |
297 i::CompleteParserRecorder log; | 297 i::CompleteParserRecorder log; |
298 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); | 298 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); |
299 scanner.Initialize(&stream); | 299 scanner.Initialize(&stream); |
300 | 300 |
301 // Flags don't allow natives syntax. | 301 // Flags don't allow natives syntax. |
302 v8::preparser::PreParser::PreParseResult result = | 302 v8::preparser::PreParser::PreParseResult result = |
303 v8::preparser::PreParser::PreParseProgram(&scanner, | 303 v8::preparser::PreParser::PreParseProgram(&scanner, |
304 &log, | 304 &log, |
(...skipping 14 matching lines...) Expand all Loading... |
319 i::Isolate::Current()->stack_guard()->SetStackLimit( | 319 i::Isolate::Current()->stack_guard()->SetStackLimit( |
320 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 320 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
321 | 321 |
322 const char* program = "var x = 'something';\n" | 322 const char* program = "var x = 'something';\n" |
323 "escape: function() {}"; | 323 "escape: function() {}"; |
324 // Fails parsing expecting an identifier after "function". | 324 // Fails parsing expecting an identifier after "function". |
325 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), | 325 // Before fix, didn't check *ok after Expect(Token::Identifier, ok), |
326 // and then used the invalid currently scanned literal. This always | 326 // and then used the invalid currently scanned literal. This always |
327 // failed in debug mode, and sometimes crashed in release mode. | 327 // failed in debug mode, and sometimes crashed in release mode. |
328 | 328 |
329 i::Utf8ToUC16CharacterStream stream(reinterpret_cast<const i::byte*>(program), | 329 i::Utf8ToUtf16CharacterStream stream( |
330 static_cast<unsigned>(strlen(program))); | 330 reinterpret_cast<const i::byte*>(program), |
| 331 static_cast<unsigned>(strlen(program))); |
331 i::ScriptDataImpl* data = | 332 i::ScriptDataImpl* data = |
332 i::ParserApi::PreParse(&stream, NULL, false); | 333 i::ParserApi::PreParse(&stream, NULL, false); |
333 CHECK(data->HasError()); | 334 CHECK(data->HasError()); |
334 delete data; | 335 delete data; |
335 } | 336 } |
336 | 337 |
337 | 338 |
338 TEST(Regress928) { | 339 TEST(Regress928) { |
339 v8::V8::Initialize(); | 340 v8::V8::Initialize(); |
340 | 341 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 386 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
386 | 387 |
387 size_t kProgramSize = 1024 * 1024; | 388 size_t kProgramSize = 1024 * 1024; |
388 i::SmartArrayPointer<char> program( | 389 i::SmartArrayPointer<char> program( |
389 reinterpret_cast<char*>(malloc(kProgramSize + 1))); | 390 reinterpret_cast<char*>(malloc(kProgramSize + 1))); |
390 memset(*program, '(', kProgramSize); | 391 memset(*program, '(', kProgramSize); |
391 program[kProgramSize] = '\0'; | 392 program[kProgramSize] = '\0'; |
392 | 393 |
393 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); | 394 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); |
394 | 395 |
395 i::Utf8ToUC16CharacterStream stream( | 396 i::Utf8ToUtf16CharacterStream stream( |
396 reinterpret_cast<const i::byte*>(*program), | 397 reinterpret_cast<const i::byte*>(*program), |
397 static_cast<unsigned>(kProgramSize)); | 398 static_cast<unsigned>(kProgramSize)); |
398 i::CompleteParserRecorder log; | 399 i::CompleteParserRecorder log; |
399 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); | 400 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); |
400 scanner.Initialize(&stream); | 401 scanner.Initialize(&stream); |
401 | 402 |
402 | 403 |
403 v8::preparser::PreParser::PreParseResult result = | 404 v8::preparser::PreParser::PreParseResult result = |
404 v8::preparser::PreParser::PreParseProgram(&scanner, | 405 v8::preparser::PreParser::PreParseProgram(&scanner, |
405 &log, | 406 &log, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 for (unsigned i = 0; i < length; i++) { | 443 for (unsigned i = 0; i < length; i++) { |
443 uc16_buffer[i] = static_cast<i::uc16>(ascii_source[i]); | 444 uc16_buffer[i] = static_cast<i::uc16>(ascii_source[i]); |
444 } | 445 } |
445 i::Vector<const char> ascii_vector(ascii_source, static_cast<int>(length)); | 446 i::Vector<const char> ascii_vector(ascii_source, static_cast<int>(length)); |
446 i::Handle<i::String> ascii_string( | 447 i::Handle<i::String> ascii_string( |
447 FACTORY->NewStringFromAscii(ascii_vector)); | 448 FACTORY->NewStringFromAscii(ascii_vector)); |
448 TestExternalResource resource(*uc16_buffer, length); | 449 TestExternalResource resource(*uc16_buffer, length); |
449 i::Handle<i::String> uc16_string( | 450 i::Handle<i::String> uc16_string( |
450 FACTORY->NewExternalStringFromTwoByte(&resource)); | 451 FACTORY->NewExternalStringFromTwoByte(&resource)); |
451 | 452 |
452 i::ExternalTwoByteStringUC16CharacterStream uc16_stream( | 453 i::ExternalTwoByteStringUtf16CharacterStream uc16_stream( |
453 i::Handle<i::ExternalTwoByteString>::cast(uc16_string), start, end); | 454 i::Handle<i::ExternalTwoByteString>::cast(uc16_string), start, end); |
454 i::GenericStringUC16CharacterStream string_stream(ascii_string, start, end); | 455 i::GenericStringUtf16CharacterStream string_stream(ascii_string, start, end); |
455 i::Utf8ToUC16CharacterStream utf8_stream( | 456 i::Utf8ToUtf16CharacterStream utf8_stream( |
456 reinterpret_cast<const i::byte*>(ascii_source), end); | 457 reinterpret_cast<const i::byte*>(ascii_source), end); |
457 utf8_stream.SeekForward(start); | 458 utf8_stream.SeekForward(start); |
458 | 459 |
459 unsigned i = start; | 460 unsigned i = start; |
460 while (i < end) { | 461 while (i < end) { |
461 // Read streams one char at a time | 462 // Read streams one char at a time |
462 CHECK_EQU(i, uc16_stream.pos()); | 463 CHECK_EQU(i, uc16_stream.pos()); |
463 CHECK_EQU(i, string_stream.pos()); | 464 CHECK_EQU(i, string_stream.pos()); |
464 CHECK_EQU(i, utf8_stream.pos()); | 465 CHECK_EQU(i, utf8_stream.pos()); |
465 int32_t c0 = ascii_source[i]; | 466 int32_t c0 = ascii_source[i]; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 static const int kAllUtf8CharsSize = | 569 static const int kAllUtf8CharsSize = |
569 (unibrow::Utf8::kMaxOneByteChar + 1) + | 570 (unibrow::Utf8::kMaxOneByteChar + 1) + |
570 (unibrow::Utf8::kMaxTwoByteChar - unibrow::Utf8::kMaxOneByteChar) * 2 + | 571 (unibrow::Utf8::kMaxTwoByteChar - unibrow::Utf8::kMaxOneByteChar) * 2 + |
571 (unibrow::Utf8::kMaxThreeByteChar - unibrow::Utf8::kMaxTwoByteChar) * 3; | 572 (unibrow::Utf8::kMaxThreeByteChar - unibrow::Utf8::kMaxTwoByteChar) * 3; |
572 static const unsigned kAllUtf8CharsSizeU = | 573 static const unsigned kAllUtf8CharsSizeU = |
573 static_cast<unsigned>(kAllUtf8CharsSize); | 574 static_cast<unsigned>(kAllUtf8CharsSize); |
574 | 575 |
575 char buffer[kAllUtf8CharsSizeU]; | 576 char buffer[kAllUtf8CharsSizeU]; |
576 unsigned cursor = 0; | 577 unsigned cursor = 0; |
577 for (int i = 0; i <= kMaxUC16Char; i++) { | 578 for (int i = 0; i <= kMaxUC16Char; i++) { |
578 cursor += unibrow::Utf8::Encode(buffer + cursor, i); | 579 cursor += unibrow::Utf8::Encode(buffer + cursor, |
| 580 i, |
| 581 unibrow::Utf16::kNoPreviousCharacter); |
579 } | 582 } |
580 ASSERT(cursor == kAllUtf8CharsSizeU); | 583 ASSERT(cursor == kAllUtf8CharsSizeU); |
581 | 584 |
582 i::Utf8ToUC16CharacterStream stream(reinterpret_cast<const i::byte*>(buffer), | 585 i::Utf8ToUtf16CharacterStream stream(reinterpret_cast<const i::byte*>(buffer), |
583 kAllUtf8CharsSizeU); | 586 kAllUtf8CharsSizeU); |
584 for (int i = 0; i <= kMaxUC16Char; i++) { | 587 for (int i = 0; i <= kMaxUC16Char; i++) { |
585 CHECK_EQU(i, stream.pos()); | 588 CHECK_EQU(i, stream.pos()); |
586 int32_t c = stream.Advance(); | 589 int32_t c = stream.Advance(); |
587 CHECK_EQ(i, c); | 590 CHECK_EQ(i, c); |
588 CHECK_EQU(i + 1, stream.pos()); | 591 CHECK_EQU(i + 1, stream.pos()); |
589 } | 592 } |
590 for (int i = kMaxUC16Char; i >= 0; i--) { | 593 for (int i = kMaxUC16Char; i >= 0; i--) { |
591 CHECK_EQU(i + 1, stream.pos()); | 594 CHECK_EQU(i + 1, stream.pos()); |
592 stream.PushBack(i); | 595 stream.PushBack(i); |
593 CHECK_EQU(i, stream.pos()); | 596 CHECK_EQU(i, stream.pos()); |
594 } | 597 } |
595 int i = 0; | 598 int i = 0; |
596 while (stream.pos() < kMaxUC16CharU) { | 599 while (stream.pos() < kMaxUC16CharU) { |
597 CHECK_EQU(i, stream.pos()); | 600 CHECK_EQU(i, stream.pos()); |
598 unsigned progress = stream.SeekForward(12); | 601 unsigned progress = stream.SeekForward(12); |
599 i += progress; | 602 i += progress; |
600 int32_t c = stream.Advance(); | 603 int32_t c = stream.Advance(); |
601 if (i <= kMaxUC16Char) { | 604 if (i <= kMaxUC16Char) { |
602 CHECK_EQ(i, c); | 605 CHECK_EQ(i, c); |
603 } else { | 606 } else { |
604 CHECK_EQ(-1, c); | 607 CHECK_EQ(-1, c); |
605 } | 608 } |
606 i += 1; | 609 i += 1; |
607 CHECK_EQU(i, stream.pos()); | 610 CHECK_EQU(i, stream.pos()); |
608 } | 611 } |
609 } | 612 } |
610 | 613 |
611 #undef CHECK_EQU | 614 #undef CHECK_EQU |
612 | 615 |
613 void TestStreamScanner(i::UC16CharacterStream* stream, | 616 void TestStreamScanner(i::Utf16CharacterStream* stream, |
614 i::Token::Value* expected_tokens, | 617 i::Token::Value* expected_tokens, |
615 int skip_pos = 0, // Zero means not skipping. | 618 int skip_pos = 0, // Zero means not skipping. |
616 int skip_to = 0) { | 619 int skip_to = 0) { |
617 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); | 620 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); |
618 scanner.Initialize(stream); | 621 scanner.Initialize(stream); |
619 | 622 |
620 int i = 0; | 623 int i = 0; |
621 do { | 624 do { |
622 i::Token::Value expected = expected_tokens[i]; | 625 i::Token::Value expected = expected_tokens[i]; |
623 i::Token::Value actual = scanner.Next(); | 626 i::Token::Value actual = scanner.Next(); |
624 CHECK_EQ(i::Token::String(expected), i::Token::String(actual)); | 627 CHECK_EQ(i::Token::String(expected), i::Token::String(actual)); |
625 if (scanner.location().end_pos == skip_pos) { | 628 if (scanner.location().end_pos == skip_pos) { |
626 scanner.SeekForward(skip_to); | 629 scanner.SeekForward(skip_to); |
627 } | 630 } |
628 i++; | 631 i++; |
629 } while (expected_tokens[i] != i::Token::ILLEGAL); | 632 } while (expected_tokens[i] != i::Token::ILLEGAL); |
630 } | 633 } |
631 | 634 |
632 TEST(StreamScanner) { | 635 TEST(StreamScanner) { |
633 v8::V8::Initialize(); | 636 v8::V8::Initialize(); |
634 | 637 |
635 const char* str1 = "{ foo get for : */ <- \n\n /*foo*/ bib"; | 638 const char* str1 = "{ foo get for : */ <- \n\n /*foo*/ bib"; |
636 i::Utf8ToUC16CharacterStream stream1(reinterpret_cast<const i::byte*>(str1), | 639 i::Utf8ToUtf16CharacterStream stream1(reinterpret_cast<const i::byte*>(str1), |
637 static_cast<unsigned>(strlen(str1))); | 640 static_cast<unsigned>(strlen(str1))); |
638 i::Token::Value expectations1[] = { | 641 i::Token::Value expectations1[] = { |
639 i::Token::LBRACE, | 642 i::Token::LBRACE, |
640 i::Token::IDENTIFIER, | 643 i::Token::IDENTIFIER, |
641 i::Token::IDENTIFIER, | 644 i::Token::IDENTIFIER, |
642 i::Token::FOR, | 645 i::Token::FOR, |
643 i::Token::COLON, | 646 i::Token::COLON, |
644 i::Token::MUL, | 647 i::Token::MUL, |
645 i::Token::DIV, | 648 i::Token::DIV, |
646 i::Token::LT, | 649 i::Token::LT, |
647 i::Token::SUB, | 650 i::Token::SUB, |
648 i::Token::IDENTIFIER, | 651 i::Token::IDENTIFIER, |
649 i::Token::EOS, | 652 i::Token::EOS, |
650 i::Token::ILLEGAL | 653 i::Token::ILLEGAL |
651 }; | 654 }; |
652 TestStreamScanner(&stream1, expectations1, 0, 0); | 655 TestStreamScanner(&stream1, expectations1, 0, 0); |
653 | 656 |
654 const char* str2 = "case default const {THIS\nPART\nSKIPPED} do"; | 657 const char* str2 = "case default const {THIS\nPART\nSKIPPED} do"; |
655 i::Utf8ToUC16CharacterStream stream2(reinterpret_cast<const i::byte*>(str2), | 658 i::Utf8ToUtf16CharacterStream stream2(reinterpret_cast<const i::byte*>(str2), |
656 static_cast<unsigned>(strlen(str2))); | 659 static_cast<unsigned>(strlen(str2))); |
657 i::Token::Value expectations2[] = { | 660 i::Token::Value expectations2[] = { |
658 i::Token::CASE, | 661 i::Token::CASE, |
659 i::Token::DEFAULT, | 662 i::Token::DEFAULT, |
660 i::Token::CONST, | 663 i::Token::CONST, |
661 i::Token::LBRACE, | 664 i::Token::LBRACE, |
662 // Skipped part here | 665 // Skipped part here |
663 i::Token::RBRACE, | 666 i::Token::RBRACE, |
664 i::Token::DO, | 667 i::Token::DO, |
665 i::Token::EOS, | 668 i::Token::EOS, |
666 i::Token::ILLEGAL | 669 i::Token::ILLEGAL |
667 }; | 670 }; |
668 ASSERT_EQ('{', str2[19]); | 671 ASSERT_EQ('{', str2[19]); |
669 ASSERT_EQ('}', str2[37]); | 672 ASSERT_EQ('}', str2[37]); |
670 TestStreamScanner(&stream2, expectations2, 20, 37); | 673 TestStreamScanner(&stream2, expectations2, 20, 37); |
671 | 674 |
672 const char* str3 = "{}}}}"; | 675 const char* str3 = "{}}}}"; |
673 i::Token::Value expectations3[] = { | 676 i::Token::Value expectations3[] = { |
674 i::Token::LBRACE, | 677 i::Token::LBRACE, |
675 i::Token::RBRACE, | 678 i::Token::RBRACE, |
676 i::Token::RBRACE, | 679 i::Token::RBRACE, |
677 i::Token::RBRACE, | 680 i::Token::RBRACE, |
678 i::Token::RBRACE, | 681 i::Token::RBRACE, |
679 i::Token::EOS, | 682 i::Token::EOS, |
680 i::Token::ILLEGAL | 683 i::Token::ILLEGAL |
681 }; | 684 }; |
682 // Skip zero-four RBRACEs. | 685 // Skip zero-four RBRACEs. |
683 for (int i = 0; i <= 4; i++) { | 686 for (int i = 0; i <= 4; i++) { |
684 expectations3[6 - i] = i::Token::ILLEGAL; | 687 expectations3[6 - i] = i::Token::ILLEGAL; |
685 expectations3[5 - i] = i::Token::EOS; | 688 expectations3[5 - i] = i::Token::EOS; |
686 i::Utf8ToUC16CharacterStream stream3( | 689 i::Utf8ToUtf16CharacterStream stream3( |
687 reinterpret_cast<const i::byte*>(str3), | 690 reinterpret_cast<const i::byte*>(str3), |
688 static_cast<unsigned>(strlen(str3))); | 691 static_cast<unsigned>(strlen(str3))); |
689 TestStreamScanner(&stream3, expectations3, 1, 1 + i); | 692 TestStreamScanner(&stream3, expectations3, 1, 1 + i); |
690 } | 693 } |
691 } | 694 } |
692 | 695 |
693 | 696 |
694 void TestScanRegExp(const char* re_source, const char* expected) { | 697 void TestScanRegExp(const char* re_source, const char* expected) { |
695 i::Utf8ToUC16CharacterStream stream( | 698 i::Utf8ToUtf16CharacterStream stream( |
696 reinterpret_cast<const i::byte*>(re_source), | 699 reinterpret_cast<const i::byte*>(re_source), |
697 static_cast<unsigned>(strlen(re_source))); | 700 static_cast<unsigned>(strlen(re_source))); |
698 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); | 701 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); |
699 scanner.Initialize(&stream); | 702 scanner.Initialize(&stream); |
700 | 703 |
701 i::Token::Value start = scanner.peek(); | 704 i::Token::Value start = scanner.peek(); |
702 CHECK(start == i::Token::DIV || start == i::Token::ASSIGN_DIV); | 705 CHECK(start == i::Token::DIV || start == i::Token::ASSIGN_DIV); |
703 CHECK(scanner.ScanRegExpPattern(start == i::Token::ASSIGN_DIV)); | 706 CHECK(scanner.ScanRegExpPattern(start == i::Token::ASSIGN_DIV)); |
704 scanner.Next(); // Current token is now the regexp literal. | 707 scanner.Next(); // Current token is now the regexp literal. |
705 CHECK(scanner.is_literal_ascii()); | 708 CHECK(scanner.is_literal_ascii()); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 " block;\n" | 831 " block;\n" |
829 " }", "\n" | 832 " }", "\n" |
830 " more;", i::BLOCK_SCOPE, i::EXTENDED_MODE }, | 833 " more;", i::BLOCK_SCOPE, i::EXTENDED_MODE }, |
831 { " for ", "(let x in {}) statement;", " more;", | 834 { " for ", "(let x in {}) statement;", " more;", |
832 i::BLOCK_SCOPE, i::EXTENDED_MODE }, | 835 i::BLOCK_SCOPE, i::EXTENDED_MODE }, |
833 { " for ", "(let x in {}) statement", "\n" | 836 { " for ", "(let x in {}) statement", "\n" |
834 " more;", i::BLOCK_SCOPE, i::EXTENDED_MODE }, | 837 " more;", i::BLOCK_SCOPE, i::EXTENDED_MODE }, |
835 { " for ", "(let x in {})\n" | 838 { " for ", "(let x in {})\n" |
836 " statement;", "\n" | 839 " statement;", "\n" |
837 " more;", i::BLOCK_SCOPE, i::EXTENDED_MODE }, | 840 " more;", i::BLOCK_SCOPE, i::EXTENDED_MODE }, |
| 841 // Check that 6-byte and 4-byte encodings of UTF-8 strings do not throw |
| 842 // the preparser off in terms of byte offsets. |
| 843 { " 'foo\355\240\201\355\260\211';\n" |
| 844 " (function fun", "(a,b) { infunction; }", ")();", |
| 845 i::FUNCTION_SCOPE, i::CLASSIC_MODE }, |
| 846 { " 'foo\360\220\220\212';\n" |
| 847 " (function fun", "(a,b) { infunction; }", ")();", |
| 848 i::FUNCTION_SCOPE, i::CLASSIC_MODE }, |
| 849 { " 'foo';\n" |
| 850 " (function fun", "(a,b) { 'bar\355\240\201\355\213'; }", ")();", |
| 851 i::FUNCTION_SCOPE, i::CLASSIC_MODE }, |
| 852 { " 'foo';\n" |
| 853 " (function fun", "(a,b) { 'bar\360\220\220\214'; }", ")();", |
| 854 i::FUNCTION_SCOPE, i::CLASSIC_MODE }, |
838 { NULL, NULL, NULL, i::EVAL_SCOPE, i::CLASSIC_MODE } | 855 { NULL, NULL, NULL, i::EVAL_SCOPE, i::CLASSIC_MODE } |
839 }; | 856 }; |
840 | 857 |
841 v8::HandleScope handles; | 858 v8::HandleScope handles; |
842 v8::Persistent<v8::Context> context = v8::Context::New(); | 859 v8::Persistent<v8::Context> context = v8::Context::New(); |
843 v8::Context::Scope context_scope(context); | 860 v8::Context::Scope context_scope(context); |
844 | 861 |
845 int marker; | 862 int marker; |
846 i::Isolate::Current()->stack_guard()->SetStackLimit( | 863 i::Isolate::Current()->stack_guard()->SetStackLimit( |
847 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); | 864 reinterpret_cast<uintptr_t>(&marker) - 128 * 1024); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 } | 904 } |
888 | 905 |
889 | 906 |
890 void TestParserSync(i::Handle<i::String> source, int flags) { | 907 void TestParserSync(i::Handle<i::String> source, int flags) { |
891 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); | 908 uintptr_t stack_limit = i::Isolate::Current()->stack_guard()->real_climit(); |
892 bool harmony_scoping = ((i::kLanguageModeMask & flags) == i::EXTENDED_MODE); | 909 bool harmony_scoping = ((i::kLanguageModeMask & flags) == i::EXTENDED_MODE); |
893 | 910 |
894 // Preparse the data. | 911 // Preparse the data. |
895 i::CompleteParserRecorder log; | 912 i::CompleteParserRecorder log; |
896 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); | 913 i::Scanner scanner(i::Isolate::Current()->unicode_cache()); |
897 i::GenericStringUC16CharacterStream stream(source, 0, source->length()); | 914 i::GenericStringUtf16CharacterStream stream(source, 0, source->length()); |
898 scanner.SetHarmonyScoping(harmony_scoping); | 915 scanner.SetHarmonyScoping(harmony_scoping); |
899 scanner.Initialize(&stream); | 916 scanner.Initialize(&stream); |
900 v8::preparser::PreParser::PreParseResult result = | 917 v8::preparser::PreParser::PreParseResult result = |
901 v8::preparser::PreParser::PreParseProgram( | 918 v8::preparser::PreParser::PreParseProgram( |
902 &scanner, &log, flags, stack_limit); | 919 &scanner, &log, flags, stack_limit); |
903 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); | 920 CHECK_EQ(v8::preparser::PreParser::kPreParseSuccess, result); |
904 i::ScriptDataImpl data(log.ExtractData()); | 921 i::ScriptDataImpl data(log.ExtractData()); |
905 | 922 |
906 // Parse the data | 923 // Parse the data |
907 i::Handle<i::Script> script = FACTORY->NewScript(source); | 924 i::Handle<i::Script> script = FACTORY->NewScript(source); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 termination_data[k], | 1093 termination_data[k], |
1077 context_data[i][1]); | 1094 context_data[i][1]); |
1078 CHECK(length == kProgramSize); | 1095 CHECK(length == kProgramSize); |
1079 i::Handle<i::String> source = | 1096 i::Handle<i::String> source = |
1080 FACTORY->NewStringFromAscii(i::CStrVector(program.start())); | 1097 FACTORY->NewStringFromAscii(i::CStrVector(program.start())); |
1081 TestParserSyncWithFlags(source); | 1098 TestParserSyncWithFlags(source); |
1082 } | 1099 } |
1083 } | 1100 } |
1084 } | 1101 } |
1085 } | 1102 } |
OLD | NEW |