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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 break; | 85 break; |
86 case Dart_CObject::kBigint: | 86 case Dart_CObject::kBigint: |
87 EXPECT_STREQ(first->value.as_bigint, second->value.as_bigint); | 87 EXPECT_STREQ(first->value.as_bigint, second->value.as_bigint); |
88 break; | 88 break; |
89 case Dart_CObject::kDouble: | 89 case Dart_CObject::kDouble: |
90 EXPECT_EQ(first->value.as_double, second->value.as_double); | 90 EXPECT_EQ(first->value.as_double, second->value.as_double); |
91 break; | 91 break; |
92 case Dart_CObject::kString: | 92 case Dart_CObject::kString: |
93 EXPECT_STREQ(first->value.as_string, second->value.as_string); | 93 EXPECT_STREQ(first->value.as_string, second->value.as_string); |
94 break; | 94 break; |
95 case Dart_CObject::kByteArray: | 95 case Dart_CObject::kUint8Array: |
96 EXPECT_EQ(first->value.as_byte_array.length, | 96 EXPECT_EQ(first->value.as_byte_array.length, |
97 second->value.as_byte_array.length); | 97 second->value.as_byte_array.length); |
98 for (int i = 0; i < first->value.as_byte_array.length; i++) { | 98 for (int i = 0; i < first->value.as_byte_array.length; i++) { |
99 EXPECT_EQ(first->value.as_byte_array.values[i], | 99 EXPECT_EQ(first->value.as_byte_array.values[i], |
100 second->value.as_byte_array.values[i]); | 100 second->value.as_byte_array.values[i]); |
101 } | 101 } |
102 break; | 102 break; |
103 case Dart_CObject::kArray: | 103 case Dart_CObject::kArray: |
104 // Use invalid type as a visited marker to avoid infinite | 104 // Use invalid type as a visited marker to avoid infinite |
105 // recursion on graphs with cycles. | 105 // recursion on graphs with cycles. |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 } | 648 } |
649 | 649 |
650 | 650 |
651 TEST_CASE(SerializeByteArray) { | 651 TEST_CASE(SerializeByteArray) { |
652 Zone zone(Isolate::Current()); | 652 Zone zone(Isolate::Current()); |
653 | 653 |
654 // Write snapshot with object content. | 654 // Write snapshot with object content. |
655 uint8_t* buffer; | 655 uint8_t* buffer; |
656 SnapshotWriter writer(Snapshot::kMessage, &buffer, &zone_allocator); | 656 SnapshotWriter writer(Snapshot::kMessage, &buffer, &zone_allocator); |
657 const int kByteArrayLength = 256; | 657 const int kByteArrayLength = 256; |
658 InternalByteArray& byte_array = | 658 Uint8Array& byte_array = |
659 InternalByteArray::Handle(InternalByteArray::New(kByteArrayLength)); | 659 Uint8Array::Handle(Uint8Array::New(kByteArrayLength)); |
660 for (int i = 0; i < kByteArrayLength; i++) { | 660 for (int i = 0; i < kByteArrayLength; i++) { |
661 byte_array.SetAt<uint8_t>(i, i); | 661 byte_array.SetAt(i, i); |
662 } | 662 } |
663 writer.WriteObject(byte_array.raw()); | 663 writer.WriteObject(byte_array.raw()); |
664 writer.FinalizeBuffer(); | 664 writer.FinalizeBuffer(); |
665 | 665 |
666 // Create a snapshot object using the buffer. | 666 // Create a snapshot object using the buffer. |
667 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 667 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
668 | 668 |
669 // Read object back from the snapshot. | 669 // Read object back from the snapshot. |
670 SnapshotReader reader(snapshot, Isolate::Current()); | 670 SnapshotReader reader(snapshot, Isolate::Current()); |
671 ByteArray& serialized_byte_array = ByteArray::Handle(); | 671 ByteArray& serialized_byte_array = ByteArray::Handle(); |
672 serialized_byte_array ^= reader.ReadObject(); | 672 serialized_byte_array ^= reader.ReadObject(); |
673 EXPECT(serialized_byte_array.IsByteArray()); | 673 EXPECT(serialized_byte_array.IsByteArray()); |
674 | 674 |
675 // Read object back from the snapshot into a C structure. | 675 // Read object back from the snapshot into a C structure. |
676 ApiNativeScope scope; | 676 ApiNativeScope scope; |
677 Dart_CObject* root = DecodeMessage(buffer + Snapshot::kHeaderSize, | 677 Dart_CObject* root = DecodeMessage(buffer + Snapshot::kHeaderSize, |
678 writer.BytesWritten(), | 678 writer.BytesWritten(), |
679 &zone_allocator); | 679 &zone_allocator); |
680 EXPECT_EQ(Dart_CObject::kByteArray, root->type); | 680 EXPECT_EQ(Dart_CObject::kUint8Array, root->type); |
681 EXPECT_EQ(kByteArrayLength, root->value.as_byte_array.length); | 681 EXPECT_EQ(kByteArrayLength, root->value.as_byte_array.length); |
682 for (int i = 0; i < kByteArrayLength; i++) { | 682 for (int i = 0; i < kByteArrayLength; i++) { |
683 EXPECT(root->value.as_byte_array.values[i] == i); | 683 EXPECT(root->value.as_byte_array.values[i] == i); |
684 } | 684 } |
685 CheckEncodeDecodeMessage(root); | 685 CheckEncodeDecodeMessage(root); |
686 } | 686 } |
687 | 687 |
688 | 688 |
689 TEST_CASE(SerializeEmptyByteArray) { | 689 TEST_CASE(SerializeEmptyByteArray) { |
690 Zone zone(Isolate::Current()); | 690 Zone zone(Isolate::Current()); |
691 | 691 |
692 // Write snapshot with object content. | 692 // Write snapshot with object content. |
693 uint8_t* buffer; | 693 uint8_t* buffer; |
694 SnapshotWriter writer(Snapshot::kMessage, &buffer, &zone_allocator); | 694 SnapshotWriter writer(Snapshot::kMessage, &buffer, &zone_allocator); |
695 const int kByteArrayLength = 0; | 695 const int kByteArrayLength = 0; |
696 InternalByteArray& byte_array = | 696 Uint8Array& byte_array = |
697 InternalByteArray::Handle(InternalByteArray::New(kByteArrayLength)); | 697 Uint8Array::Handle(Uint8Array::New(kByteArrayLength)); |
698 writer.WriteObject(byte_array.raw()); | 698 writer.WriteObject(byte_array.raw()); |
699 writer.FinalizeBuffer(); | 699 writer.FinalizeBuffer(); |
700 | 700 |
701 // Create a snapshot object using the buffer. | 701 // Create a snapshot object using the buffer. |
702 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 702 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
703 | 703 |
704 // Read object back from the snapshot. | 704 // Read object back from the snapshot. |
705 SnapshotReader reader(snapshot, Isolate::Current()); | 705 SnapshotReader reader(snapshot, Isolate::Current()); |
706 ByteArray& serialized_byte_array = ByteArray::Handle(); | 706 ByteArray& serialized_byte_array = ByteArray::Handle(); |
707 serialized_byte_array ^= reader.ReadObject(); | 707 serialized_byte_array ^= reader.ReadObject(); |
708 EXPECT(serialized_byte_array.IsByteArray()); | 708 EXPECT(serialized_byte_array.IsByteArray()); |
709 | 709 |
710 // Read object back from the snapshot into a C structure. | 710 // Read object back from the snapshot into a C structure. |
711 ApiNativeScope scope; | 711 ApiNativeScope scope; |
712 Dart_CObject* root = DecodeMessage(buffer + Snapshot::kHeaderSize, | 712 Dart_CObject* root = DecodeMessage(buffer + Snapshot::kHeaderSize, |
713 writer.BytesWritten(), | 713 writer.BytesWritten(), |
714 &zone_allocator); | 714 &zone_allocator); |
715 EXPECT_EQ(Dart_CObject::kByteArray, root->type); | 715 EXPECT_EQ(Dart_CObject::kUint8Array, root->type); |
716 EXPECT_EQ(kByteArrayLength, root->value.as_byte_array.length); | 716 EXPECT_EQ(kByteArrayLength, root->value.as_byte_array.length); |
717 EXPECT(root->value.as_byte_array.values == NULL); | 717 EXPECT(root->value.as_byte_array.values == NULL); |
718 CheckEncodeDecodeMessage(root); | 718 CheckEncodeDecodeMessage(root); |
719 } | 719 } |
720 | 720 |
721 | 721 |
722 TEST_CASE(SerializeScript) { | 722 TEST_CASE(SerializeScript) { |
723 const char* kScriptChars = | 723 const char* kScriptChars = |
724 "class A {\n" | 724 "class A {\n" |
725 " static bar() { return 42; }\n" | 725 " static bar() { return 42; }\n" |
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1297 " for (var i = 0; i < kArrayLength; i++) list[i] = bigint;\n" | 1297 " for (var i = 0; i < kArrayLength; i++) list[i] = bigint;\n" |
1298 " return list;\n" | 1298 " return list;\n" |
1299 "}\n" | 1299 "}\n" |
1300 "getDoubleList() {\n" | 1300 "getDoubleList() {\n" |
1301 " var d = 3.14;\n" | 1301 " var d = 3.14;\n" |
1302 " var list = new List<double>(kArrayLength);\n" | 1302 " var list = new List<double>(kArrayLength);\n" |
1303 " for (var i = 0; i < kArrayLength; i++) list[i] = d;\n" | 1303 " for (var i = 0; i < kArrayLength; i++) list[i] = d;\n" |
1304 " return list;\n" | 1304 " return list;\n" |
1305 "}\n" | 1305 "}\n" |
1306 "getByteArrayList() {\n" | 1306 "getByteArrayList() {\n" |
1307 " var byte_array = new ByteArray(256);\n" | 1307 " var byte_array = new Uint8List(256);\n" |
1308 " var list = new List<ByteArray>(kArrayLength);\n" | 1308 " var list = new List(kArrayLength);\n" |
1309 " for (var i = 0; i < kArrayLength; i++) list[i] = byte_array;\n" | 1309 " for (var i = 0; i < kArrayLength; i++) list[i] = byte_array;\n" |
1310 " return list;\n" | 1310 " return list;\n" |
1311 "}\n" | 1311 "}\n" |
1312 "getMixedList() {\n" | 1312 "getMixedList() {\n" |
1313 " var list = new List(kArrayLength);\n" | 1313 " var list = new List(kArrayLength);\n" |
1314 " for (var i = 0; i < kArrayLength; i++) {\n" | 1314 " for (var i = 0; i < kArrayLength; i++) {\n" |
1315 " list[i] = ((i % 2) == 0) ? 'A' : 2.72;\n" | 1315 " list[i] = ((i % 2) == 0) ? 'A' : 2.72;\n" |
1316 " }\n" | 1316 " }\n" |
1317 " return list;\n" | 1317 " return list;\n" |
1318 "}\n" | 1318 "}\n" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1392 { | 1392 { |
1393 // Generate a list of doubles from Dart code. | 1393 // Generate a list of doubles from Dart code. |
1394 ApiNativeScope scope; | 1394 ApiNativeScope scope; |
1395 Dart_CObject* root = GetDeserializedDartMessage(lib, "getByteArrayList"); | 1395 Dart_CObject* root = GetDeserializedDartMessage(lib, "getByteArrayList"); |
1396 EXPECT_NOTNULL(root); | 1396 EXPECT_NOTNULL(root); |
1397 EXPECT_EQ(Dart_CObject::kArray, root->type); | 1397 EXPECT_EQ(Dart_CObject::kArray, root->type); |
1398 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1398 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
1399 for (int i = 0; i < kArrayLength; i++) { | 1399 for (int i = 0; i < kArrayLength; i++) { |
1400 Dart_CObject* element = root->value.as_array.values[i]; | 1400 Dart_CObject* element = root->value.as_array.values[i]; |
1401 EXPECT_EQ(root->value.as_array.values[0], element); | 1401 EXPECT_EQ(root->value.as_array.values[0], element); |
1402 EXPECT_EQ(Dart_CObject::kByteArray, element->type); | 1402 EXPECT_EQ(Dart_CObject::kUint8Array, element->type); |
1403 EXPECT_EQ(256, element->value.as_byte_array.length); | 1403 EXPECT_EQ(256, element->value.as_byte_array.length); |
1404 } | 1404 } |
1405 } | 1405 } |
1406 { | 1406 { |
1407 // Generate a list of objects of different types from Dart code. | 1407 // Generate a list of objects of different types from Dart code. |
1408 ApiNativeScope scope; | 1408 ApiNativeScope scope; |
1409 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); | 1409 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); |
1410 EXPECT_NOTNULL(root); | 1410 EXPECT_NOTNULL(root); |
1411 EXPECT_EQ(Dart_CObject::kArray, root->type); | 1411 EXPECT_EQ(Dart_CObject::kArray, root->type); |
1412 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1412 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1532 EXPECT(Dart_ErrorHasException(result)); | 1532 EXPECT(Dart_ErrorHasException(result)); |
1533 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", | 1533 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", |
1534 Dart_GetError(result)); | 1534 Dart_GetError(result)); |
1535 | 1535 |
1536 Dart_ExitScope(); | 1536 Dart_ExitScope(); |
1537 } | 1537 } |
1538 | 1538 |
1539 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 1539 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
1540 | 1540 |
1541 } // namespace dart | 1541 } // namespace dart |
OLD | NEW |