| 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 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 void WriteScript(const Script& script) { | 674 void WriteScript(const Script& script) { |
| 675 WriteObject(script.raw()); | 675 WriteObject(script.raw()); |
| 676 UnmarkAll(); | 676 UnmarkAll(); |
| 677 } | 677 } |
| 678 | 678 |
| 679 private: | 679 private: |
| 680 DISALLOW_COPY_AND_ASSIGN(TestSnapshotWriter); | 680 DISALLOW_COPY_AND_ASSIGN(TestSnapshotWriter); |
| 681 }; | 681 }; |
| 682 | 682 |
| 683 | 683 |
| 684 static void GenerateSourceAndCheck(const Script& script) { |
| 685 // Check if we are able to generate the source from the token stream. |
| 686 // Rescan this source and compare the token stream to see if they are |
| 687 // the same. |
| 688 const TokenStream& expected_tokens = TokenStream::Handle(script.tokens()); |
| 689 TokenStream::Iterator expected_iterator(expected_tokens, 0); |
| 690 const String& str = String::Handle(expected_tokens.GenerateSource()); |
| 691 const String& private_key = String::Handle(expected_tokens.PrivateKey()); |
| 692 Scanner scanner(str, private_key); |
| 693 const TokenStream& reconstructed_tokens = |
| 694 TokenStream::Handle(TokenStream::New(scanner.GetStream(), private_key)); |
| 695 expected_iterator.SetCurrentPosition(0); |
| 696 TokenStream::Iterator reconstructed_iterator(reconstructed_tokens, 0); |
| 697 Token::Kind expected_kind = expected_iterator.CurrentTokenKind(); |
| 698 Token::Kind reconstructed_kind = reconstructed_iterator.CurrentTokenKind(); |
| 699 String& expected_literal = String::Handle(); |
| 700 String& actual_literal = String::Handle(); |
| 701 while (expected_kind != Token::kEOS && reconstructed_kind != Token::kEOS) { |
| 702 EXPECT_EQ(expected_kind, reconstructed_kind); |
| 703 expected_literal ^= expected_iterator.CurrentLiteral(); |
| 704 actual_literal ^= reconstructed_iterator.CurrentLiteral(); |
| 705 EXPECT(expected_literal.Equals(actual_literal)); |
| 706 expected_iterator.Advance(); |
| 707 reconstructed_iterator.Advance(); |
| 708 expected_kind = expected_iterator.CurrentTokenKind(); |
| 709 reconstructed_kind = reconstructed_iterator.CurrentTokenKind(); |
| 710 } |
| 711 } |
| 712 |
| 713 |
| 684 TEST_CASE(SerializeScript) { | 714 TEST_CASE(SerializeScript) { |
| 685 const char* kScriptChars = | 715 const char* kScriptChars = |
| 686 "class A {\n" | 716 "class A {\n" |
| 687 " static bar() { return 42; }\n" | 717 " static bar() { return 42; }\n" |
| 688 " static fly() { return 5; }\n" | 718 " static fly() { return 5; }\n" |
| 689 " static s1() { return 'this is a string in the source'; }\n" | 719 " static s1() { return 'this is a string in the source'; }\n" |
| 690 " static s2() { return 'this is a \"string\" in the source'; }\n" | 720 " static s2() { return 'this is a \"string\" in the source'; }\n" |
| 691 " static s3() { return 'this is a \\\'string\\\' in \"the\" source'; }\n" | 721 " static s3() { return 'this is a \\\'string\\\' in \"the\" source'; }\n" |
| 692 " static s4() { return 'this \"is\" a \"string\" in \"the\" source'; }\n" | 722 " static s4() { return 'this \"is\" a \"string\" in \"the\" source'; }\n" |
| 693 "}\n"; | 723 "}\n"; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 739 EXPECT(expected_literal.Equals(actual_literal)); | 769 EXPECT(expected_literal.Equals(actual_literal)); |
| 740 expected_iterator.Advance(); | 770 expected_iterator.Advance(); |
| 741 serialized_iterator.Advance(); | 771 serialized_iterator.Advance(); |
| 742 expected_kind = expected_iterator.CurrentTokenKind(); | 772 expected_kind = expected_iterator.CurrentTokenKind(); |
| 743 serialized_kind = serialized_iterator.CurrentTokenKind(); | 773 serialized_kind = serialized_iterator.CurrentTokenKind(); |
| 744 } | 774 } |
| 745 | 775 |
| 746 // Check if we are able to generate the source from the token stream. | 776 // Check if we are able to generate the source from the token stream. |
| 747 // Rescan this source and compare the token stream to see if they are | 777 // Rescan this source and compare the token stream to see if they are |
| 748 // the same. | 778 // the same. |
| 749 str ^= serialized_tokens.GenerateSource(); | 779 GenerateSourceAndCheck(serialized_script); |
| 750 const String& dummy_key = String::Handle(String::New("")); | |
| 751 Scanner scanner(str, dummy_key); | |
| 752 const TokenStream& reconstructed_tokens = | |
| 753 TokenStream::Handle(TokenStream::New(scanner.GetStream(), dummy_key)); | |
| 754 expected_iterator.SetCurrentPosition(0); | |
| 755 TokenStream::Iterator reconstructed_iterator(reconstructed_tokens, 0); | |
| 756 expected_kind = expected_iterator.CurrentTokenKind(); | |
| 757 Token::Kind reconstructed_kind = reconstructed_iterator.CurrentTokenKind(); | |
| 758 while (expected_kind != Token::kEOS && reconstructed_kind != Token::kEOS) { | |
| 759 EXPECT_EQ(expected_kind, reconstructed_kind); | |
| 760 expected_literal ^= expected_iterator.CurrentLiteral(); | |
| 761 actual_literal ^= reconstructed_iterator.CurrentLiteral(); | |
| 762 EXPECT(expected_literal.Equals(actual_literal)); | |
| 763 expected_iterator.Advance(); | |
| 764 reconstructed_iterator.Advance(); | |
| 765 expected_kind = expected_iterator.CurrentTokenKind(); | |
| 766 reconstructed_kind = reconstructed_iterator.CurrentTokenKind(); | |
| 767 } | |
| 768 | 780 |
| 769 free(buffer); | 781 free(buffer); |
| 770 } | 782 } |
| 771 | 783 |
| 772 | 784 |
| 785 static void IterateScripts(const Library& lib) { |
| 786 const Array& lib_scripts = Array::Handle(lib.LoadedScripts()); |
| 787 Script& script = Script::Handle(); |
| 788 for (intptr_t i = 0; i < lib_scripts.Length(); i++) { |
| 789 script ^= lib_scripts.At(i); |
| 790 EXPECT(!script.IsNull()); |
| 791 GenerateSourceAndCheck(script); |
| 792 } |
| 793 } |
| 794 |
| 795 TEST_CASE(GenerateSource) { |
| 796 Library& lib = Library::Handle(); |
| 797 // Check core lib. |
| 798 lib = Library::CoreLibrary(); |
| 799 EXPECT(!lib.IsNull()); |
| 800 IterateScripts(lib); |
| 801 |
| 802 // Check core impl lib. |
| 803 lib = Library::CoreImplLibrary(); |
| 804 EXPECT(!lib.IsNull()); |
| 805 IterateScripts(lib); |
| 806 |
| 807 // Check isolate lib. |
| 808 lib = Library::IsolateLibrary(); |
| 809 EXPECT(!lib.IsNull()); |
| 810 IterateScripts(lib); |
| 811 |
| 812 // Check math lib. |
| 813 lib = Library::MathLibrary(); |
| 814 EXPECT(!lib.IsNull()); |
| 815 IterateScripts(lib); |
| 816 |
| 817 // Check mirrors lib. |
| 818 lib = Library::MirrorsLibrary(); |
| 819 EXPECT(!lib.IsNull()); |
| 820 IterateScripts(lib); |
| 821 } |
| 822 |
| 823 |
| 773 // Only ia32 and x64 can run execution tests. | 824 // Only ia32 and x64 can run execution tests. |
| 774 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 825 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 775 UNIT_TEST_CASE(FullSnapshot) { | 826 UNIT_TEST_CASE(FullSnapshot) { |
| 776 const char* kScriptChars = | 827 const char* kScriptChars = |
| 777 "class Fields {\n" | 828 "class Fields {\n" |
| 778 " Fields(int i, int j) : fld1 = i, fld2 = j {}\n" | 829 " Fields(int i, int j) : fld1 = i, fld2 = j {}\n" |
| 779 " int fld1;\n" | 830 " int fld1;\n" |
| 780 " final int fld2;\n" | 831 " final int fld2;\n" |
| 781 " final int bigint_fld = 0xfffffffffff;\n" | 832 " final int bigint_fld = 0xfffffffffff;\n" |
| 782 " static int fld3;\n" | 833 " static int fld3;\n" |
| (...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1526 EXPECT(Dart_ErrorHasException(result)); | 1577 EXPECT(Dart_ErrorHasException(result)); |
| 1527 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", | 1578 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", |
| 1528 Dart_GetError(result)); | 1579 Dart_GetError(result)); |
| 1529 | 1580 |
| 1530 Dart_ExitScope(); | 1581 Dart_ExitScope(); |
| 1531 } | 1582 } |
| 1532 | 1583 |
| 1533 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 1584 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 1534 | 1585 |
| 1535 } // namespace dart | 1586 } // namespace dart |
| OLD | NEW |