OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 | 6 |
7 #include "include/dart_tools_api.h" | 7 #include "include/dart_tools_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 DISALLOW_COPY_AND_ASSIGN(TestSnapshotWriter); | 857 DISALLOW_COPY_AND_ASSIGN(TestSnapshotWriter); |
858 }; | 858 }; |
859 | 859 |
860 | 860 |
861 static void GenerateSourceAndCheck(const Script& script) { | 861 static void GenerateSourceAndCheck(const Script& script) { |
862 // Check if we are able to generate the source from the token stream. | 862 // Check if we are able to generate the source from the token stream. |
863 // Rescan this source and compare the token stream to see if they are | 863 // Rescan this source and compare the token stream to see if they are |
864 // the same. | 864 // the same. |
865 const TokenStream& expected_tokens = TokenStream::Handle(script.tokens()); | 865 const TokenStream& expected_tokens = TokenStream::Handle(script.tokens()); |
866 TokenStream::Iterator expected_iterator( | 866 TokenStream::Iterator expected_iterator( |
867 expected_tokens, 0, TokenStream::Iterator::kAllTokens); | 867 expected_tokens, |
| 868 TokenPosition::kMinSource, |
| 869 TokenStream::Iterator::kAllTokens); |
868 const String& str = String::Handle(expected_tokens.GenerateSource()); | 870 const String& str = String::Handle(expected_tokens.GenerateSource()); |
869 const String& private_key = String::Handle(expected_tokens.PrivateKey()); | 871 const String& private_key = String::Handle(expected_tokens.PrivateKey()); |
870 Scanner scanner(str, private_key); | 872 Scanner scanner(str, private_key); |
871 const TokenStream& reconstructed_tokens = | 873 const TokenStream& reconstructed_tokens = |
872 TokenStream::Handle(TokenStream::New(scanner.GetStream(), | 874 TokenStream::Handle(TokenStream::New(scanner.GetStream(), |
873 private_key, | 875 private_key, |
874 false)); | 876 false)); |
875 expected_iterator.SetCurrentPosition(0); | 877 expected_iterator.SetCurrentPosition(TokenPosition::kMinSource); |
876 TokenStream::Iterator reconstructed_iterator( | 878 TokenStream::Iterator reconstructed_iterator( |
877 reconstructed_tokens, 0, TokenStream::Iterator::kAllTokens); | 879 reconstructed_tokens, |
| 880 TokenPosition::kMinSource, |
| 881 TokenStream::Iterator::kAllTokens); |
878 Token::Kind expected_kind = expected_iterator.CurrentTokenKind(); | 882 Token::Kind expected_kind = expected_iterator.CurrentTokenKind(); |
879 Token::Kind reconstructed_kind = reconstructed_iterator.CurrentTokenKind(); | 883 Token::Kind reconstructed_kind = reconstructed_iterator.CurrentTokenKind(); |
880 String& expected_literal = String::Handle(); | 884 String& expected_literal = String::Handle(); |
881 String& actual_literal = String::Handle(); | 885 String& actual_literal = String::Handle(); |
882 while (expected_kind != Token::kEOS && reconstructed_kind != Token::kEOS) { | 886 while (expected_kind != Token::kEOS && reconstructed_kind != Token::kEOS) { |
883 EXPECT_EQ(expected_kind, reconstructed_kind); | 887 EXPECT_EQ(expected_kind, reconstructed_kind); |
884 expected_literal ^= expected_iterator.CurrentLiteral(); | 888 expected_literal ^= expected_iterator.CurrentLiteral(); |
885 actual_literal ^= reconstructed_iterator.CurrentLiteral(); | 889 actual_literal ^= reconstructed_iterator.CurrentLiteral(); |
886 EXPECT_STREQ(expected_literal.ToCString(), actual_literal.ToCString()); | 890 EXPECT_STREQ(expected_literal.ToCString(), actual_literal.ToCString()); |
887 expected_iterator.Advance(); | 891 expected_iterator.Advance(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 EXPECT(url.Equals(str)); | 968 EXPECT(url.Equals(str)); |
965 | 969 |
966 const TokenStream& expected_tokens = TokenStream::Handle(script.tokens()); | 970 const TokenStream& expected_tokens = TokenStream::Handle(script.tokens()); |
967 const TokenStream& serialized_tokens = | 971 const TokenStream& serialized_tokens = |
968 TokenStream::Handle(serialized_script.tokens()); | 972 TokenStream::Handle(serialized_script.tokens()); |
969 const ExternalTypedData& expected_data = | 973 const ExternalTypedData& expected_data = |
970 ExternalTypedData::Handle(expected_tokens.GetStream()); | 974 ExternalTypedData::Handle(expected_tokens.GetStream()); |
971 const ExternalTypedData& serialized_data = | 975 const ExternalTypedData& serialized_data = |
972 ExternalTypedData::Handle(serialized_tokens.GetStream()); | 976 ExternalTypedData::Handle(serialized_tokens.GetStream()); |
973 EXPECT_EQ(expected_data.Length(), serialized_data.Length()); | 977 EXPECT_EQ(expected_data.Length(), serialized_data.Length()); |
974 TokenStream::Iterator expected_iterator(expected_tokens, 0); | 978 TokenStream::Iterator expected_iterator(expected_tokens, |
975 TokenStream::Iterator serialized_iterator(serialized_tokens, 0); | 979 TokenPosition::kMinSource); |
| 980 TokenStream::Iterator serialized_iterator(serialized_tokens, |
| 981 TokenPosition::kMinSource); |
976 Token::Kind expected_kind = expected_iterator.CurrentTokenKind(); | 982 Token::Kind expected_kind = expected_iterator.CurrentTokenKind(); |
977 Token::Kind serialized_kind = serialized_iterator.CurrentTokenKind(); | 983 Token::Kind serialized_kind = serialized_iterator.CurrentTokenKind(); |
978 while (expected_kind != Token::kEOS && serialized_kind != Token::kEOS) { | 984 while (expected_kind != Token::kEOS && serialized_kind != Token::kEOS) { |
979 EXPECT_EQ(expected_kind, serialized_kind); | 985 EXPECT_EQ(expected_kind, serialized_kind); |
980 expected_literal ^= expected_iterator.CurrentLiteral(); | 986 expected_literal ^= expected_iterator.CurrentLiteral(); |
981 actual_literal ^= serialized_iterator.CurrentLiteral(); | 987 actual_literal ^= serialized_iterator.CurrentLiteral(); |
982 EXPECT(expected_literal.Equals(actual_literal)); | 988 EXPECT(expected_literal.Equals(actual_literal)); |
983 expected_iterator.Advance(); | 989 expected_iterator.Advance(); |
984 serialized_iterator.Advance(); | 990 serialized_iterator.Advance(); |
985 expected_kind = expected_iterator.CurrentTokenKind(); | 991 expected_kind = expected_iterator.CurrentTokenKind(); |
(...skipping 2019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3005 StackZone zone(Thread::Current()); | 3011 StackZone zone(Thread::Current()); |
3006 uint8_t* buffer; | 3012 uint8_t* buffer; |
3007 MessageWriter writer(&buffer, &zone_allocator, true); | 3013 MessageWriter writer(&buffer, &zone_allocator, true); |
3008 writer.WriteInlinedObjectHeader(kOmittedObjectId); | 3014 writer.WriteInlinedObjectHeader(kOmittedObjectId); |
3009 // For performance, we'd like single-byte headers when ids are omitted. | 3015 // For performance, we'd like single-byte headers when ids are omitted. |
3010 // If this starts failing, consider renumbering the snapshot ids. | 3016 // If this starts failing, consider renumbering the snapshot ids. |
3011 EXPECT_EQ(1, writer.BytesWritten()); | 3017 EXPECT_EQ(1, writer.BytesWritten()); |
3012 } | 3018 } |
3013 | 3019 |
3014 } // namespace dart | 3020 } // namespace dart |
OLD | NEW |