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 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 739 // Create a snapshot object using the buffer. | 739 // Create a snapshot object using the buffer. |
| 740 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 740 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
| 741 | 741 |
| 742 // Read object back from the snapshot. | 742 // Read object back from the snapshot. |
| 743 SnapshotReader reader(snapshot, Isolate::Current()); | 743 SnapshotReader reader(snapshot, Isolate::Current()); |
| 744 Script& serialized_script = Script::Handle(); | 744 Script& serialized_script = Script::Handle(); |
| 745 serialized_script ^= reader.ReadObject(); | 745 serialized_script ^= reader.ReadObject(); |
| 746 | 746 |
| 747 // Check if the serialized script object matches the original script. | 747 // Check if the serialized script object matches the original script. |
| 748 String& str = String::Handle(); | 748 String& str = String::Handle(); |
| 749 str ^= serialized_script.source(); | |
| 750 EXPECT(source.Equals(str)); | |
| 751 str ^= serialized_script.url(); | 749 str ^= serialized_script.url(); |
| 752 EXPECT(url.Equals(str)); | 750 EXPECT(url.Equals(str)); |
| 753 const TokenStream& expected_tokens = TokenStream::Handle(script.tokens()); | 751 const TokenStream& expected_tokens = TokenStream::Handle(script.tokens()); |
| 754 const TokenStream& serialized_tokens = | 752 const TokenStream& serialized_tokens = |
| 755 TokenStream::Handle(serialized_script.tokens()); | 753 TokenStream::Handle(serialized_script.tokens()); |
| 756 EXPECT_EQ(expected_tokens.Length(), serialized_tokens.Length()); | 754 EXPECT_EQ(expected_tokens.Length(), serialized_tokens.Length()); |
| 757 String& expected_literal = String::Handle(); | 755 String& expected_literal = String::Handle(); |
| 758 String& actual_literal = String::Handle(); | 756 String& actual_literal = String::Handle(); |
| 759 for (intptr_t i = 0; i < expected_tokens.Length(); i++) { | 757 for (intptr_t i = 0; i < expected_tokens.Length(); i++) { |
| 760 EXPECT_EQ(expected_tokens.KindAt(i), serialized_tokens.KindAt(i)); | 758 EXPECT_EQ(expected_tokens.KindAt(i), serialized_tokens.KindAt(i)); |
| 761 expected_literal ^= expected_tokens.LiteralAt(i); | 759 expected_literal ^= expected_tokens.LiteralAt(i); |
| 762 actual_literal ^= serialized_tokens.LiteralAt(i); | 760 actual_literal ^= serialized_tokens.LiteralAt(i); |
| 763 EXPECT(expected_literal.Equals(actual_literal)); | 761 EXPECT(expected_literal.Equals(actual_literal)); |
| 764 } | 762 } |
| 763 // Check if we are able to generate the source from the token stream | |
| 764 // rescan this source and compare the token stream to see if they are | |
|
hausner
2012/05/18 21:14:34
New sentence?
siva
2012/05/18 22:23:02
Done.
| |
| 765 // the same. | |
| 766 str ^= serialized_tokens.GenerateSource(); | |
| 767 const String& dummy_key = String::Handle(String::New("")); | |
| 768 Scanner scanner(str, dummy_key); | |
| 769 const TokenStream& reconstructed_tokens = | |
| 770 TokenStream::Handle(TokenStream::New(scanner.GetStream())); | |
| 771 for (intptr_t i = 0; i < expected_tokens.Length(); i++) { | |
| 772 EXPECT_EQ(expected_tokens.KindAt(i), serialized_tokens.KindAt(i)); | |
| 773 expected_literal ^= expected_tokens.LiteralAt(i); | |
| 774 actual_literal ^= reconstructed_tokens.LiteralAt(i); | |
| 775 EXPECT(expected_literal.Equals(actual_literal)); | |
| 776 } | |
| 765 | 777 |
| 766 free(buffer); | 778 free(buffer); |
| 767 } | 779 } |
| 768 | 780 |
| 769 | 781 |
| 770 // Only ia32 and x64 can run execution tests. | 782 // Only ia32 and x64 can run execution tests. |
| 771 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) | 783 #if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64) |
| 772 UNIT_TEST_CASE(FullSnapshot) { | 784 UNIT_TEST_CASE(FullSnapshot) { |
| 773 const char* kScriptChars = | 785 const char* kScriptChars = |
| 774 "class Fields {\n" | 786 "class Fields {\n" |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1528 EXPECT(Dart_ErrorHasException(result)); | 1540 EXPECT(Dart_ErrorHasException(result)); |
| 1529 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", | 1541 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", |
| 1530 Dart_GetError(result)); | 1542 Dart_GetError(result)); |
| 1531 | 1543 |
| 1532 Dart_ExitScope(); | 1544 Dart_ExitScope(); |
| 1533 } | 1545 } |
| 1534 | 1546 |
| 1535 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 1547 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 1536 | 1548 |
| 1537 } // namespace dart | 1549 } // namespace dart |
| OLD | NEW |