Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 8585049: Add an interface for retrieving the value of unsigned 64-bit integers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/bigint_operations_test.cc ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/dart_api_impl.cc
diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc
index 7b5940dc59dd5096760bafd839307caed562e817..9f869fefb12ee16bc2910e16c78fb4eb5c0b8c45 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -950,20 +950,42 @@ DART_EXPORT bool Dart_IsInteger(Dart_Handle object) {
DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer,
bool* fits) {
DARTSCOPE(Isolate::Current());
- const Object& obj = Object::Handle(Api::UnwrapHandle(integer));
- if (obj.IsSmi() || obj.IsMint()) {
+ const Integer& int_obj = Api::UnwrapIntegerHandle(integer);
+ if (int_obj.IsNull()) {
+ RETURN_TYPE_ERROR(integer, Integer);
+ }
+ if (int_obj.IsSmi() || int_obj.IsMint()) {
*fits = true;
return Api::Success();
turnidge 2011/12/08 22:58:22 Remove this?
- } else if (obj.IsBigint()) {
+ } else {
+ ASSERT(int_obj.IsBigint());
#if defined(DEBUG)
Bigint& bigint = Bigint::Handle();
- bigint ^= obj.raw();
+ bigint ^= int_obj.raw();
ASSERT(!BigintOperations::FitsIntoInt64(bigint));
#endif
*fits = false;
- return Api::Success();
}
- return Api::Error("Object is not a Integer");
+ return Api::Success();
+}
+
+
+DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer,
+ bool* fits) {
+ DARTSCOPE(Isolate::Current());
+ const Integer& int_obj = Api::UnwrapIntegerHandle(integer);
+ if (int_obj.IsNull()) {
+ RETURN_TYPE_ERROR(integer, Integer);
+ }
+ if (int_obj.IsSmi() || int_obj.IsMint()) {
+ *fits = !int_obj.IsNegative();
+ } else {
+ ASSERT(int_obj.IsBigint());
+ Bigint& bigint = Bigint::Handle();
+ bigint ^= int_obj.raw();
+ *fits = BigintOperations::FitsIntoUint64(bigint);
+ }
+ return Api::Success();
}
@@ -982,47 +1004,73 @@ DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) {
}
-DART_EXPORT Dart_Handle Dart_IntegerValue(Dart_Handle integer, int64_t* value) {
+DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer,
+ int64_t* value) {
DARTSCOPE(Isolate::Current());
- const Object& obj = Object::Handle(Api::UnwrapHandle(integer));
- if (obj.IsSmi() || obj.IsMint()) {
- Integer& integer = Integer::Handle();
- integer ^= obj.raw();
- *value = integer.AsInt64Value();
- return Api::Success();
+ const Integer& int_obj = Api::UnwrapIntegerHandle(integer);
+ if (int_obj.IsNull()) {
+ RETURN_TYPE_ERROR(integer, Integer);
}
- if (obj.IsBigint()) {
+ if (int_obj.IsSmi() || int_obj.IsMint()) {
+ *value = int_obj.AsInt64Value();
+ } else {
+ ASSERT(int_obj.IsBigint());
Bigint& bigint = Bigint::Handle();
- bigint ^= obj.raw();
+ bigint ^= int_obj.raw();
if (BigintOperations::FitsIntoInt64(bigint)) {
*value = BigintOperations::ToInt64(bigint);
- return Api::Success();
} else {
- return Api::Error("Integer too big to fit in int64_t");
+ return Api::Error("%s: Integer %s cannot be represented as an int64_t.",
+ CURRENT_FUNC, int_obj.ToCString());
+ }
+ }
+ return Api::Success();
+}
+
+
+DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer,
+ uint64_t* value) {
+ DARTSCOPE(Isolate::Current());
+ const Integer& int_obj = Api::UnwrapIntegerHandle(integer);
+ if (int_obj.IsNull()) {
+ RETURN_TYPE_ERROR(integer, Integer);
+ }
+ if (int_obj.IsSmi() || int_obj.IsMint()) {
+ if (!int_obj.IsNegative()) {
+ *value = int_obj.AsInt64Value();
+ return Api::Success();
+ }
+ } else {
+ ASSERT(int_obj.IsBigint());
+ Bigint& bigint = Bigint::Handle();
+ bigint ^= int_obj.raw();
+ if (BigintOperations::FitsIntoUint64(bigint)) {
+ *value = BigintOperations::ToUint64(bigint);
+ return Api::Success();
}
}
- return Api::Error("Object is not a Integer");
+ return Api::Error("%s: Integer %s cannot be represented as a uint64_t.",
+ CURRENT_FUNC, int_obj.ToCString());
turnidge 2011/12/08 22:58:22 Make consistent with IntegerToInt64? (That is, fa
}
-DART_EXPORT Dart_Handle Dart_IntegerValueHexCString(Dart_Handle integer,
- const char** value) {
+DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer,
+ const char** value) {
DARTSCOPE(Isolate::Current());
- const Object& obj = Object::Handle(Api::UnwrapHandle(integer));
+ const Integer& int_obj = Api::UnwrapIntegerHandle(integer);
+ if (int_obj.IsNull()) {
+ RETURN_TYPE_ERROR(integer, Integer);
+ }
Bigint& bigint = Bigint::Handle();
- if (obj.IsSmi() || obj.IsMint()) {
- Integer& integer = Integer::Handle();
- integer ^= obj.raw();
- bigint ^= BigintOperations::NewFromInt64(integer.AsInt64Value());
+ if (int_obj.IsSmi() || int_obj.IsMint()) {
+ bigint ^= BigintOperations::NewFromInt64(int_obj.AsInt64Value());
*value = BigintOperations::ToHexCString(bigint, &Api::Allocate);
- return Api::Success();
- }
- if (obj.IsBigint()) {
- bigint ^= obj.raw();
+ } else {
+ ASSERT(int_obj.IsBigint());
+ bigint ^= int_obj.raw();
*value = BigintOperations::ToHexCString(bigint, &Api::Allocate);
- return Api::Success();
}
- return Api::Error("Object is not a Integer");
+ return Api::Success();
}
« no previous file with comments | « runtime/vm/bigint_operations_test.cc ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698