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 "bin/builtin.h" | 5 #include "bin/builtin.h" |
6 #include "include/dart_api.h" | 6 #include "include/dart_api.h" |
7 #include "include/dart_debugger_api.h" | 7 #include "include/dart_debugger_api.h" |
8 #include "include/dart_mirrors_api.h" | 8 #include "include/dart_mirrors_api.h" |
9 #include "include/dart_native_api.h" | 9 #include "include/dart_native_api.h" |
10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
(...skipping 1853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1864 | 1864 |
1865 | 1865 |
1866 TEST_CASE(TypedDataDirectAccessVerified) { | 1866 TEST_CASE(TypedDataDirectAccessVerified) { |
1867 FLAG_verify_acquired_data = true; | 1867 FLAG_verify_acquired_data = true; |
1868 TestTypedDataDirectAccess(); | 1868 TestTypedDataDirectAccess(); |
1869 } | 1869 } |
1870 | 1870 |
1871 | 1871 |
1872 static void TestDirectAccess(Dart_Handle lib, | 1872 static void TestDirectAccess(Dart_Handle lib, |
1873 Dart_Handle array, | 1873 Dart_Handle array, |
1874 Dart_TypedData_Type expected_type) { | 1874 Dart_TypedData_Type expected_type, |
| 1875 bool is_external) { |
1875 Dart_Handle result; | 1876 Dart_Handle result; |
1876 | 1877 |
1877 // Invoke the dart function that sets initial values. | 1878 // Invoke the dart function that sets initial values. |
1878 Dart_Handle dart_args[1]; | 1879 Dart_Handle dart_args[1]; |
1879 dart_args[0] = array; | 1880 dart_args[0] = array; |
1880 result = Dart_Invoke(lib, NewString("setMain"), 1, dart_args); | 1881 result = Dart_Invoke(lib, NewString("setMain"), 1, dart_args); |
1881 EXPECT_VALID(result); | 1882 EXPECT_VALID(result); |
1882 | 1883 |
1883 // Now Get a direct access to this typed data object and check it's contents. | 1884 // Now Get a direct access to this typed data object and check it's contents. |
1884 const int kLength = 10; | 1885 const int kLength = 10; |
1885 Dart_TypedData_Type type; | 1886 Dart_TypedData_Type type; |
1886 void* data; | 1887 void* data; |
1887 intptr_t len; | 1888 intptr_t len; |
1888 result = Dart_TypedDataAcquireData(array, &type, &data, &len); | 1889 result = Dart_TypedDataAcquireData(array, &type, &data, &len); |
1889 EXPECT_VALID(result); | 1890 EXPECT_VALID(result); |
1890 EXPECT_EQ(expected_type, type); | 1891 EXPECT_EQ(expected_type, type); |
1891 EXPECT_EQ(kLength, len); | 1892 EXPECT_EQ(kLength, len); |
1892 int8_t* dataP = reinterpret_cast<int8_t*>(data); | 1893 int8_t* dataP = reinterpret_cast<int8_t*>(data); |
1893 for (int i = 0; i < kLength; i++) { | 1894 for (int i = 0; i < kLength; i++) { |
1894 EXPECT_EQ(i, dataP[i]); | 1895 EXPECT_EQ(i, dataP[i]); |
1895 } | 1896 } |
1896 | 1897 |
| 1898 if (!is_external) { |
| 1899 // Now try allocating a string with outstanding Acquires and it should |
| 1900 // return an error. |
| 1901 result = NewString("We expect an error here"); |
| 1902 EXPECT_ERROR(result, |
| 1903 "Internal Dart data pointers have been acquired, " |
| 1904 "please release them using Dart_TypedDataReleaseData."); |
| 1905 } |
| 1906 |
1897 // Now modify the values in the directly accessible array and then check | 1907 // Now modify the values in the directly accessible array and then check |
1898 // it we see the changes back in dart. | 1908 // it we see the changes back in dart. |
1899 for (int i = 0; i < kLength; i++) { | 1909 for (int i = 0; i < kLength; i++) { |
1900 dataP[i] += 10; | 1910 dataP[i] += 10; |
1901 } | 1911 } |
1902 | 1912 |
1903 // Release direct accesss to the typed data object. | 1913 // Release direct accesss to the typed data object. |
1904 result = Dart_TypedDataReleaseData(array); | 1914 result = Dart_TypedDataReleaseData(array); |
1905 EXPECT_VALID(result); | 1915 EXPECT_VALID(result); |
1906 | 1916 |
(...skipping 28 matching lines...) Expand all Loading... |
1935 " var a = new Int8List(10);" | 1945 " var a = new Int8List(10);" |
1936 " return a;" | 1946 " return a;" |
1937 "}\n"; | 1947 "}\n"; |
1938 // Create a test library and Load up a test script in it. | 1948 // Create a test library and Load up a test script in it. |
1939 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 1949 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
1940 | 1950 |
1941 // Test with an regular typed data object. | 1951 // Test with an regular typed data object. |
1942 Dart_Handle list_access_test_obj; | 1952 Dart_Handle list_access_test_obj; |
1943 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL); | 1953 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL); |
1944 EXPECT_VALID(list_access_test_obj); | 1954 EXPECT_VALID(list_access_test_obj); |
1945 TestDirectAccess(lib, list_access_test_obj, Dart_TypedData_kInt8); | 1955 TestDirectAccess(lib, list_access_test_obj, Dart_TypedData_kInt8, false); |
1946 | 1956 |
1947 // Test with an external typed data object. | 1957 // Test with an external typed data object. |
1948 uint8_t data[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; | 1958 uint8_t data[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; |
1949 intptr_t data_length = ARRAY_SIZE(data); | 1959 intptr_t data_length = ARRAY_SIZE(data); |
1950 Dart_Handle ext_list_access_test_obj; | 1960 Dart_Handle ext_list_access_test_obj; |
1951 ext_list_access_test_obj = Dart_NewExternalTypedData(Dart_TypedData_kUint8, | 1961 ext_list_access_test_obj = Dart_NewExternalTypedData(Dart_TypedData_kUint8, |
1952 data, data_length); | 1962 data, data_length); |
1953 EXPECT_VALID(ext_list_access_test_obj); | 1963 EXPECT_VALID(ext_list_access_test_obj); |
1954 TestDirectAccess(lib, ext_list_access_test_obj, Dart_TypedData_kUint8); | 1964 TestDirectAccess(lib, ext_list_access_test_obj, Dart_TypedData_kUint8, true); |
1955 } | 1965 } |
1956 | 1966 |
1957 | 1967 |
1958 TEST_CASE(TypedDataDirectAccess1Unverified) { | 1968 TEST_CASE(TypedDataDirectAccess1Unverified) { |
1959 FLAG_verify_acquired_data = false; | 1969 FLAG_verify_acquired_data = false; |
1960 TestTypedDataDirectAccess1(); | 1970 TestTypedDataDirectAccess1(); |
1961 } | 1971 } |
1962 | 1972 |
1963 | 1973 |
1964 TEST_CASE(TypedDataDirectAccess1Verified) { | 1974 TEST_CASE(TypedDataDirectAccess1Verified) { |
(...skipping 30 matching lines...) Expand all Loading... |
1995 " var view = new Int8List.view(a.buffer, 50, 10);" | 2005 " var view = new Int8List.view(a.buffer, 50, 10);" |
1996 " return view;" | 2006 " return view;" |
1997 "}\n"; | 2007 "}\n"; |
1998 // Create a test library and Load up a test script in it. | 2008 // Create a test library and Load up a test script in it. |
1999 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2009 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
2000 | 2010 |
2001 // Test with a typed data view object. | 2011 // Test with a typed data view object. |
2002 Dart_Handle list_access_test_obj; | 2012 Dart_Handle list_access_test_obj; |
2003 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL); | 2013 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL); |
2004 EXPECT_VALID(list_access_test_obj); | 2014 EXPECT_VALID(list_access_test_obj); |
2005 TestDirectAccess(lib, list_access_test_obj, Dart_TypedData_kInt8); | 2015 TestDirectAccess(lib, list_access_test_obj, Dart_TypedData_kInt8, false); |
2006 } | 2016 } |
2007 | 2017 |
2008 | 2018 |
2009 TEST_CASE(TypedDataViewDirectAccessUnverified) { | 2019 TEST_CASE(TypedDataViewDirectAccessUnverified) { |
2010 FLAG_verify_acquired_data = false; | 2020 FLAG_verify_acquired_data = false; |
2011 TestTypedDataViewDirectAccess(); | 2021 TestTypedDataViewDirectAccess(); |
2012 } | 2022 } |
2013 | 2023 |
2014 | 2024 |
2015 TEST_CASE(TypedDataViewDirectAccessVerified) { | 2025 TEST_CASE(TypedDataViewDirectAccessVerified) { |
(...skipping 30 matching lines...) Expand all Loading... |
2046 " var view = new ByteData.view(a.buffer, 50, 10);" | 2056 " var view = new ByteData.view(a.buffer, 50, 10);" |
2047 " return view;" | 2057 " return view;" |
2048 "}\n"; | 2058 "}\n"; |
2049 // Create a test library and Load up a test script in it. | 2059 // Create a test library and Load up a test script in it. |
2050 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2060 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
2051 | 2061 |
2052 // Test with a typed data view object. | 2062 // Test with a typed data view object. |
2053 Dart_Handle list_access_test_obj; | 2063 Dart_Handle list_access_test_obj; |
2054 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL); | 2064 list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL); |
2055 EXPECT_VALID(list_access_test_obj); | 2065 EXPECT_VALID(list_access_test_obj); |
2056 TestDirectAccess(lib, list_access_test_obj, Dart_TypedData_kByteData); | 2066 TestDirectAccess(lib, list_access_test_obj, Dart_TypedData_kByteData, false); |
2057 } | 2067 } |
2058 | 2068 |
2059 | 2069 |
2060 TEST_CASE(ByteDataDirectAccessUnverified) { | 2070 TEST_CASE(ByteDataDirectAccessUnverified) { |
2061 FLAG_verify_acquired_data = false; | 2071 FLAG_verify_acquired_data = false; |
2062 TestByteDataDirectAccess(); | 2072 TestByteDataDirectAccess(); |
2063 } | 2073 } |
2064 | 2074 |
2065 | 2075 |
2066 TEST_CASE(ByteDataDirectAccessVerified) { | 2076 TEST_CASE(ByteDataDirectAccessVerified) { |
(...skipping 7064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9131 result = Dart_Invoke(lib, | 9141 result = Dart_Invoke(lib, |
9132 NewString("testView16"), | 9142 NewString("testView16"), |
9133 1, | 9143 1, |
9134 dart_args); | 9144 dart_args); |
9135 EXPECT_VALID(result); | 9145 EXPECT_VALID(result); |
9136 EXPECT(Dart_IsString(result)); | 9146 EXPECT(Dart_IsString(result)); |
9137 } | 9147 } |
9138 } | 9148 } |
9139 | 9149 |
9140 } // namespace dart | 9150 } // namespace dart |
OLD | NEW |