Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
| 6 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
| 7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
| 8 | 8 |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "vm/class_finalizer.h" | 10 #include "vm/class_finalizer.h" |
| (...skipping 2716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2727 return Api::NewHandle(isolate, Send1Arg( | 2727 return Api::NewHandle(isolate, Send1Arg( |
| 2728 instance, | 2728 instance, |
| 2729 Symbols::IndexToken(), | 2729 Symbols::IndexToken(), |
| 2730 Instance::Handle(isolate, Integer::New(index)))); | 2730 Instance::Handle(isolate, Integer::New(index)))); |
| 2731 } | 2731 } |
| 2732 return Api::NewError("Object does not implement the 'List' interface"); | 2732 return Api::NewError("Object does not implement the 'List' interface"); |
| 2733 } | 2733 } |
| 2734 } | 2734 } |
| 2735 | 2735 |
| 2736 | 2736 |
| 2737 #define GET_LIST_RANGE(isolate, type, obj, offset, length) \ | |
| 2738 const type& array_obj = type::Cast(obj); \ | |
| 2739 if ((offset >= 0) && (offset + length < array_obj.Length())) { \ | |
| 2740 for (intptr_t index = 0; index < length; ++index) \ | |
| 2741 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
| |
| 2742 return Api::Success(); \ | |
| 2743 } \ | |
| 2744 return Api::NewError("Invalid index passed in to access list element"); \ | |
|
siva
2015/08/12 17:07:25
Invalid offset/index passed.....
| |
| 2745 | |
| 2746 | |
| 2747 DART_EXPORT Dart_Handle Dart_ListGetRange(Dart_Handle list, | |
| 2748 intptr_t offset, | |
| 2749 intptr_t length, | |
| 2750 Dart_Handle* result) { | |
| 2751 Isolate* isolate = Isolate::Current(); | |
| 2752 DARTSCOPE(isolate); | |
|
siva
2015/08/12 17:07:25
if (result == NULL) {
RETURN_NULL_ERROR(result);
| |
| 2753 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | |
| 2754 if (obj.IsArray()) { | |
| 2755 GET_LIST_RANGE(isolate, Array, obj, offset, length); | |
| 2756 } else if (obj.IsGrowableObjectArray()) { | |
| 2757 GET_LIST_RANGE(isolate, GrowableObjectArray, obj, offset, length); | |
| 2758 } else if (obj.IsError()) { | |
| 2759 return list; | |
| 2760 } else { | |
| 2761 CHECK_CALLBACK_STATE(isolate); | |
| 2762 // Check and handle a dart object that implements the List interface. | |
| 2763 const Instance& instance = | |
| 2764 Instance::Handle(isolate, GetListInstance(isolate, obj)); | |
| 2765 if (!instance.IsNull()) { | |
| 2766 for (intptr_t index = 0; index < length; ++index) { | |
| 2767 Dart_Handle value = Api::NewHandle(isolate, Send1Arg( | |
| 2768 instance, | |
| 2769 Symbols::IndexToken(), | |
| 2770 Instance::Handle(isolate, Integer::New(index)))); | |
|
siva
2015/08/12 17:07:25
This would be a little more optimal if we did not
| |
| 2771 if (Dart_IsError(value)) | |
| 2772 return value; | |
| 2773 result[index] = value; | |
| 2774 } | |
| 2775 return Api::Success(); | |
| 2776 } | |
| 2777 return Api::NewError("Object does not implement the 'List' interface"); | |
| 2778 } | |
| 2779 } | |
| 2780 | |
| 2781 | |
| 2737 #define SET_LIST_ELEMENT(isolate, type, obj, index, value) \ | 2782 #define SET_LIST_ELEMENT(isolate, type, obj, index, value) \ |
| 2738 const type& array = type::Cast(obj); \ | 2783 const type& array = type::Cast(obj); \ |
| 2739 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); \ | 2784 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); \ |
| 2740 if (!value_obj.IsNull() && !value_obj.IsInstance()) { \ | 2785 if (!value_obj.IsNull() && !value_obj.IsInstance()) { \ |
| 2741 RETURN_TYPE_ERROR(isolate, value, Instance); \ | 2786 RETURN_TYPE_ERROR(isolate, value, Instance); \ |
| 2742 } \ | 2787 } \ |
| 2743 if ((index >= 0) && (index < array.Length())) { \ | 2788 if ((index >= 0) && (index < array.Length())) { \ |
| 2744 array.SetAt(index, value_obj); \ | 2789 array.SetAt(index, value_obj); \ |
| 2745 return Api::Success(); \ | 2790 return Api::Success(); \ |
| 2746 } \ | 2791 } \ |
| (...skipping 3110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5857 ASSERT(stream != NULL); | 5902 ASSERT(stream != NULL); |
| 5858 TimelineEvent* event = stream->StartEvent(); | 5903 TimelineEvent* event = stream->StartEvent(); |
| 5859 if (event != NULL) { | 5904 if (event != NULL) { |
| 5860 event->AsyncEnd(label, async_id); | 5905 event->AsyncEnd(label, async_id); |
| 5861 event->Complete(); | 5906 event->Complete(); |
| 5862 } | 5907 } |
| 5863 return Api::Success(); | 5908 return Api::Success(); |
| 5864 } | 5909 } |
| 5865 | 5910 |
| 5866 } // namespace dart | 5911 } // namespace dart |
| OLD | NEW |