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 6536e08d26540ffeb475b6a4e8127a3b38d596e7..137d9a54f68c4d7ce1a3f40f6dc0b91a65ac6b04 100644 |
| --- a/runtime/vm/dart_api_impl.cc |
| +++ b/runtime/vm/dart_api_impl.cc |
| @@ -2734,6 +2734,51 @@ DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { |
| } |
| +#define GET_LIST_RANGE(isolate, type, obj, offset, length) \ |
| + const type& array_obj = type::Cast(obj); \ |
| + if ((offset >= 0) && (offset + length < array_obj.Length())) { \ |
| + for (intptr_t index = 0; index < length; ++index) \ |
| + result[index] = Api::NewHandle(isolate, array_obj.At(index + offset)); \ |
|
siva
2015/08/12 17:07:25
We normally use { ... } even if there is only one
|
| + return Api::Success(); \ |
| + } \ |
| + return Api::NewError("Invalid index passed in to access list element"); \ |
|
siva
2015/08/12 17:07:25
Invalid offset/index passed.....
|
| + |
| + |
| +DART_EXPORT Dart_Handle Dart_ListGetRange(Dart_Handle list, |
| + intptr_t offset, |
| + intptr_t length, |
| + Dart_Handle* result) { |
| + Isolate* isolate = Isolate::Current(); |
| + DARTSCOPE(isolate); |
|
siva
2015/08/12 17:07:25
if (result == NULL) {
RETURN_NULL_ERROR(result);
|
| + const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
| + if (obj.IsArray()) { |
| + GET_LIST_RANGE(isolate, Array, obj, offset, length); |
| + } else if (obj.IsGrowableObjectArray()) { |
| + GET_LIST_RANGE(isolate, GrowableObjectArray, obj, offset, length); |
| + } else if (obj.IsError()) { |
| + return list; |
| + } else { |
| + CHECK_CALLBACK_STATE(isolate); |
| + // Check and handle a dart object that implements the List interface. |
| + const Instance& instance = |
| + Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| + if (!instance.IsNull()) { |
| + for (intptr_t index = 0; index < length; ++index) { |
| + Dart_Handle value = Api::NewHandle(isolate, Send1Arg( |
| + instance, |
| + Symbols::IndexToken(), |
| + Instance::Handle(isolate, Integer::New(index)))); |
|
siva
2015/08/12 17:07:25
This would be a little more optimal if we did not
|
| + if (Dart_IsError(value)) |
| + return value; |
| + result[index] = value; |
| + } |
| + return Api::Success(); |
| + } |
| + return Api::NewError("Object does not implement the 'List' interface"); |
| + } |
| +} |
| + |
| + |
| #define SET_LIST_ELEMENT(isolate, type, obj, index, value) \ |
| const type& array = type::Cast(obj); \ |
| const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); \ |