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::kByteArray: |
95 EXPECT_EQ(first->value.as_byte_array.length, | 95 EXPECT_EQ(first->value.as_byte_array.length, |
96 second->value.as_byte_array.length); | 96 second->value.as_byte_array.length); |
97 for (int i = 0; i < first->value.as_byte_array.length; i++) { | 97 for (int i = 0; i < first->value.as_byte_array.length; i++) { |
98 EXPECT_EQ(first->value.as_byte_array.values[i], | 98 EXPECT_EQ(first->value.as_byte_array.values[i], |
99 second->value.as_byte_array.values[i]); | 99 second->value.as_byte_array.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. |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_byte_array = TypedData::Handle(); |
628 serialized_byte_array ^= reader.ReadObject(); | 628 serialized_byte_array ^= reader.ReadObject(); |
629 EXPECT(serialized_byte_array.IsTypedData()); | 629 EXPECT(serialized_byte_array.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::kByteArray, root->type); |
636 EXPECT_EQ(kByteArrayLength, root->value.as_byte_array.length); | 636 EXPECT_EQ(kByteArrayLength, root->value.as_byte_array.length); |
637 for (int i = 0; i < kByteArrayLength; i++) { | 637 for (int i = 0; i < kByteArrayLength; i++) { |
638 EXPECT(root->value.as_byte_array.values[i] == i); | 638 EXPECT(root->value.as_byte_array.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 { \ |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_byte_array = TypedData::Handle(); |
737 serialized_byte_array ^= reader.ReadObject(); | 737 serialized_byte_array ^= reader.ReadObject(); |
738 EXPECT(serialized_byte_array.IsTypedData()); | 738 EXPECT(serialized_byte_array.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::kByteArray, root->type); |
| 745 EXPECT_EQ(Dart_CObject::kUint8Array, root->value.as_byte_array.type); |
745 EXPECT_EQ(kByteArrayLength, root->value.as_byte_array.length); | 746 EXPECT_EQ(kByteArrayLength, root->value.as_byte_array.length); |
746 EXPECT(root->value.as_byte_array.values == NULL); | 747 EXPECT(root->value.as_byte_array.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) |
(...skipping 1146 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::kByteArray, element->type); |
| 1913 EXPECT_EQ(Dart_CObject::kUint8Array, element->value.as_byte_array.type); |
1912 EXPECT_EQ(256, element->value.as_byte_array.length); | 1914 EXPECT_EQ(256, element->value.as_byte_array.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::kByteArray, element->type); |
| 1929 EXPECT_EQ(Dart_CObject::kUint8Array, element->value.as_byte_array.type); |
1927 EXPECT_EQ(128, element->value.as_byte_array.length); | 1930 EXPECT_EQ(128, element->value.as_byte_array.length); |
1928 EXPECT_EQ(1, element->value.as_byte_array.values[0]); | 1931 EXPECT_EQ(1, element->value.as_byte_array.values[0]); |
1929 EXPECT_EQ(0, element->value.as_byte_array.values[1]); | 1932 EXPECT_EQ(0, element->value.as_byte_array.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); |
(...skipping 166 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::kByteArray, element->type); |
| 2117 EXPECT_EQ(Dart_CObject::kUint8Array, element->value.as_byte_array.type); |
2114 EXPECT_EQ(256, element->value.as_byte_array.length); | 2118 EXPECT_EQ(256, element->value.as_byte_array.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::kByteArray, element->type); |
| 2133 EXPECT_EQ(Dart_CObject::kUint8Array, element->value.as_byte_array.type); |
2129 EXPECT_EQ(128, element->value.as_byte_array.length); | 2134 EXPECT_EQ(128, element->value.as_byte_array.length); |
2130 EXPECT_EQ(1, element->value.as_byte_array.values[0]); | 2135 EXPECT_EQ(1, element->value.as_byte_array.values[0]); |
2131 EXPECT_EQ(0, element->value.as_byte_array.values[1]); | 2136 EXPECT_EQ(0, element->value.as_byte_array.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); |
(...skipping 24 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 CheckByteArray(Dart_CObject* object, |
| 2179 Dart_CObject::ByteArrayType byte_array_type, |
| 2180 int len) { |
| 2181 EXPECT_EQ(Dart_CObject::kByteArray, object->type); |
| 2182 EXPECT_EQ(byte_array_type, object->value.as_byte_array.type); |
| 2183 EXPECT_EQ(len, object->value.as_byte_array.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 CheckByteArray(root->value.as_array.values[0], |
| 2230 Dart_CObject::kInt8Array, |
| 2231 256); |
| 2232 CheckByteArray(root->value.as_array.values[1], |
| 2233 Dart_CObject::kUint8Array, |
| 2234 256); |
| 2235 CheckByteArray(root->value.as_array.values[2], |
| 2236 Dart_CObject::kInt16Array, |
| 2237 512); |
| 2238 CheckByteArray(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 CheckByteArray(root->value.as_array.values[0], |
| 2251 Dart_CObject::kInt8Array, |
| 2252 256); |
| 2253 CheckByteArray(root->value.as_array.values[1], |
| 2254 Dart_CObject::kUint8Array, |
| 2255 256); |
| 2256 CheckByteArray(root->value.as_array.values[2], |
| 2257 Dart_CObject::kInt16Array, |
| 2258 512); |
| 2259 CheckByteArray(root->value.as_array.values[3], |
| 2260 Dart_CObject::kUint16Array, |
| 2261 512); |
| 2262 CheckByteArray(root->value.as_array.values[4], |
| 2263 Dart_CObject::kInt8Array, |
| 2264 512); |
| 2265 CheckByteArray(root->value.as_array.values[5], |
| 2266 Dart_CObject::kUint8Array, |
| 2267 512); |
| 2268 CheckByteArray(root->value.as_array.values[6], |
| 2269 Dart_CObject::kInt16Array, |
| 2270 256); |
| 2271 CheckByteArray(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 |