Fix for issue 23547, return an proper ApiError instead of a string when we report outstanding typed data acquire errors.

BUG=23547
R=koda@google.com

Review URL: https://codereview.chromium.org//1156993012
This commit is contained in:
Siva Annamalai 2015-05-29 11:13:33 -07:00
parent 1017ea0fca
commit 7af681ead9
2 changed files with 18 additions and 7 deletions

View file

@ -1871,7 +1871,8 @@ TEST_CASE(TypedDataDirectAccessVerified) {
static void TestDirectAccess(Dart_Handle lib,
Dart_Handle array,
Dart_TypedData_Type expected_type) {
Dart_TypedData_Type expected_type,
bool is_external) {
Dart_Handle result;
// Invoke the dart function that sets initial values.
@ -1894,6 +1895,15 @@ static void TestDirectAccess(Dart_Handle lib,
EXPECT_EQ(i, dataP[i]);
}
if (!is_external) {
// Now try allocating a string with outstanding Acquires and it should
// return an error.
result = NewString("We expect an error here");
EXPECT_ERROR(result,
"Internal Dart data pointers have been acquired, "
"please release them using Dart_TypedDataReleaseData.");
}
// Now modify the values in the directly accessible array and then check
// it we see the changes back in dart.
for (int i = 0; i < kLength; i++) {
@ -1942,7 +1952,7 @@ static void TestTypedDataDirectAccess1() {
Dart_Handle list_access_test_obj;
list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL);
EXPECT_VALID(list_access_test_obj);
TestDirectAccess(lib, list_access_test_obj, Dart_TypedData_kInt8);
TestDirectAccess(lib, list_access_test_obj, Dart_TypedData_kInt8, false);
// Test with an external typed data object.
uint8_t data[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
@ -1951,7 +1961,7 @@ static void TestTypedDataDirectAccess1() {
ext_list_access_test_obj = Dart_NewExternalTypedData(Dart_TypedData_kUint8,
data, data_length);
EXPECT_VALID(ext_list_access_test_obj);
TestDirectAccess(lib, ext_list_access_test_obj, Dart_TypedData_kUint8);
TestDirectAccess(lib, ext_list_access_test_obj, Dart_TypedData_kUint8, true);
}
@ -2002,7 +2012,7 @@ static void TestTypedDataViewDirectAccess() {
Dart_Handle list_access_test_obj;
list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL);
EXPECT_VALID(list_access_test_obj);
TestDirectAccess(lib, list_access_test_obj, Dart_TypedData_kInt8);
TestDirectAccess(lib, list_access_test_obj, Dart_TypedData_kInt8, false);
}
@ -2053,7 +2063,7 @@ static void TestByteDataDirectAccess() {
Dart_Handle list_access_test_obj;
list_access_test_obj = Dart_Invoke(lib, NewString("main"), 0, NULL);
EXPECT_VALID(list_access_test_obj);
TestDirectAccess(lib, list_access_test_obj, Dart_TypedData_kByteData);
TestDirectAccess(lib, list_access_test_obj, Dart_TypedData_kByteData, false);
}

View file

@ -818,10 +818,11 @@ class ApiState {
void SetupAcquiredError() {
ASSERT(acquired_error_ == NULL);
acquired_error_ = persistent_handles().AllocateHandle();
acquired_error_->set_raw(
const String& msg = String::Handle(
String::New("Internal Dart data pointers have been acquired, "
"please release them using Dart_TypedDataReleaseData."));
acquired_error_ = persistent_handles().AllocateHandle();
acquired_error_->set_raw(ApiError::New(msg));
}
PersistentHandle* AcquiredError() const {