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

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 1284633004: Add Dart_ListGetRange (Closed) Base URL: https://chromium.googlesource.com/external/github.com/dart-lang/sdk.git@master
Patch Set: Address review comments Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2725 matching lines...) Expand 10 before | Expand all | Expand 10 after
2736 return Api::NewHandle(isolate, Send1Arg( 2736 return Api::NewHandle(isolate, Send1Arg(
2737 instance, 2737 instance,
2738 Symbols::IndexToken(), 2738 Symbols::IndexToken(),
2739 Instance::Handle(isolate, Integer::New(index)))); 2739 Instance::Handle(isolate, Integer::New(index))));
2740 } 2740 }
2741 return Api::NewError("Object does not implement the 'List' interface"); 2741 return Api::NewError("Object does not implement the 'List' interface");
2742 } 2742 }
2743 } 2743 }
2744 2744
2745 2745
2746 #define GET_LIST_RANGE(isolate, type, obj, offset, length) \
2747 const type& array_obj = type::Cast(obj); \
2748 if ((offset >= 0) && (offset + length <= array_obj.Length())) { \
2749 for (intptr_t index = 0; index < length; ++index) { \
2750 result[index] = Api::NewHandle(isolate, array_obj.At(index + offset)); \
2751 } \
2752 return Api::Success(); \
2753 } \
2754 return Api::NewError("Invalid offset/length passed in to access list"); \
2755
2756
2757 DART_EXPORT Dart_Handle Dart_ListGetRange(Dart_Handle list,
2758 intptr_t offset,
2759 intptr_t length,
2760 Dart_Handle* result) {
2761 Isolate* isolate = Isolate::Current();
2762 DARTSCOPE(isolate);
2763 if (result == NULL) {
2764 RETURN_NULL_ERROR(result);
2765 }
2766 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list));
2767 if (obj.IsArray()) {
2768 GET_LIST_RANGE(isolate, Array, obj, offset, length);
2769 } else if (obj.IsGrowableObjectArray()) {
2770 GET_LIST_RANGE(isolate, GrowableObjectArray, obj, offset, length);
2771 } else if (obj.IsError()) {
2772 return list;
2773 } else {
2774 CHECK_CALLBACK_STATE(isolate);
2775 // Check and handle a dart object that implements the List interface.
2776 const Instance& instance =
2777 Instance::Handle(isolate, GetListInstance(isolate, obj));
2778 if (!instance.IsNull()) {
2779 const intptr_t kNumArgs = 2;
2780 ArgumentsDescriptor args_desc(
2781 Array::Handle(ArgumentsDescriptor::New(kNumArgs)));
2782 const Function& function = Function::Handle(
2783 isolate,
2784 Resolver::ResolveDynamic(instance,
2785 Symbols::AssignIndexToken(),
2786 args_desc));
2787 if (!function.IsNull()) {
2788 const Array& args = Array::Handle(Array::New(kNumArgs));
2789 args.SetAt(0, instance);
2790 Instance& index = Instance::Handle(isolate);
2791 for (intptr_t i = 0; i < length; ++i) {
2792 index = Integer::New(i);
2793 args.SetAt(1, index);
2794 Dart_Handle value = Api::NewHandle(isolate,
2795 DartEntry::InvokeFunction(function, args));
2796 if (Dart_IsError(value))
2797 return value;
2798 result[i] = value;
2799 }
2800 return Api::Success();
2801 }
2802 }
2803 return Api::NewError("Object does not implement the 'List' interface");
2804 }
2805 }
2806
2807
2746 #define SET_LIST_ELEMENT(isolate, type, obj, index, value) \ 2808 #define SET_LIST_ELEMENT(isolate, type, obj, index, value) \
2747 const type& array = type::Cast(obj); \ 2809 const type& array = type::Cast(obj); \
2748 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); \ 2810 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); \
2749 if (!value_obj.IsNull() && !value_obj.IsInstance()) { \ 2811 if (!value_obj.IsNull() && !value_obj.IsInstance()) { \
2750 RETURN_TYPE_ERROR(isolate, value, Instance); \ 2812 RETURN_TYPE_ERROR(isolate, value, Instance); \
2751 } \ 2813 } \
2752 if ((index >= 0) && (index < array.Length())) { \ 2814 if ((index >= 0) && (index < array.Length())) { \
2753 array.SetAt(index, value_obj); \ 2815 array.SetAt(index, value_obj); \
2754 return Api::Success(); \ 2816 return Api::Success(); \
2755 } \ 2817 } \
(...skipping 3199 matching lines...) Expand 10 before | Expand all | Expand 10 after
5955 ASSERT(stream != NULL); 6017 ASSERT(stream != NULL);
5956 TimelineEvent* event = stream->StartEvent(); 6018 TimelineEvent* event = stream->StartEvent();
5957 if (event != NULL) { 6019 if (event != NULL) {
5958 event->AsyncEnd(label, async_id); 6020 event->AsyncEnd(label, async_id);
5959 event->Complete(); 6021 event->Complete();
5960 } 6022 }
5961 return Api::Success(); 6023 return Api::Success();
5962 } 6024 }
5963 6025
5964 } // namespace dart 6026 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698