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 "platform/globals.h" | 5 #include "platform/globals.h" |
6 | 6 |
7 #include "include/dart_tools_api.h" | 7 #include "include/dart_tools_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 } | 234 } |
235 | 235 |
236 | 236 |
237 Dart_CObject* SerializeAndDeserializeMint(const Mint& mint) { | 237 Dart_CObject* SerializeAndDeserializeMint(const Mint& mint) { |
238 // Write snapshot with object content. | 238 // Write snapshot with object content. |
239 uint8_t* buffer; | 239 uint8_t* buffer; |
240 MessageWriter writer(&buffer, &zone_allocator, true); | 240 MessageWriter writer(&buffer, &zone_allocator, true); |
241 writer.WriteMessage(mint); | 241 writer.WriteMessage(mint); |
242 intptr_t buffer_len = writer.BytesWritten(); | 242 intptr_t buffer_len = writer.BytesWritten(); |
243 | 243 |
244 // Read object back from the snapshot. | 244 { |
245 MessageSnapshotReader reader(buffer, | 245 // Switch to a regular zone, where VM handle allocation is allowed. |
246 buffer_len, | 246 StackZone zone(Isolate::Current()); |
247 Isolate::Current(), | 247 // Read object back from the snapshot. |
248 Thread::Current()->zone()); | 248 MessageSnapshotReader reader(buffer, |
249 const Object& serialized_object = Object::Handle(reader.ReadObject()); | 249 buffer_len, |
250 EXPECT(serialized_object.IsMint()); | 250 Isolate::Current(), |
| 251 Thread::Current()->zone()); |
| 252 const Object& serialized_object = Object::Handle(reader.ReadObject()); |
| 253 EXPECT(serialized_object.IsMint()); |
| 254 } |
251 | 255 |
252 // Read object back from the snapshot into a C structure. | 256 // Read object back from the snapshot into a C structure. |
253 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 257 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
254 Dart_CObject* root = api_reader.ReadMessage(); | 258 Dart_CObject* root = api_reader.ReadMessage(); |
255 EXPECT_NOTNULL(root); | 259 EXPECT_NOTNULL(root); |
256 CheckEncodeDecodeMessage(root); | 260 CheckEncodeDecodeMessage(root); |
257 return root; | 261 return root; |
258 } | 262 } |
259 | 263 |
260 | 264 |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 } | 438 } |
435 | 439 |
436 | 440 |
437 Dart_CObject* SerializeAndDeserializeBigint(const Bigint& bigint) { | 441 Dart_CObject* SerializeAndDeserializeBigint(const Bigint& bigint) { |
438 // Write snapshot with object content. | 442 // Write snapshot with object content. |
439 uint8_t* buffer; | 443 uint8_t* buffer; |
440 MessageWriter writer(&buffer, &zone_allocator, true); | 444 MessageWriter writer(&buffer, &zone_allocator, true); |
441 writer.WriteMessage(bigint); | 445 writer.WriteMessage(bigint); |
442 intptr_t buffer_len = writer.BytesWritten(); | 446 intptr_t buffer_len = writer.BytesWritten(); |
443 | 447 |
444 // Read object back from the snapshot. | 448 { |
445 MessageSnapshotReader reader(buffer, | 449 // Switch to a regular zone, where VM handle allocation is allowed. |
446 buffer_len, | 450 StackZone zone(Isolate::Current()); |
447 Isolate::Current(), | 451 // Read object back from the snapshot. |
448 Thread::Current()->zone()); | 452 MessageSnapshotReader reader(buffer, |
449 Bigint& serialized_bigint = Bigint::Handle(); | 453 buffer_len, |
450 serialized_bigint ^= reader.ReadObject(); | 454 Isolate::Current(), |
451 const char* str1 = bigint.ToHexCString(allocator); | 455 Thread::Current()->zone()); |
452 const char* str2 = serialized_bigint.ToHexCString(allocator); | 456 Bigint& serialized_bigint = Bigint::Handle(); |
453 EXPECT_STREQ(str1, str2); | 457 serialized_bigint ^= reader.ReadObject(); |
454 free(const_cast<char*>(str1)); | 458 const char* str1 = bigint.ToHexCString(allocator); |
455 free(const_cast<char*>(str2)); | 459 const char* str2 = serialized_bigint.ToHexCString(allocator); |
| 460 EXPECT_STREQ(str1, str2); |
| 461 free(const_cast<char*>(str1)); |
| 462 free(const_cast<char*>(str2)); |
| 463 } |
456 | 464 |
457 // Read object back from the snapshot into a C structure. | 465 // Read object back from the snapshot into a C structure. |
458 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 466 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
459 Dart_CObject* root = api_reader.ReadMessage(); | 467 Dart_CObject* root = api_reader.ReadMessage(); |
460 // Bigint not supported. | 468 // Bigint not supported. |
461 EXPECT_NOTNULL(root); | 469 EXPECT_NOTNULL(root); |
462 CheckEncodeDecodeMessage(root); | 470 CheckEncodeDecodeMessage(root); |
463 return root; | 471 return root; |
464 } | 472 } |
465 | 473 |
466 | 474 |
467 void CheckBigint(const char* bigint_value) { | 475 void CheckBigint(const char* bigint_value) { |
468 StackZone zone(Isolate::Current()); | 476 StackZone zone(Isolate::Current()); |
469 ApiNativeScope scope; | |
470 | |
471 Bigint& bigint = Bigint::Handle(); | 477 Bigint& bigint = Bigint::Handle(); |
472 bigint ^= Bigint::NewFromCString(bigint_value); | 478 bigint ^= Bigint::NewFromCString(bigint_value); |
| 479 ApiNativeScope scope; |
473 Dart_CObject* bigint_cobject = SerializeAndDeserializeBigint(bigint); | 480 Dart_CObject* bigint_cobject = SerializeAndDeserializeBigint(bigint); |
474 EXPECT_EQ(Dart_CObject_kBigint, bigint_cobject->type); | 481 EXPECT_EQ(Dart_CObject_kBigint, bigint_cobject->type); |
475 char* hex_value = TestCase::BigintToHexValue(bigint_cobject); | 482 char* hex_value = TestCase::BigintToHexValue(bigint_cobject); |
476 EXPECT_STREQ(bigint_value, hex_value); | 483 EXPECT_STREQ(bigint_value, hex_value); |
477 free(hex_value); | 484 free(hex_value); |
478 } | 485 } |
479 | 486 |
480 | 487 |
481 TEST_CASE(SerializeBigint2) { | 488 TEST_CASE(SerializeBigint2) { |
482 CheckBigint("0x0"); | 489 CheckBigint("0x0"); |
(...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1582 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1589 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
1583 for (int i = 0; i < kArrayLength; i++) { | 1590 for (int i = 0; i < kArrayLength; i++) { |
1584 Dart_CObject* element = root->value.as_array.values[i]; | 1591 Dart_CObject* element = root->value.as_array.values[i]; |
1585 EXPECT_EQ(Dart_CObject_kInt32, element->type); | 1592 EXPECT_EQ(Dart_CObject_kInt32, element->type); |
1586 EXPECT_EQ(i + 1, element->value.as_int32); | 1593 EXPECT_EQ(i + 1, element->value.as_int32); |
1587 } | 1594 } |
1588 CheckEncodeDecodeMessage(root); | 1595 CheckEncodeDecodeMessage(root); |
1589 } | 1596 } |
1590 | 1597 |
1591 | 1598 |
1592 // Helper function to call a top level Dart function, serialize the | 1599 // Helper function to call a top level Dart function and serialize the result. |
1593 // result and deserialize the result into a Dart_CObject structure. | 1600 static uint8_t* GetSerialized(Dart_Handle lib, |
1594 static Dart_CObject* GetDeserializedDartMessage(Dart_Handle lib, | 1601 const char* dart_function, |
1595 const char* dart_function) { | 1602 intptr_t* buffer_len) { |
1596 Dart_Handle result; | 1603 Dart_Handle result; |
1597 result = Dart_Invoke(lib, NewString(dart_function), 0, NULL); | 1604 result = Dart_Invoke(lib, NewString(dart_function), 0, NULL); |
1598 EXPECT_VALID(result); | 1605 EXPECT_VALID(result); |
| 1606 Object& obj = Object::Handle(Api::UnwrapHandle(result)); |
1599 | 1607 |
1600 // Serialize the list into a message. | 1608 // Serialize the object into a message. |
1601 const Object& list = Object::Handle(Api::UnwrapHandle(result)); | |
1602 uint8_t* buffer; | 1609 uint8_t* buffer; |
1603 MessageWriter writer(&buffer, &zone_allocator, false); | 1610 MessageWriter writer(&buffer, &zone_allocator, false); |
1604 writer.WriteMessage(list); | 1611 writer.WriteMessage(obj); |
1605 intptr_t buffer_len = writer.BytesWritten(); | 1612 *buffer_len = writer.BytesWritten(); |
| 1613 return buffer; |
| 1614 } |
1606 | 1615 |
| 1616 |
| 1617 // Helper function to deserialize the result into a Dart_CObject structure. |
| 1618 static Dart_CObject* GetDeserialized(uint8_t* buffer, intptr_t buffer_len) { |
1607 // Read object back from the snapshot into a C structure. | 1619 // Read object back from the snapshot into a C structure. |
1608 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 1620 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
1609 return api_reader.ReadMessage(); | 1621 return api_reader.ReadMessage(); |
1610 } | 1622 } |
1611 | 1623 |
1612 | 1624 |
1613 static void CheckString(Dart_Handle dart_string, const char* expected) { | 1625 static void CheckString(Dart_Handle dart_string, const char* expected) { |
1614 StackZone zone(Isolate::Current()); | 1626 StackZone zone(Isolate::Current()); |
1615 String& str = String::Handle(); | 1627 String& str = String::Handle(); |
1616 str ^= Api::UnwrapHandle(dart_string); | 1628 str ^= Api::UnwrapHandle(dart_string); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1824 TestCase::CreateTestIsolate(); | 1836 TestCase::CreateTestIsolate(); |
1825 Isolate* isolate = Isolate::Current(); | 1837 Isolate* isolate = Isolate::Current(); |
1826 EXPECT(isolate != NULL); | 1838 EXPECT(isolate != NULL); |
1827 Dart_EnterScope(); | 1839 Dart_EnterScope(); |
1828 | 1840 |
1829 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 1841 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
1830 EXPECT_VALID(lib); | 1842 EXPECT_VALID(lib); |
1831 | 1843 |
1832 { | 1844 { |
1833 DARTSCOPE(isolate); | 1845 DARTSCOPE(isolate); |
| 1846 StackZone zone(isolate); |
| 1847 intptr_t buf_len = 0; |
1834 { | 1848 { |
1835 // Generate a list of nulls from Dart code. | 1849 // Generate a list of nulls from Dart code. |
| 1850 uint8_t* buf = GetSerialized(lib, "getList", &buf_len); |
1836 ApiNativeScope scope; | 1851 ApiNativeScope scope; |
1837 Dart_CObject* root = GetDeserializedDartMessage(lib, "getList"); | 1852 Dart_CObject* root = GetDeserialized(buf, buf_len); |
1838 EXPECT_NOTNULL(root); | 1853 EXPECT_NOTNULL(root); |
1839 EXPECT_EQ(Dart_CObject_kArray, root->type); | 1854 EXPECT_EQ(Dart_CObject_kArray, root->type); |
1840 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1855 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
1841 for (int i = 0; i < kArrayLength; i++) { | 1856 for (int i = 0; i < kArrayLength; i++) { |
1842 EXPECT_EQ(Dart_CObject_kNull, root->value.as_array.values[i]->type); | 1857 EXPECT_EQ(Dart_CObject_kNull, root->value.as_array.values[i]->type); |
1843 } | 1858 } |
1844 CheckEncodeDecodeMessage(root); | 1859 CheckEncodeDecodeMessage(root); |
1845 } | 1860 } |
1846 { | 1861 { |
1847 // Generate a list of ints from Dart code. | 1862 // Generate a list of ints from Dart code. |
| 1863 uint8_t* buf = GetSerialized(lib, "getIntList", &buf_len); |
1848 ApiNativeScope scope; | 1864 ApiNativeScope scope; |
1849 Dart_CObject* root = GetDeserializedDartMessage(lib, "getIntList"); | 1865 Dart_CObject* root = GetDeserialized(buf, buf_len); |
1850 EXPECT_NOTNULL(root); | 1866 EXPECT_NOTNULL(root); |
1851 EXPECT_EQ(Dart_CObject_kArray, root->type); | 1867 EXPECT_EQ(Dart_CObject_kArray, root->type); |
1852 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1868 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
1853 for (int i = 0; i < kArrayLength; i++) { | 1869 for (int i = 0; i < kArrayLength; i++) { |
1854 EXPECT_EQ(Dart_CObject_kInt32, root->value.as_array.values[i]->type); | 1870 EXPECT_EQ(Dart_CObject_kInt32, root->value.as_array.values[i]->type); |
1855 EXPECT_EQ(i, root->value.as_array.values[i]->value.as_int32); | 1871 EXPECT_EQ(i, root->value.as_array.values[i]->value.as_int32); |
1856 } | 1872 } |
1857 CheckEncodeDecodeMessage(root); | 1873 CheckEncodeDecodeMessage(root); |
1858 } | 1874 } |
1859 { | 1875 { |
1860 // Generate a list of strings from Dart code. | 1876 // Generate a list of strings from Dart code. |
| 1877 uint8_t* buf = GetSerialized(lib, "getStringList", &buf_len); |
1861 ApiNativeScope scope; | 1878 ApiNativeScope scope; |
1862 Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList"); | 1879 Dart_CObject* root = GetDeserialized(buf, buf_len); |
1863 EXPECT_NOTNULL(root); | 1880 EXPECT_NOTNULL(root); |
1864 EXPECT_EQ(Dart_CObject_kArray, root->type); | 1881 EXPECT_EQ(Dart_CObject_kArray, root->type); |
1865 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1882 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
1866 for (int i = 0; i < kArrayLength; i++) { | 1883 for (int i = 0; i < kArrayLength; i++) { |
1867 EXPECT_EQ(Dart_CObject_kString, root->value.as_array.values[i]->type); | 1884 EXPECT_EQ(Dart_CObject_kString, root->value.as_array.values[i]->type); |
1868 char buffer[3]; | 1885 char buffer[3]; |
1869 snprintf(buffer, sizeof(buffer), "%d", i); | 1886 snprintf(buffer, sizeof(buffer), "%d", i); |
1870 EXPECT_STREQ(buffer, root->value.as_array.values[i]->value.as_string); | 1887 EXPECT_STREQ(buffer, root->value.as_array.values[i]->value.as_string); |
1871 } | 1888 } |
1872 } | 1889 } |
1873 { | 1890 { |
1874 // Generate a list of objects of different types from Dart code. | 1891 // Generate a list of objects of different types from Dart code. |
| 1892 uint8_t* buf = GetSerialized(lib, "getMixedList", &buf_len); |
1875 ApiNativeScope scope; | 1893 ApiNativeScope scope; |
1876 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); | 1894 Dart_CObject* root = GetDeserialized(buf, buf_len); |
1877 EXPECT_NOTNULL(root); | 1895 EXPECT_NOTNULL(root); |
1878 EXPECT_EQ(Dart_CObject_kArray, root->type); | 1896 EXPECT_EQ(Dart_CObject_kArray, root->type); |
1879 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1897 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
1880 | 1898 |
1881 EXPECT_EQ(Dart_CObject_kInt32, root->value.as_array.values[0]->type); | 1899 EXPECT_EQ(Dart_CObject_kInt32, root->value.as_array.values[0]->type); |
1882 EXPECT_EQ(0, root->value.as_array.values[0]->value.as_int32); | 1900 EXPECT_EQ(0, root->value.as_array.values[0]->value.as_int32); |
1883 EXPECT_EQ(Dart_CObject_kString, root->value.as_array.values[1]->type); | 1901 EXPECT_EQ(Dart_CObject_kString, root->value.as_array.values[1]->type); |
1884 EXPECT_STREQ("1", root->value.as_array.values[1]->value.as_string); | 1902 EXPECT_STREQ("1", root->value.as_array.values[1]->value.as_string); |
1885 EXPECT_EQ(Dart_CObject_kDouble, root->value.as_array.values[2]->type); | 1903 EXPECT_EQ(Dart_CObject_kDouble, root->value.as_array.values[2]->type); |
1886 EXPECT_EQ(2.2, root->value.as_array.values[2]->value.as_double); | 1904 EXPECT_EQ(2.2, root->value.as_array.values[2]->value.as_double); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1942 TestCase::CreateTestIsolate(); | 1960 TestCase::CreateTestIsolate(); |
1943 Isolate* isolate = Isolate::Current(); | 1961 Isolate* isolate = Isolate::Current(); |
1944 EXPECT(isolate != NULL); | 1962 EXPECT(isolate != NULL); |
1945 Dart_EnterScope(); | 1963 Dart_EnterScope(); |
1946 | 1964 |
1947 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 1965 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
1948 EXPECT_VALID(lib); | 1966 EXPECT_VALID(lib); |
1949 | 1967 |
1950 { | 1968 { |
1951 DARTSCOPE(isolate); | 1969 DARTSCOPE(isolate); |
| 1970 StackZone zone(isolate); |
| 1971 intptr_t buf_len = 0; |
1952 { | 1972 { |
1953 // Generate a list of nulls from Dart code. | 1973 // Generate a list of nulls from Dart code. |
| 1974 uint8_t* buf = GetSerialized(lib, "getList", &buf_len); |
1954 ApiNativeScope scope; | 1975 ApiNativeScope scope; |
1955 Dart_CObject* root = GetDeserializedDartMessage(lib, "getList"); | 1976 Dart_CObject* root = GetDeserialized(buf, buf_len); |
1956 EXPECT_NOTNULL(root); | 1977 EXPECT_NOTNULL(root); |
1957 EXPECT_EQ(Dart_CObject_kArray, root->type); | 1978 EXPECT_EQ(Dart_CObject_kArray, root->type); |
1958 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1979 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
1959 for (int i = 0; i < kArrayLength; i++) { | 1980 for (int i = 0; i < kArrayLength; i++) { |
1960 EXPECT_EQ(Dart_CObject_kNull, root->value.as_array.values[i]->type); | 1981 EXPECT_EQ(Dart_CObject_kNull, root->value.as_array.values[i]->type); |
1961 } | 1982 } |
1962 CheckEncodeDecodeMessage(root); | 1983 CheckEncodeDecodeMessage(root); |
1963 } | 1984 } |
1964 { | 1985 { |
1965 // Generate a list of ints from Dart code. | 1986 // Generate a list of ints from Dart code. |
| 1987 uint8_t* buf = GetSerialized(lib, "getIntList", &buf_len); |
1966 ApiNativeScope scope; | 1988 ApiNativeScope scope; |
1967 Dart_CObject* root = GetDeserializedDartMessage(lib, "getIntList"); | 1989 Dart_CObject* root = GetDeserialized(buf, buf_len); |
1968 EXPECT_NOTNULL(root); | 1990 EXPECT_NOTNULL(root); |
1969 EXPECT_EQ(Dart_CObject_kArray, root->type); | 1991 EXPECT_EQ(Dart_CObject_kArray, root->type); |
1970 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1992 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
1971 for (int i = 0; i < kArrayLength; i++) { | 1993 for (int i = 0; i < kArrayLength; i++) { |
1972 EXPECT_EQ(Dart_CObject_kInt32, root->value.as_array.values[i]->type); | 1994 EXPECT_EQ(Dart_CObject_kInt32, root->value.as_array.values[i]->type); |
1973 EXPECT_EQ(i, root->value.as_array.values[i]->value.as_int32); | 1995 EXPECT_EQ(i, root->value.as_array.values[i]->value.as_int32); |
1974 } | 1996 } |
1975 CheckEncodeDecodeMessage(root); | 1997 CheckEncodeDecodeMessage(root); |
1976 } | 1998 } |
1977 { | 1999 { |
1978 // Generate a list of strings from Dart code. | 2000 // Generate a list of strings from Dart code. |
| 2001 uint8_t* buf = GetSerialized(lib, "getStringList", &buf_len); |
1979 ApiNativeScope scope; | 2002 ApiNativeScope scope; |
1980 Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList"); | 2003 Dart_CObject* root = GetDeserialized(buf, buf_len); |
1981 EXPECT_NOTNULL(root); | 2004 EXPECT_NOTNULL(root); |
1982 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2005 EXPECT_EQ(Dart_CObject_kArray, root->type); |
1983 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2006 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
1984 for (int i = 0; i < kArrayLength; i++) { | 2007 for (int i = 0; i < kArrayLength; i++) { |
1985 EXPECT_EQ(Dart_CObject_kString, root->value.as_array.values[i]->type); | 2008 EXPECT_EQ(Dart_CObject_kString, root->value.as_array.values[i]->type); |
1986 char buffer[3]; | 2009 char buffer[3]; |
1987 snprintf(buffer, sizeof(buffer), "%d", i); | 2010 snprintf(buffer, sizeof(buffer), "%d", i); |
1988 EXPECT_STREQ(buffer, root->value.as_array.values[i]->value.as_string); | 2011 EXPECT_STREQ(buffer, root->value.as_array.values[i]->value.as_string); |
1989 } | 2012 } |
1990 } | 2013 } |
1991 { | 2014 { |
1992 // Generate a list of lists from Dart code. | 2015 // Generate a list of lists from Dart code. |
| 2016 uint8_t* buf = GetSerialized(lib, "getListList", &buf_len); |
1993 ApiNativeScope scope; | 2017 ApiNativeScope scope; |
1994 Dart_CObject* root = GetDeserializedDartMessage(lib, "getListList"); | 2018 Dart_CObject* root = GetDeserialized(buf, buf_len); |
1995 EXPECT_NOTNULL(root); | 2019 EXPECT_NOTNULL(root); |
1996 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2020 EXPECT_EQ(Dart_CObject_kArray, root->type); |
1997 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2021 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
1998 for (int i = 0; i < kArrayLength; i++) { | 2022 for (int i = 0; i < kArrayLength; i++) { |
1999 Dart_CObject* element = root->value.as_array.values[i]; | 2023 Dart_CObject* element = root->value.as_array.values[i]; |
2000 EXPECT_EQ(Dart_CObject_kArray, element->type); | 2024 EXPECT_EQ(Dart_CObject_kArray, element->type); |
2001 EXPECT_EQ(i, element->value.as_array.length); | 2025 EXPECT_EQ(i, element->value.as_array.length); |
2002 for (int j = 0; j < i; j++) { | 2026 for (int j = 0; j < i; j++) { |
2003 EXPECT_EQ(Dart_CObject_kInt32, | 2027 EXPECT_EQ(Dart_CObject_kInt32, |
2004 element->value.as_array.values[j]->type); | 2028 element->value.as_array.values[j]->type); |
2005 EXPECT_EQ(j, element->value.as_array.values[j]->value.as_int32); | 2029 EXPECT_EQ(j, element->value.as_array.values[j]->value.as_int32); |
2006 } | 2030 } |
2007 } | 2031 } |
2008 } | 2032 } |
2009 { | 2033 { |
2010 // Generate a list of objects of different types from Dart code. | 2034 // Generate a list of objects of different types from Dart code. |
| 2035 uint8_t* buf = GetSerialized(lib, "getMixedList", &buf_len); |
2011 ApiNativeScope scope; | 2036 ApiNativeScope scope; |
2012 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); | 2037 Dart_CObject* root = GetDeserialized(buf, buf_len); |
2013 EXPECT_NOTNULL(root); | 2038 EXPECT_NOTNULL(root); |
2014 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2039 EXPECT_EQ(Dart_CObject_kArray, root->type); |
2015 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2040 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
2016 | 2041 |
2017 EXPECT_EQ(Dart_CObject_kInt32, root->value.as_array.values[0]->type); | 2042 EXPECT_EQ(Dart_CObject_kInt32, root->value.as_array.values[0]->type); |
2018 EXPECT_EQ(0, root->value.as_array.values[0]->value.as_int32); | 2043 EXPECT_EQ(0, root->value.as_array.values[0]->value.as_int32); |
2019 EXPECT_EQ(Dart_CObject_kString, root->value.as_array.values[1]->type); | 2044 EXPECT_EQ(Dart_CObject_kString, root->value.as_array.values[1]->type); |
2020 EXPECT_STREQ("1", root->value.as_array.values[1]->value.as_string); | 2045 EXPECT_STREQ("1", root->value.as_array.values[1]->value.as_string); |
2021 EXPECT_EQ(Dart_CObject_kDouble, root->value.as_array.values[2]->type); | 2046 EXPECT_EQ(Dart_CObject_kDouble, root->value.as_array.values[2]->type); |
2022 EXPECT_EQ(2.2, root->value.as_array.values[2]->value.as_double); | 2047 EXPECT_EQ(2.2, root->value.as_array.values[2]->value.as_double); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2174 TestCase::CreateTestIsolate(); | 2199 TestCase::CreateTestIsolate(); |
2175 Isolate* isolate = Isolate::Current(); | 2200 Isolate* isolate = Isolate::Current(); |
2176 EXPECT(isolate != NULL); | 2201 EXPECT(isolate != NULL); |
2177 Dart_EnterScope(); | 2202 Dart_EnterScope(); |
2178 | 2203 |
2179 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2204 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
2180 EXPECT_VALID(lib); | 2205 EXPECT_VALID(lib); |
2181 | 2206 |
2182 { | 2207 { |
2183 DARTSCOPE(isolate); | 2208 DARTSCOPE(isolate); |
2184 | 2209 StackZone zone(isolate); |
| 2210 intptr_t buf_len = 0; |
2185 { | 2211 { |
2186 // Generate a list of strings from Dart code. | 2212 // Generate a list of strings from Dart code. |
| 2213 uint8_t* buf = GetSerialized(lib, "getStringList", &buf_len); |
2187 ApiNativeScope scope; | 2214 ApiNativeScope scope; |
2188 Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList"); | 2215 Dart_CObject* root = GetDeserialized(buf, buf_len); |
2189 EXPECT_NOTNULL(root); | 2216 EXPECT_NOTNULL(root); |
2190 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2217 EXPECT_EQ(Dart_CObject_kArray, root->type); |
2191 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2218 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
2192 for (int i = 0; i < kArrayLength; i++) { | 2219 for (int i = 0; i < kArrayLength; i++) { |
2193 Dart_CObject* element = root->value.as_array.values[i]; | 2220 Dart_CObject* element = root->value.as_array.values[i]; |
2194 EXPECT_EQ(root->value.as_array.values[0], element); | 2221 EXPECT_EQ(root->value.as_array.values[0], element); |
2195 EXPECT_EQ(Dart_CObject_kString, element->type); | 2222 EXPECT_EQ(Dart_CObject_kString, element->type); |
2196 EXPECT_STREQ("Hello, world!", element->value.as_string); | 2223 EXPECT_STREQ("Hello, world!", element->value.as_string); |
2197 } | 2224 } |
2198 } | 2225 } |
2199 { | 2226 { |
2200 // Generate a list of medium ints from Dart code. | 2227 // Generate a list of medium ints from Dart code. |
| 2228 uint8_t* buf = GetSerialized(lib, "getMintList", &buf_len); |
2201 ApiNativeScope scope; | 2229 ApiNativeScope scope; |
2202 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMintList"); | 2230 Dart_CObject* root = GetDeserialized(buf, buf_len); |
2203 EXPECT_NOTNULL(root); | 2231 EXPECT_NOTNULL(root); |
2204 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2232 EXPECT_EQ(Dart_CObject_kArray, root->type); |
2205 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2233 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
2206 for (int i = 0; i < kArrayLength; i++) { | 2234 for (int i = 0; i < kArrayLength; i++) { |
2207 Dart_CObject* element = root->value.as_array.values[i]; | 2235 Dart_CObject* element = root->value.as_array.values[i]; |
2208 EXPECT_EQ(root->value.as_array.values[0], element); | 2236 EXPECT_EQ(root->value.as_array.values[0], element); |
2209 EXPECT_EQ(Dart_CObject_kInt64, element->type); | 2237 EXPECT_EQ(Dart_CObject_kInt64, element->type); |
2210 EXPECT_EQ(DART_INT64_C(0x7FFFFFFFFFFFFFFF), element->value.as_int64); | 2238 EXPECT_EQ(DART_INT64_C(0x7FFFFFFFFFFFFFFF), element->value.as_int64); |
2211 } | 2239 } |
2212 } | 2240 } |
2213 { | 2241 { |
2214 // Generate a list of bigints from Dart code. | 2242 // Generate a list of bigints from Dart code. |
| 2243 uint8_t* buf = GetSerialized(lib, "getBigintList", &buf_len); |
2215 ApiNativeScope scope; | 2244 ApiNativeScope scope; |
2216 Dart_CObject* root = GetDeserializedDartMessage(lib, "getBigintList"); | 2245 Dart_CObject* root = GetDeserialized(buf, buf_len); |
2217 EXPECT_NOTNULL(root); | 2246 EXPECT_NOTNULL(root); |
2218 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2247 EXPECT_EQ(Dart_CObject_kArray, root->type); |
2219 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2248 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
2220 for (int i = 0; i < kArrayLength; i++) { | 2249 for (int i = 0; i < kArrayLength; i++) { |
2221 Dart_CObject* element = root->value.as_array.values[i]; | 2250 Dart_CObject* element = root->value.as_array.values[i]; |
2222 EXPECT_EQ(root->value.as_array.values[0], element); | 2251 EXPECT_EQ(root->value.as_array.values[0], element); |
2223 EXPECT_EQ(Dart_CObject_kBigint, element->type); | 2252 EXPECT_EQ(Dart_CObject_kBigint, element->type); |
2224 char* hex_value = TestCase::BigintToHexValue(element); | 2253 char* hex_value = TestCase::BigintToHexValue(element); |
2225 EXPECT_STREQ("0x1234567890123456789012345678901234567890", hex_value); | 2254 EXPECT_STREQ("0x1234567890123456789012345678901234567890", hex_value); |
2226 free(hex_value); | 2255 free(hex_value); |
2227 } | 2256 } |
2228 } | 2257 } |
2229 { | 2258 { |
2230 // Generate a list of doubles from Dart code. | 2259 // Generate a list of doubles from Dart code. |
| 2260 uint8_t* buf = GetSerialized(lib, "getDoubleList", &buf_len); |
2231 ApiNativeScope scope; | 2261 ApiNativeScope scope; |
2232 Dart_CObject* root = GetDeserializedDartMessage(lib, "getDoubleList"); | 2262 Dart_CObject* root = GetDeserialized(buf, buf_len); |
2233 EXPECT_NOTNULL(root); | 2263 EXPECT_NOTNULL(root); |
2234 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2264 EXPECT_EQ(Dart_CObject_kArray, root->type); |
2235 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2265 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
2236 Dart_CObject* element = root->value.as_array.values[0]; | 2266 Dart_CObject* element = root->value.as_array.values[0]; |
2237 EXPECT_EQ(Dart_CObject_kDouble, element->type); | 2267 EXPECT_EQ(Dart_CObject_kDouble, element->type); |
2238 EXPECT_EQ(3.14, element->value.as_double); | 2268 EXPECT_EQ(3.14, element->value.as_double); |
2239 for (int i = 1; i < kArrayLength; i++) { | 2269 for (int i = 1; i < kArrayLength; i++) { |
2240 element = root->value.as_array.values[i]; | 2270 element = root->value.as_array.values[i]; |
2241 // Double values are expected to not be canonicalized in messages. | 2271 // Double values are expected to not be canonicalized in messages. |
2242 EXPECT_NE(root->value.as_array.values[0], element); | 2272 EXPECT_NE(root->value.as_array.values[0], element); |
2243 EXPECT_EQ(Dart_CObject_kDouble, element->type); | 2273 EXPECT_EQ(Dart_CObject_kDouble, element->type); |
2244 EXPECT_EQ(3.14, element->value.as_double); | 2274 EXPECT_EQ(3.14, element->value.as_double); |
2245 } | 2275 } |
2246 } | 2276 } |
2247 { | 2277 { |
2248 // Generate a list of Uint8Lists from Dart code. | 2278 // Generate a list of Uint8Lists from Dart code. |
| 2279 uint8_t* buf = GetSerialized(lib, "getTypedDataList", &buf_len); |
2249 ApiNativeScope scope; | 2280 ApiNativeScope scope; |
2250 Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList"); | 2281 Dart_CObject* root = GetDeserialized(buf, buf_len); |
2251 EXPECT_NOTNULL(root); | 2282 EXPECT_NOTNULL(root); |
2252 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2283 EXPECT_EQ(Dart_CObject_kArray, root->type); |
2253 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2284 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
2254 for (int i = 0; i < kArrayLength; i++) { | 2285 for (int i = 0; i < kArrayLength; i++) { |
2255 Dart_CObject* element = root->value.as_array.values[i]; | 2286 Dart_CObject* element = root->value.as_array.values[i]; |
2256 EXPECT_EQ(root->value.as_array.values[0], element); | 2287 EXPECT_EQ(root->value.as_array.values[0], element); |
2257 EXPECT_EQ(Dart_CObject_kTypedData, element->type); | 2288 EXPECT_EQ(Dart_CObject_kTypedData, element->type); |
2258 EXPECT_EQ(Dart_TypedData_kUint8, element->value.as_typed_data.type); | 2289 EXPECT_EQ(Dart_TypedData_kUint8, element->value.as_typed_data.type); |
2259 EXPECT_EQ(256, element->value.as_typed_data.length); | 2290 EXPECT_EQ(256, element->value.as_typed_data.length); |
2260 } | 2291 } |
2261 } | 2292 } |
2262 { | 2293 { |
2263 // Generate a list of Uint8List views from Dart code. | 2294 // Generate a list of Uint8List views from Dart code. |
| 2295 uint8_t* buf = GetSerialized(lib, "getTypedDataViewList", &buf_len); |
2264 ApiNativeScope scope; | 2296 ApiNativeScope scope; |
2265 Dart_CObject* root = | 2297 Dart_CObject* root = GetDeserialized(buf, buf_len); |
2266 GetDeserializedDartMessage(lib, "getTypedDataViewList"); | |
2267 EXPECT_NOTNULL(root); | 2298 EXPECT_NOTNULL(root); |
2268 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2299 EXPECT_EQ(Dart_CObject_kArray, root->type); |
2269 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2300 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
2270 for (int i = 0; i < kArrayLength; i++) { | 2301 for (int i = 0; i < kArrayLength; i++) { |
2271 Dart_CObject* element = root->value.as_array.values[i]; | 2302 Dart_CObject* element = root->value.as_array.values[i]; |
2272 EXPECT_EQ(root->value.as_array.values[0], element); | 2303 EXPECT_EQ(root->value.as_array.values[0], element); |
2273 EXPECT_EQ(Dart_CObject_kTypedData, element->type); | 2304 EXPECT_EQ(Dart_CObject_kTypedData, element->type); |
2274 EXPECT_EQ(Dart_TypedData_kUint8, element->value.as_typed_data.type); | 2305 EXPECT_EQ(Dart_TypedData_kUint8, element->value.as_typed_data.type); |
2275 EXPECT_EQ(128, element->value.as_typed_data.length); | 2306 EXPECT_EQ(128, element->value.as_typed_data.length); |
2276 EXPECT_EQ(1, element->value.as_typed_data.values[0]); | 2307 EXPECT_EQ(1, element->value.as_typed_data.values[0]); |
2277 EXPECT_EQ(0, element->value.as_typed_data.values[1]); | 2308 EXPECT_EQ(0, element->value.as_typed_data.values[1]); |
2278 } | 2309 } |
2279 } | 2310 } |
2280 { | 2311 { |
2281 // Generate a list of objects of different types from Dart code. | 2312 // Generate a list of objects of different types from Dart code. |
| 2313 uint8_t* buf = GetSerialized(lib, "getMixedList", &buf_len); |
2282 ApiNativeScope scope; | 2314 ApiNativeScope scope; |
2283 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); | 2315 Dart_CObject* root = GetDeserialized(buf, buf_len); |
2284 EXPECT_NOTNULL(root); | 2316 EXPECT_NOTNULL(root); |
2285 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2317 EXPECT_EQ(Dart_CObject_kArray, root->type); |
2286 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2318 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
2287 Dart_CObject* element = root->value.as_array.values[0]; | 2319 Dart_CObject* element = root->value.as_array.values[0]; |
2288 EXPECT_EQ(Dart_CObject_kString, element->type); | 2320 EXPECT_EQ(Dart_CObject_kString, element->type); |
2289 EXPECT_STREQ("A", element->value.as_string); | 2321 EXPECT_STREQ("A", element->value.as_string); |
2290 element = root->value.as_array.values[1]; | 2322 element = root->value.as_array.values[1]; |
2291 EXPECT_EQ(Dart_CObject_kDouble, element->type); | 2323 EXPECT_EQ(Dart_CObject_kDouble, element->type); |
2292 EXPECT_STREQ(2.72, element->value.as_double); | 2324 EXPECT_STREQ(2.72, element->value.as_double); |
2293 for (int i = 2; i < kArrayLength; i++) { | 2325 for (int i = 2; i < kArrayLength; i++) { |
2294 element = root->value.as_array.values[i]; | 2326 element = root->value.as_array.values[i]; |
2295 if ((i % 2) == 0) { | 2327 if ((i % 2) == 0) { |
2296 EXPECT_EQ(root->value.as_array.values[0], element); | 2328 EXPECT_EQ(root->value.as_array.values[0], element); |
2297 EXPECT_EQ(Dart_CObject_kString, element->type); | 2329 EXPECT_EQ(Dart_CObject_kString, element->type); |
2298 EXPECT_STREQ("A", element->value.as_string); | 2330 EXPECT_STREQ("A", element->value.as_string); |
2299 } else { | 2331 } else { |
2300 // Double values are expected to not be canonicalized in messages. | 2332 // Double values are expected to not be canonicalized in messages. |
2301 EXPECT_NE(root->value.as_array.values[1], element); | 2333 EXPECT_NE(root->value.as_array.values[1], element); |
2302 EXPECT_EQ(Dart_CObject_kDouble, element->type); | 2334 EXPECT_EQ(Dart_CObject_kDouble, element->type); |
2303 EXPECT_STREQ(2.72, element->value.as_double); | 2335 EXPECT_STREQ(2.72, element->value.as_double); |
2304 } | 2336 } |
2305 } | 2337 } |
2306 } | 2338 } |
2307 { | 2339 { |
2308 // Generate a list of objects of different types from Dart code. | 2340 // Generate a list of objects of different types from Dart code. |
| 2341 uint8_t* buf = GetSerialized(lib, "getSelfRefList", &buf_len); |
2309 ApiNativeScope scope; | 2342 ApiNativeScope scope; |
2310 Dart_CObject* root = GetDeserializedDartMessage(lib, "getSelfRefList"); | 2343 Dart_CObject* root = GetDeserialized(buf, buf_len); |
2311 EXPECT_NOTNULL(root); | 2344 EXPECT_NOTNULL(root); |
2312 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2345 EXPECT_EQ(Dart_CObject_kArray, root->type); |
2313 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2346 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
2314 for (int i = 0; i < kArrayLength; i++) { | 2347 for (int i = 0; i < kArrayLength; i++) { |
2315 Dart_CObject* element = root->value.as_array.values[i]; | 2348 Dart_CObject* element = root->value.as_array.values[i]; |
2316 EXPECT_EQ(Dart_CObject_kArray, element->type); | 2349 EXPECT_EQ(Dart_CObject_kArray, element->type); |
2317 EXPECT_EQ(root, element); | 2350 EXPECT_EQ(root, element); |
2318 } | 2351 } |
2319 } | 2352 } |
2320 } | 2353 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2391 TestCase::CreateTestIsolate(); | 2424 TestCase::CreateTestIsolate(); |
2392 Isolate* isolate = Isolate::Current(); | 2425 Isolate* isolate = Isolate::Current(); |
2393 EXPECT(isolate != NULL); | 2426 EXPECT(isolate != NULL); |
2394 Dart_EnterScope(); | 2427 Dart_EnterScope(); |
2395 | 2428 |
2396 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2429 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
2397 EXPECT_VALID(lib); | 2430 EXPECT_VALID(lib); |
2398 | 2431 |
2399 { | 2432 { |
2400 DARTSCOPE(isolate); | 2433 DARTSCOPE(isolate); |
| 2434 StackZone zone(isolate); |
| 2435 intptr_t buf_len = 0; |
2401 { | 2436 { |
2402 // Generate a list of strings from Dart code. | 2437 // Generate a list of strings from Dart code. |
| 2438 uint8_t* buf = GetSerialized(lib, "getStringList", &buf_len); |
2403 ApiNativeScope scope; | 2439 ApiNativeScope scope; |
2404 Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList"); | 2440 Dart_CObject* root = GetDeserialized(buf, buf_len); |
2405 EXPECT_NOTNULL(root); | 2441 EXPECT_NOTNULL(root); |
2406 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2442 EXPECT_EQ(Dart_CObject_kArray, root->type); |
2407 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2443 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
2408 for (int i = 0; i < kArrayLength; i++) { | 2444 for (int i = 0; i < kArrayLength; i++) { |
2409 Dart_CObject* element = root->value.as_array.values[i]; | 2445 Dart_CObject* element = root->value.as_array.values[i]; |
2410 EXPECT_EQ(root->value.as_array.values[0], element); | 2446 EXPECT_EQ(root->value.as_array.values[0], element); |
2411 EXPECT_EQ(Dart_CObject_kString, element->type); | 2447 EXPECT_EQ(Dart_CObject_kString, element->type); |
2412 EXPECT_STREQ("Hello, world!", element->value.as_string); | 2448 EXPECT_STREQ("Hello, world!", element->value.as_string); |
2413 } | 2449 } |
2414 } | 2450 } |
2415 { | 2451 { |
2416 // Generate a list of medium ints from Dart code. | 2452 // Generate a list of medium ints from Dart code. |
| 2453 uint8_t* buf = GetSerialized(lib, "getMintList", &buf_len); |
2417 ApiNativeScope scope; | 2454 ApiNativeScope scope; |
2418 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMintList"); | 2455 Dart_CObject* root = GetDeserialized(buf, buf_len); |
2419 EXPECT_NOTNULL(root); | 2456 EXPECT_NOTNULL(root); |
2420 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2457 EXPECT_EQ(Dart_CObject_kArray, root->type); |
2421 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2458 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
2422 for (int i = 0; i < kArrayLength; i++) { | 2459 for (int i = 0; i < kArrayLength; i++) { |
2423 Dart_CObject* element = root->value.as_array.values[i]; | 2460 Dart_CObject* element = root->value.as_array.values[i]; |
2424 EXPECT_EQ(root->value.as_array.values[0], element); | 2461 EXPECT_EQ(root->value.as_array.values[0], element); |
2425 EXPECT_EQ(Dart_CObject_kInt64, element->type); | 2462 EXPECT_EQ(Dart_CObject_kInt64, element->type); |
2426 EXPECT_EQ(DART_INT64_C(0x7FFFFFFFFFFFFFFF), element->value.as_int64); | 2463 EXPECT_EQ(DART_INT64_C(0x7FFFFFFFFFFFFFFF), element->value.as_int64); |
2427 } | 2464 } |
2428 } | 2465 } |
2429 { | 2466 { |
2430 // Generate a list of bigints from Dart code. | 2467 // Generate a list of bigints from Dart code. |
| 2468 uint8_t* buf = GetSerialized(lib, "getBigintList", &buf_len); |
2431 ApiNativeScope scope; | 2469 ApiNativeScope scope; |
2432 Dart_CObject* root = GetDeserializedDartMessage(lib, "getBigintList"); | 2470 Dart_CObject* root = GetDeserialized(buf, buf_len); |
2433 EXPECT_NOTNULL(root); | 2471 EXPECT_NOTNULL(root); |
2434 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2472 EXPECT_EQ(Dart_CObject_kArray, root->type); |
2435 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2473 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
2436 for (int i = 0; i < kArrayLength; i++) { | 2474 for (int i = 0; i < kArrayLength; i++) { |
2437 Dart_CObject* element = root->value.as_array.values[i]; | 2475 Dart_CObject* element = root->value.as_array.values[i]; |
2438 EXPECT_EQ(root->value.as_array.values[0], element); | 2476 EXPECT_EQ(root->value.as_array.values[0], element); |
2439 EXPECT_EQ(Dart_CObject_kBigint, element->type); | 2477 EXPECT_EQ(Dart_CObject_kBigint, element->type); |
2440 char* hex_value = TestCase::BigintToHexValue(element); | 2478 char* hex_value = TestCase::BigintToHexValue(element); |
2441 EXPECT_STREQ("0x1234567890123456789012345678901234567890", hex_value); | 2479 EXPECT_STREQ("0x1234567890123456789012345678901234567890", hex_value); |
2442 free(hex_value); | 2480 free(hex_value); |
2443 } | 2481 } |
2444 } | 2482 } |
2445 { | 2483 { |
2446 // Generate a list of doubles from Dart code. | 2484 // Generate a list of doubles from Dart code. |
| 2485 uint8_t* buf = GetSerialized(lib, "getDoubleList", &buf_len); |
2447 ApiNativeScope scope; | 2486 ApiNativeScope scope; |
2448 Dart_CObject* root = GetDeserializedDartMessage(lib, "getDoubleList"); | 2487 Dart_CObject* root = GetDeserialized(buf, buf_len); |
2449 EXPECT_NOTNULL(root); | 2488 EXPECT_NOTNULL(root); |
2450 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2489 EXPECT_EQ(Dart_CObject_kArray, root->type); |
2451 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2490 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
2452 Dart_CObject* element = root->value.as_array.values[0]; | 2491 Dart_CObject* element = root->value.as_array.values[0]; |
2453 // Double values are expected to not be canonicalized in messages. | 2492 // Double values are expected to not be canonicalized in messages. |
2454 EXPECT_EQ(Dart_CObject_kDouble, element->type); | 2493 EXPECT_EQ(Dart_CObject_kDouble, element->type); |
2455 EXPECT_EQ(3.14, element->value.as_double); | 2494 EXPECT_EQ(3.14, element->value.as_double); |
2456 for (int i = 1; i < kArrayLength; i++) { | 2495 for (int i = 1; i < kArrayLength; i++) { |
2457 element = root->value.as_array.values[i]; | 2496 element = root->value.as_array.values[i]; |
2458 // Double values are expected to not be canonicalized in messages. | 2497 // Double values are expected to not be canonicalized in messages. |
2459 EXPECT_NE(root->value.as_array.values[0], element); | 2498 EXPECT_NE(root->value.as_array.values[0], element); |
2460 EXPECT_EQ(Dart_CObject_kDouble, element->type); | 2499 EXPECT_EQ(Dart_CObject_kDouble, element->type); |
2461 EXPECT_EQ(3.14, element->value.as_double); | 2500 EXPECT_EQ(3.14, element->value.as_double); |
2462 } | 2501 } |
2463 } | 2502 } |
2464 { | 2503 { |
2465 // Generate a list of Uint8Lists from Dart code. | 2504 // Generate a list of Uint8Lists from Dart code. |
| 2505 uint8_t* buf = GetSerialized(lib, "getTypedDataList", &buf_len); |
2466 ApiNativeScope scope; | 2506 ApiNativeScope scope; |
2467 Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList"); | 2507 Dart_CObject* root = GetDeserialized(buf, buf_len); |
2468 EXPECT_NOTNULL(root); | 2508 EXPECT_NOTNULL(root); |
2469 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2509 EXPECT_EQ(Dart_CObject_kArray, root->type); |
2470 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2510 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
2471 for (int i = 0; i < kArrayLength; i++) { | 2511 for (int i = 0; i < kArrayLength; i++) { |
2472 Dart_CObject* element = root->value.as_array.values[i]; | 2512 Dart_CObject* element = root->value.as_array.values[i]; |
2473 EXPECT_EQ(root->value.as_array.values[0], element); | 2513 EXPECT_EQ(root->value.as_array.values[0], element); |
2474 EXPECT_EQ(Dart_CObject_kTypedData, element->type); | 2514 EXPECT_EQ(Dart_CObject_kTypedData, element->type); |
2475 EXPECT_EQ(Dart_TypedData_kUint8, element->value.as_typed_data.type); | 2515 EXPECT_EQ(Dart_TypedData_kUint8, element->value.as_typed_data.type); |
2476 EXPECT_EQ(256, element->value.as_typed_data.length); | 2516 EXPECT_EQ(256, element->value.as_typed_data.length); |
2477 } | 2517 } |
2478 } | 2518 } |
2479 { | 2519 { |
2480 // Generate a list of Uint8List views from Dart code. | 2520 // Generate a list of Uint8List views from Dart code. |
| 2521 uint8_t* buf = GetSerialized(lib, "getTypedDataViewList", &buf_len); |
2481 ApiNativeScope scope; | 2522 ApiNativeScope scope; |
2482 Dart_CObject* root = | 2523 Dart_CObject* root = GetDeserialized(buf, buf_len); |
2483 GetDeserializedDartMessage(lib, "getTypedDataViewList"); | |
2484 EXPECT_NOTNULL(root); | 2524 EXPECT_NOTNULL(root); |
2485 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2525 EXPECT_EQ(Dart_CObject_kArray, root->type); |
2486 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2526 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
2487 for (int i = 0; i < kArrayLength; i++) { | 2527 for (int i = 0; i < kArrayLength; i++) { |
2488 Dart_CObject* element = root->value.as_array.values[i]; | 2528 Dart_CObject* element = root->value.as_array.values[i]; |
2489 EXPECT_EQ(root->value.as_array.values[0], element); | 2529 EXPECT_EQ(root->value.as_array.values[0], element); |
2490 EXPECT_EQ(Dart_CObject_kTypedData, element->type); | 2530 EXPECT_EQ(Dart_CObject_kTypedData, element->type); |
2491 EXPECT_EQ(Dart_TypedData_kUint8, element->value.as_typed_data.type); | 2531 EXPECT_EQ(Dart_TypedData_kUint8, element->value.as_typed_data.type); |
2492 EXPECT_EQ(128, element->value.as_typed_data.length); | 2532 EXPECT_EQ(128, element->value.as_typed_data.length); |
2493 EXPECT_EQ(1, element->value.as_typed_data.values[0]); | 2533 EXPECT_EQ(1, element->value.as_typed_data.values[0]); |
2494 EXPECT_EQ(0, element->value.as_typed_data.values[1]); | 2534 EXPECT_EQ(0, element->value.as_typed_data.values[1]); |
2495 } | 2535 } |
2496 } | 2536 } |
2497 { | 2537 { |
2498 // Generate a list of objects of different types from Dart code. | 2538 // Generate a list of objects of different types from Dart code. |
| 2539 uint8_t* buf = GetSerialized(lib, "getMixedList", &buf_len); |
2499 ApiNativeScope scope; | 2540 ApiNativeScope scope; |
2500 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); | 2541 Dart_CObject* root = GetDeserialized(buf, buf_len); |
2501 EXPECT_NOTNULL(root); | 2542 EXPECT_NOTNULL(root); |
2502 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2543 EXPECT_EQ(Dart_CObject_kArray, root->type); |
2503 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2544 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
2504 Dart_CObject* element = root->value.as_array.values[0]; | 2545 Dart_CObject* element = root->value.as_array.values[0]; |
2505 EXPECT_EQ(Dart_CObject_kString, element->type); | 2546 EXPECT_EQ(Dart_CObject_kString, element->type); |
2506 EXPECT_STREQ(".", element->value.as_string); | 2547 EXPECT_STREQ(".", element->value.as_string); |
2507 element = root->value.as_array.values[1]; | 2548 element = root->value.as_array.values[1]; |
2508 EXPECT_EQ(Dart_CObject_kDouble, element->type); | 2549 EXPECT_EQ(Dart_CObject_kDouble, element->type); |
2509 EXPECT_STREQ(2.72, element->value.as_double); | 2550 EXPECT_STREQ(2.72, element->value.as_double); |
2510 for (int i = 2; i < kArrayLength; i++) { | 2551 for (int i = 2; i < kArrayLength; i++) { |
2511 Dart_CObject* element = root->value.as_array.values[i]; | 2552 Dart_CObject* element = root->value.as_array.values[i]; |
2512 if ((i % 2) == 0) { | 2553 if ((i % 2) == 0) { |
2513 EXPECT_EQ(root->value.as_array.values[0], element); | 2554 EXPECT_EQ(root->value.as_array.values[0], element); |
2514 EXPECT_EQ(Dart_CObject_kString, element->type); | 2555 EXPECT_EQ(Dart_CObject_kString, element->type); |
2515 EXPECT_STREQ(".", element->value.as_string); | 2556 EXPECT_STREQ(".", element->value.as_string); |
2516 } else { | 2557 } else { |
2517 // Double values are expected to not be canonicalized in messages. | 2558 // Double values are expected to not be canonicalized in messages. |
2518 EXPECT_NE(root->value.as_array.values[1], element); | 2559 EXPECT_NE(root->value.as_array.values[1], element); |
2519 EXPECT_EQ(Dart_CObject_kDouble, element->type); | 2560 EXPECT_EQ(Dart_CObject_kDouble, element->type); |
2520 EXPECT_STREQ(2.72, element->value.as_double); | 2561 EXPECT_STREQ(2.72, element->value.as_double); |
2521 } | 2562 } |
2522 } | 2563 } |
2523 } | 2564 } |
2524 { | 2565 { |
2525 // Generate a list of objects of different types from Dart code. | 2566 // Generate a list of objects of different types from Dart code. |
| 2567 uint8_t* buf = GetSerialized(lib, "getSelfRefList", &buf_len); |
2526 ApiNativeScope scope; | 2568 ApiNativeScope scope; |
2527 Dart_CObject* root = GetDeserializedDartMessage(lib, "getSelfRefList"); | 2569 Dart_CObject* root = GetDeserialized(buf, buf_len); |
2528 EXPECT_NOTNULL(root); | 2570 EXPECT_NOTNULL(root); |
2529 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2571 EXPECT_EQ(Dart_CObject_kArray, root->type); |
2530 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2572 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
2531 for (int i = 0; i < kArrayLength; i++) { | 2573 for (int i = 0; i < kArrayLength; i++) { |
2532 Dart_CObject* element = root->value.as_array.values[i]; | 2574 Dart_CObject* element = root->value.as_array.values[i]; |
2533 EXPECT_EQ(Dart_CObject_kArray, element->type); | 2575 EXPECT_EQ(Dart_CObject_kArray, element->type); |
2534 EXPECT_EQ(root, element); | 2576 EXPECT_EQ(root, element); |
2535 } | 2577 } |
2536 } | 2578 } |
2537 } | 2579 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2623 TestCase::CreateTestIsolate(); | 2665 TestCase::CreateTestIsolate(); |
2624 Isolate* isolate = Isolate::Current(); | 2666 Isolate* isolate = Isolate::Current(); |
2625 EXPECT(isolate != NULL); | 2667 EXPECT(isolate != NULL); |
2626 Dart_EnterScope(); | 2668 Dart_EnterScope(); |
2627 | 2669 |
2628 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2670 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
2629 EXPECT_VALID(lib); | 2671 EXPECT_VALID(lib); |
2630 | 2672 |
2631 { | 2673 { |
2632 DARTSCOPE(isolate); | 2674 DARTSCOPE(isolate); |
| 2675 StackZone zone(isolate); |
| 2676 intptr_t buf_len = 0; |
2633 { | 2677 { |
2634 // Generate a list of Uint8Lists from Dart code. | 2678 // Generate a list of Uint8Lists from Dart code. |
| 2679 uint8_t* buf = GetSerialized(lib, "getTypedDataList", &buf_len); |
2635 ApiNativeScope scope; | 2680 ApiNativeScope scope; |
2636 Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList"); | 2681 Dart_CObject* root = GetDeserialized(buf, buf_len); |
2637 EXPECT_NOTNULL(root); | 2682 EXPECT_NOTNULL(root); |
2638 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2683 EXPECT_EQ(Dart_CObject_kArray, root->type); |
2639 struct { | 2684 struct { |
2640 Dart_TypedData_Type type; | 2685 Dart_TypedData_Type type; |
2641 int size; | 2686 int size; |
2642 } expected[] = { | 2687 } expected[] = { |
2643 { Dart_TypedData_kInt8, 256}, | 2688 { Dart_TypedData_kInt8, 256}, |
2644 { Dart_TypedData_kUint8, 256}, | 2689 { Dart_TypedData_kUint8, 256}, |
2645 { Dart_TypedData_kInt16, 512}, | 2690 { Dart_TypedData_kInt16, 512}, |
2646 { Dart_TypedData_kUint16, 512}, | 2691 { Dart_TypedData_kUint16, 512}, |
(...skipping 10 matching lines...) Expand all Loading... |
2657 while (expected[i].type != Dart_TypedData_kInvalid) { | 2702 while (expected[i].type != Dart_TypedData_kInvalid) { |
2658 CheckTypedData(root->value.as_array.values[i], | 2703 CheckTypedData(root->value.as_array.values[i], |
2659 expected[i].type, | 2704 expected[i].type, |
2660 expected[i].size); | 2705 expected[i].size); |
2661 i++; | 2706 i++; |
2662 } | 2707 } |
2663 EXPECT_EQ(i, root->value.as_array.length); | 2708 EXPECT_EQ(i, root->value.as_array.length); |
2664 } | 2709 } |
2665 { | 2710 { |
2666 // Generate a list of Uint8List views from Dart code. | 2711 // Generate a list of Uint8List views from Dart code. |
2667 | 2712 uint8_t* buf = GetSerialized(lib, "getTypedDataViewList", &buf_len); |
2668 ApiNativeScope scope; | 2713 ApiNativeScope scope; |
2669 Dart_CObject* root = | 2714 Dart_CObject* root = GetDeserialized(buf, buf_len); |
2670 GetDeserializedDartMessage(lib, "getTypedDataViewList"); | |
2671 EXPECT_NOTNULL(root); | 2715 EXPECT_NOTNULL(root); |
2672 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2716 EXPECT_EQ(Dart_CObject_kArray, root->type); |
2673 struct { | 2717 struct { |
2674 Dart_TypedData_Type type; | 2718 Dart_TypedData_Type type; |
2675 int size; | 2719 int size; |
2676 } expected[] = { | 2720 } expected[] = { |
2677 { Dart_TypedData_kInt8, 256}, | 2721 { Dart_TypedData_kInt8, 256}, |
2678 { Dart_TypedData_kUint8, 256}, | 2722 { Dart_TypedData_kUint8, 256}, |
2679 { Dart_TypedData_kInt16, 512}, | 2723 { Dart_TypedData_kInt16, 512}, |
2680 { Dart_TypedData_kUint16, 512}, | 2724 { Dart_TypedData_kUint16, 512}, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2714 while (expected[i].type != Dart_TypedData_kInvalid) { | 2758 while (expected[i].type != Dart_TypedData_kInvalid) { |
2715 CheckTypedData(root->value.as_array.values[i], | 2759 CheckTypedData(root->value.as_array.values[i], |
2716 expected[i].type, | 2760 expected[i].type, |
2717 expected[i].size); | 2761 expected[i].size); |
2718 i++; | 2762 i++; |
2719 } | 2763 } |
2720 EXPECT_EQ(i, root->value.as_array.length); | 2764 EXPECT_EQ(i, root->value.as_array.length); |
2721 } | 2765 } |
2722 { | 2766 { |
2723 // Generate a list of Uint8Lists from Dart code. | 2767 // Generate a list of Uint8Lists from Dart code. |
| 2768 uint8_t* buf = |
| 2769 GetSerialized(lib, "getMultipleTypedDataViewList", &buf_len); |
2724 ApiNativeScope scope; | 2770 ApiNativeScope scope; |
2725 Dart_CObject* root = | 2771 Dart_CObject* root = GetDeserialized(buf, buf_len); |
2726 GetDeserializedDartMessage(lib, "getMultipleTypedDataViewList"); | |
2727 EXPECT_NOTNULL(root); | 2772 EXPECT_NOTNULL(root); |
2728 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2773 EXPECT_EQ(Dart_CObject_kArray, root->type); |
2729 struct { | 2774 struct { |
2730 Dart_TypedData_Type type; | 2775 Dart_TypedData_Type type; |
2731 int size; | 2776 int size; |
2732 } expected[] = { | 2777 } expected[] = { |
2733 { Dart_TypedData_kInt8, 256}, | 2778 { Dart_TypedData_kInt8, 256}, |
2734 { Dart_TypedData_kUint8, 256}, | 2779 { Dart_TypedData_kUint8, 256}, |
2735 { Dart_TypedData_kInt16, 256}, | 2780 { Dart_TypedData_kInt16, 256}, |
2736 { Dart_TypedData_kUint16, 256}, | 2781 { Dart_TypedData_kUint16, 256}, |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2862 StackZone zone(Isolate::Current()); | 2907 StackZone zone(Isolate::Current()); |
2863 uint8_t* buffer; | 2908 uint8_t* buffer; |
2864 MessageWriter writer(&buffer, &zone_allocator, true); | 2909 MessageWriter writer(&buffer, &zone_allocator, true); |
2865 writer.WriteInlinedObjectHeader(kOmittedObjectId); | 2910 writer.WriteInlinedObjectHeader(kOmittedObjectId); |
2866 // For performance, we'd like single-byte headers when ids are omitted. | 2911 // For performance, we'd like single-byte headers when ids are omitted. |
2867 // If this starts failing, consider renumbering the snapshot ids. | 2912 // If this starts failing, consider renumbering the snapshot ids. |
2868 EXPECT_EQ(1, writer.BytesWritten()); | 2913 EXPECT_EQ(1, writer.BytesWritten()); |
2869 } | 2914 } |
2870 | 2915 |
2871 } // namespace dart | 2916 } // namespace dart |
OLD | NEW |