| 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/dartutils.h" | 5 #include "bin/dartutils.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
| 9 | 9 |
| 10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 | 66 |
| 67 int64_t DartUtils::GetIntegerValue(Dart_Handle value_obj) { | 67 int64_t DartUtils::GetIntegerValue(Dart_Handle value_obj) { |
| 68 int64_t value = 0; | 68 int64_t value = 0; |
| 69 Dart_Handle result = Dart_IntegerToInt64(value_obj, &value); | 69 Dart_Handle result = Dart_IntegerToInt64(value_obj, &value); |
| 70 if (Dart_IsError(result)) Dart_PropagateError(result); | 70 if (Dart_IsError(result)) Dart_PropagateError(result); |
| 71 return value; | 71 return value; |
| 72 } | 72 } |
| 73 | 73 |
| 74 | 74 |
| 75 int64_t DartUtils::GetIntegerValueCheckRange( |
| 76 Dart_Handle value_obj, int64_t lower, int64_t upper) { |
| 77 int64_t value = DartUtils::GetIntegerValue(value_obj); |
| 78 if (value < lower || upper < value) { |
| 79 Dart_PropagateError(Dart_NewApiError("Value outside expected range")); |
| 80 } |
| 81 return value; |
| 82 } |
| 83 |
| 84 |
| 75 intptr_t DartUtils::GetIntptrValue(Dart_Handle value_obj) { | 85 intptr_t DartUtils::GetIntptrValue(Dart_Handle value_obj) { |
| 76 int64_t value = 0; | 86 int64_t value = 0; |
| 77 Dart_Handle result = Dart_IntegerToInt64(value_obj, &value); | 87 Dart_Handle result = Dart_IntegerToInt64(value_obj, &value); |
| 78 if (Dart_IsError(result)) Dart_PropagateError(result); | 88 if (Dart_IsError(result)) Dart_PropagateError(result); |
| 79 if (value < kIntptrMin || kIntptrMax < value) { | 89 if (value < kIntptrMin || kIntptrMax < value) { |
| 80 Dart_PropagateError(Dart_NewApiError("Value outside intptr:t range")); | 90 Dart_PropagateError(Dart_NewApiError("Value outside intptr_t range")); |
| 81 } | 91 } |
| 82 return static_cast<intptr_t>(value); | 92 return static_cast<intptr_t>(value); |
| 83 } | 93 } |
| 84 | 94 |
| 85 | 95 |
| 86 bool DartUtils::GetInt64Value(Dart_Handle value_obj, int64_t* value) { | 96 bool DartUtils::GetInt64Value(Dart_Handle value_obj, int64_t* value) { |
| 87 bool valid = Dart_IsInteger(value_obj); | 97 bool valid = Dart_IsInteger(value_obj); |
| 88 if (valid) { | 98 if (valid) { |
| 89 Dart_Handle result = Dart_IntegerFitsIntoInt64(value_obj, &valid); | 99 Dart_Handle result = Dart_IntegerFitsIntoInt64(value_obj, &valid); |
| 90 if (Dart_IsError(result)) Dart_PropagateError(result); | 100 if (Dart_IsError(result)) Dart_PropagateError(result); |
| (...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 new CObjectString(CObject::NewString(os_error->message())); | 1059 new CObjectString(CObject::NewString(os_error->message())); |
| 1050 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 1060 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
| 1051 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 1061 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
| 1052 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 1062 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
| 1053 result->SetAt(2, error_message); | 1063 result->SetAt(2, error_message); |
| 1054 return result; | 1064 return result; |
| 1055 } | 1065 } |
| 1056 | 1066 |
| 1057 } // namespace bin | 1067 } // namespace bin |
| 1058 } // namespace dart | 1068 } // namespace dart |
| OLD | NEW |