mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 02:07:06 +00:00
Add Dart_NewIntegerFromUint64. Fix Dart_IntegerToUint64 for negative Smis.
R=asiva@google.com Review URL: https://codereview.chromium.org//1086713002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@45143 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
5b1c199b22
commit
5797153584
|
@ -1396,6 +1396,16 @@ DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer,
|
|||
*/
|
||||
DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value);
|
||||
|
||||
/**
|
||||
* Returns an Integer with the provided value.
|
||||
*
|
||||
* \param value The unsigned value of the integer.
|
||||
*
|
||||
* \return The Integer object if no error occurs. Otherwise returns
|
||||
* an error handle.
|
||||
*/
|
||||
DART_EXPORT Dart_Handle Dart_NewIntegerFromUint64(uint64_t value);
|
||||
|
||||
/**
|
||||
* Returns an Integer with the provided value.
|
||||
*
|
||||
|
|
|
@ -2031,6 +2031,14 @@ DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) {
|
|||
}
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle Dart_NewIntegerFromUint64(uint64_t value) {
|
||||
Isolate* isolate = Isolate::Current();
|
||||
DARTSCOPE(isolate);
|
||||
CHECK_CALLBACK_STATE(isolate);
|
||||
return Api::NewHandle(isolate, Integer::NewFromUint64(value));
|
||||
}
|
||||
|
||||
|
||||
DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) {
|
||||
Isolate* isolate = Isolate::Current();
|
||||
DARTSCOPE(isolate);
|
||||
|
@ -2089,8 +2097,9 @@ DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer,
|
|||
if (int_obj.IsNull()) {
|
||||
RETURN_TYPE_ERROR(isolate, integer, Integer);
|
||||
}
|
||||
ASSERT(!int_obj.IsSmi());
|
||||
if (int_obj.IsMint() && !int_obj.IsNegative()) {
|
||||
if (int_obj.IsSmi()) {
|
||||
ASSERT(int_obj.IsNegative());
|
||||
} else if (int_obj.IsMint() && !int_obj.IsNegative()) {
|
||||
*value = int_obj.AsInt64Value();
|
||||
return Api::Success();
|
||||
} else {
|
||||
|
|
|
@ -796,6 +796,7 @@ TEST_CASE(IntegerValues) {
|
|||
const int64_t kIntegerVal1 = 100;
|
||||
const int64_t kIntegerVal2 = 0xffffffff;
|
||||
const char* kIntegerVal3 = "0x123456789123456789123456789";
|
||||
const uint64_t kIntegerVal4 = 0xffffffffffffffff;
|
||||
|
||||
Dart_Handle val1 = Dart_NewInteger(kIntegerVal1);
|
||||
EXPECT(Dart_IsInteger(val1));
|
||||
|
@ -829,6 +830,19 @@ TEST_CASE(IntegerValues) {
|
|||
result = Dart_IntegerToHexCString(val3, &chars);
|
||||
EXPECT_VALID(result);
|
||||
EXPECT(!strcmp(kIntegerVal3, chars));
|
||||
|
||||
Dart_Handle val4 = Dart_NewIntegerFromUint64(kIntegerVal4);
|
||||
EXPECT_VALID(val4);
|
||||
uint64_t out4 = 0;
|
||||
result = Dart_IntegerToUint64(val4, &out4);
|
||||
EXPECT_VALID(result);
|
||||
EXPECT_EQ(kIntegerVal4, out4);
|
||||
|
||||
Dart_Handle val5 = Dart_NewInteger(-1);
|
||||
EXPECT_VALID(val5);
|
||||
uint64_t out5 = 0;
|
||||
result = Dart_IntegerToUint64(val5, &out5);
|
||||
EXPECT(Dart_IsError(result));
|
||||
}
|
||||
|
||||
|
||||
|
@ -847,7 +861,7 @@ TEST_CASE(IntegerFitsIntoInt64) {
|
|||
EXPECT_VALID(result);
|
||||
EXPECT(!fits);
|
||||
|
||||
Dart_Handle min = Dart_NewInteger(kMaxInt64);
|
||||
Dart_Handle min = Dart_NewInteger(kMinInt64);
|
||||
EXPECT(Dart_IsInteger(min));
|
||||
fits = false;
|
||||
result = Dart_IntegerFitsIntoInt64(min, &fits);
|
||||
|
@ -864,7 +878,7 @@ TEST_CASE(IntegerFitsIntoInt64) {
|
|||
|
||||
|
||||
TEST_CASE(IntegerFitsIntoUint64) {
|
||||
Dart_Handle max = Dart_NewIntegerFromHexCString("0xFFFFFFFFFFFFFFFF");
|
||||
Dart_Handle max = Dart_NewIntegerFromUint64(kMaxUint64);
|
||||
EXPECT(Dart_IsInteger(max));
|
||||
bool fits = false;
|
||||
Dart_Handle result = Dart_IntegerFitsIntoUint64(max, &fits);
|
||||
|
|
Loading…
Reference in a new issue