| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 break; | 84 break; |
| 85 case Dart_CObject::kBigint: | 85 case Dart_CObject::kBigint: |
| 86 EXPECT_STREQ(first->value.as_bigint, second->value.as_bigint); | 86 EXPECT_STREQ(first->value.as_bigint, second->value.as_bigint); |
| 87 break; | 87 break; |
| 88 case Dart_CObject::kDouble: | 88 case Dart_CObject::kDouble: |
| 89 EXPECT_EQ(first->value.as_double, second->value.as_double); | 89 EXPECT_EQ(first->value.as_double, second->value.as_double); |
| 90 break; | 90 break; |
| 91 case Dart_CObject::kString: | 91 case Dart_CObject::kString: |
| 92 EXPECT_STREQ(first->value.as_string, second->value.as_string); | 92 EXPECT_STREQ(first->value.as_string, second->value.as_string); |
| 93 break; | 93 break; |
| 94 case Dart_CObject::kUint8Array: | 94 case Dart_CObject::kTypedData: |
| 95 EXPECT_EQ(first->value.as_byte_array.length, | 95 EXPECT_EQ(first->value.as_typed_data.length, |
| 96 second->value.as_byte_array.length); | 96 second->value.as_typed_data.length); |
| 97 for (int i = 0; i < first->value.as_byte_array.length; i++) { | 97 for (int i = 0; i < first->value.as_typed_data.length; i++) { |
| 98 EXPECT_EQ(first->value.as_byte_array.values[i], | 98 EXPECT_EQ(first->value.as_typed_data.values[i], |
| 99 second->value.as_byte_array.values[i]); | 99 second->value.as_typed_data.values[i]); |
| 100 } | 100 } |
| 101 break; | 101 break; |
| 102 case Dart_CObject::kArray: | 102 case Dart_CObject::kArray: |
| 103 // Use invalid type as a visited marker to avoid infinite | 103 // Use invalid type as a visited marker to avoid infinite |
| 104 // recursion on graphs with cycles. | 104 // recursion on graphs with cycles. |
| 105 second->type = Dart_CObject::kNumberOfTypes; | 105 second->type = Dart_CObject::kNumberOfTypes; |
| 106 EXPECT_EQ(first->value.as_array.length, second->value.as_array.length); | 106 EXPECT_EQ(first->value.as_array.length, second->value.as_array.length); |
| 107 for (int i = 0; i < first->value.as_array.length; i++) { | 107 for (int i = 0; i < first->value.as_array.length; i++) { |
| 108 CompareDartCObjects(first->value.as_array.values[i], | 108 CompareDartCObjects(first->value.as_array.values[i], |
| 109 second->value.as_array.values[i]); | 109 second->value.as_array.values[i]); |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 CheckEncodeDecodeMessage(root); | 605 CheckEncodeDecodeMessage(root); |
| 606 } | 606 } |
| 607 | 607 |
| 608 | 608 |
| 609 TEST_CASE(SerializeByteArray) { | 609 TEST_CASE(SerializeByteArray) { |
| 610 StackZone zone(Isolate::Current()); | 610 StackZone zone(Isolate::Current()); |
| 611 | 611 |
| 612 // Write snapshot with object content. | 612 // Write snapshot with object content. |
| 613 uint8_t* buffer; | 613 uint8_t* buffer; |
| 614 MessageWriter writer(&buffer, &zone_allocator); | 614 MessageWriter writer(&buffer, &zone_allocator); |
| 615 const int kByteArrayLength = 256; | 615 const int kTypedDataLength = 256; |
| 616 TypedData& byte_array = TypedData::Handle( | 616 TypedData& typed_data = TypedData::Handle( |
| 617 TypedData::New(kTypedDataUint8ArrayCid, kByteArrayLength)); | 617 TypedData::New(kTypedDataUint8ArrayCid, kTypedDataLength)); |
| 618 for (int i = 0; i < kByteArrayLength; i++) { | 618 for (int i = 0; i < kTypedDataLength; i++) { |
| 619 byte_array.SetUint8(i, i); | 619 typed_data.SetUint8(i, i); |
| 620 } | 620 } |
| 621 writer.WriteMessage(byte_array); | 621 writer.WriteMessage(typed_data); |
| 622 intptr_t buffer_len = writer.BytesWritten(); | 622 intptr_t buffer_len = writer.BytesWritten(); |
| 623 | 623 |
| 624 // Read object back from the snapshot. | 624 // Read object back from the snapshot. |
| 625 SnapshotReader reader(buffer, buffer_len, | 625 SnapshotReader reader(buffer, buffer_len, |
| 626 Snapshot::kMessage, Isolate::Current()); | 626 Snapshot::kMessage, Isolate::Current()); |
| 627 TypedData& serialized_byte_array = TypedData::Handle(); | 627 TypedData& serialized_typed_data = TypedData::Handle(); |
| 628 serialized_byte_array ^= reader.ReadObject(); | 628 serialized_typed_data ^= reader.ReadObject(); |
| 629 EXPECT(serialized_byte_array.IsTypedData()); | 629 EXPECT(serialized_typed_data.IsTypedData()); |
| 630 | 630 |
| 631 // Read object back from the snapshot into a C structure. | 631 // Read object back from the snapshot into a C structure. |
| 632 ApiNativeScope scope; | 632 ApiNativeScope scope; |
| 633 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 633 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
| 634 Dart_CObject* root = api_reader.ReadMessage(); | 634 Dart_CObject* root = api_reader.ReadMessage(); |
| 635 EXPECT_EQ(Dart_CObject::kUint8Array, root->type); | 635 EXPECT_EQ(Dart_CObject::kTypedData, root->type); |
| 636 EXPECT_EQ(kByteArrayLength, root->value.as_byte_array.length); | 636 EXPECT_EQ(kTypedDataLength, root->value.as_typed_data.length); |
| 637 for (int i = 0; i < kByteArrayLength; i++) { | 637 for (int i = 0; i < kTypedDataLength; i++) { |
| 638 EXPECT(root->value.as_byte_array.values[i] == i); | 638 EXPECT(root->value.as_typed_data.values[i] == i); |
| 639 } | 639 } |
| 640 CheckEncodeDecodeMessage(root); | 640 CheckEncodeDecodeMessage(root); |
| 641 } | 641 } |
| 642 | 642 |
| 643 | 643 |
| 644 #define TEST_TYPED_ARRAY(darttype, ctype) \ | 644 #define TEST_TYPED_ARRAY(darttype, ctype) \ |
| 645 { \ | 645 { \ |
| 646 StackZone zone(Isolate::Current()); \ | 646 StackZone zone(Isolate::Current()); \ |
| 647 uint8_t* buffer; \ | 647 uint8_t* buffer; \ |
| 648 MessageWriter writer(&buffer, &zone_allocator); \ | 648 MessageWriter writer(&buffer, &zone_allocator); \ |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 TEST_EXTERNAL_TYPED_ARRAY(Float64, double); | 717 TEST_EXTERNAL_TYPED_ARRAY(Float64, double); |
| 718 } | 718 } |
| 719 | 719 |
| 720 | 720 |
| 721 TEST_CASE(SerializeEmptyByteArray) { | 721 TEST_CASE(SerializeEmptyByteArray) { |
| 722 StackZone zone(Isolate::Current()); | 722 StackZone zone(Isolate::Current()); |
| 723 | 723 |
| 724 // Write snapshot with object content. | 724 // Write snapshot with object content. |
| 725 uint8_t* buffer; | 725 uint8_t* buffer; |
| 726 MessageWriter writer(&buffer, &zone_allocator); | 726 MessageWriter writer(&buffer, &zone_allocator); |
| 727 const int kByteArrayLength = 0; | 727 const int kTypedDataLength = 0; |
| 728 TypedData& byte_array = TypedData::Handle( | 728 TypedData& typed_data = TypedData::Handle( |
| 729 TypedData::New(kTypedDataUint8ArrayCid, kByteArrayLength)); | 729 TypedData::New(kTypedDataUint8ArrayCid, kTypedDataLength)); |
| 730 writer.WriteMessage(byte_array); | 730 writer.WriteMessage(typed_data); |
| 731 intptr_t buffer_len = writer.BytesWritten(); | 731 intptr_t buffer_len = writer.BytesWritten(); |
| 732 | 732 |
| 733 // Read object back from the snapshot. | 733 // Read object back from the snapshot. |
| 734 SnapshotReader reader(buffer, buffer_len, | 734 SnapshotReader reader(buffer, buffer_len, |
| 735 Snapshot::kMessage, Isolate::Current()); | 735 Snapshot::kMessage, Isolate::Current()); |
| 736 TypedData& serialized_byte_array = TypedData::Handle(); | 736 TypedData& serialized_typed_data = TypedData::Handle(); |
| 737 serialized_byte_array ^= reader.ReadObject(); | 737 serialized_typed_data ^= reader.ReadObject(); |
| 738 EXPECT(serialized_byte_array.IsTypedData()); | 738 EXPECT(serialized_typed_data.IsTypedData()); |
| 739 | 739 |
| 740 // Read object back from the snapshot into a C structure. | 740 // Read object back from the snapshot into a C structure. |
| 741 ApiNativeScope scope; | 741 ApiNativeScope scope; |
| 742 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 742 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
| 743 Dart_CObject* root = api_reader.ReadMessage(); | 743 Dart_CObject* root = api_reader.ReadMessage(); |
| 744 EXPECT_EQ(Dart_CObject::kUint8Array, root->type); | 744 EXPECT_EQ(Dart_CObject::kTypedData, root->type); |
| 745 EXPECT_EQ(kByteArrayLength, root->value.as_byte_array.length); | 745 EXPECT_EQ(Dart_CObject::kUint8Array, root->value.as_typed_data.type); |
| 746 EXPECT(root->value.as_byte_array.values == NULL); | 746 EXPECT_EQ(kTypedDataLength, root->value.as_typed_data.length); |
| 747 EXPECT(root->value.as_typed_data.values == NULL); |
| 747 CheckEncodeDecodeMessage(root); | 748 CheckEncodeDecodeMessage(root); |
| 748 } | 749 } |
| 749 | 750 |
| 750 | 751 |
| 751 class TestSnapshotWriter : public SnapshotWriter { | 752 class TestSnapshotWriter : public SnapshotWriter { |
| 752 public: | 753 public: |
| 753 static const intptr_t kInitialSize = 64 * KB; | 754 static const intptr_t kInitialSize = 64 * KB; |
| 754 TestSnapshotWriter(uint8_t** buffer, ReAlloc alloc) | 755 TestSnapshotWriter(uint8_t** buffer, ReAlloc alloc) |
| 755 : SnapshotWriter(Snapshot::kScript, buffer, alloc, kInitialSize) { | 756 : SnapshotWriter(Snapshot::kScript, buffer, alloc, kInitialSize) { |
| 756 ASSERT(buffer != NULL); | 757 ASSERT(buffer != NULL); |
| (...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1901 { | 1902 { |
| 1902 // Generate a list of Uint8Lists from Dart code. | 1903 // Generate a list of Uint8Lists from Dart code. |
| 1903 ApiNativeScope scope; | 1904 ApiNativeScope scope; |
| 1904 Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList"); | 1905 Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList"); |
| 1905 EXPECT_NOTNULL(root); | 1906 EXPECT_NOTNULL(root); |
| 1906 EXPECT_EQ(Dart_CObject::kArray, root->type); | 1907 EXPECT_EQ(Dart_CObject::kArray, root->type); |
| 1907 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1908 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 1908 for (int i = 0; i < kArrayLength; i++) { | 1909 for (int i = 0; i < kArrayLength; i++) { |
| 1909 Dart_CObject* element = root->value.as_array.values[i]; | 1910 Dart_CObject* element = root->value.as_array.values[i]; |
| 1910 EXPECT_EQ(root->value.as_array.values[0], element); | 1911 EXPECT_EQ(root->value.as_array.values[0], element); |
| 1911 EXPECT_EQ(Dart_CObject::kUint8Array, element->type); | 1912 EXPECT_EQ(Dart_CObject::kTypedData, element->type); |
| 1912 EXPECT_EQ(256, element->value.as_byte_array.length); | 1913 EXPECT_EQ(Dart_CObject::kUint8Array, element->value.as_typed_data.type); |
| 1914 EXPECT_EQ(256, element->value.as_typed_data.length); |
| 1913 } | 1915 } |
| 1914 } | 1916 } |
| 1915 { | 1917 { |
| 1916 // Generate a list of Uint8List views from Dart code. | 1918 // Generate a list of Uint8List views from Dart code. |
| 1917 ApiNativeScope scope; | 1919 ApiNativeScope scope; |
| 1918 Dart_CObject* root = | 1920 Dart_CObject* root = |
| 1919 GetDeserializedDartMessage(lib, "getTypedDataViewList"); | 1921 GetDeserializedDartMessage(lib, "getTypedDataViewList"); |
| 1920 EXPECT_NOTNULL(root); | 1922 EXPECT_NOTNULL(root); |
| 1921 EXPECT_EQ(Dart_CObject::kArray, root->type); | 1923 EXPECT_EQ(Dart_CObject::kArray, root->type); |
| 1922 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1924 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 1923 for (int i = 0; i < kArrayLength; i++) { | 1925 for (int i = 0; i < kArrayLength; i++) { |
| 1924 Dart_CObject* element = root->value.as_array.values[i]; | 1926 Dart_CObject* element = root->value.as_array.values[i]; |
| 1925 EXPECT_EQ(root->value.as_array.values[0], element); | 1927 EXPECT_EQ(root->value.as_array.values[0], element); |
| 1926 EXPECT_EQ(Dart_CObject::kUint8Array, element->type); | 1928 EXPECT_EQ(Dart_CObject::kTypedData, element->type); |
| 1927 EXPECT_EQ(128, element->value.as_byte_array.length); | 1929 EXPECT_EQ(Dart_CObject::kUint8Array, element->value.as_typed_data.type); |
| 1928 EXPECT_EQ(1, element->value.as_byte_array.values[0]); | 1930 EXPECT_EQ(128, element->value.as_typed_data.length); |
| 1929 EXPECT_EQ(0, element->value.as_byte_array.values[1]); | 1931 EXPECT_EQ(1, element->value.as_typed_data.values[0]); |
| 1932 EXPECT_EQ(0, element->value.as_typed_data.values[1]); |
| 1930 } | 1933 } |
| 1931 } | 1934 } |
| 1932 { | 1935 { |
| 1933 // Generate a list of objects of different types from Dart code. | 1936 // Generate a list of objects of different types from Dart code. |
| 1934 ApiNativeScope scope; | 1937 ApiNativeScope scope; |
| 1935 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); | 1938 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); |
| 1936 EXPECT_NOTNULL(root); | 1939 EXPECT_NOTNULL(root); |
| 1937 EXPECT_EQ(Dart_CObject::kArray, root->type); | 1940 EXPECT_EQ(Dart_CObject::kArray, root->type); |
| 1938 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1941 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 1939 for (int i = 0; i < kArrayLength; i++) { | 1942 for (int i = 0; i < kArrayLength; i++) { |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2103 { | 2106 { |
| 2104 // Generate a list of Uint8Lists from Dart code. | 2107 // Generate a list of Uint8Lists from Dart code. |
| 2105 ApiNativeScope scope; | 2108 ApiNativeScope scope; |
| 2106 Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList"); | 2109 Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList"); |
| 2107 EXPECT_NOTNULL(root); | 2110 EXPECT_NOTNULL(root); |
| 2108 EXPECT_EQ(Dart_CObject::kArray, root->type); | 2111 EXPECT_EQ(Dart_CObject::kArray, root->type); |
| 2109 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2112 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2110 for (int i = 0; i < kArrayLength; i++) { | 2113 for (int i = 0; i < kArrayLength; i++) { |
| 2111 Dart_CObject* element = root->value.as_array.values[i]; | 2114 Dart_CObject* element = root->value.as_array.values[i]; |
| 2112 EXPECT_EQ(root->value.as_array.values[0], element); | 2115 EXPECT_EQ(root->value.as_array.values[0], element); |
| 2113 EXPECT_EQ(Dart_CObject::kUint8Array, element->type); | 2116 EXPECT_EQ(Dart_CObject::kTypedData, element->type); |
| 2114 EXPECT_EQ(256, element->value.as_byte_array.length); | 2117 EXPECT_EQ(Dart_CObject::kUint8Array, element->value.as_typed_data.type); |
| 2118 EXPECT_EQ(256, element->value.as_typed_data.length); |
| 2115 } | 2119 } |
| 2116 } | 2120 } |
| 2117 { | 2121 { |
| 2118 // Generate a list of Uint8List views from Dart code. | 2122 // Generate a list of Uint8List views from Dart code. |
| 2119 ApiNativeScope scope; | 2123 ApiNativeScope scope; |
| 2120 Dart_CObject* root = | 2124 Dart_CObject* root = |
| 2121 GetDeserializedDartMessage(lib, "getTypedDataViewList"); | 2125 GetDeserializedDartMessage(lib, "getTypedDataViewList"); |
| 2122 EXPECT_NOTNULL(root); | 2126 EXPECT_NOTNULL(root); |
| 2123 EXPECT_EQ(Dart_CObject::kArray, root->type); | 2127 EXPECT_EQ(Dart_CObject::kArray, root->type); |
| 2124 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2128 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2125 for (int i = 0; i < kArrayLength; i++) { | 2129 for (int i = 0; i < kArrayLength; i++) { |
| 2126 Dart_CObject* element = root->value.as_array.values[i]; | 2130 Dart_CObject* element = root->value.as_array.values[i]; |
| 2127 EXPECT_EQ(root->value.as_array.values[0], element); | 2131 EXPECT_EQ(root->value.as_array.values[0], element); |
| 2128 EXPECT_EQ(Dart_CObject::kUint8Array, element->type); | 2132 EXPECT_EQ(Dart_CObject::kTypedData, element->type); |
| 2129 EXPECT_EQ(128, element->value.as_byte_array.length); | 2133 EXPECT_EQ(Dart_CObject::kUint8Array, element->value.as_typed_data.type); |
| 2130 EXPECT_EQ(1, element->value.as_byte_array.values[0]); | 2134 EXPECT_EQ(128, element->value.as_typed_data.length); |
| 2131 EXPECT_EQ(0, element->value.as_byte_array.values[1]); | 2135 EXPECT_EQ(1, element->value.as_typed_data.values[0]); |
| 2136 EXPECT_EQ(0, element->value.as_typed_data.values[1]); |
| 2132 } | 2137 } |
| 2133 } | 2138 } |
| 2134 { | 2139 { |
| 2135 // Generate a list of objects of different types from Dart code. | 2140 // Generate a list of objects of different types from Dart code. |
| 2136 ApiNativeScope scope; | 2141 ApiNativeScope scope; |
| 2137 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); | 2142 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); |
| 2138 EXPECT_NOTNULL(root); | 2143 EXPECT_NOTNULL(root); |
| 2139 EXPECT_EQ(Dart_CObject::kArray, root->type); | 2144 EXPECT_EQ(Dart_CObject::kArray, root->type); |
| 2140 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2145 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2141 for (int i = 0; i < kArrayLength; i++) { | 2146 for (int i = 0; i < kArrayLength; i++) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2163 EXPECT_EQ(Dart_CObject::kArray, element->type); | 2168 EXPECT_EQ(Dart_CObject::kArray, element->type); |
| 2164 EXPECT_EQ(root, element); | 2169 EXPECT_EQ(root, element); |
| 2165 } | 2170 } |
| 2166 } | 2171 } |
| 2167 } | 2172 } |
| 2168 Dart_ExitScope(); | 2173 Dart_ExitScope(); |
| 2169 Dart_ShutdownIsolate(); | 2174 Dart_ShutdownIsolate(); |
| 2170 } | 2175 } |
| 2171 | 2176 |
| 2172 | 2177 |
| 2178 static void CheckTypedData(Dart_CObject* object, |
| 2179 Dart_CObject::TypedDataType typed_data_type, |
| 2180 int len) { |
| 2181 EXPECT_EQ(Dart_CObject::kTypedData, object->type); |
| 2182 EXPECT_EQ(typed_data_type, object->value.as_typed_data.type); |
| 2183 EXPECT_EQ(len, object->value.as_typed_data.length); |
| 2184 } |
| 2185 |
| 2186 UNIT_TEST_CASE(DartGeneratedListMessagesWithTypedData) { |
| 2187 const int kArrayLength = 10; |
| 2188 static const char* kScriptChars = |
| 2189 "import 'dart:typeddata';\n" |
| 2190 "final int kArrayLength = 10;\n" |
| 2191 "getTypedDataList() {\n" |
| 2192 " var list = new List(kArrayLength);\n" |
| 2193 " list[0] = new Int8List(256);\n" |
| 2194 " list[1] = new Uint8List(256);\n" |
| 2195 " list[2] = new Int16List(256);\n" |
| 2196 " list[3] = new Uint16List(256);\n" |
| 2197 " return list;\n" |
| 2198 "}\n" |
| 2199 "getTypedDataViewList() {\n" |
| 2200 " var list = new List(kArrayLength);\n" |
| 2201 " list[0] = new Int8List.view(new Int8List(256));\n" |
| 2202 " list[1] = new Uint8List.view(new Uint8List(256));\n" |
| 2203 " list[2] = new Int16List.view(new Int16List(256));\n" |
| 2204 " list[3] = new Uint16List.view(new Uint16List(256));\n" |
| 2205 " list[4] = new Int8List.view(new Int16List(256));\n" |
| 2206 " list[5] = new Uint8List.view(new Uint16List(256));\n" |
| 2207 " list[6] = new Int16List.view(new Int8List(256));\n" |
| 2208 " list[7] = new Uint16List.view(new Uint8List(256));\n" |
| 2209 " return list;\n" |
| 2210 "}\n"; |
| 2211 |
| 2212 TestCase::CreateTestIsolate(); |
| 2213 Isolate* isolate = Isolate::Current(); |
| 2214 EXPECT(isolate != NULL); |
| 2215 Dart_EnterScope(); |
| 2216 |
| 2217 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 2218 EXPECT_VALID(lib); |
| 2219 |
| 2220 { |
| 2221 DARTSCOPE(isolate); |
| 2222 { |
| 2223 // Generate a list of Uint8Lists from Dart code. |
| 2224 ApiNativeScope scope; |
| 2225 Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList"); |
| 2226 EXPECT_NOTNULL(root); |
| 2227 EXPECT_EQ(Dart_CObject::kArray, root->type); |
| 2228 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2229 CheckTypedData(root->value.as_array.values[0], |
| 2230 Dart_CObject::kInt8Array, |
| 2231 256); |
| 2232 CheckTypedData(root->value.as_array.values[1], |
| 2233 Dart_CObject::kUint8Array, |
| 2234 256); |
| 2235 CheckTypedData(root->value.as_array.values[2], |
| 2236 Dart_CObject::kInt16Array, |
| 2237 512); |
| 2238 CheckTypedData(root->value.as_array.values[3], |
| 2239 Dart_CObject::kUint16Array, |
| 2240 512); |
| 2241 } |
| 2242 { |
| 2243 // Generate a list of Uint8List views from Dart code. |
| 2244 ApiNativeScope scope; |
| 2245 Dart_CObject* root = |
| 2246 GetDeserializedDartMessage(lib, "getTypedDataViewList"); |
| 2247 EXPECT_NOTNULL(root); |
| 2248 EXPECT_EQ(Dart_CObject::kArray, root->type); |
| 2249 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2250 CheckTypedData(root->value.as_array.values[0], |
| 2251 Dart_CObject::kInt8Array, |
| 2252 256); |
| 2253 CheckTypedData(root->value.as_array.values[1], |
| 2254 Dart_CObject::kUint8Array, |
| 2255 256); |
| 2256 CheckTypedData(root->value.as_array.values[2], |
| 2257 Dart_CObject::kInt16Array, |
| 2258 512); |
| 2259 CheckTypedData(root->value.as_array.values[3], |
| 2260 Dart_CObject::kUint16Array, |
| 2261 512); |
| 2262 CheckTypedData(root->value.as_array.values[4], |
| 2263 Dart_CObject::kInt8Array, |
| 2264 512); |
| 2265 CheckTypedData(root->value.as_array.values[5], |
| 2266 Dart_CObject::kUint8Array, |
| 2267 512); |
| 2268 CheckTypedData(root->value.as_array.values[6], |
| 2269 Dart_CObject::kInt16Array, |
| 2270 256); |
| 2271 CheckTypedData(root->value.as_array.values[7], |
| 2272 Dart_CObject::kUint16Array, |
| 2273 256); |
| 2274 } |
| 2275 } |
| 2276 Dart_ExitScope(); |
| 2277 Dart_ShutdownIsolate(); |
| 2278 } |
| 2279 |
| 2280 |
| 2173 UNIT_TEST_CASE(PostCObject) { | 2281 UNIT_TEST_CASE(PostCObject) { |
| 2174 // Create a native port for posting from C to Dart | 2282 // Create a native port for posting from C to Dart |
| 2175 TestIsolateScope __test_isolate__; | 2283 TestIsolateScope __test_isolate__; |
| 2176 const char* kScriptChars = | 2284 const char* kScriptChars = |
| 2177 "import 'dart:isolate';\n" | 2285 "import 'dart:isolate';\n" |
| 2178 "main() {\n" | 2286 "main() {\n" |
| 2179 " var messageCount = 0;\n" | 2287 " var messageCount = 0;\n" |
| 2180 " var exception = '';\n" | 2288 " var exception = '';\n" |
| 2181 " var port = new ReceivePort();\n" | 2289 " var port = new ReceivePort();\n" |
| 2182 " port.receive((message, replyTo) {\n" | 2290 " port.receive((message, replyTo) {\n" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2263 EXPECT(Dart_ErrorHasException(result)); | 2371 EXPECT(Dart_ErrorHasException(result)); |
| 2264 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n", | 2372 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n", |
| 2265 Dart_GetError(result)); | 2373 Dart_GetError(result)); |
| 2266 | 2374 |
| 2267 Dart_ExitScope(); | 2375 Dart_ExitScope(); |
| 2268 } | 2376 } |
| 2269 | 2377 |
| 2270 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 2378 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 2271 | 2379 |
| 2272 } // namespace dart | 2380 } // namespace dart |
| OLD | NEW |