Chromium Code Reviews| Index: runtime/vm/dart_api_impl.cc |
| diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc |
| index f445bdb442af1c153a919c74f965d4caadba70c4..7640e6247a3826782c573050954a722fe7dcc821 100644 |
| --- a/runtime/vm/dart_api_impl.cc |
| +++ b/runtime/vm/dart_api_impl.cc |
| @@ -714,7 +714,8 @@ 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()) { |
| @@ -737,6 +738,34 @@ DART_EXPORT Dart_Handle Dart_IntegerValue(Dart_Handle integer, int64_t* value) { |
| } |
| +DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer, |
| + uint64_t* value) { |
|
turnidge
2011/11/17 23:19:02
Seeing "Uint64", I might actually prefer the form
cshapiro
2011/11/18 10:06:54
I agree, but I was the one who put the UInt into t
turnidge
2011/11/22 21:06:14
Okay, go ahead with Uint then. That seems okay.
|
| + DARTSCOPE(Isolate::Current()); |
| + const Object& obj = Object::Handle(Api::UnwrapHandle(integer)); |
| + if (obj.IsSmi() || obj.IsMint()) { |
| + Integer& integer = Integer::Handle(); |
| + integer ^= obj.raw(); |
| + if (integer.IsNegative()) { |
| + return Api::Error("Integer too small to fit in uint64_t"); |
| + } |
| + integer ^= obj.raw(); |
| + *value = integer.AsInt64Value(); |
| + return Api::Success(); |
| + } |
| + if (obj.IsBigint()) { |
| + Bigint& bigint = Bigint::Handle(); |
| + bigint ^= obj.raw(); |
| + if (BigintOperations::FitsIntoUint64(bigint)) { |
| + *value = BigintOperations::ToUint64(bigint); |
| + return Api::Success(); |
| + } else { |
| + return Api::Error("Integer too big to fit in uint64_t"); |
|
turnidge
2011/11/17 23:19:02
Regarding the range checks here and above.
Not su
cshapiro
2011/11/18 10:06:54
The missing negative test is an outright bug. (Th
|
| + } |
| + } |
| + return Api::Error("Object is not a Integer"); |
| +} |
| + |
| + |
| DART_EXPORT Dart_Handle Dart_IntegerValueHexCString(Dart_Handle integer, |
| const char** value) { |
|
turnidge
2011/11/17 23:19:02
I think we should make this name consistent with t
cshapiro
2011/11/18 10:06:54
We should certainly try and reduce the amount of n
|
| DARTSCOPE(Isolate::Current()); |