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

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

Issue 17582016: Convert implementation in mirrors.cc to use Dart_GetType instead of Dart_GetClass. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | no next file » | 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_mirrors_api.h" 5 #include "include/dart_mirrors_api.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart.h" 9 #include "vm/dart.h"
10 #include "vm/dart_api_impl.h" 10 #include "vm/dart_api_impl.h"
(...skipping 30 matching lines...) Expand all
41 return Api::NewHandle(isolate, type.raw()); 41 return Api::NewHandle(isolate, type.raw());
42 } else { 42 } else {
43 return Api::NewError("%s: unexpected type '%s' encountered.", 43 return Api::NewError("%s: unexpected type '%s' encountered.",
44 function_name, type.ToCString()); 44 function_name, type.ToCString());
45 } 45 }
46 } 46 }
47 47
48 48
49 // --- Classes and Interfaces Reflection --- 49 // --- Classes and Interfaces Reflection ---
50 50
51 DART_EXPORT Dart_Handle Dart_ClassName(Dart_Handle clazz) { 51 DART_EXPORT Dart_Handle Dart_ClassName(Dart_Handle object) {
52 Isolate* isolate = Isolate::Current(); 52 Isolate* isolate = Isolate::Current();
53 DARTSCOPE(isolate); 53 DARTSCOPE(isolate);
54 const Class& cls = Api::UnwrapClassHandle(isolate, clazz); 54 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
55 if (cls.IsNull()) { 55 if (obj.IsType() || obj.IsClass()) {
56 RETURN_TYPE_ERROR(isolate, clazz, Class); 56 const Class& cls = (obj.IsType()) ?
57 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj);
58 return Api::NewHandle(isolate, cls.UserVisibleName());
59 } else {
60 RETURN_TYPE_ERROR(isolate, object, Class/Type);
57 } 61 }
58 return Api::NewHandle(isolate, cls.UserVisibleName());
59 } 62 }
60 63
61 64
62 DART_EXPORT Dart_Handle Dart_ClassGetLibrary(Dart_Handle clazz) { 65 DART_EXPORT Dart_Handle Dart_ClassGetLibrary(Dart_Handle object) {
63 Isolate* isolate = Isolate::Current(); 66 Isolate* isolate = Isolate::Current();
64 DARTSCOPE(isolate); 67 DARTSCOPE(isolate);
65 const Class& cls = Api::UnwrapClassHandle(isolate, clazz); 68 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
66 if (cls.IsNull()) { 69 if (!obj.IsType() && !obj.IsClass()) {
67 RETURN_TYPE_ERROR(isolate, clazz, Class); 70 RETURN_TYPE_ERROR(isolate, object, Class/Type);
68 } 71 }
72 const Class& cls = (obj.IsType()) ?
73 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj);
69 74
70 #if defined(DEBUG) 75 #if defined(DEBUG)
71 const Library& lib = Library::Handle(cls.library()); 76 const Library& lib = Library::Handle(cls.library());
72 if (lib.IsNull()) { 77 if (lib.IsNull()) {
73 // ASSERT(cls.IsDynamicClass() || cls.IsVoidClass()); 78 // ASSERT(cls.IsDynamicClass() || cls.IsVoidClass());
74 if (!cls.IsDynamicClass() && !cls.IsVoidClass()) { 79 if (!cls.IsDynamicClass() && !cls.IsVoidClass()) {
75 fprintf(stderr, "NO LIBRARY: %s\n", cls.ToCString()); 80 fprintf(stderr, "NO LIBRARY: %s\n", cls.ToCString());
76 } 81 }
77 } 82 }
78 #endif 83 #endif
79 84
80 return Api::NewHandle(isolate, cls.library()); 85 return Api::NewHandle(isolate, cls.library());
81 } 86 }
82 87
83 88
84 DART_EXPORT Dart_Handle Dart_ClassGetInterfaceCount(Dart_Handle clazz, 89 DART_EXPORT Dart_Handle Dart_ClassGetInterfaceCount(Dart_Handle object,
85 intptr_t* count) { 90 intptr_t* count) {
86 Isolate* isolate = Isolate::Current(); 91 Isolate* isolate = Isolate::Current();
87 DARTSCOPE(isolate); 92 DARTSCOPE(isolate);
88 const Class& cls = Api::UnwrapClassHandle(isolate, clazz); 93 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
89 if (cls.IsNull()) { 94 if (!obj.IsType() && !obj.IsClass()) {
90 RETURN_TYPE_ERROR(isolate, clazz, Class); 95 RETURN_TYPE_ERROR(isolate, object, Class/Type);
91 } 96 }
92 97 const Class& cls = (obj.IsType()) ?
98 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj);
93 const Array& interface_types = Array::Handle(isolate, cls.interfaces()); 99 const Array& interface_types = Array::Handle(isolate, cls.interfaces());
94 if (interface_types.IsNull()) { 100 if (interface_types.IsNull()) {
95 *count = 0; 101 *count = 0;
96 } else { 102 } else {
97 *count = interface_types.Length(); 103 *count = interface_types.Length();
98 } 104 }
99 return Api::Success(); 105 return Api::Success();
100 } 106 }
101 107
102 108
103 DART_EXPORT Dart_Handle Dart_ClassGetInterfaceAt(Dart_Handle clazz, 109 DART_EXPORT Dart_Handle Dart_ClassGetInterfaceAt(Dart_Handle object,
104 intptr_t index) { 110 intptr_t index) {
105 Isolate* isolate = Isolate::Current(); 111 Isolate* isolate = Isolate::Current();
106 DARTSCOPE(isolate); 112 DARTSCOPE(isolate);
107 const Class& cls = Api::UnwrapClassHandle(isolate, clazz); 113 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
108 if (cls.IsNull()) { 114 if (!obj.IsType() && !obj.IsClass()) {
109 RETURN_TYPE_ERROR(isolate, clazz, Class); 115 RETURN_TYPE_ERROR(isolate, object, Class/Type);
110 } 116 }
117 const Class& cls = (obj.IsType()) ?
118 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj);
111 119
112 // Finalize all classes. 120 // Finalize all classes.
113 Dart_Handle state = Api::CheckIsolateState(isolate); 121 Dart_Handle state = Api::CheckIsolateState(isolate);
114 if (::Dart_IsError(state)) { 122 if (::Dart_IsError(state)) {
115 return state; 123 return state;
116 } 124 }
117 125
118 const Array& interface_types = Array::Handle(isolate, cls.interfaces()); 126 const Array& interface_types = Array::Handle(isolate, cls.interfaces());
119 if (index < 0 || index >= interface_types.Length()) { 127 if (index < 0 || index >= interface_types.Length()) {
120 return Api::NewError("%s: argument 'index' out of bounds.", CURRENT_FUNC); 128 return Api::NewError("%s: argument 'index' out of bounds.", CURRENT_FUNC);
121 } 129 }
122 Type& interface_type = Type::Handle(isolate); 130 Type& interface_type = Type::Handle(isolate);
123 interface_type ^= interface_types.At(index); 131 interface_type ^= interface_types.At(index);
124 if (interface_type.HasResolvedTypeClass()) { 132 if (interface_type.HasResolvedTypeClass()) {
125 return Api::NewHandle(isolate, interface_type.type_class()); 133 return Api::NewHandle(isolate, interface_type.type_class());
126 } 134 }
127 const String& type_name = 135 const String& type_name =
128 String::Handle(isolate, interface_type.TypeClassName()); 136 String::Handle(isolate, interface_type.TypeClassName());
129 return Api::NewError("%s: internal error: found unresolved type class '%s'.", 137 return Api::NewError("%s: internal error: found unresolved type class '%s'.",
130 CURRENT_FUNC, type_name.ToCString()); 138 CURRENT_FUNC, type_name.ToCString());
131 } 139 }
132 140
133 141
134 DART_EXPORT bool Dart_ClassIsTypedef(Dart_Handle clazz) { 142 DART_EXPORT bool Dart_ClassIsTypedef(Dart_Handle object) {
135 Isolate* isolate = Isolate::Current(); 143 Isolate* isolate = Isolate::Current();
136 DARTSCOPE(isolate); 144 DARTSCOPE(isolate);
137 const Class& cls = Api::UnwrapClassHandle(isolate, clazz); 145 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
138 if (cls.IsNull()) { 146 if (!obj.IsType() && !obj.IsClass()) {
139 RETURN_TYPE_ERROR(isolate, clazz, Class); 147 RETURN_TYPE_ERROR(isolate, object, Class/Type);
140 } 148 }
149 const Class& cls = (obj.IsType()) ?
150 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj);
141 // For now we represent typedefs as non-canonical signature classes. 151 // For now we represent typedefs as non-canonical signature classes.
142 // I anticipate this may change if we make typedefs more general. 152 // I anticipate this may change if we make typedefs more general.
143 return cls.IsSignatureClass() && !cls.IsCanonicalSignatureClass(); 153 return cls.IsSignatureClass() && !cls.IsCanonicalSignatureClass();
144 } 154 }
145 155
146 156
147 DART_EXPORT Dart_Handle Dart_ClassGetTypedefReferent(Dart_Handle clazz) { 157 DART_EXPORT Dart_Handle Dart_ClassGetTypedefReferent(Dart_Handle object) {
148 Isolate* isolate = Isolate::Current(); 158 Isolate* isolate = Isolate::Current();
149 DARTSCOPE(isolate); 159 DARTSCOPE(isolate);
150 const Class& cls = Api::UnwrapClassHandle(isolate, clazz); 160 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
151 if (cls.IsNull()) { 161 if (!obj.IsType() && !obj.IsClass()) {
152 RETURN_TYPE_ERROR(isolate, clazz, Class); 162 RETURN_TYPE_ERROR(isolate, object, Class/Type);
153 } 163 }
154 164 const Class& cls = (obj.IsType()) ?
165 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj);
155 if (!cls.IsSignatureClass() && !cls.IsCanonicalSignatureClass()) { 166 if (!cls.IsSignatureClass() && !cls.IsCanonicalSignatureClass()) {
156 const String& cls_name = String::Handle(cls.UserVisibleName()); 167 const String& cls_name = String::Handle(cls.UserVisibleName());
157 return Api::NewError("%s: class '%s' is not a typedef class. " 168 return Api::NewError("%s: class '%s' is not a typedef class. "
158 "See Dart_ClassIsTypedef.", 169 "See Dart_ClassIsTypedef.",
159 CURRENT_FUNC, cls_name.ToCString()); 170 CURRENT_FUNC, cls_name.ToCString());
160 } 171 }
161 172
162 const Function& func = Function::Handle(isolate, cls.signature_function()); 173 const Function& func = Function::Handle(isolate, cls.signature_function());
163 return Api::NewHandle(isolate, func.signature_class()); 174 return Api::NewHandle(isolate, func.signature_class());
164 } 175 }
165 176
166 177
167 DART_EXPORT bool Dart_ClassIsFunctionType(Dart_Handle clazz) { 178 DART_EXPORT bool Dart_ClassIsFunctionType(Dart_Handle object) {
168 Isolate* isolate = Isolate::Current(); 179 Isolate* isolate = Isolate::Current();
169 DARTSCOPE(isolate); 180 DARTSCOPE(isolate);
170 const Class& cls = Api::UnwrapClassHandle(isolate, clazz); 181 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
171 if (cls.IsNull()) { 182 if (!obj.IsType() && !obj.IsClass()) {
172 RETURN_TYPE_ERROR(isolate, clazz, Class); 183 RETURN_TYPE_ERROR(isolate, object, Class/Type);
173 } 184 }
185 const Class& cls = (obj.IsType()) ?
186 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj);
174 // A class represents a function type when it is a canonical 187 // A class represents a function type when it is a canonical
175 // signature class. 188 // signature class.
176 return cls.IsCanonicalSignatureClass(); 189 return cls.IsCanonicalSignatureClass();
177 } 190 }
178 191
179 192
180 DART_EXPORT Dart_Handle Dart_ClassGetFunctionTypeSignature(Dart_Handle clazz) { 193 DART_EXPORT Dart_Handle Dart_ClassGetFunctionTypeSignature(Dart_Handle object) {
181 Isolate* isolate = Isolate::Current(); 194 Isolate* isolate = Isolate::Current();
182 DARTSCOPE(isolate); 195 DARTSCOPE(isolate);
183 const Class& cls = Api::UnwrapClassHandle(isolate, clazz); 196 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
184 if (cls.IsNull()) { 197 if (!obj.IsType() && !obj.IsClass()) {
185 RETURN_TYPE_ERROR(isolate, clazz, Class); 198 RETURN_TYPE_ERROR(isolate, object, Class/Type);
186 } 199 }
200 const Class& cls = (obj.IsType()) ?
201 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj);
187 if (!cls.IsCanonicalSignatureClass()) { 202 if (!cls.IsCanonicalSignatureClass()) {
188 const String& cls_name = String::Handle(cls.UserVisibleName()); 203 const String& cls_name = String::Handle(cls.UserVisibleName());
189 return Api::NewError("%s: class '%s' is not a function-type class. " 204 return Api::NewError("%s: class '%s' is not a function-type class. "
190 "See Dart_ClassIsFunctionType.", 205 "See Dart_ClassIsFunctionType.",
191 CURRENT_FUNC, cls_name.ToCString()); 206 CURRENT_FUNC, cls_name.ToCString());
192 } 207 }
193 return Api::NewHandle(isolate, cls.signature_function()); 208 return Api::NewHandle(isolate, cls.signature_function());
194 } 209 }
195 210
196 211
(...skipping 17 matching lines...) Expand all
214 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); 229 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target));
215 if (obj.IsError()) { 230 if (obj.IsError()) {
216 return target; 231 return target;
217 } 232 }
218 233
219 const GrowableObjectArray& names = 234 const GrowableObjectArray& names =
220 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New()); 235 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New());
221 Function& func = Function::Handle(); 236 Function& func = Function::Handle();
222 String& name = String::Handle(); 237 String& name = String::Handle();
223 238
224 if (obj.IsClass()) { 239 if (obj.IsType() || obj.IsClass()) {
225 const Class& cls = Class::Cast(obj); 240 // For backwards compatibility we allow class objects to be passed in
241 // for now. This needs to be removed once all code that uses class
242 // objects to invoke Dart_Invoke is removed.
243 const Class& cls = (obj.IsType()) ?
244 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj);
226 const Error& error = Error::Handle(isolate, cls.EnsureIsFinalized(isolate)); 245 const Error& error = Error::Handle(isolate, cls.EnsureIsFinalized(isolate));
227 if (!error.IsNull()) { 246 if (!error.IsNull()) {
228 return Api::NewHandle(isolate, error.raw()); 247 return Api::NewHandle(isolate, error.raw());
229 } 248 }
230 const Array& func_array = Array::Handle(cls.functions()); 249 const Array& func_array = Array::Handle(cls.functions());
231 250
232 // Some special types like 'dynamic' have a null functions list. 251 // Some special types like 'dynamic' have a null functions list.
233 if (!func_array.IsNull()) { 252 if (!func_array.IsNull()) {
234 for (intptr_t i = 0; i < func_array.Length(); ++i) { 253 for (intptr_t i = 0; i < func_array.Length(); ++i) {
235 func ^= func_array.At(i); 254 func ^= func_array.At(i);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 if (obj.IsError()) { 295 if (obj.IsError()) {
277 return target; 296 return target;
278 } 297 }
279 const String& func_name = Api::UnwrapStringHandle(isolate, function_name); 298 const String& func_name = Api::UnwrapStringHandle(isolate, function_name);
280 if (func_name.IsNull()) { 299 if (func_name.IsNull()) {
281 RETURN_TYPE_ERROR(isolate, function_name, String); 300 RETURN_TYPE_ERROR(isolate, function_name, String);
282 } 301 }
283 302
284 Function& func = Function::Handle(isolate); 303 Function& func = Function::Handle(isolate);
285 String& tmp_name = String::Handle(isolate); 304 String& tmp_name = String::Handle(isolate);
286 if (obj.IsClass()) { 305 if (obj.IsType() || obj.IsClass()) {
287 const Class& cls = Class::Cast(obj); 306 // For backwards compatibility we allow class objects to be passed in
307 // for now. This needs to be removed once all code that uses class
308 // objects to invoke Dart_Invoke is removed.
309 const Class& cls = (obj.IsType()) ?
310 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj);
288 311
289 // Case 1. Lookup the unmodified function name. 312 // Case 1. Lookup the unmodified function name.
290 func = cls.LookupFunctionAllowPrivate(func_name); 313 func = cls.LookupFunctionAllowPrivate(func_name);
291 314
292 // Case 2. Lookup the function without the external setter suffix 315 // Case 2. Lookup the function without the external setter suffix
293 // '='. Make sure to do this check after the regular lookup, so 316 // '='. Make sure to do this check after the regular lookup, so
294 // that we don't interfere with operator lookups (like ==). 317 // that we don't interfere with operator lookups (like ==).
295 if (func.IsNull() && HasExternalSetterSuffix(func_name)) { 318 if (func.IsNull() && HasExternalSetterSuffix(func_name)) {
296 tmp_name = RemoveExternalSetterSuffix(func_name); 319 tmp_name = RemoveExternalSetterSuffix(func_name);
297 tmp_name = Field::SetterName(tmp_name); 320 tmp_name = Field::SetterName(tmp_name);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); 577 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target));
555 if (obj.IsError()) { 578 if (obj.IsError()) {
556 return target; 579 return target;
557 } 580 }
558 581
559 const GrowableObjectArray& names = 582 const GrowableObjectArray& names =
560 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New()); 583 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New());
561 Field& field = Field::Handle(isolate); 584 Field& field = Field::Handle(isolate);
562 String& name = String::Handle(isolate); 585 String& name = String::Handle(isolate);
563 586
564 if (obj.IsClass()) { 587 if (obj.IsType() || obj.IsClass()) {
565 const Class& cls = Class::Cast(obj); 588 // For backwards compatibility we allow class objects to be passed in
589 // for now. This needs to be removed once all code that uses class
590 // objects to invoke Dart_Invoke is removed.
591 const Class& cls = (obj.IsType()) ?
592 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj);
566 const Error& error = Error::Handle(isolate, cls.EnsureIsFinalized(isolate)); 593 const Error& error = Error::Handle(isolate, cls.EnsureIsFinalized(isolate));
567 if (!error.IsNull()) { 594 if (!error.IsNull()) {
568 return Api::NewHandle(isolate, error.raw()); 595 return Api::NewHandle(isolate, error.raw());
569 } 596 }
570 const Array& field_array = Array::Handle(cls.fields()); 597 const Array& field_array = Array::Handle(cls.fields());
571 598
572 // Some special types like 'dynamic' have a null fields list. 599 // Some special types like 'dynamic' have a null fields list.
573 // 600 //
574 // TODO(turnidge): Fix 'dynamic' so that it does not have a null 601 // TODO(turnidge): Fix 'dynamic' so that it does not have a null
575 // fields list. This will have to wait until the empty array is 602 // fields list. This will have to wait until the empty array is
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 Isolate* isolate = Isolate::Current(); 634 Isolate* isolate = Isolate::Current();
608 DARTSCOPE(isolate); 635 DARTSCOPE(isolate);
609 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); 636 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target));
610 if (obj.IsError()) { 637 if (obj.IsError()) {
611 return target; 638 return target;
612 } 639 }
613 const String& var_name = Api::UnwrapStringHandle(isolate, variable_name); 640 const String& var_name = Api::UnwrapStringHandle(isolate, variable_name);
614 if (var_name.IsNull()) { 641 if (var_name.IsNull()) {
615 RETURN_TYPE_ERROR(isolate, variable_name, String); 642 RETURN_TYPE_ERROR(isolate, variable_name, String);
616 } 643 }
617 if (obj.IsClass()) { 644 if (obj.IsType() || obj.IsClass()) {
618 const Class& cls = Class::Cast(obj); 645 // For backwards compatibility we allow class objects to be passed in
646 // for now. This needs to be removed once all code that uses class
647 // objects to invoke Dart_Invoke is removed.
648 const Class& cls = (obj.IsType()) ?
649 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj);
619 return Api::NewHandle(isolate, cls.LookupField(var_name)); 650 return Api::NewHandle(isolate, cls.LookupField(var_name));
620 } 651 }
621 if (obj.IsLibrary()) { 652 if (obj.IsLibrary()) {
622 const Library& lib = Library::Cast(obj); 653 const Library& lib = Library::Cast(obj);
623 return Api::NewHandle(isolate, lib.LookupFieldAllowPrivate(var_name)); 654 return Api::NewHandle(isolate, lib.LookupFieldAllowPrivate(var_name));
624 } 655 }
625 return Api::NewError( 656 return Api::NewError(
626 "%s expects argument 'target' to be a class or library.", 657 "%s expects argument 'target' to be a class or library.",
627 CURRENT_FUNC); 658 CURRENT_FUNC);
628 } 659 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 const Field& var = Api::UnwrapFieldHandle(isolate, variable); 708 const Field& var = Api::UnwrapFieldHandle(isolate, variable);
678 if (var.IsNull()) { 709 if (var.IsNull()) {
679 RETURN_TYPE_ERROR(isolate, variable, Field); 710 RETURN_TYPE_ERROR(isolate, variable, Field);
680 } 711 }
681 712
682 const AbstractType& type = AbstractType::Handle(isolate, var.type()); 713 const AbstractType& type = AbstractType::Handle(isolate, var.type());
683 return TypeToHandle(isolate, "Dart_VariableType", type); 714 return TypeToHandle(isolate, "Dart_VariableType", type);
684 } 715 }
685 716
686 717
687 DART_EXPORT Dart_Handle Dart_GetTypeVariableNames(Dart_Handle clazz) { 718 DART_EXPORT Dart_Handle Dart_GetTypeVariableNames(Dart_Handle object) {
688 Isolate* isolate = Isolate::Current(); 719 Isolate* isolate = Isolate::Current();
689 DARTSCOPE(isolate); 720 DARTSCOPE(isolate);
690 const Class& cls = Api::UnwrapClassHandle(isolate, clazz); 721 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
691 if (cls.IsNull()) { 722 if (!obj.IsType() && !obj.IsClass()) {
692 RETURN_TYPE_ERROR(isolate, clazz, Class); 723 RETURN_TYPE_ERROR(isolate, object, Class/Type);
693 } 724 }
694 725 const Class& cls = (obj.IsType()) ?
726 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj);
695 const intptr_t num_type_params = cls.NumTypeParameters(); 727 const intptr_t num_type_params = cls.NumTypeParameters();
696 const TypeArguments& type_params = 728 const TypeArguments& type_params =
697 TypeArguments::Handle(cls.type_parameters()); 729 TypeArguments::Handle(cls.type_parameters());
698 730
699 const GrowableObjectArray& names = 731 const GrowableObjectArray& names =
700 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New()); 732 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New());
701 TypeParameter& type_param = TypeParameter::Handle(isolate); 733 TypeParameter& type_param = TypeParameter::Handle(isolate);
702 String& name = String::Handle(isolate); 734 String& name = String::Handle(isolate);
703 for (intptr_t i = 0; i < num_type_params; i++) { 735 for (intptr_t i = 0; i < num_type_params; i++) {
704 type_param ^= type_params.TypeAt(i); 736 type_param ^= type_params.TypeAt(i);
705 name = type_param.name(); 737 name = type_param.name();
706 names.Add(name); 738 names.Add(name);
707 } 739 }
708 return Api::NewHandle(isolate, Array::MakeArray(names)); 740 return Api::NewHandle(isolate, Array::MakeArray(names));
709 } 741 }
710 742
711 743
712 DART_EXPORT Dart_Handle Dart_LookupTypeVariable( 744 DART_EXPORT Dart_Handle Dart_LookupTypeVariable(
713 Dart_Handle clazz, 745 Dart_Handle object,
714 Dart_Handle type_variable_name) { 746 Dart_Handle type_variable_name) {
715 Isolate* isolate = Isolate::Current(); 747 Isolate* isolate = Isolate::Current();
716 DARTSCOPE(isolate); 748 DARTSCOPE(isolate);
717 const Class& cls = Api::UnwrapClassHandle(isolate, clazz); 749 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
718 if (cls.IsNull()) { 750 if (!obj.IsType() && !obj.IsClass()) {
719 RETURN_TYPE_ERROR(isolate, clazz, Class); 751 RETURN_TYPE_ERROR(isolate, object, Class/Type);
720 } 752 }
753 const Class& cls = (obj.IsType()) ?
754 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj);
721 const String& var_name = Api::UnwrapStringHandle(isolate, type_variable_name); 755 const String& var_name = Api::UnwrapStringHandle(isolate, type_variable_name);
722 if (var_name.IsNull()) { 756 if (var_name.IsNull()) {
723 RETURN_TYPE_ERROR(isolate, type_variable_name, String); 757 RETURN_TYPE_ERROR(isolate, type_variable_name, String);
724 } 758 }
725 759
726 const intptr_t num_type_params = cls.NumTypeParameters(); 760 const intptr_t num_type_params = cls.NumTypeParameters();
727 const TypeArguments& type_params = 761 const TypeArguments& type_params =
728 TypeArguments::Handle(cls.type_parameters()); 762 TypeArguments::Handle(cls.type_parameters());
729 763
730 TypeParameter& type_param = TypeParameter::Handle(isolate); 764 TypeParameter& type_param = TypeParameter::Handle(isolate);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 } else if (obj.IsField()) { 895 } else if (obj.IsField()) {
862 cls = Field::Cast(obj).origin(); 896 cls = Field::Cast(obj).origin();
863 } else { 897 } else {
864 return Api::NewHandle(isolate, Object::empty_array().raw()); 898 return Api::NewHandle(isolate, Object::empty_array().raw());
865 } 899 }
866 const Library& lib = Library::Handle(cls.library()); 900 const Library& lib = Library::Handle(cls.library());
867 return Api::NewHandle(isolate, lib.GetMetadata(obj)); 901 return Api::NewHandle(isolate, lib.GetMetadata(obj));
868 } 902 }
869 903
870 } // namespace dart 904 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698