| 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 "include/dart_debugger_api.h" | 5 #include "include/dart_debugger_api.h" |
| 6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
| 7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
| 10 #include "vm/dart_api_message.h" | 10 #include "vm/dart_api_message.h" |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 | 742 |
| 743 // Create a snapshot object using the buffer. | 743 // Create a snapshot object using the buffer. |
| 744 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 744 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
| 745 | 745 |
| 746 // Read object back from the snapshot. | 746 // Read object back from the snapshot. |
| 747 SnapshotReader reader(snapshot, Isolate::Current()); | 747 SnapshotReader reader(snapshot, Isolate::Current()); |
| 748 Script& serialized_script = Script::Handle(); | 748 Script& serialized_script = Script::Handle(); |
| 749 serialized_script ^= reader.ReadObject(); | 749 serialized_script ^= reader.ReadObject(); |
| 750 | 750 |
| 751 // Check if the serialized script object matches the original script. | 751 // Check if the serialized script object matches the original script. |
| 752 String& expected_literal = String::Handle(); |
| 753 String& actual_literal = String::Handle(); |
| 752 String& str = String::Handle(); | 754 String& str = String::Handle(); |
| 753 str ^= serialized_script.url(); | 755 str ^= serialized_script.url(); |
| 754 EXPECT(url.Equals(str)); | 756 EXPECT(url.Equals(str)); |
| 757 |
| 755 const TokenStream& expected_tokens = TokenStream::Handle(script.tokens()); | 758 const TokenStream& expected_tokens = TokenStream::Handle(script.tokens()); |
| 756 const TokenStream& serialized_tokens = | 759 const TokenStream& serialized_tokens = |
| 757 TokenStream::Handle(serialized_script.tokens()); | 760 TokenStream::Handle(serialized_script.tokens()); |
| 758 EXPECT_EQ(expected_tokens.Length(), serialized_tokens.Length()); | 761 EXPECT_EQ(expected_tokens.Length(), serialized_tokens.Length()); |
| 759 String& expected_literal = String::Handle(); | 762 TokenStream::Iterator expected_iterator(expected_tokens, 0); |
| 760 String& actual_literal = String::Handle(); | 763 TokenStream::Iterator serialized_iterator(serialized_tokens, 0); |
| 761 for (intptr_t i = 0; i < expected_tokens.Length(); i++) { | 764 Token::Kind expected_kind = expected_iterator.CurrentTokenKind(); |
| 762 EXPECT_EQ(expected_tokens.KindAt(i), serialized_tokens.KindAt(i)); | 765 Token::Kind serialized_kind = serialized_iterator.CurrentTokenKind(); |
| 763 expected_literal ^= expected_tokens.LiteralAt(i); | 766 while (expected_kind != Token::kEOS && serialized_kind != Token::kEOS) { |
| 764 actual_literal ^= serialized_tokens.LiteralAt(i); | 767 EXPECT_EQ(expected_kind, serialized_kind); |
| 768 expected_literal ^= expected_iterator.CurrentLiteral(); |
| 769 actual_literal ^= serialized_iterator.CurrentLiteral(); |
| 765 EXPECT(expected_literal.Equals(actual_literal)); | 770 EXPECT(expected_literal.Equals(actual_literal)); |
| 771 expected_iterator.Advance(); |
| 772 serialized_iterator.Advance(); |
| 773 expected_kind = expected_iterator.CurrentTokenKind(); |
| 774 serialized_kind = serialized_iterator.CurrentTokenKind(); |
| 766 } | 775 } |
| 776 |
| 767 // Check if we are able to generate the source from the token stream. | 777 // Check if we are able to generate the source from the token stream. |
| 768 // Rescan this source and compare the token stream to see if they are | 778 // Rescan this source and compare the token stream to see if they are |
| 769 // the same. | 779 // the same. |
| 770 str ^= serialized_tokens.GenerateSource(); | 780 str ^= serialized_tokens.GenerateSource(); |
| 771 const String& dummy_key = String::Handle(String::New("")); | 781 const String& dummy_key = String::Handle(String::New("")); |
| 772 Scanner scanner(str, dummy_key); | 782 Scanner scanner(str, dummy_key); |
| 773 const TokenStream& reconstructed_tokens = | 783 const TokenStream& reconstructed_tokens = |
| 774 TokenStream::Handle(TokenStream::New(scanner.GetStream())); | 784 TokenStream::Handle(TokenStream::New(scanner.GetStream())); |
| 775 for (intptr_t i = 0; i < expected_tokens.Length(); i++) { | 785 expected_iterator.SetCurrentPosition(0); |
| 776 EXPECT_EQ(expected_tokens.KindAt(i), serialized_tokens.KindAt(i)); | 786 TokenStream::Iterator reconstructed_iterator(reconstructed_tokens, 0); |
| 777 expected_literal ^= expected_tokens.LiteralAt(i); | 787 expected_kind = expected_iterator.CurrentTokenKind(); |
| 778 actual_literal ^= reconstructed_tokens.LiteralAt(i); | 788 Token::Kind reconstructed_kind = reconstructed_iterator.CurrentTokenKind(); |
| 789 while (expected_kind != Token::kEOS && reconstructed_kind != Token::kEOS) { |
| 790 EXPECT_EQ(expected_kind, reconstructed_kind); |
| 791 expected_literal ^= expected_iterator.CurrentLiteral(); |
| 792 actual_literal ^= reconstructed_iterator.CurrentLiteral(); |
| 779 EXPECT(expected_literal.Equals(actual_literal)); | 793 EXPECT(expected_literal.Equals(actual_literal)); |
| 794 expected_iterator.Advance(); |
| 795 reconstructed_iterator.Advance(); |
| 796 expected_kind = expected_iterator.CurrentTokenKind(); |
| 797 reconstructed_kind = reconstructed_iterator.CurrentTokenKind(); |
| 780 } | 798 } |
| 781 | 799 |
| 782 free(buffer); | 800 free(buffer); |
| 783 } | 801 } |
| 784 | 802 |
| 785 | 803 |
| 786 // Only ia32 and x64 can run execution tests. | 804 // Only ia32 and x64 can run execution tests. |
| 787 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 805 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 788 UNIT_TEST_CASE(FullSnapshot) { | 806 UNIT_TEST_CASE(FullSnapshot) { |
| 789 const char* kScriptChars = | 807 const char* kScriptChars = |
| (...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1542 EXPECT(Dart_ErrorHasException(result)); | 1560 EXPECT(Dart_ErrorHasException(result)); |
| 1543 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", | 1561 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", |
| 1544 Dart_GetError(result)); | 1562 Dart_GetError(result)); |
| 1545 | 1563 |
| 1546 Dart_ExitScope(); | 1564 Dart_ExitScope(); |
| 1547 } | 1565 } |
| 1548 | 1566 |
| 1549 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 1567 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 1550 | 1568 |
| 1551 } // namespace dart | 1569 } // namespace dart |
| OLD | NEW |