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 1239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1250 const Object& list = Object::Handle(Api::UnwrapHandle(result)); | 1250 const Object& list = Object::Handle(Api::UnwrapHandle(result)); |
1251 writer.WriteMessage(list); | 1251 writer.WriteMessage(list); |
1252 intptr_t buffer_len = writer.BytesWritten(); | 1252 intptr_t buffer_len = writer.BytesWritten(); |
1253 | 1253 |
1254 // Read object back from the snapshot into a C structure. | 1254 // Read object back from the snapshot into a C structure. |
1255 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 1255 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
1256 return api_reader.ReadMessage(); | 1256 return api_reader.ReadMessage(); |
1257 } | 1257 } |
1258 | 1258 |
1259 | 1259 |
1260 static void CheckString(Dart_Handle string, const char* expected) { | |
1261 StackZone zone(Isolate::Current()); | |
1262 uint8_t* buffer; | |
1263 MessageWriter writer(&buffer, &zone_allocator); | |
1264 String& str = String::Handle(); | |
1265 str ^= Api::UnwrapHandle(string); | |
1266 writer.WriteMessage(str); | |
1267 intptr_t buffer_len = writer.BytesWritten(); | |
1268 | |
1269 // Read object back from the snapshot into a C structure. | |
1270 ApiNativeScope scope; | |
1271 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | |
1272 Dart_CObject* root = api_reader.ReadMessage(); | |
1273 EXPECT_NOTNULL(root); | |
1274 EXPECT_EQ(Dart_CObject::kString, root->type); | |
1275 EXPECT_STREQ(expected, root->value.as_string); | |
1276 CheckEncodeDecodeMessage(root); | |
1277 } | |
1278 | |
1279 | |
1260 UNIT_TEST_CASE(DartGeneratedMessages) { | 1280 UNIT_TEST_CASE(DartGeneratedMessages) { |
1261 static const char* kCustomIsolateScriptChars = | 1281 static const char* kCustomIsolateScriptChars = |
1262 "getSmi() {\n" | 1282 "getSmi() {\n" |
1263 " return 42;\n" | 1283 " return 42;\n" |
1264 "}\n" | 1284 "}\n" |
1265 "getBigint() {\n" | 1285 "getBigint() {\n" |
1266 " return -0x424242424242424242424242424242424242;\n" | 1286 " return -0x424242424242424242424242424242424242;\n" |
1267 "}\n" | 1287 "}\n" |
1268 "getAsciiString() {\n" | 1288 "getAsciiString() {\n" |
1269 " return \"Hello, world!\";\n" | 1289 " return \"Hello, world!\";\n" |
1270 "}\n" | 1290 "}\n" |
1271 "getNonAsciiString() {\n" | 1291 "getNonAsciiString() {\n" |
1272 " return \"Blåbærgrød\";\n" | 1292 " return \"Blåbærgrød\";\n" |
1273 "}\n" | 1293 "}\n" |
1294 "getNonBMPString() {\n" | |
1295 " return \"\\u{10000}\\u{1F601}\\u{1F637}\\u{20000}\";\n" | |
erikcorry
2012/11/23 14:25:47
😁
| |
1296 "}\n" | |
1297 "getLeadSurrogateString() {\n" | |
1298 " return new String.fromCharCodes([0xd800]);\n" | |
1299 "}\n" | |
1300 "getTrailSurrogateString() {\n" | |
1301 " return \"\\u{10000}\".substring(1);\n" | |
1302 "}\n" | |
1303 "getSurrogatesString() {\n" | |
1304 " return new String.fromCharCodes([0xdc00, 0xdc00, 0xd800, 0xd800]);\n" | |
1305 "}\n" | |
1306 "getCrappyString() {\n" | |
1307 " return new String.fromCharCodes([0xd800, 32, 0xdc00, 32]);\n" | |
1308 "}\n" | |
1274 "getList() {\n" | 1309 "getList() {\n" |
1275 " return new List(kArrayLength);\n" | 1310 " return new List(kArrayLength);\n" |
1276 "}\n"; | 1311 "}\n"; |
1277 | 1312 |
1278 TestCase::CreateTestIsolate(); | 1313 TestCase::CreateTestIsolate(); |
1279 Isolate* isolate = Isolate::Current(); | 1314 Isolate* isolate = Isolate::Current(); |
1280 EXPECT(isolate != NULL); | 1315 EXPECT(isolate != NULL); |
1281 Dart_EnterScope(); | 1316 Dart_EnterScope(); |
1282 | 1317 |
1283 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars, | 1318 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars, |
1284 NULL); | 1319 NULL); |
1285 EXPECT_VALID(lib); | 1320 EXPECT_VALID(lib); |
1286 Dart_Handle smi_result; | 1321 Dart_Handle smi_result; |
1287 smi_result = Dart_Invoke(lib, NewString("getSmi"), 0, NULL); | 1322 smi_result = Dart_Invoke(lib, NewString("getSmi"), 0, NULL); |
1288 EXPECT_VALID(smi_result); | 1323 EXPECT_VALID(smi_result); |
1289 Dart_Handle bigint_result; | 1324 Dart_Handle bigint_result; |
1290 bigint_result = Dart_Invoke(lib, NewString("getBigint"), 0, NULL); | 1325 bigint_result = Dart_Invoke(lib, NewString("getBigint"), 0, NULL); |
1291 EXPECT_VALID(bigint_result); | 1326 EXPECT_VALID(bigint_result); |
1327 | |
1292 Dart_Handle ascii_string_result; | 1328 Dart_Handle ascii_string_result; |
1293 ascii_string_result = Dart_Invoke(lib, NewString("getAsciiString"), 0, NULL); | 1329 ascii_string_result = Dart_Invoke(lib, NewString("getAsciiString"), 0, NULL); |
1294 EXPECT_VALID(ascii_string_result); | 1330 EXPECT_VALID(ascii_string_result); |
1295 EXPECT(Dart_IsString(ascii_string_result)); | 1331 EXPECT(Dart_IsString(ascii_string_result)); |
1332 | |
1296 Dart_Handle non_ascii_string_result; | 1333 Dart_Handle non_ascii_string_result; |
1297 non_ascii_string_result = | 1334 non_ascii_string_result = |
1298 Dart_Invoke(lib, NewString("getNonAsciiString"), 0, NULL); | 1335 Dart_Invoke(lib, NewString("getNonAsciiString"), 0, NULL); |
1299 EXPECT_VALID(non_ascii_string_result); | 1336 EXPECT_VALID(non_ascii_string_result); |
1300 EXPECT(Dart_IsString(non_ascii_string_result)); | 1337 EXPECT(Dart_IsString(non_ascii_string_result)); |
1301 | 1338 |
1339 Dart_Handle non_bmp_string_result; | |
1340 non_bmp_string_result = | |
1341 Dart_Invoke(lib, NewString("getNonBMPString"), 0, NULL); | |
1342 EXPECT_VALID(non_bmp_string_result); | |
1343 EXPECT(Dart_IsString(non_bmp_string_result)); | |
1344 | |
1345 Dart_Handle lead_surrogate_string_result; | |
1346 lead_surrogate_string_result = | |
1347 Dart_Invoke(lib, NewString("getLeadSurrogateString"), 0, NULL); | |
1348 EXPECT_VALID(lead_surrogate_string_result); | |
1349 EXPECT(Dart_IsString(lead_surrogate_string_result)); | |
1350 | |
1351 Dart_Handle trail_surrogate_string_result; | |
1352 trail_surrogate_string_result = | |
1353 Dart_Invoke(lib, NewString("getTrailSurrogateString"), 0, NULL); | |
1354 EXPECT_VALID(trail_surrogate_string_result); | |
1355 EXPECT(Dart_IsString(trail_surrogate_string_result)); | |
1356 | |
1357 Dart_Handle surrogates_string_result; | |
1358 surrogates_string_result = | |
1359 Dart_Invoke(lib, NewString("getSurrogatesString"), 0, NULL); | |
1360 EXPECT_VALID(surrogates_string_result); | |
1361 EXPECT(Dart_IsString(surrogates_string_result)); | |
1362 | |
1363 Dart_Handle crappy_string_result; | |
1364 crappy_string_result = | |
1365 Dart_Invoke(lib, NewString("getCrappyString"), 0, NULL); | |
1366 EXPECT_VALID(crappy_string_result); | |
1367 EXPECT(Dart_IsString(crappy_string_result)); | |
1368 | |
1302 { | 1369 { |
1303 DARTSCOPE_NOCHECKS(isolate); | 1370 DARTSCOPE_NOCHECKS(isolate); |
1304 | 1371 |
1305 { | 1372 { |
1306 StackZone zone(Isolate::Current()); | 1373 StackZone zone(Isolate::Current()); |
1307 uint8_t* buffer; | 1374 uint8_t* buffer; |
1308 MessageWriter writer(&buffer, &zone_allocator); | 1375 MessageWriter writer(&buffer, &zone_allocator); |
1309 Smi& smi = Smi::Handle(); | 1376 Smi& smi = Smi::Handle(); |
1310 smi ^= Api::UnwrapHandle(smi_result); | 1377 smi ^= Api::UnwrapHandle(smi_result); |
1311 writer.WriteMessage(smi); | 1378 writer.WriteMessage(smi); |
(...skipping 20 matching lines...) Expand all Loading... | |
1332 // Read object back from the snapshot into a C structure. | 1399 // Read object back from the snapshot into a C structure. |
1333 ApiNativeScope scope; | 1400 ApiNativeScope scope; |
1334 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 1401 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
1335 Dart_CObject* root = api_reader.ReadMessage(); | 1402 Dart_CObject* root = api_reader.ReadMessage(); |
1336 EXPECT_NOTNULL(root); | 1403 EXPECT_NOTNULL(root); |
1337 EXPECT_EQ(Dart_CObject::kBigint, root->type); | 1404 EXPECT_EQ(Dart_CObject::kBigint, root->type); |
1338 EXPECT_STREQ("-424242424242424242424242424242424242", | 1405 EXPECT_STREQ("-424242424242424242424242424242424242", |
1339 root->value.as_bigint); | 1406 root->value.as_bigint); |
1340 CheckEncodeDecodeMessage(root); | 1407 CheckEncodeDecodeMessage(root); |
1341 } | 1408 } |
1342 { | 1409 CheckString(ascii_string_result, "Hello, world!"); |
1343 StackZone zone(Isolate::Current()); | 1410 CheckString(non_ascii_string_result, "Blåbærgrød"); |
1344 uint8_t* buffer; | 1411 CheckString(non_bmp_string_result, |
1345 MessageWriter writer(&buffer, &zone_allocator); | 1412 "\xf0\x90\x80\x80" |
1346 String& str = String::Handle(); | 1413 "\xf0\x9f\x98\x81" |
1347 str ^= Api::UnwrapHandle(ascii_string_result); | 1414 "\xf0\x9f\x98\xb7" |
1348 writer.WriteMessage(str); | 1415 "\xf0\xa0\x80\x80"); |
1349 intptr_t buffer_len = writer.BytesWritten(); | 1416 CheckString(lead_surrogate_string_result, "\xed\xa0\x80"); |
1350 | 1417 CheckString(trail_surrogate_string_result, "\xed\xb0\x80"); |
1351 // Read object back from the snapshot into a C structure. | 1418 CheckString(crappy_string_result, |
1352 ApiNativeScope scope; | 1419 "\xed\xa0\x80\x20\xed\xb0\x80\x20"); |
1353 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 1420 CheckString(surrogates_string_result, |
1354 Dart_CObject* root = api_reader.ReadMessage(); | 1421 "\xed\xb0\x80\xed\xb0\x80\xed\xa0\x80\xed\xa0\x80"); |
1355 EXPECT_NOTNULL(root); | |
1356 EXPECT_EQ(Dart_CObject::kString, root->type); | |
1357 EXPECT_STREQ("Hello, world!", root->value.as_string); | |
1358 CheckEncodeDecodeMessage(root); | |
1359 } | |
1360 { | |
1361 StackZone zone(Isolate::Current()); | |
1362 uint8_t* buffer; | |
1363 MessageWriter writer(&buffer, &zone_allocator); | |
1364 String& str = String::Handle(); | |
1365 str ^= Api::UnwrapHandle(non_ascii_string_result); | |
1366 writer.WriteMessage(str); | |
1367 intptr_t buffer_len = writer.BytesWritten(); | |
1368 | |
1369 // Read object back from the snapshot into a C structure. | |
1370 ApiNativeScope scope; | |
1371 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | |
1372 Dart_CObject* root = api_reader.ReadMessage(); | |
1373 EXPECT_NOTNULL(root); | |
1374 EXPECT_EQ(Dart_CObject::kString, root->type); | |
1375 EXPECT_STREQ("Blåbærgrød", root->value.as_string); | |
1376 CheckEncodeDecodeMessage(root); | |
1377 } | |
1378 } | 1422 } |
1379 Dart_ExitScope(); | 1423 Dart_ExitScope(); |
1380 Dart_ShutdownIsolate(); | 1424 Dart_ShutdownIsolate(); |
1381 } | 1425 } |
1382 | 1426 |
1383 | 1427 |
1384 UNIT_TEST_CASE(DartGeneratedListMessages) { | 1428 UNIT_TEST_CASE(DartGeneratedListMessages) { |
1385 const int kArrayLength = 10; | 1429 const int kArrayLength = 10; |
1386 static const char* kScriptChars = | 1430 static const char* kScriptChars = |
1387 "final int kArrayLength = 10;\n" | 1431 "final int kArrayLength = 10;\n" |
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2063 " }\n" | 2107 " }\n" |
2064 " }\n" | 2108 " }\n" |
2065 " messageCount++;\n" | 2109 " messageCount++;\n" |
2066 " if (messageCount == 9) throw new Exception(exception);\n" | 2110 " if (messageCount == 9) throw new Exception(exception);\n" |
2067 " });\n" | 2111 " });\n" |
2068 " return port.toSendPort();\n" | 2112 " return port.toSendPort();\n" |
2069 "}\n"; | 2113 "}\n"; |
2070 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2114 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
2071 Dart_EnterScope(); | 2115 Dart_EnterScope(); |
2072 | 2116 |
2073 // xxx | |
2074 Dart_Handle send_port = Dart_Invoke(lib, NewString("main"), 0, NULL); | 2117 Dart_Handle send_port = Dart_Invoke(lib, NewString("main"), 0, NULL); |
2075 EXPECT_VALID(send_port); | 2118 EXPECT_VALID(send_port); |
2076 Dart_Handle result = Dart_GetField(send_port, NewString("_id")); | 2119 Dart_Handle result = Dart_GetField(send_port, NewString("_id")); |
2077 ASSERT(!Dart_IsError(result)); | 2120 ASSERT(!Dart_IsError(result)); |
2078 ASSERT(Dart_IsInteger(result)); | 2121 ASSERT(Dart_IsInteger(result)); |
2079 int64_t send_port_id; | 2122 int64_t send_port_id; |
2080 Dart_Handle result2 = Dart_IntegerToInt64(result, &send_port_id); | 2123 Dart_Handle result2 = Dart_IntegerToInt64(result, &send_port_id); |
2081 ASSERT(!Dart_IsError(result2)); | 2124 ASSERT(!Dart_IsError(result2)); |
2082 | 2125 |
2083 // Setup single object message. | 2126 // Setup single object message. |
(...skipping 15 matching lines...) Expand all Loading... | |
2099 EXPECT(Dart_PostCObject(send_port_id, &object)); | 2142 EXPECT(Dart_PostCObject(send_port_id, &object)); |
2100 | 2143 |
2101 object.type = Dart_CObject::kString; | 2144 object.type = Dart_CObject::kString; |
2102 object.value.as_string = const_cast<char*>("456"); | 2145 object.value.as_string = const_cast<char*>("456"); |
2103 EXPECT(Dart_PostCObject(send_port_id, &object)); | 2146 EXPECT(Dart_PostCObject(send_port_id, &object)); |
2104 | 2147 |
2105 object.type = Dart_CObject::kString; | 2148 object.type = Dart_CObject::kString; |
2106 object.value.as_string = const_cast<char*>("æøå"); | 2149 object.value.as_string = const_cast<char*>("æøå"); |
2107 EXPECT(Dart_PostCObject(send_port_id, &object)); | 2150 EXPECT(Dart_PostCObject(send_port_id, &object)); |
2108 | 2151 |
2109 // Try to post an invalid UTF-8 sequence (lead surrogate). | |
2110 const char* data = "\xED\xA0\x80"; // U+D800 | |
2111 object.type = Dart_CObject::kString; | |
2112 object.value.as_string = const_cast<char*>(data); | |
2113 EXPECT(!Dart_PostCObject(send_port_id, &object)); | |
2114 | |
2115 object.type = Dart_CObject::kDouble; | 2152 object.type = Dart_CObject::kDouble; |
2116 object.value.as_double = 3.14; | 2153 object.value.as_double = 3.14; |
2117 EXPECT(Dart_PostCObject(send_port_id, &object)); | 2154 EXPECT(Dart_PostCObject(send_port_id, &object)); |
2118 | 2155 |
2119 object.type = Dart_CObject::kArray; | 2156 object.type = Dart_CObject::kArray; |
2120 object.value.as_array.length = 0; | 2157 object.value.as_array.length = 0; |
2121 EXPECT(Dart_PostCObject(send_port_id, &object)); | 2158 EXPECT(Dart_PostCObject(send_port_id, &object)); |
2122 | 2159 |
2123 static const int kArrayLength = 10; | 2160 static const int kArrayLength = 10; |
2124 Dart_CObject* array = | 2161 Dart_CObject* array = |
(...skipping 19 matching lines...) Expand all Loading... | |
2144 EXPECT(Dart_ErrorHasException(result)); | 2181 EXPECT(Dart_ErrorHasException(result)); |
2145 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n", | 2182 EXPECT_SUBSTRING("Exception: nulltruefalse123456æøå3.14[]100123456789\n", |
2146 Dart_GetError(result)); | 2183 Dart_GetError(result)); |
2147 | 2184 |
2148 Dart_ExitScope(); | 2185 Dart_ExitScope(); |
2149 } | 2186 } |
2150 | 2187 |
2151 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 2188 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
2152 | 2189 |
2153 } // namespace dart | 2190 } // namespace dart |
OLD | NEW |