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/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 list_class, | 73 list_class, |
74 TypeArguments::Handle(isolate), | 74 TypeArguments::Handle(isolate), |
75 &malformed_type_error)) { | 75 &malformed_type_error)) { |
76 ASSERT(malformed_type_error.IsNull()); // Type is a raw List. | 76 ASSERT(malformed_type_error.IsNull()); // Type is a raw List. |
77 return instance.raw(); | 77 return instance.raw(); |
78 } | 78 } |
79 } | 79 } |
80 return Instance::null(); | 80 return Instance::null(); |
81 } | 81 } |
82 | 82 |
83 static RawInstance* GetMapInstance(Isolate* isolate, const Object& obj) { | |
84 if (obj.IsInstance()) { | |
85 const Library& core_lib = Library::Handle(Library::CoreLibrary()); | |
86 const Class& map_class = | |
87 Class::Handle(core_lib.LookupClass(Symbols::Map())); | |
88 ASSERT(!map_class.IsNull()); | |
89 const Instance& instance = Instance::Cast(obj); | |
90 const Class& obj_class = Class::Handle(isolate, obj.clazz()); | |
91 Error& malformed_type_error = Error::Handle(isolate); | |
92 if (obj_class.IsSubtypeOf(TypeArguments::Handle(isolate), | |
93 map_class, | |
94 TypeArguments::Handle(isolate), | |
95 &malformed_type_error)) { | |
96 ASSERT(malformed_type_error.IsNull()); // Type is a raw Map. | |
97 return instance.raw(); | |
98 } | |
99 } | |
100 return Instance::null(); | |
101 } | |
102 | |
83 | 103 |
84 static bool GetNativeStringArgument(NativeArguments* arguments, | 104 static bool GetNativeStringArgument(NativeArguments* arguments, |
85 int arg_index, | 105 int arg_index, |
86 Dart_Handle* str, | 106 Dart_Handle* str, |
87 void** peer) { | 107 void** peer) { |
88 ASSERT(peer != NULL); | 108 ASSERT(peer != NULL); |
89 if (Api::StringGetPeerHelper(arguments, arg_index, peer)) { | 109 if (Api::StringGetPeerHelper(arguments, arg_index, peer)) { |
90 *str = NULL; | 110 *str = NULL; |
91 return true; | 111 return true; |
92 } | 112 } |
(...skipping 1689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1782 return true; | 1802 return true; |
1783 } | 1803 } |
1784 | 1804 |
1785 Isolate* isolate = Isolate::Current(); | 1805 Isolate* isolate = Isolate::Current(); |
1786 DARTSCOPE(isolate); | 1806 DARTSCOPE(isolate); |
1787 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 1807 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
1788 return GetListInstance(isolate, obj) != Instance::null(); | 1808 return GetListInstance(isolate, obj) != Instance::null(); |
1789 } | 1809 } |
1790 | 1810 |
1791 | 1811 |
1812 DART_EXPORT bool Dart_IsMap(Dart_Handle object) { | |
1813 Isolate* isolate = Isolate::Current(); | |
1814 DARTSCOPE(isolate); | |
1815 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | |
1816 return GetMapInstance(isolate, obj) != Instance::null(); | |
1817 } | |
1818 | |
1819 | |
1792 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { | 1820 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { |
1793 TRACE_API_CALL(CURRENT_FUNC); | 1821 TRACE_API_CALL(CURRENT_FUNC); |
1794 return Api::ClassId(object) == kLibraryCid; | 1822 return Api::ClassId(object) == kLibraryCid; |
1795 } | 1823 } |
1796 | 1824 |
1797 | 1825 |
1798 DART_EXPORT bool Dart_IsType(Dart_Handle handle) { | 1826 DART_EXPORT bool Dart_IsType(Dart_Handle handle) { |
1799 TRACE_API_CALL(CURRENT_FUNC); | 1827 TRACE_API_CALL(CURRENT_FUNC); |
1800 return Api::ClassId(handle) == kTypeCid; | 1828 return Api::ClassId(handle) == kTypeCid; |
1801 } | 1829 } |
(...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2865 return Api::NewHandle(isolate, result.raw()); | 2893 return Api::NewHandle(isolate, result.raw()); |
2866 } | 2894 } |
2867 } | 2895 } |
2868 return Api::Success(); | 2896 return Api::Success(); |
2869 } | 2897 } |
2870 } | 2898 } |
2871 return Api::NewError("Object does not implement the 'List' interface"); | 2899 return Api::NewError("Object does not implement the 'List' interface"); |
2872 } | 2900 } |
2873 | 2901 |
2874 | 2902 |
2903 // --- Maps --- | |
2904 | |
2905 DART_EXPORT Dart_Handle Dart_MapGetAt(Dart_Handle map, Dart_Handle key) { | |
2906 Isolate* isolate = Isolate::Current(); | |
2907 DARTSCOPE(isolate); | |
2908 CHECK_CALLBACK_STATE(isolate); | |
2909 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(map)); | |
2910 const Instance& instance = | |
2911 Instance::Handle(isolate, GetMapInstance(isolate, obj)); | |
2912 if (!instance.IsNull()) { | |
2913 const intptr_t kNumArgs = 2; | |
2914 ArgumentsDescriptor args_desc( | |
2915 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); | |
2916 const Function& function = Function::Handle( | |
2917 isolate, | |
2918 Resolver::ResolveDynamic(instance, | |
2919 Symbols::IndexToken(), | |
2920 args_desc)); | |
2921 if (!function.IsNull()) { | |
2922 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | |
2923 args.SetAt(0, instance); | |
2924 args.SetAt(1, Object::Handle(isolate, Api::UnwrapHandle(key))); | |
2925 return Api::NewHandle(isolate, DartEntry::InvokeFunction(function, | |
2926 args)); | |
2927 } | |
2928 } | |
2929 return Api::NewError("Object does not implement the 'Map' interface"); | |
2930 } | |
2931 | |
2932 | |
2933 DART_EXPORT Dart_Handle Dart_MapContainsKey(Dart_Handle map, Dart_Handle key) { | |
koda
2014/05/22 23:40:24
These two functions only differ by the method name
rmacnak
2014/05/30 17:23:33
Factored out 0 and 1 argument sends, and used in L
| |
2934 Isolate* isolate = Isolate::Current(); | |
2935 DARTSCOPE(isolate); | |
2936 CHECK_CALLBACK_STATE(isolate); | |
2937 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(map)); | |
2938 const Instance& instance = | |
2939 Instance::Handle(isolate, GetMapInstance(isolate, obj)); | |
2940 if (!instance.IsNull()) { | |
2941 const intptr_t kNumArgs = 2; | |
2942 ArgumentsDescriptor args_desc( | |
2943 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); | |
2944 const Function& function = Function::Handle( | |
2945 isolate, | |
koda
2014/05/22 23:40:24
Indentation.
| |
2946 Resolver::ResolveDynamic(instance, | |
2947 String::Handle(String::New("containsKey")), | |
2948 args_desc)); | |
2949 if (!function.IsNull()) { | |
2950 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | |
2951 args.SetAt(0, instance); | |
2952 args.SetAt(1, Object::Handle(isolate, Api::UnwrapHandle(key))); | |
2953 return Api::NewHandle(isolate, DartEntry::InvokeFunction(function, | |
2954 args)); | |
2955 } | |
2956 } | |
2957 return Api::NewError("Object does not implement the 'Map' interface"); | |
2958 } | |
2959 | |
2960 | |
2961 DART_EXPORT Dart_Handle Dart_MapKeys(Dart_Handle map) { | |
2962 Isolate* isolate = Isolate::Current(); | |
2963 DARTSCOPE(isolate); | |
2964 CHECK_CALLBACK_STATE(isolate); | |
2965 Object& obj = Object::Handle(isolate, Api::UnwrapHandle(map)); | |
2966 Instance& instance = | |
2967 Instance::Handle(isolate, GetMapInstance(isolate, obj)); | |
2968 if (!instance.IsNull()) { | |
2969 const intptr_t kNumArgs = 1; | |
2970 ArgumentsDescriptor args_desc( | |
2971 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); | |
2972 Function& function = Function::Handle( | |
2973 isolate, | |
2974 Resolver::ResolveDynamic(instance, | |
2975 String::Handle(String::New("get:keys")), | |
2976 args_desc)); | |
2977 if (!function.IsNull()) { | |
2978 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | |
2979 args.SetAt(0, instance); | |
2980 obj = DartEntry::InvokeFunction(function, args); | |
2981 if (!obj.IsInstance()) { | |
2982 return Api::NewHandle(isolate, obj.raw()); | |
2983 } | |
2984 instance ^= obj.raw(); | |
koda
2014/05/22 23:40:24
To help the reader, please create a new handle (wi
rmacnak
2014/05/30 17:23:33
Intermediate result named iterator.
| |
2985 function = Resolver::ResolveDynamic(instance, | |
2986 String::Handle(String::New("toList")), | |
2987 args_desc); | |
2988 args.SetAt(0, instance); | |
koda
2014/05/23 00:33:05
Consider passing in 'false' as an argument to get
rmacnak
2014/05/30 17:23:33
Not worth another helper to handle the optional pa
| |
2989 if (!function.IsNull()) { | |
2990 return Api::NewHandle(isolate, DartEntry::InvokeFunction(function, | |
2991 args)); | |
2992 } | |
2993 } | |
2994 } | |
2995 return Api::NewError("Object does not implement the 'Map' interface"); | |
2996 } | |
2997 | |
2998 | |
2875 // --- Typed Data --- | 2999 // --- Typed Data --- |
2876 | 3000 |
2877 // Helper method to get the type of a TypedData object. | 3001 // Helper method to get the type of a TypedData object. |
2878 static Dart_TypedData_Type GetType(intptr_t class_id) { | 3002 static Dart_TypedData_Type GetType(intptr_t class_id) { |
2879 Dart_TypedData_Type type; | 3003 Dart_TypedData_Type type; |
2880 switch (class_id) { | 3004 switch (class_id) { |
2881 case kByteDataViewCid : | 3005 case kByteDataViewCid : |
2882 type = Dart_TypedData_kByteData; | 3006 type = Dart_TypedData_kByteData; |
2883 break; | 3007 break; |
2884 case kTypedDataInt8ArrayCid : | 3008 case kTypedDataInt8ArrayCid : |
(...skipping 2166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5051 | 5175 |
5052 | 5176 |
5053 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 5177 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
5054 const char* name, | 5178 const char* name, |
5055 Dart_ServiceRequestCallback callback, | 5179 Dart_ServiceRequestCallback callback, |
5056 void* user_data) { | 5180 void* user_data) { |
5057 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 5181 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
5058 } | 5182 } |
5059 | 5183 |
5060 } // namespace dart | 5184 } // namespace dart |
OLD | NEW |