Chromium Code Reviews| 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_debugger_api.h" | 7 #include "include/dart_debugger_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 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1581 EXPECT_EQ(Dart_CObject_kInt32, element->type); | 1588 EXPECT_EQ(Dart_CObject_kInt32, element->type); |
| 1582 EXPECT_EQ(i + 1, element->value.as_int32); | 1589 EXPECT_EQ(i + 1, element->value.as_int32); |
| 1583 } | 1590 } |
| 1584 CheckEncodeDecodeMessage(root); | 1591 CheckEncodeDecodeMessage(root); |
| 1585 } | 1592 } |
| 1586 | 1593 |
| 1587 | 1594 |
| 1588 // Helper function to call a top level Dart function, serialize the | 1595 // Helper function to call a top level Dart function, serialize the |
| 1589 // result and deserialize the result into a Dart_CObject structure. | 1596 // result and deserialize the result into a Dart_CObject structure. |
| 1590 static Dart_CObject* GetDeserializedDartMessage(Dart_Handle lib, | 1597 static Dart_CObject* GetDeserializedDartMessage(Dart_Handle lib, |
| 1591 const char* dart_function) { | 1598 const char* dart_function, |
| 1599 Object* tmp_handle) { | |
|
siva
2015/06/19 23:30:46
Why is it not Ok to allocate the StackZone here in
koda
2015/06/22 17:18:51
That would make the return value a dangling pointe
| |
| 1592 Dart_Handle result; | 1600 Dart_Handle result; |
| 1593 result = Dart_Invoke(lib, NewString(dart_function), 0, NULL); | 1601 result = Dart_Invoke(lib, NewString(dart_function), 0, NULL); |
| 1594 EXPECT_VALID(result); | 1602 EXPECT_VALID(result); |
| 1595 | 1603 |
| 1596 // Serialize the list into a message. | 1604 // Serialize the list into a message. |
| 1597 uint8_t* buffer; | 1605 uint8_t* buffer; |
| 1598 MessageWriter writer(&buffer, &zone_allocator, false); | 1606 MessageWriter writer(&buffer, &zone_allocator, false); |
| 1599 const Object& list = Object::Handle(Api::UnwrapHandle(result)); | 1607 *tmp_handle = Api::UnwrapHandle(result); |
| 1600 writer.WriteMessage(list); | 1608 writer.WriteMessage(*tmp_handle); |
| 1601 intptr_t buffer_len = writer.BytesWritten(); | 1609 intptr_t buffer_len = writer.BytesWritten(); |
| 1602 | 1610 |
| 1603 // Read object back from the snapshot into a C structure. | 1611 // Read object back from the snapshot into a C structure. |
| 1604 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); | 1612 ApiMessageReader api_reader(buffer, buffer_len, &zone_allocator); |
| 1605 return api_reader.ReadMessage(); | 1613 return api_reader.ReadMessage(); |
| 1606 } | 1614 } |
| 1607 | 1615 |
| 1608 | 1616 |
| 1609 static void CheckString(Dart_Handle dart_string, const char* expected) { | 1617 static void CheckString(Dart_Handle dart_string, const char* expected) { |
| 1610 StackZone zone(Isolate::Current()); | 1618 StackZone zone(Isolate::Current()); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1820 TestCase::CreateTestIsolate(); | 1828 TestCase::CreateTestIsolate(); |
| 1821 Isolate* isolate = Isolate::Current(); | 1829 Isolate* isolate = Isolate::Current(); |
| 1822 EXPECT(isolate != NULL); | 1830 EXPECT(isolate != NULL); |
| 1823 Dart_EnterScope(); | 1831 Dart_EnterScope(); |
| 1824 | 1832 |
| 1825 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 1833 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 1826 EXPECT_VALID(lib); | 1834 EXPECT_VALID(lib); |
| 1827 | 1835 |
| 1828 { | 1836 { |
| 1829 DARTSCOPE(isolate); | 1837 DARTSCOPE(isolate); |
| 1838 StackZone zone(isolate); | |
| 1839 Object& tmp = Object::Handle(); | |
| 1830 { | 1840 { |
| 1831 // Generate a list of nulls from Dart code. | 1841 // Generate a list of nulls from Dart code. |
| 1832 ApiNativeScope scope; | 1842 ApiNativeScope scope; |
| 1833 Dart_CObject* root = GetDeserializedDartMessage(lib, "getList"); | 1843 Dart_CObject* root = GetDeserializedDartMessage(lib, "getList", &tmp); |
| 1834 EXPECT_NOTNULL(root); | 1844 EXPECT_NOTNULL(root); |
| 1835 EXPECT_EQ(Dart_CObject_kArray, root->type); | 1845 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 1836 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1846 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 1837 for (int i = 0; i < kArrayLength; i++) { | 1847 for (int i = 0; i < kArrayLength; i++) { |
| 1838 EXPECT_EQ(Dart_CObject_kNull, root->value.as_array.values[i]->type); | 1848 EXPECT_EQ(Dart_CObject_kNull, root->value.as_array.values[i]->type); |
| 1839 } | 1849 } |
| 1840 CheckEncodeDecodeMessage(root); | 1850 CheckEncodeDecodeMessage(root); |
| 1841 } | 1851 } |
| 1842 { | 1852 { |
| 1843 // Generate a list of ints from Dart code. | 1853 // Generate a list of ints from Dart code. |
| 1844 ApiNativeScope scope; | 1854 ApiNativeScope scope; |
| 1845 Dart_CObject* root = GetDeserializedDartMessage(lib, "getIntList"); | 1855 Dart_CObject* root = GetDeserializedDartMessage(lib, "getIntList", &tmp); |
| 1846 EXPECT_NOTNULL(root); | 1856 EXPECT_NOTNULL(root); |
| 1847 EXPECT_EQ(Dart_CObject_kArray, root->type); | 1857 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 1848 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1858 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 1849 for (int i = 0; i < kArrayLength; i++) { | 1859 for (int i = 0; i < kArrayLength; i++) { |
| 1850 EXPECT_EQ(Dart_CObject_kInt32, root->value.as_array.values[i]->type); | 1860 EXPECT_EQ(Dart_CObject_kInt32, root->value.as_array.values[i]->type); |
| 1851 EXPECT_EQ(i, root->value.as_array.values[i]->value.as_int32); | 1861 EXPECT_EQ(i, root->value.as_array.values[i]->value.as_int32); |
| 1852 } | 1862 } |
| 1853 CheckEncodeDecodeMessage(root); | 1863 CheckEncodeDecodeMessage(root); |
| 1854 } | 1864 } |
| 1855 { | 1865 { |
| 1856 // Generate a list of strings from Dart code. | 1866 // Generate a list of strings from Dart code. |
| 1857 ApiNativeScope scope; | 1867 ApiNativeScope scope; |
| 1858 Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList"); | 1868 Dart_CObject* root = |
| 1869 GetDeserializedDartMessage(lib, "getStringList", &tmp); | |
| 1859 EXPECT_NOTNULL(root); | 1870 EXPECT_NOTNULL(root); |
| 1860 EXPECT_EQ(Dart_CObject_kArray, root->type); | 1871 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 1861 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1872 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 1862 for (int i = 0; i < kArrayLength; i++) { | 1873 for (int i = 0; i < kArrayLength; i++) { |
| 1863 EXPECT_EQ(Dart_CObject_kString, root->value.as_array.values[i]->type); | 1874 EXPECT_EQ(Dart_CObject_kString, root->value.as_array.values[i]->type); |
| 1864 char buffer[3]; | 1875 char buffer[3]; |
| 1865 snprintf(buffer, sizeof(buffer), "%d", i); | 1876 snprintf(buffer, sizeof(buffer), "%d", i); |
| 1866 EXPECT_STREQ(buffer, root->value.as_array.values[i]->value.as_string); | 1877 EXPECT_STREQ(buffer, root->value.as_array.values[i]->value.as_string); |
| 1867 } | 1878 } |
| 1868 } | 1879 } |
| 1869 { | 1880 { |
| 1870 // Generate a list of objects of different types from Dart code. | 1881 // Generate a list of objects of different types from Dart code. |
| 1871 ApiNativeScope scope; | 1882 ApiNativeScope scope; |
| 1872 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); | 1883 Dart_CObject* root = |
| 1884 GetDeserializedDartMessage(lib, "getMixedList", &tmp); | |
| 1873 EXPECT_NOTNULL(root); | 1885 EXPECT_NOTNULL(root); |
| 1874 EXPECT_EQ(Dart_CObject_kArray, root->type); | 1886 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 1875 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1887 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 1876 | 1888 |
| 1877 EXPECT_EQ(Dart_CObject_kInt32, root->value.as_array.values[0]->type); | 1889 EXPECT_EQ(Dart_CObject_kInt32, root->value.as_array.values[0]->type); |
| 1878 EXPECT_EQ(0, root->value.as_array.values[0]->value.as_int32); | 1890 EXPECT_EQ(0, root->value.as_array.values[0]->value.as_int32); |
| 1879 EXPECT_EQ(Dart_CObject_kString, root->value.as_array.values[1]->type); | 1891 EXPECT_EQ(Dart_CObject_kString, root->value.as_array.values[1]->type); |
| 1880 EXPECT_STREQ("1", root->value.as_array.values[1]->value.as_string); | 1892 EXPECT_STREQ("1", root->value.as_array.values[1]->value.as_string); |
| 1881 EXPECT_EQ(Dart_CObject_kDouble, root->value.as_array.values[2]->type); | 1893 EXPECT_EQ(Dart_CObject_kDouble, root->value.as_array.values[2]->type); |
| 1882 EXPECT_EQ(2.2, root->value.as_array.values[2]->value.as_double); | 1894 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... | |
| 1938 TestCase::CreateTestIsolate(); | 1950 TestCase::CreateTestIsolate(); |
| 1939 Isolate* isolate = Isolate::Current(); | 1951 Isolate* isolate = Isolate::Current(); |
| 1940 EXPECT(isolate != NULL); | 1952 EXPECT(isolate != NULL); |
| 1941 Dart_EnterScope(); | 1953 Dart_EnterScope(); |
| 1942 | 1954 |
| 1943 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 1955 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 1944 EXPECT_VALID(lib); | 1956 EXPECT_VALID(lib); |
| 1945 | 1957 |
| 1946 { | 1958 { |
| 1947 DARTSCOPE(isolate); | 1959 DARTSCOPE(isolate); |
| 1960 StackZone zone(isolate); | |
| 1961 Object& tmp = Object::Handle(); | |
| 1948 { | 1962 { |
| 1949 // Generate a list of nulls from Dart code. | 1963 // Generate a list of nulls from Dart code. |
| 1950 ApiNativeScope scope; | 1964 ApiNativeScope scope; |
| 1951 Dart_CObject* root = GetDeserializedDartMessage(lib, "getList"); | 1965 Dart_CObject* root = GetDeserializedDartMessage(lib, "getList", &tmp); |
| 1952 EXPECT_NOTNULL(root); | 1966 EXPECT_NOTNULL(root); |
| 1953 EXPECT_EQ(Dart_CObject_kArray, root->type); | 1967 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 1954 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1968 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 1955 for (int i = 0; i < kArrayLength; i++) { | 1969 for (int i = 0; i < kArrayLength; i++) { |
| 1956 EXPECT_EQ(Dart_CObject_kNull, root->value.as_array.values[i]->type); | 1970 EXPECT_EQ(Dart_CObject_kNull, root->value.as_array.values[i]->type); |
| 1957 } | 1971 } |
| 1958 CheckEncodeDecodeMessage(root); | 1972 CheckEncodeDecodeMessage(root); |
| 1959 } | 1973 } |
| 1960 { | 1974 { |
| 1961 // Generate a list of ints from Dart code. | 1975 // Generate a list of ints from Dart code. |
| 1962 ApiNativeScope scope; | 1976 ApiNativeScope scope; |
| 1963 Dart_CObject* root = GetDeserializedDartMessage(lib, "getIntList"); | 1977 Dart_CObject* root = |
| 1978 GetDeserializedDartMessage(lib, "getIntList", &tmp); | |
| 1964 EXPECT_NOTNULL(root); | 1979 EXPECT_NOTNULL(root); |
| 1965 EXPECT_EQ(Dart_CObject_kArray, root->type); | 1980 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 1966 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1981 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 1967 for (int i = 0; i < kArrayLength; i++) { | 1982 for (int i = 0; i < kArrayLength; i++) { |
| 1968 EXPECT_EQ(Dart_CObject_kInt32, root->value.as_array.values[i]->type); | 1983 EXPECT_EQ(Dart_CObject_kInt32, root->value.as_array.values[i]->type); |
| 1969 EXPECT_EQ(i, root->value.as_array.values[i]->value.as_int32); | 1984 EXPECT_EQ(i, root->value.as_array.values[i]->value.as_int32); |
| 1970 } | 1985 } |
| 1971 CheckEncodeDecodeMessage(root); | 1986 CheckEncodeDecodeMessage(root); |
| 1972 } | 1987 } |
| 1973 { | 1988 { |
| 1974 // Generate a list of strings from Dart code. | 1989 // Generate a list of strings from Dart code. |
| 1975 ApiNativeScope scope; | 1990 ApiNativeScope scope; |
| 1976 Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList"); | 1991 Dart_CObject* root = |
| 1992 GetDeserializedDartMessage(lib, "getStringList", &tmp); | |
| 1977 EXPECT_NOTNULL(root); | 1993 EXPECT_NOTNULL(root); |
| 1978 EXPECT_EQ(Dart_CObject_kArray, root->type); | 1994 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 1979 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 1995 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 1980 for (int i = 0; i < kArrayLength; i++) { | 1996 for (int i = 0; i < kArrayLength; i++) { |
| 1981 EXPECT_EQ(Dart_CObject_kString, root->value.as_array.values[i]->type); | 1997 EXPECT_EQ(Dart_CObject_kString, root->value.as_array.values[i]->type); |
| 1982 char buffer[3]; | 1998 char buffer[3]; |
| 1983 snprintf(buffer, sizeof(buffer), "%d", i); | 1999 snprintf(buffer, sizeof(buffer), "%d", i); |
| 1984 EXPECT_STREQ(buffer, root->value.as_array.values[i]->value.as_string); | 2000 EXPECT_STREQ(buffer, root->value.as_array.values[i]->value.as_string); |
| 1985 } | 2001 } |
| 1986 } | 2002 } |
| 1987 { | 2003 { |
| 1988 // Generate a list of lists from Dart code. | 2004 // Generate a list of lists from Dart code. |
| 1989 ApiNativeScope scope; | 2005 ApiNativeScope scope; |
| 1990 Dart_CObject* root = GetDeserializedDartMessage(lib, "getListList"); | 2006 Dart_CObject* root = |
| 2007 GetDeserializedDartMessage(lib, "getListList", &tmp); | |
| 1991 EXPECT_NOTNULL(root); | 2008 EXPECT_NOTNULL(root); |
| 1992 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2009 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 1993 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2010 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 1994 for (int i = 0; i < kArrayLength; i++) { | 2011 for (int i = 0; i < kArrayLength; i++) { |
| 1995 Dart_CObject* element = root->value.as_array.values[i]; | 2012 Dart_CObject* element = root->value.as_array.values[i]; |
| 1996 EXPECT_EQ(Dart_CObject_kArray, element->type); | 2013 EXPECT_EQ(Dart_CObject_kArray, element->type); |
| 1997 EXPECT_EQ(i, element->value.as_array.length); | 2014 EXPECT_EQ(i, element->value.as_array.length); |
| 1998 for (int j = 0; j < i; j++) { | 2015 for (int j = 0; j < i; j++) { |
| 1999 EXPECT_EQ(Dart_CObject_kInt32, | 2016 EXPECT_EQ(Dart_CObject_kInt32, |
| 2000 element->value.as_array.values[j]->type); | 2017 element->value.as_array.values[j]->type); |
| 2001 EXPECT_EQ(j, element->value.as_array.values[j]->value.as_int32); | 2018 EXPECT_EQ(j, element->value.as_array.values[j]->value.as_int32); |
| 2002 } | 2019 } |
| 2003 } | 2020 } |
| 2004 } | 2021 } |
| 2005 { | 2022 { |
| 2006 // Generate a list of objects of different types from Dart code. | 2023 // Generate a list of objects of different types from Dart code. |
| 2007 ApiNativeScope scope; | 2024 ApiNativeScope scope; |
| 2008 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); | 2025 Dart_CObject* root = |
| 2026 GetDeserializedDartMessage(lib, "getMixedList", &tmp); | |
| 2009 EXPECT_NOTNULL(root); | 2027 EXPECT_NOTNULL(root); |
| 2010 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2028 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 2011 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2029 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2012 | 2030 |
| 2013 EXPECT_EQ(Dart_CObject_kInt32, root->value.as_array.values[0]->type); | 2031 EXPECT_EQ(Dart_CObject_kInt32, root->value.as_array.values[0]->type); |
| 2014 EXPECT_EQ(0, root->value.as_array.values[0]->value.as_int32); | 2032 EXPECT_EQ(0, root->value.as_array.values[0]->value.as_int32); |
| 2015 EXPECT_EQ(Dart_CObject_kString, root->value.as_array.values[1]->type); | 2033 EXPECT_EQ(Dart_CObject_kString, root->value.as_array.values[1]->type); |
| 2016 EXPECT_STREQ("1", root->value.as_array.values[1]->value.as_string); | 2034 EXPECT_STREQ("1", root->value.as_array.values[1]->value.as_string); |
| 2017 EXPECT_EQ(Dart_CObject_kDouble, root->value.as_array.values[2]->type); | 2035 EXPECT_EQ(Dart_CObject_kDouble, root->value.as_array.values[2]->type); |
| 2018 EXPECT_EQ(2.2, root->value.as_array.values[2]->value.as_double); | 2036 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... | |
| 2170 TestCase::CreateTestIsolate(); | 2188 TestCase::CreateTestIsolate(); |
| 2171 Isolate* isolate = Isolate::Current(); | 2189 Isolate* isolate = Isolate::Current(); |
| 2172 EXPECT(isolate != NULL); | 2190 EXPECT(isolate != NULL); |
| 2173 Dart_EnterScope(); | 2191 Dart_EnterScope(); |
| 2174 | 2192 |
| 2175 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2193 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 2176 EXPECT_VALID(lib); | 2194 EXPECT_VALID(lib); |
| 2177 | 2195 |
| 2178 { | 2196 { |
| 2179 DARTSCOPE(isolate); | 2197 DARTSCOPE(isolate); |
| 2180 | 2198 StackZone zone(isolate); |
| 2199 Object& tmp = Object::Handle(); | |
| 2181 { | 2200 { |
| 2182 // Generate a list of strings from Dart code. | 2201 // Generate a list of strings from Dart code. |
| 2183 ApiNativeScope scope; | 2202 ApiNativeScope scope; |
| 2184 Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList"); | 2203 Dart_CObject* root = |
| 2204 GetDeserializedDartMessage(lib, "getStringList", &tmp); | |
| 2185 EXPECT_NOTNULL(root); | 2205 EXPECT_NOTNULL(root); |
| 2186 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2206 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 2187 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2207 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2188 for (int i = 0; i < kArrayLength; i++) { | 2208 for (int i = 0; i < kArrayLength; i++) { |
| 2189 Dart_CObject* element = root->value.as_array.values[i]; | 2209 Dart_CObject* element = root->value.as_array.values[i]; |
| 2190 EXPECT_EQ(root->value.as_array.values[0], element); | 2210 EXPECT_EQ(root->value.as_array.values[0], element); |
| 2191 EXPECT_EQ(Dart_CObject_kString, element->type); | 2211 EXPECT_EQ(Dart_CObject_kString, element->type); |
| 2192 EXPECT_STREQ("Hello, world!", element->value.as_string); | 2212 EXPECT_STREQ("Hello, world!", element->value.as_string); |
| 2193 } | 2213 } |
| 2194 } | 2214 } |
| 2195 { | 2215 { |
| 2196 // Generate a list of medium ints from Dart code. | 2216 // Generate a list of medium ints from Dart code. |
| 2197 ApiNativeScope scope; | 2217 ApiNativeScope scope; |
| 2198 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMintList"); | 2218 Dart_CObject* root = |
| 2219 GetDeserializedDartMessage(lib, "getMintList", &tmp); | |
| 2199 EXPECT_NOTNULL(root); | 2220 EXPECT_NOTNULL(root); |
| 2200 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2221 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 2201 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2222 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2202 for (int i = 0; i < kArrayLength; i++) { | 2223 for (int i = 0; i < kArrayLength; i++) { |
| 2203 Dart_CObject* element = root->value.as_array.values[i]; | 2224 Dart_CObject* element = root->value.as_array.values[i]; |
| 2204 EXPECT_EQ(root->value.as_array.values[0], element); | 2225 EXPECT_EQ(root->value.as_array.values[0], element); |
| 2205 EXPECT_EQ(Dart_CObject_kInt64, element->type); | 2226 EXPECT_EQ(Dart_CObject_kInt64, element->type); |
| 2206 EXPECT_EQ(DART_INT64_C(0x7FFFFFFFFFFFFFFF), element->value.as_int64); | 2227 EXPECT_EQ(DART_INT64_C(0x7FFFFFFFFFFFFFFF), element->value.as_int64); |
| 2207 } | 2228 } |
| 2208 } | 2229 } |
| 2209 { | 2230 { |
| 2210 // Generate a list of bigints from Dart code. | 2231 // Generate a list of bigints from Dart code. |
| 2211 ApiNativeScope scope; | 2232 ApiNativeScope scope; |
| 2212 Dart_CObject* root = GetDeserializedDartMessage(lib, "getBigintList"); | 2233 Dart_CObject* root = |
| 2234 GetDeserializedDartMessage(lib, "getBigintList", &tmp); | |
| 2213 EXPECT_NOTNULL(root); | 2235 EXPECT_NOTNULL(root); |
| 2214 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2236 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 2215 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2237 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2216 for (int i = 0; i < kArrayLength; i++) { | 2238 for (int i = 0; i < kArrayLength; i++) { |
| 2217 Dart_CObject* element = root->value.as_array.values[i]; | 2239 Dart_CObject* element = root->value.as_array.values[i]; |
| 2218 EXPECT_EQ(root->value.as_array.values[0], element); | 2240 EXPECT_EQ(root->value.as_array.values[0], element); |
| 2219 EXPECT_EQ(Dart_CObject_kBigint, element->type); | 2241 EXPECT_EQ(Dart_CObject_kBigint, element->type); |
| 2220 char* hex_value = TestCase::BigintToHexValue(element); | 2242 char* hex_value = TestCase::BigintToHexValue(element); |
| 2221 EXPECT_STREQ("0x1234567890123456789012345678901234567890", hex_value); | 2243 EXPECT_STREQ("0x1234567890123456789012345678901234567890", hex_value); |
| 2222 free(hex_value); | 2244 free(hex_value); |
| 2223 } | 2245 } |
| 2224 } | 2246 } |
| 2225 { | 2247 { |
| 2226 // Generate a list of doubles from Dart code. | 2248 // Generate a list of doubles from Dart code. |
| 2227 ApiNativeScope scope; | 2249 ApiNativeScope scope; |
| 2228 Dart_CObject* root = GetDeserializedDartMessage(lib, "getDoubleList"); | 2250 Dart_CObject* root = |
| 2251 GetDeserializedDartMessage(lib, "getDoubleList", &tmp); | |
| 2229 EXPECT_NOTNULL(root); | 2252 EXPECT_NOTNULL(root); |
| 2230 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2253 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 2231 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2254 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2232 Dart_CObject* element = root->value.as_array.values[0]; | 2255 Dart_CObject* element = root->value.as_array.values[0]; |
| 2233 EXPECT_EQ(Dart_CObject_kDouble, element->type); | 2256 EXPECT_EQ(Dart_CObject_kDouble, element->type); |
| 2234 EXPECT_EQ(3.14, element->value.as_double); | 2257 EXPECT_EQ(3.14, element->value.as_double); |
| 2235 for (int i = 1; i < kArrayLength; i++) { | 2258 for (int i = 1; i < kArrayLength; i++) { |
| 2236 element = root->value.as_array.values[i]; | 2259 element = root->value.as_array.values[i]; |
| 2237 // Double values are expected to not be canonicalized in messages. | 2260 // Double values are expected to not be canonicalized in messages. |
| 2238 EXPECT_NE(root->value.as_array.values[0], element); | 2261 EXPECT_NE(root->value.as_array.values[0], element); |
| 2239 EXPECT_EQ(Dart_CObject_kDouble, element->type); | 2262 EXPECT_EQ(Dart_CObject_kDouble, element->type); |
| 2240 EXPECT_EQ(3.14, element->value.as_double); | 2263 EXPECT_EQ(3.14, element->value.as_double); |
| 2241 } | 2264 } |
| 2242 } | 2265 } |
| 2243 { | 2266 { |
| 2244 // Generate a list of Uint8Lists from Dart code. | 2267 // Generate a list of Uint8Lists from Dart code. |
| 2245 ApiNativeScope scope; | 2268 ApiNativeScope scope; |
| 2246 Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList"); | 2269 Dart_CObject* root = |
| 2270 GetDeserializedDartMessage(lib, "getTypedDataList", &tmp); | |
| 2247 EXPECT_NOTNULL(root); | 2271 EXPECT_NOTNULL(root); |
| 2248 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2272 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 2249 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2273 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2250 for (int i = 0; i < kArrayLength; i++) { | 2274 for (int i = 0; i < kArrayLength; i++) { |
| 2251 Dart_CObject* element = root->value.as_array.values[i]; | 2275 Dart_CObject* element = root->value.as_array.values[i]; |
| 2252 EXPECT_EQ(root->value.as_array.values[0], element); | 2276 EXPECT_EQ(root->value.as_array.values[0], element); |
| 2253 EXPECT_EQ(Dart_CObject_kTypedData, element->type); | 2277 EXPECT_EQ(Dart_CObject_kTypedData, element->type); |
| 2254 EXPECT_EQ(Dart_TypedData_kUint8, element->value.as_typed_data.type); | 2278 EXPECT_EQ(Dart_TypedData_kUint8, element->value.as_typed_data.type); |
| 2255 EXPECT_EQ(256, element->value.as_typed_data.length); | 2279 EXPECT_EQ(256, element->value.as_typed_data.length); |
| 2256 } | 2280 } |
| 2257 } | 2281 } |
| 2258 { | 2282 { |
| 2259 // Generate a list of Uint8List views from Dart code. | 2283 // Generate a list of Uint8List views from Dart code. |
| 2260 ApiNativeScope scope; | 2284 ApiNativeScope scope; |
| 2261 Dart_CObject* root = | 2285 Dart_CObject* root = |
| 2262 GetDeserializedDartMessage(lib, "getTypedDataViewList"); | 2286 GetDeserializedDartMessage(lib, "getTypedDataViewList", &tmp); |
| 2263 EXPECT_NOTNULL(root); | 2287 EXPECT_NOTNULL(root); |
| 2264 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2288 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 2265 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2289 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2266 for (int i = 0; i < kArrayLength; i++) { | 2290 for (int i = 0; i < kArrayLength; i++) { |
| 2267 Dart_CObject* element = root->value.as_array.values[i]; | 2291 Dart_CObject* element = root->value.as_array.values[i]; |
| 2268 EXPECT_EQ(root->value.as_array.values[0], element); | 2292 EXPECT_EQ(root->value.as_array.values[0], element); |
| 2269 EXPECT_EQ(Dart_CObject_kTypedData, element->type); | 2293 EXPECT_EQ(Dart_CObject_kTypedData, element->type); |
| 2270 EXPECT_EQ(Dart_TypedData_kUint8, element->value.as_typed_data.type); | 2294 EXPECT_EQ(Dart_TypedData_kUint8, element->value.as_typed_data.type); |
| 2271 EXPECT_EQ(128, element->value.as_typed_data.length); | 2295 EXPECT_EQ(128, element->value.as_typed_data.length); |
| 2272 EXPECT_EQ(1, element->value.as_typed_data.values[0]); | 2296 EXPECT_EQ(1, element->value.as_typed_data.values[0]); |
| 2273 EXPECT_EQ(0, element->value.as_typed_data.values[1]); | 2297 EXPECT_EQ(0, element->value.as_typed_data.values[1]); |
| 2274 } | 2298 } |
| 2275 } | 2299 } |
| 2276 { | 2300 { |
| 2277 // Generate a list of objects of different types from Dart code. | 2301 // Generate a list of objects of different types from Dart code. |
| 2278 ApiNativeScope scope; | 2302 ApiNativeScope scope; |
| 2279 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); | 2303 Dart_CObject* root = |
| 2304 GetDeserializedDartMessage(lib, "getMixedList", &tmp); | |
| 2280 EXPECT_NOTNULL(root); | 2305 EXPECT_NOTNULL(root); |
| 2281 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2306 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 2282 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2307 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2283 Dart_CObject* element = root->value.as_array.values[0]; | 2308 Dart_CObject* element = root->value.as_array.values[0]; |
| 2284 EXPECT_EQ(Dart_CObject_kString, element->type); | 2309 EXPECT_EQ(Dart_CObject_kString, element->type); |
| 2285 EXPECT_STREQ("A", element->value.as_string); | 2310 EXPECT_STREQ("A", element->value.as_string); |
| 2286 element = root->value.as_array.values[1]; | 2311 element = root->value.as_array.values[1]; |
| 2287 EXPECT_EQ(Dart_CObject_kDouble, element->type); | 2312 EXPECT_EQ(Dart_CObject_kDouble, element->type); |
| 2288 EXPECT_STREQ(2.72, element->value.as_double); | 2313 EXPECT_STREQ(2.72, element->value.as_double); |
| 2289 for (int i = 2; i < kArrayLength; i++) { | 2314 for (int i = 2; i < kArrayLength; i++) { |
| 2290 element = root->value.as_array.values[i]; | 2315 element = root->value.as_array.values[i]; |
| 2291 if ((i % 2) == 0) { | 2316 if ((i % 2) == 0) { |
| 2292 EXPECT_EQ(root->value.as_array.values[0], element); | 2317 EXPECT_EQ(root->value.as_array.values[0], element); |
| 2293 EXPECT_EQ(Dart_CObject_kString, element->type); | 2318 EXPECT_EQ(Dart_CObject_kString, element->type); |
| 2294 EXPECT_STREQ("A", element->value.as_string); | 2319 EXPECT_STREQ("A", element->value.as_string); |
| 2295 } else { | 2320 } else { |
| 2296 // Double values are expected to not be canonicalized in messages. | 2321 // Double values are expected to not be canonicalized in messages. |
| 2297 EXPECT_NE(root->value.as_array.values[1], element); | 2322 EXPECT_NE(root->value.as_array.values[1], element); |
| 2298 EXPECT_EQ(Dart_CObject_kDouble, element->type); | 2323 EXPECT_EQ(Dart_CObject_kDouble, element->type); |
| 2299 EXPECT_STREQ(2.72, element->value.as_double); | 2324 EXPECT_STREQ(2.72, element->value.as_double); |
| 2300 } | 2325 } |
| 2301 } | 2326 } |
| 2302 } | 2327 } |
| 2303 { | 2328 { |
| 2304 // Generate a list of objects of different types from Dart code. | 2329 // Generate a list of objects of different types from Dart code. |
| 2305 ApiNativeScope scope; | 2330 ApiNativeScope scope; |
| 2306 Dart_CObject* root = GetDeserializedDartMessage(lib, "getSelfRefList"); | 2331 Dart_CObject* root = |
| 2332 GetDeserializedDartMessage(lib, "getSelfRefList", &tmp); | |
| 2307 EXPECT_NOTNULL(root); | 2333 EXPECT_NOTNULL(root); |
| 2308 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2334 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 2309 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2335 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2310 for (int i = 0; i < kArrayLength; i++) { | 2336 for (int i = 0; i < kArrayLength; i++) { |
| 2311 Dart_CObject* element = root->value.as_array.values[i]; | 2337 Dart_CObject* element = root->value.as_array.values[i]; |
| 2312 EXPECT_EQ(Dart_CObject_kArray, element->type); | 2338 EXPECT_EQ(Dart_CObject_kArray, element->type); |
| 2313 EXPECT_EQ(root, element); | 2339 EXPECT_EQ(root, element); |
| 2314 } | 2340 } |
| 2315 } | 2341 } |
| 2316 } | 2342 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2387 TestCase::CreateTestIsolate(); | 2413 TestCase::CreateTestIsolate(); |
| 2388 Isolate* isolate = Isolate::Current(); | 2414 Isolate* isolate = Isolate::Current(); |
| 2389 EXPECT(isolate != NULL); | 2415 EXPECT(isolate != NULL); |
| 2390 Dart_EnterScope(); | 2416 Dart_EnterScope(); |
| 2391 | 2417 |
| 2392 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2418 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 2393 EXPECT_VALID(lib); | 2419 EXPECT_VALID(lib); |
| 2394 | 2420 |
| 2395 { | 2421 { |
| 2396 DARTSCOPE(isolate); | 2422 DARTSCOPE(isolate); |
| 2423 StackZone zone(isolate); | |
| 2424 Object& tmp = Object::Handle(); | |
| 2397 { | 2425 { |
| 2398 // Generate a list of strings from Dart code. | 2426 // Generate a list of strings from Dart code. |
| 2399 ApiNativeScope scope; | 2427 ApiNativeScope scope; |
| 2400 Dart_CObject* root = GetDeserializedDartMessage(lib, "getStringList"); | 2428 Dart_CObject* root = |
| 2429 GetDeserializedDartMessage(lib, "getStringList", &tmp); | |
| 2401 EXPECT_NOTNULL(root); | 2430 EXPECT_NOTNULL(root); |
| 2402 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2431 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 2403 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2432 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2404 for (int i = 0; i < kArrayLength; i++) { | 2433 for (int i = 0; i < kArrayLength; i++) { |
| 2405 Dart_CObject* element = root->value.as_array.values[i]; | 2434 Dart_CObject* element = root->value.as_array.values[i]; |
| 2406 EXPECT_EQ(root->value.as_array.values[0], element); | 2435 EXPECT_EQ(root->value.as_array.values[0], element); |
| 2407 EXPECT_EQ(Dart_CObject_kString, element->type); | 2436 EXPECT_EQ(Dart_CObject_kString, element->type); |
| 2408 EXPECT_STREQ("Hello, world!", element->value.as_string); | 2437 EXPECT_STREQ("Hello, world!", element->value.as_string); |
| 2409 } | 2438 } |
| 2410 } | 2439 } |
| 2411 { | 2440 { |
| 2412 // Generate a list of medium ints from Dart code. | 2441 // Generate a list of medium ints from Dart code. |
| 2413 ApiNativeScope scope; | 2442 ApiNativeScope scope; |
| 2414 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMintList"); | 2443 Dart_CObject* root = |
| 2444 GetDeserializedDartMessage(lib, "getMintList", &tmp); | |
| 2415 EXPECT_NOTNULL(root); | 2445 EXPECT_NOTNULL(root); |
| 2416 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2446 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 2417 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2447 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2418 for (int i = 0; i < kArrayLength; i++) { | 2448 for (int i = 0; i < kArrayLength; i++) { |
| 2419 Dart_CObject* element = root->value.as_array.values[i]; | 2449 Dart_CObject* element = root->value.as_array.values[i]; |
| 2420 EXPECT_EQ(root->value.as_array.values[0], element); | 2450 EXPECT_EQ(root->value.as_array.values[0], element); |
| 2421 EXPECT_EQ(Dart_CObject_kInt64, element->type); | 2451 EXPECT_EQ(Dart_CObject_kInt64, element->type); |
| 2422 EXPECT_EQ(DART_INT64_C(0x7FFFFFFFFFFFFFFF), element->value.as_int64); | 2452 EXPECT_EQ(DART_INT64_C(0x7FFFFFFFFFFFFFFF), element->value.as_int64); |
| 2423 } | 2453 } |
| 2424 } | 2454 } |
| 2425 { | 2455 { |
| 2426 // Generate a list of bigints from Dart code. | 2456 // Generate a list of bigints from Dart code. |
| 2427 ApiNativeScope scope; | 2457 ApiNativeScope scope; |
| 2428 Dart_CObject* root = GetDeserializedDartMessage(lib, "getBigintList"); | 2458 Dart_CObject* root = |
| 2459 GetDeserializedDartMessage(lib, "getBigintList", &tmp); | |
| 2429 EXPECT_NOTNULL(root); | 2460 EXPECT_NOTNULL(root); |
| 2430 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2461 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 2431 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2462 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2432 for (int i = 0; i < kArrayLength; i++) { | 2463 for (int i = 0; i < kArrayLength; i++) { |
| 2433 Dart_CObject* element = root->value.as_array.values[i]; | 2464 Dart_CObject* element = root->value.as_array.values[i]; |
| 2434 EXPECT_EQ(root->value.as_array.values[0], element); | 2465 EXPECT_EQ(root->value.as_array.values[0], element); |
| 2435 EXPECT_EQ(Dart_CObject_kBigint, element->type); | 2466 EXPECT_EQ(Dart_CObject_kBigint, element->type); |
| 2436 char* hex_value = TestCase::BigintToHexValue(element); | 2467 char* hex_value = TestCase::BigintToHexValue(element); |
| 2437 EXPECT_STREQ("0x1234567890123456789012345678901234567890", hex_value); | 2468 EXPECT_STREQ("0x1234567890123456789012345678901234567890", hex_value); |
| 2438 free(hex_value); | 2469 free(hex_value); |
| 2439 } | 2470 } |
| 2440 } | 2471 } |
| 2441 { | 2472 { |
| 2442 // Generate a list of doubles from Dart code. | 2473 // Generate a list of doubles from Dart code. |
| 2443 ApiNativeScope scope; | 2474 ApiNativeScope scope; |
| 2444 Dart_CObject* root = GetDeserializedDartMessage(lib, "getDoubleList"); | 2475 Dart_CObject* root = |
| 2476 GetDeserializedDartMessage(lib, "getDoubleList", &tmp); | |
| 2445 EXPECT_NOTNULL(root); | 2477 EXPECT_NOTNULL(root); |
| 2446 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2478 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 2447 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2479 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2448 Dart_CObject* element = root->value.as_array.values[0]; | 2480 Dart_CObject* element = root->value.as_array.values[0]; |
| 2449 // Double values are expected to not be canonicalized in messages. | 2481 // Double values are expected to not be canonicalized in messages. |
| 2450 EXPECT_EQ(Dart_CObject_kDouble, element->type); | 2482 EXPECT_EQ(Dart_CObject_kDouble, element->type); |
| 2451 EXPECT_EQ(3.14, element->value.as_double); | 2483 EXPECT_EQ(3.14, element->value.as_double); |
| 2452 for (int i = 1; i < kArrayLength; i++) { | 2484 for (int i = 1; i < kArrayLength; i++) { |
| 2453 element = root->value.as_array.values[i]; | 2485 element = root->value.as_array.values[i]; |
| 2454 // Double values are expected to not be canonicalized in messages. | 2486 // Double values are expected to not be canonicalized in messages. |
| 2455 EXPECT_NE(root->value.as_array.values[0], element); | 2487 EXPECT_NE(root->value.as_array.values[0], element); |
| 2456 EXPECT_EQ(Dart_CObject_kDouble, element->type); | 2488 EXPECT_EQ(Dart_CObject_kDouble, element->type); |
| 2457 EXPECT_EQ(3.14, element->value.as_double); | 2489 EXPECT_EQ(3.14, element->value.as_double); |
| 2458 } | 2490 } |
| 2459 } | 2491 } |
| 2460 { | 2492 { |
| 2461 // Generate a list of Uint8Lists from Dart code. | 2493 // Generate a list of Uint8Lists from Dart code. |
| 2462 ApiNativeScope scope; | 2494 ApiNativeScope scope; |
| 2463 Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList"); | 2495 Dart_CObject* root = |
| 2496 GetDeserializedDartMessage(lib, "getTypedDataList", &tmp); | |
| 2464 EXPECT_NOTNULL(root); | 2497 EXPECT_NOTNULL(root); |
| 2465 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2498 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 2466 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2499 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2467 for (int i = 0; i < kArrayLength; i++) { | 2500 for (int i = 0; i < kArrayLength; i++) { |
| 2468 Dart_CObject* element = root->value.as_array.values[i]; | 2501 Dart_CObject* element = root->value.as_array.values[i]; |
| 2469 EXPECT_EQ(root->value.as_array.values[0], element); | 2502 EXPECT_EQ(root->value.as_array.values[0], element); |
| 2470 EXPECT_EQ(Dart_CObject_kTypedData, element->type); | 2503 EXPECT_EQ(Dart_CObject_kTypedData, element->type); |
| 2471 EXPECT_EQ(Dart_TypedData_kUint8, element->value.as_typed_data.type); | 2504 EXPECT_EQ(Dart_TypedData_kUint8, element->value.as_typed_data.type); |
| 2472 EXPECT_EQ(256, element->value.as_typed_data.length); | 2505 EXPECT_EQ(256, element->value.as_typed_data.length); |
| 2473 } | 2506 } |
| 2474 } | 2507 } |
| 2475 { | 2508 { |
| 2476 // Generate a list of Uint8List views from Dart code. | 2509 // Generate a list of Uint8List views from Dart code. |
| 2477 ApiNativeScope scope; | 2510 ApiNativeScope scope; |
| 2478 Dart_CObject* root = | 2511 Dart_CObject* root = |
| 2479 GetDeserializedDartMessage(lib, "getTypedDataViewList"); | 2512 GetDeserializedDartMessage(lib, "getTypedDataViewList", &tmp); |
| 2480 EXPECT_NOTNULL(root); | 2513 EXPECT_NOTNULL(root); |
| 2481 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2514 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 2482 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2515 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2483 for (int i = 0; i < kArrayLength; i++) { | 2516 for (int i = 0; i < kArrayLength; i++) { |
| 2484 Dart_CObject* element = root->value.as_array.values[i]; | 2517 Dart_CObject* element = root->value.as_array.values[i]; |
| 2485 EXPECT_EQ(root->value.as_array.values[0], element); | 2518 EXPECT_EQ(root->value.as_array.values[0], element); |
| 2486 EXPECT_EQ(Dart_CObject_kTypedData, element->type); | 2519 EXPECT_EQ(Dart_CObject_kTypedData, element->type); |
| 2487 EXPECT_EQ(Dart_TypedData_kUint8, element->value.as_typed_data.type); | 2520 EXPECT_EQ(Dart_TypedData_kUint8, element->value.as_typed_data.type); |
| 2488 EXPECT_EQ(128, element->value.as_typed_data.length); | 2521 EXPECT_EQ(128, element->value.as_typed_data.length); |
| 2489 EXPECT_EQ(1, element->value.as_typed_data.values[0]); | 2522 EXPECT_EQ(1, element->value.as_typed_data.values[0]); |
| 2490 EXPECT_EQ(0, element->value.as_typed_data.values[1]); | 2523 EXPECT_EQ(0, element->value.as_typed_data.values[1]); |
| 2491 } | 2524 } |
| 2492 } | 2525 } |
| 2493 { | 2526 { |
| 2494 // Generate a list of objects of different types from Dart code. | 2527 // Generate a list of objects of different types from Dart code. |
| 2495 ApiNativeScope scope; | 2528 ApiNativeScope scope; |
| 2496 Dart_CObject* root = GetDeserializedDartMessage(lib, "getMixedList"); | 2529 Dart_CObject* root = |
| 2530 GetDeserializedDartMessage(lib, "getMixedList", &tmp); | |
| 2497 EXPECT_NOTNULL(root); | 2531 EXPECT_NOTNULL(root); |
| 2498 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2532 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 2499 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2533 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2500 Dart_CObject* element = root->value.as_array.values[0]; | 2534 Dart_CObject* element = root->value.as_array.values[0]; |
| 2501 EXPECT_EQ(Dart_CObject_kString, element->type); | 2535 EXPECT_EQ(Dart_CObject_kString, element->type); |
| 2502 EXPECT_STREQ(".", element->value.as_string); | 2536 EXPECT_STREQ(".", element->value.as_string); |
| 2503 element = root->value.as_array.values[1]; | 2537 element = root->value.as_array.values[1]; |
| 2504 EXPECT_EQ(Dart_CObject_kDouble, element->type); | 2538 EXPECT_EQ(Dart_CObject_kDouble, element->type); |
| 2505 EXPECT_STREQ(2.72, element->value.as_double); | 2539 EXPECT_STREQ(2.72, element->value.as_double); |
| 2506 for (int i = 2; i < kArrayLength; i++) { | 2540 for (int i = 2; i < kArrayLength; i++) { |
| 2507 Dart_CObject* element = root->value.as_array.values[i]; | 2541 Dart_CObject* element = root->value.as_array.values[i]; |
| 2508 if ((i % 2) == 0) { | 2542 if ((i % 2) == 0) { |
| 2509 EXPECT_EQ(root->value.as_array.values[0], element); | 2543 EXPECT_EQ(root->value.as_array.values[0], element); |
| 2510 EXPECT_EQ(Dart_CObject_kString, element->type); | 2544 EXPECT_EQ(Dart_CObject_kString, element->type); |
| 2511 EXPECT_STREQ(".", element->value.as_string); | 2545 EXPECT_STREQ(".", element->value.as_string); |
| 2512 } else { | 2546 } else { |
| 2513 // Double values are expected to not be canonicalized in messages. | 2547 // Double values are expected to not be canonicalized in messages. |
| 2514 EXPECT_NE(root->value.as_array.values[1], element); | 2548 EXPECT_NE(root->value.as_array.values[1], element); |
| 2515 EXPECT_EQ(Dart_CObject_kDouble, element->type); | 2549 EXPECT_EQ(Dart_CObject_kDouble, element->type); |
| 2516 EXPECT_STREQ(2.72, element->value.as_double); | 2550 EXPECT_STREQ(2.72, element->value.as_double); |
| 2517 } | 2551 } |
| 2518 } | 2552 } |
| 2519 } | 2553 } |
| 2520 { | 2554 { |
| 2521 // Generate a list of objects of different types from Dart code. | 2555 // Generate a list of objects of different types from Dart code. |
| 2522 ApiNativeScope scope; | 2556 ApiNativeScope scope; |
| 2523 Dart_CObject* root = GetDeserializedDartMessage(lib, "getSelfRefList"); | 2557 Dart_CObject* root = |
| 2558 GetDeserializedDartMessage(lib, "getSelfRefList", &tmp); | |
| 2524 EXPECT_NOTNULL(root); | 2559 EXPECT_NOTNULL(root); |
| 2525 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2560 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 2526 EXPECT_EQ(kArrayLength, root->value.as_array.length); | 2561 EXPECT_EQ(kArrayLength, root->value.as_array.length); |
| 2527 for (int i = 0; i < kArrayLength; i++) { | 2562 for (int i = 0; i < kArrayLength; i++) { |
| 2528 Dart_CObject* element = root->value.as_array.values[i]; | 2563 Dart_CObject* element = root->value.as_array.values[i]; |
| 2529 EXPECT_EQ(Dart_CObject_kArray, element->type); | 2564 EXPECT_EQ(Dart_CObject_kArray, element->type); |
| 2530 EXPECT_EQ(root, element); | 2565 EXPECT_EQ(root, element); |
| 2531 } | 2566 } |
| 2532 } | 2567 } |
| 2533 } | 2568 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2619 TestCase::CreateTestIsolate(); | 2654 TestCase::CreateTestIsolate(); |
| 2620 Isolate* isolate = Isolate::Current(); | 2655 Isolate* isolate = Isolate::Current(); |
| 2621 EXPECT(isolate != NULL); | 2656 EXPECT(isolate != NULL); |
| 2622 Dart_EnterScope(); | 2657 Dart_EnterScope(); |
| 2623 | 2658 |
| 2624 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2659 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 2625 EXPECT_VALID(lib); | 2660 EXPECT_VALID(lib); |
| 2626 | 2661 |
| 2627 { | 2662 { |
| 2628 DARTSCOPE(isolate); | 2663 DARTSCOPE(isolate); |
| 2664 StackZone zone(isolate); | |
| 2665 Object& tmp = Object::Handle(); | |
| 2629 { | 2666 { |
| 2630 // Generate a list of Uint8Lists from Dart code. | 2667 // Generate a list of Uint8Lists from Dart code. |
| 2631 ApiNativeScope scope; | 2668 ApiNativeScope scope; |
| 2632 Dart_CObject* root = GetDeserializedDartMessage(lib, "getTypedDataList"); | 2669 Dart_CObject* root = |
| 2670 GetDeserializedDartMessage(lib, "getTypedDataList", &tmp); | |
| 2633 EXPECT_NOTNULL(root); | 2671 EXPECT_NOTNULL(root); |
| 2634 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2672 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 2635 struct { | 2673 struct { |
| 2636 Dart_TypedData_Type type; | 2674 Dart_TypedData_Type type; |
| 2637 int size; | 2675 int size; |
| 2638 } expected[] = { | 2676 } expected[] = { |
| 2639 { Dart_TypedData_kInt8, 256}, | 2677 { Dart_TypedData_kInt8, 256}, |
| 2640 { Dart_TypedData_kUint8, 256}, | 2678 { Dart_TypedData_kUint8, 256}, |
| 2641 { Dart_TypedData_kInt16, 512}, | 2679 { Dart_TypedData_kInt16, 512}, |
| 2642 { Dart_TypedData_kUint16, 512}, | 2680 { Dart_TypedData_kUint16, 512}, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 2656 expected[i].size); | 2694 expected[i].size); |
| 2657 i++; | 2695 i++; |
| 2658 } | 2696 } |
| 2659 EXPECT_EQ(i, root->value.as_array.length); | 2697 EXPECT_EQ(i, root->value.as_array.length); |
| 2660 } | 2698 } |
| 2661 { | 2699 { |
| 2662 // Generate a list of Uint8List views from Dart code. | 2700 // Generate a list of Uint8List views from Dart code. |
| 2663 | 2701 |
| 2664 ApiNativeScope scope; | 2702 ApiNativeScope scope; |
| 2665 Dart_CObject* root = | 2703 Dart_CObject* root = |
| 2666 GetDeserializedDartMessage(lib, "getTypedDataViewList"); | 2704 GetDeserializedDartMessage(lib, "getTypedDataViewList", &tmp); |
| 2667 EXPECT_NOTNULL(root); | 2705 EXPECT_NOTNULL(root); |
| 2668 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2706 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 2669 struct { | 2707 struct { |
| 2670 Dart_TypedData_Type type; | 2708 Dart_TypedData_Type type; |
| 2671 int size; | 2709 int size; |
| 2672 } expected[] = { | 2710 } expected[] = { |
| 2673 { Dart_TypedData_kInt8, 256}, | 2711 { Dart_TypedData_kInt8, 256}, |
| 2674 { Dart_TypedData_kUint8, 256}, | 2712 { Dart_TypedData_kUint8, 256}, |
| 2675 { Dart_TypedData_kInt16, 512}, | 2713 { Dart_TypedData_kInt16, 512}, |
| 2676 { Dart_TypedData_kUint16, 512}, | 2714 { Dart_TypedData_kUint16, 512}, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2712 expected[i].type, | 2750 expected[i].type, |
| 2713 expected[i].size); | 2751 expected[i].size); |
| 2714 i++; | 2752 i++; |
| 2715 } | 2753 } |
| 2716 EXPECT_EQ(i, root->value.as_array.length); | 2754 EXPECT_EQ(i, root->value.as_array.length); |
| 2717 } | 2755 } |
| 2718 { | 2756 { |
| 2719 // Generate a list of Uint8Lists from Dart code. | 2757 // Generate a list of Uint8Lists from Dart code. |
| 2720 ApiNativeScope scope; | 2758 ApiNativeScope scope; |
| 2721 Dart_CObject* root = | 2759 Dart_CObject* root = |
| 2722 GetDeserializedDartMessage(lib, "getMultipleTypedDataViewList"); | 2760 GetDeserializedDartMessage(lib, "getMultipleTypedDataViewList", &tmp); |
| 2723 EXPECT_NOTNULL(root); | 2761 EXPECT_NOTNULL(root); |
| 2724 EXPECT_EQ(Dart_CObject_kArray, root->type); | 2762 EXPECT_EQ(Dart_CObject_kArray, root->type); |
| 2725 struct { | 2763 struct { |
| 2726 Dart_TypedData_Type type; | 2764 Dart_TypedData_Type type; |
| 2727 int size; | 2765 int size; |
| 2728 } expected[] = { | 2766 } expected[] = { |
| 2729 { Dart_TypedData_kInt8, 256}, | 2767 { Dart_TypedData_kInt8, 256}, |
| 2730 { Dart_TypedData_kUint8, 256}, | 2768 { Dart_TypedData_kUint8, 256}, |
| 2731 { Dart_TypedData_kInt16, 256}, | 2769 { Dart_TypedData_kInt16, 256}, |
| 2732 { Dart_TypedData_kUint16, 256}, | 2770 { Dart_TypedData_kUint16, 256}, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2858 StackZone zone(Isolate::Current()); | 2896 StackZone zone(Isolate::Current()); |
| 2859 uint8_t* buffer; | 2897 uint8_t* buffer; |
| 2860 MessageWriter writer(&buffer, &zone_allocator, true); | 2898 MessageWriter writer(&buffer, &zone_allocator, true); |
| 2861 writer.WriteInlinedObjectHeader(kOmittedObjectId); | 2899 writer.WriteInlinedObjectHeader(kOmittedObjectId); |
| 2862 // For performance, we'd like single-byte headers when ids are omitted. | 2900 // For performance, we'd like single-byte headers when ids are omitted. |
| 2863 // If this starts failing, consider renumbering the snapshot ids. | 2901 // If this starts failing, consider renumbering the snapshot ids. |
| 2864 EXPECT_EQ(1, writer.BytesWritten()); | 2902 EXPECT_EQ(1, writer.BytesWritten()); |
| 2865 } | 2903 } |
| 2866 | 2904 |
| 2867 } // namespace dart | 2905 } // namespace dart |
| OLD | NEW |