Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(608)

Side by Side Diff: test/cctest/test-parsing.cc

Issue 2184393002: Implement a character stream for external one byte streams (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/parsing/scanner-character-streams.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 for (unsigned i = 0; i < length; i++) { 587 for (unsigned i = 0; i < length; i++) {
588 uc16_buffer[i] = static_cast<i::uc16>(one_byte_source[i]); 588 uc16_buffer[i] = static_cast<i::uc16>(one_byte_source[i]);
589 } 589 }
590 i::Vector<const char> one_byte_vector(one_byte_source, 590 i::Vector<const char> one_byte_vector(one_byte_source,
591 static_cast<int>(length)); 591 static_cast<int>(length));
592 i::Handle<i::String> one_byte_string = 592 i::Handle<i::String> one_byte_string =
593 factory->NewStringFromAscii(one_byte_vector).ToHandleChecked(); 593 factory->NewStringFromAscii(one_byte_vector).ToHandleChecked();
594 TestExternalResource resource(uc16_buffer.get(), length); 594 TestExternalResource resource(uc16_buffer.get(), length);
595 i::Handle<i::String> uc16_string( 595 i::Handle<i::String> uc16_string(
596 factory->NewExternalStringFromTwoByte(&resource).ToHandleChecked()); 596 factory->NewExternalStringFromTwoByte(&resource).ToHandleChecked());
597 ScriptResource one_byte_resource(one_byte_source, length);
598 i::Handle<i::String> ext_one_byte_string(
599 factory->NewExternalStringFromOneByte(&one_byte_resource)
600 .ToHandleChecked());
597 601
598 i::ExternalTwoByteStringUtf16CharacterStream uc16_stream( 602 i::ExternalTwoByteStringUtf16CharacterStream uc16_stream(
599 i::Handle<i::ExternalTwoByteString>::cast(uc16_string), start, end); 603 i::Handle<i::ExternalTwoByteString>::cast(uc16_string), start, end);
604 i::ExternalOneByteStringUtf16CharacterStream one_byte_stream(
605 i::Handle<i::ExternalOneByteString>::cast(ext_one_byte_string), start,
606 end);
600 i::GenericStringUtf16CharacterStream string_stream(one_byte_string, start, 607 i::GenericStringUtf16CharacterStream string_stream(one_byte_string, start,
601 end); 608 end);
602 i::Utf8ToUtf16CharacterStream utf8_stream( 609 i::Utf8ToUtf16CharacterStream utf8_stream(
603 reinterpret_cast<const i::byte*>(one_byte_source), end); 610 reinterpret_cast<const i::byte*>(one_byte_source), end);
604 utf8_stream.SeekForward(start); 611 utf8_stream.SeekForward(start);
605 612
606 unsigned i = start; 613 unsigned i = start;
607 while (i < end) { 614 while (i < end) {
608 // Read streams one char at a time 615 // Read streams one char at a time
609 CHECK_EQU(i, uc16_stream.pos()); 616 CHECK_EQU(i, uc16_stream.pos());
610 CHECK_EQU(i, string_stream.pos()); 617 CHECK_EQU(i, string_stream.pos());
611 CHECK_EQU(i, utf8_stream.pos()); 618 CHECK_EQU(i, utf8_stream.pos());
619 CHECK_EQU(i, one_byte_stream.pos());
612 int32_t c0 = one_byte_source[i]; 620 int32_t c0 = one_byte_source[i];
613 int32_t c1 = uc16_stream.Advance(); 621 int32_t c1 = uc16_stream.Advance();
614 int32_t c2 = string_stream.Advance(); 622 int32_t c2 = string_stream.Advance();
615 int32_t c3 = utf8_stream.Advance(); 623 int32_t c3 = utf8_stream.Advance();
624 int32_t c4 = one_byte_stream.Advance();
616 i++; 625 i++;
617 CHECK_EQ(c0, c1); 626 CHECK_EQ(c0, c1);
618 CHECK_EQ(c0, c2); 627 CHECK_EQ(c0, c2);
619 CHECK_EQ(c0, c3); 628 CHECK_EQ(c0, c3);
629 CHECK_EQ(c0, c4);
620 CHECK_EQU(i, uc16_stream.pos()); 630 CHECK_EQU(i, uc16_stream.pos());
621 CHECK_EQU(i, string_stream.pos()); 631 CHECK_EQU(i, string_stream.pos());
622 CHECK_EQU(i, utf8_stream.pos()); 632 CHECK_EQU(i, utf8_stream.pos());
633 CHECK_EQU(i, one_byte_stream.pos());
623 } 634 }
624 while (i > start + sub_length / 4) { 635 while (i > start + sub_length / 4) {
625 // Pushback, re-read, pushback again. 636 // Pushback, re-read, pushback again.
626 int32_t c0 = one_byte_source[i - 1]; 637 int32_t c0 = one_byte_source[i - 1];
627 CHECK_EQU(i, uc16_stream.pos()); 638 CHECK_EQU(i, uc16_stream.pos());
628 CHECK_EQU(i, string_stream.pos()); 639 CHECK_EQU(i, string_stream.pos());
629 CHECK_EQU(i, utf8_stream.pos()); 640 CHECK_EQU(i, utf8_stream.pos());
641 CHECK_EQU(i, one_byte_stream.pos());
630 uc16_stream.PushBack(c0); 642 uc16_stream.PushBack(c0);
631 string_stream.PushBack(c0); 643 string_stream.PushBack(c0);
632 utf8_stream.PushBack(c0); 644 utf8_stream.PushBack(c0);
645 one_byte_stream.PushBack(c0);
633 i--; 646 i--;
634 CHECK_EQU(i, uc16_stream.pos()); 647 CHECK_EQU(i, uc16_stream.pos());
635 CHECK_EQU(i, string_stream.pos()); 648 CHECK_EQU(i, string_stream.pos());
636 CHECK_EQU(i, utf8_stream.pos()); 649 CHECK_EQU(i, utf8_stream.pos());
650 CHECK_EQU(i, one_byte_stream.pos());
637 int32_t c1 = uc16_stream.Advance(); 651 int32_t c1 = uc16_stream.Advance();
638 int32_t c2 = string_stream.Advance(); 652 int32_t c2 = string_stream.Advance();
639 int32_t c3 = utf8_stream.Advance(); 653 int32_t c3 = utf8_stream.Advance();
654 int32_t c4 = one_byte_stream.Advance();
640 i++; 655 i++;
641 CHECK_EQU(i, uc16_stream.pos()); 656 CHECK_EQU(i, uc16_stream.pos());
642 CHECK_EQU(i, string_stream.pos()); 657 CHECK_EQU(i, string_stream.pos());
643 CHECK_EQU(i, utf8_stream.pos()); 658 CHECK_EQU(i, utf8_stream.pos());
659 CHECK_EQU(i, one_byte_stream.pos());
644 CHECK_EQ(c0, c1); 660 CHECK_EQ(c0, c1);
645 CHECK_EQ(c0, c2); 661 CHECK_EQ(c0, c2);
646 CHECK_EQ(c0, c3); 662 CHECK_EQ(c0, c3);
663 CHECK_EQ(c0, c4);
647 uc16_stream.PushBack(c0); 664 uc16_stream.PushBack(c0);
648 string_stream.PushBack(c0); 665 string_stream.PushBack(c0);
649 utf8_stream.PushBack(c0); 666 utf8_stream.PushBack(c0);
667 one_byte_stream.PushBack(c0);
650 i--; 668 i--;
651 CHECK_EQU(i, uc16_stream.pos()); 669 CHECK_EQU(i, uc16_stream.pos());
652 CHECK_EQU(i, string_stream.pos()); 670 CHECK_EQU(i, string_stream.pos());
653 CHECK_EQU(i, utf8_stream.pos()); 671 CHECK_EQU(i, utf8_stream.pos());
672 CHECK_EQU(i, one_byte_stream.pos());
654 } 673 }
655 unsigned halfway = start + sub_length / 2; 674 unsigned halfway = start + sub_length / 2;
656 uc16_stream.SeekForward(halfway - i); 675 uc16_stream.SeekForward(halfway - i);
657 string_stream.SeekForward(halfway - i); 676 string_stream.SeekForward(halfway - i);
658 utf8_stream.SeekForward(halfway - i); 677 utf8_stream.SeekForward(halfway - i);
678 one_byte_stream.SeekForward(halfway - i);
659 i = halfway; 679 i = halfway;
660 CHECK_EQU(i, uc16_stream.pos()); 680 CHECK_EQU(i, uc16_stream.pos());
661 CHECK_EQU(i, string_stream.pos()); 681 CHECK_EQU(i, string_stream.pos());
662 CHECK_EQU(i, utf8_stream.pos()); 682 CHECK_EQU(i, utf8_stream.pos());
683 CHECK_EQU(i, one_byte_stream.pos());
663 684
664 while (i < end) { 685 while (i < end) {
665 // Read streams one char at a time 686 // Read streams one char at a time
666 CHECK_EQU(i, uc16_stream.pos()); 687 CHECK_EQU(i, uc16_stream.pos());
667 CHECK_EQU(i, string_stream.pos()); 688 CHECK_EQU(i, string_stream.pos());
668 CHECK_EQU(i, utf8_stream.pos()); 689 CHECK_EQU(i, utf8_stream.pos());
690 CHECK_EQU(i, one_byte_stream.pos());
669 int32_t c0 = one_byte_source[i]; 691 int32_t c0 = one_byte_source[i];
670 int32_t c1 = uc16_stream.Advance(); 692 int32_t c1 = uc16_stream.Advance();
671 int32_t c2 = string_stream.Advance(); 693 int32_t c2 = string_stream.Advance();
672 int32_t c3 = utf8_stream.Advance(); 694 int32_t c3 = utf8_stream.Advance();
695 int32_t c4 = one_byte_stream.Advance();
673 i++; 696 i++;
674 CHECK_EQ(c0, c1); 697 CHECK_EQ(c0, c1);
675 CHECK_EQ(c0, c2); 698 CHECK_EQ(c0, c2);
676 CHECK_EQ(c0, c3); 699 CHECK_EQ(c0, c3);
700 CHECK_EQ(c0, c4);
677 CHECK_EQU(i, uc16_stream.pos()); 701 CHECK_EQU(i, uc16_stream.pos());
678 CHECK_EQU(i, string_stream.pos()); 702 CHECK_EQU(i, string_stream.pos());
679 CHECK_EQU(i, utf8_stream.pos()); 703 CHECK_EQU(i, utf8_stream.pos());
704 CHECK_EQU(i, one_byte_stream.pos());
680 } 705 }
681 706
682 int32_t c1 = uc16_stream.Advance(); 707 int32_t c1 = uc16_stream.Advance();
683 int32_t c2 = string_stream.Advance(); 708 int32_t c2 = string_stream.Advance();
684 int32_t c3 = utf8_stream.Advance(); 709 int32_t c3 = utf8_stream.Advance();
710 int32_t c4 = one_byte_stream.Advance();
685 CHECK_LT(c1, 0); 711 CHECK_LT(c1, 0);
686 CHECK_LT(c2, 0); 712 CHECK_LT(c2, 0);
687 CHECK_LT(c3, 0); 713 CHECK_LT(c3, 0);
714 CHECK_LT(c4, 0);
688 } 715 }
689 716
690 717
691 TEST(CharacterStreams) { 718 TEST(CharacterStreams) {
692 v8::Isolate* isolate = CcTest::isolate(); 719 v8::Isolate* isolate = CcTest::isolate();
693 v8::HandleScope handles(isolate); 720 v8::HandleScope handles(isolate);
694 v8::Local<v8::Context> context = v8::Context::New(isolate); 721 v8::Local<v8::Context> context = v8::Context::New(isolate);
695 v8::Context::Scope context_scope(context); 722 v8::Context::Scope context_scope(context);
696 723
697 TestCharacterStream("abc\0\n\r\x7f", 7); 724 TestCharacterStream("abc\0\n\r\x7f", 7);
(...skipping 7261 matching lines...) Expand 10 before | Expand all | Expand 10 after
7959 "(a,);", 7986 "(a,);",
7960 "(a,b,c,);", 7987 "(a,b,c,);",
7961 NULL 7988 NULL
7962 }; 7989 };
7963 // clang-format on 7990 // clang-format on
7964 7991
7965 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas}; 7992 static const ParserFlag always_flags[] = {kAllowHarmonyTrailingCommas};
7966 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 7993 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
7967 arraysize(always_flags)); 7994 arraysize(always_flags));
7968 } 7995 }
OLDNEW
« no previous file with comments | « src/parsing/scanner-character-streams.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698