Chromium Code Reviews| 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 RawString* UnmangleName(const String& name) { | |
| 685 intptr_t len = name.Length(); | |
| 686 intptr_t start = 0; | |
| 687 intptr_t at_pos = len; // Position of '@' in the name. | |
| 688 intptr_t dot_pos = len; // Position of '.' in the name. | |
| 689 | |
| 690 for (int i = 0; i < name.Length(); i++) { | |
| 691 if (name.CharAt(i) == '@') { | |
| 692 ASSERT(at_pos == len); | |
| 693 at_pos = i; | |
| 694 } else if (name.CharAt(i) == '.') { | |
| 695 dot_pos = i; | |
| 696 break; | |
| 697 } | |
| 698 } | |
| 699 intptr_t limit = (at_pos < dot_pos ? at_pos : dot_pos); | |
| 700 if (start == 0 && limit == len) { | |
| 701 // This name is fine as it is. | |
| 702 return name.raw(); | |
| 703 } | |
| 704 | |
| 705 const String& result = | |
| 706 String::Handle(String::SubString(name, start, (limit - start))); | |
| 707 | |
| 708 // Look for a second '@' now to correctly handle names like | |
| 709 // "_ReceivePortImpl@6be832b._internal@6be832b". | |
| 710 at_pos = len; | |
| 711 for (int i = dot_pos; i < name.Length(); i++) { | |
| 712 if (name.CharAt(i) == '@') { | |
| 713 ASSERT(at_pos == len); | |
| 714 at_pos = i; | |
| 715 } | |
| 716 } | |
| 717 | |
| 718 intptr_t suffix_len = at_pos - dot_pos; | |
| 719 if (suffix_len > 1) { | |
| 720 // This is a named constructor. Add the name back to the string. | |
| 721 const String& suffix = | |
| 722 String::Handle(String::SubString(name, dot_pos, suffix_len)); | |
| 723 return String::Concat(result, suffix); | |
| 724 } | |
| 725 | |
| 726 return result.raw(); | |
| 727 } | |
| 728 | |
| 729 | |
| 730 static void GenerateSourceAndCheck(const Script& script) { | |
|
hausner
2012/09/07 22:12:29
You could pass in the private_key value that is us
siva
2012/09/09 04:57:29
Good point.
Passed in private key and got rid of
| |
| 731 // Check if we are able to generate the source from the token stream. | |
| 732 // Rescan this source and compare the token stream to see if they are | |
| 733 // the same. | |
| 734 const TokenStream& expected_tokens = TokenStream::Handle(script.tokens()); | |
| 735 TokenStream::Iterator expected_iterator(expected_tokens, 0); | |
| 736 const String& str = String::Handle(expected_tokens.GenerateSource()); | |
| 737 const String& dummy_key = String::Handle(String::New("")); | |
| 738 Scanner scanner(str, dummy_key); | |
| 739 const TokenStream& reconstructed_tokens = | |
| 740 TokenStream::Handle(TokenStream::New(scanner.GetStream(), dummy_key)); | |
| 741 expected_iterator.SetCurrentPosition(0); | |
| 742 TokenStream::Iterator reconstructed_iterator(reconstructed_tokens, 0); | |
| 743 Token::Kind expected_kind = expected_iterator.CurrentTokenKind(); | |
| 744 Token::Kind reconstructed_kind = reconstructed_iterator.CurrentTokenKind(); | |
| 745 String& expected_literal = String::Handle(); | |
| 746 String& actual_literal = String::Handle(); | |
| 747 while (expected_kind != Token::kEOS && reconstructed_kind != Token::kEOS) { | |
| 748 EXPECT_EQ(expected_kind, reconstructed_kind); | |
| 749 expected_literal ^= expected_iterator.CurrentLiteral(); | |
| 750 expected_literal = UnmangleName(expected_literal); | |
| 751 actual_literal ^= reconstructed_iterator.CurrentLiteral(); | |
| 752 actual_literal = UnmangleName(actual_literal); | |
| 753 EXPECT(expected_literal.Equals(actual_literal)); | |
| 754 expected_iterator.Advance(); | |
| 755 reconstructed_iterator.Advance(); | |
| 756 expected_kind = expected_iterator.CurrentTokenKind(); | |
| 757 reconstructed_kind = reconstructed_iterator.CurrentTokenKind(); | |
| 758 } | |
| 759 } | |
| 760 | |
| 761 | |
| 684 TEST_CASE(SerializeScript) { | 762 TEST_CASE(SerializeScript) { |
| 685 const char* kScriptChars = | 763 const char* kScriptChars = |
| 686 "class A {\n" | 764 "class A {\n" |
| 687 " static bar() { return 42; }\n" | 765 " static bar() { return 42; }\n" |
| 688 " static fly() { return 5; }\n" | 766 " static fly() { return 5; }\n" |
| 689 " static s1() { return 'this is a string in the source'; }\n" | 767 " static s1() { return 'this is a string in the source'; }\n" |
| 690 " static s2() { return 'this is a \"string\" in the source'; }\n" | 768 " static s2() { return 'this is a \"string\" in the source'; }\n" |
| 691 " static s3() { return 'this is a \\\'string\\\' in \"the\" source'; }\n" | 769 " static s3() { return 'this is a \\\'string\\\' in \"the\" source'; }\n" |
| 692 " static s4() { return 'this \"is\" a \"string\" in \"the\" source'; }\n" | 770 " static s4() { return 'this \"is\" a \"string\" in \"the\" source'; }\n" |
| 693 "}\n"; | 771 "}\n"; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 739 EXPECT(expected_literal.Equals(actual_literal)); | 817 EXPECT(expected_literal.Equals(actual_literal)); |
| 740 expected_iterator.Advance(); | 818 expected_iterator.Advance(); |
| 741 serialized_iterator.Advance(); | 819 serialized_iterator.Advance(); |
| 742 expected_kind = expected_iterator.CurrentTokenKind(); | 820 expected_kind = expected_iterator.CurrentTokenKind(); |
| 743 serialized_kind = serialized_iterator.CurrentTokenKind(); | 821 serialized_kind = serialized_iterator.CurrentTokenKind(); |
| 744 } | 822 } |
| 745 | 823 |
| 746 // Check if we are able to generate the source from the token stream. | 824 // 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 | 825 // Rescan this source and compare the token stream to see if they are |
| 748 // the same. | 826 // the same. |
| 749 str ^= serialized_tokens.GenerateSource(); | 827 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 | 828 |
| 769 free(buffer); | 829 free(buffer); |
| 770 } | 830 } |
| 771 | 831 |
| 772 | 832 |
| 833 static void IterateScripts(const Library& lib) { | |
| 834 const Array& lib_scripts = Array::Handle(lib.LoadedScripts()); | |
| 835 Script& script = Script::Handle(); | |
| 836 for (intptr_t i = 0; i < lib_scripts.Length(); i++) { | |
| 837 script ^= lib_scripts.At(i); | |
| 838 EXPECT(!script.IsNull()); | |
| 839 GenerateSourceAndCheck(script); | |
| 840 } | |
| 841 } | |
| 842 | |
| 843 TEST_CASE(GenerateSource) { | |
| 844 Library& lib = Library::Handle(); | |
| 845 // Check core lib. | |
| 846 lib = Library::CoreLibrary(); | |
| 847 EXPECT(!lib.IsNull()); | |
| 848 IterateScripts(lib); | |
| 849 | |
| 850 // Check core impl lib. | |
| 851 lib = Library::CoreImplLibrary(); | |
| 852 EXPECT(!lib.IsNull()); | |
| 853 IterateScripts(lib); | |
| 854 | |
| 855 // Check isolate lib. | |
| 856 lib = Library::IsolateLibrary(); | |
| 857 EXPECT(!lib.IsNull()); | |
| 858 IterateScripts(lib); | |
| 859 | |
| 860 // Check math lib. | |
| 861 lib = Library::MathLibrary(); | |
| 862 EXPECT(!lib.IsNull()); | |
| 863 IterateScripts(lib); | |
| 864 | |
| 865 // Check mirrors lib. | |
| 866 lib = Library::MirrorsLibrary(); | |
| 867 EXPECT(!lib.IsNull()); | |
| 868 IterateScripts(lib); | |
| 869 } | |
| 870 | |
| 871 | |
| 773 // Only ia32 and x64 can run execution tests. | 872 // Only ia32 and x64 can run execution tests. |
| 774 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 873 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 775 UNIT_TEST_CASE(FullSnapshot) { | 874 UNIT_TEST_CASE(FullSnapshot) { |
| 776 const char* kScriptChars = | 875 const char* kScriptChars = |
| 777 "class Fields {\n" | 876 "class Fields {\n" |
| 778 " Fields(int i, int j) : fld1 = i, fld2 = j {}\n" | 877 " Fields(int i, int j) : fld1 = i, fld2 = j {}\n" |
| 779 " int fld1;\n" | 878 " int fld1;\n" |
| 780 " final int fld2;\n" | 879 " final int fld2;\n" |
| 781 " final int bigint_fld = 0xfffffffffff;\n" | 880 " final int bigint_fld = 0xfffffffffff;\n" |
| 782 " static int fld3;\n" | 881 " static int fld3;\n" |
| (...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1526 EXPECT(Dart_ErrorHasException(result)); | 1625 EXPECT(Dart_ErrorHasException(result)); |
| 1527 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", | 1626 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", |
| 1528 Dart_GetError(result)); | 1627 Dart_GetError(result)); |
| 1529 | 1628 |
| 1530 Dart_ExitScope(); | 1629 Dart_ExitScope(); |
| 1531 } | 1630 } |
| 1532 | 1631 |
| 1533 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 1632 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 1534 | 1633 |
| 1535 } // namespace dart | 1634 } // namespace dart |
| OLD | NEW |