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

Unified Diff: runtime/vm/dart_api_impl.cc

Issue 10941018: Constraint List length values to the Smi type. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 months 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 | « no previous file | no next file » | 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 dbb20cc14f6f9328958283ea5f6f4169cf3ae3fa..a677d4db6b6e03fee525c21c5267e7bf179f41b3 100644
--- a/runtime/vm/dart_api_impl.cc
+++ b/runtime/vm/dart_api_impl.cc
@@ -1276,7 +1276,7 @@ DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer,
*fits = true;
return Api::Success(isolate);
}
-
+ // Slow path for Mints and Bigints.
DARTSCOPE_NOCHECKS(isolate);
const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer);
if (int_obj.IsNull()) {
@@ -1297,13 +1297,14 @@ DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer,
*fits = (Api::SmiValue(integer) >= 0);
return Api::Success(isolate);
}
-
+ // Slow path for Mints and Bigints.
DARTSCOPE_NOCHECKS(isolate);
const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer);
if (int_obj.IsNull()) {
RETURN_TYPE_ERROR(isolate, integer, Integer);
}
- if (int_obj.IsSmi() || int_obj.IsMint()) {
+ ASSERT(!int_obj.IsSmi());
+ if (int_obj.IsMint()) {
*fits = !int_obj.IsNegative();
} else {
*fits = BigintOperations::FitsIntoUint64(Bigint::Cast(int_obj));
@@ -1318,9 +1319,9 @@ DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) {
CHECK_ISOLATE(isolate);
if (Smi::IsValid64(value)) {
NOHANDLESCOPE(isolate);
- return Api::NewHandle(isolate, Smi::New(value));
+ return Api::NewHandle(isolate, Smi::New(static_cast<intptr_t>(value)));
}
-
+ // Slow path for Mints and Bigints.
DARTSCOPE_NOCHECKS(isolate);
return Api::NewHandle(isolate, Integer::New(value));
}
@@ -1343,13 +1344,14 @@ DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer,
*value = Api::SmiValue(integer);
return Api::Success(isolate);
}
-
+ // Slow path for Mints and Bigints.
DARTSCOPE_NOCHECKS(isolate);
const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer);
if (int_obj.IsNull()) {
RETURN_TYPE_ERROR(isolate, integer, Integer);
}
- if (int_obj.IsSmi() || int_obj.IsMint()) {
+ ASSERT(!int_obj.IsSmi());
+ if (int_obj.IsMint()) {
*value = int_obj.AsInt64Value();
return Api::Success(isolate);
} else {
@@ -1376,17 +1378,16 @@ DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer,
return Api::Success(isolate);
}
}
-
+ // Slow path for Mints and Bigints.
DARTSCOPE_NOCHECKS(isolate);
const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer);
if (int_obj.IsNull()) {
RETURN_TYPE_ERROR(isolate, integer, Integer);
}
- if (int_obj.IsSmi() || int_obj.IsMint()) {
- if (!int_obj.IsNegative()) {
- *value = int_obj.AsInt64Value();
- return Api::Success(isolate);
- }
+ ASSERT(!int_obj.IsSmi());
+ if (int_obj.IsMint() && !int_obj.IsNegative()) {
+ *value = int_obj.AsInt64Value();
+ return Api::Success(isolate);
} else {
const Bigint& bigint = Bigint::Cast(int_obj);
if (BigintOperations::FitsIntoUint64(bigint)) {
@@ -1839,18 +1840,12 @@ DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) {
const Object& retval = Object::Handle(
isolate,
DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames));
- if (retval.IsSmi() || retval.IsMint()) {
- *len = Integer::Cast(retval).AsInt64Value();
+ if (retval.IsSmi()) {
+ *len = Smi::Cast(retval).Value();
return Api::Success(isolate);
siva 2012/09/19 00:57:34 As discussed offline we should probably allow for
- } else if (retval.IsBigint()) {
- const Bigint& bigint = Bigint::Cast(retval);
- if (BigintOperations::FitsIntoMint(bigint)) {
- *len = BigintOperations::ToMint(bigint);
- return Api::Success(isolate);
- } else {
- return Api::NewError("Length of List object is greater than the "
- "maximum value that 'len' parameter can hold");
- }
+ } else if (retval.IsMint() || retval.IsBigint()) {
+ return Api::NewError("Length of List object is greater than the "
+ "maximum value that 'len' parameter can hold");
} else if (retval.IsError()) {
return Api::NewHandle(isolate, retval.raw());
} else {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698