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

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, 6 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
« runtime/lib/mirrors.cc ('K') | « runtime/lib/mirrors.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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); 214 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target));
215 if (obj.IsError()) { 215 if (obj.IsError()) {
216 return target; 216 return target;
217 } 217 }
218 218
219 const GrowableObjectArray& names = 219 const GrowableObjectArray& names =
220 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New()); 220 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New());
221 Function& func = Function::Handle(); 221 Function& func = Function::Handle();
222 String& name = String::Handle(); 222 String& name = String::Handle();
223 223
224 if (obj.IsClass()) { 224 if (obj.IsType() || obj.IsClass()) {
225 const Class& cls = Class::Cast(obj); 225 // For backwards compatibility we allow class objects to be passed in
226 // for now. This needs to be removed once all code that uses class
227 // objects to invoke Dart_Invoke is removed.
228 const Class& cls = (obj.IsType()) ?
229 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj);
226 const Error& error = Error::Handle(isolate, cls.EnsureIsFinalized(isolate)); 230 const Error& error = Error::Handle(isolate, cls.EnsureIsFinalized(isolate));
227 if (!error.IsNull()) { 231 if (!error.IsNull()) {
228 return Api::NewHandle(isolate, error.raw()); 232 return Api::NewHandle(isolate, error.raw());
229 } 233 }
230 const Array& func_array = Array::Handle(cls.functions()); 234 const Array& func_array = Array::Handle(cls.functions());
231 235
232 // Some special types like 'dynamic' have a null functions list. 236 // Some special types like 'dynamic' have a null functions list.
233 if (!func_array.IsNull()) { 237 if (!func_array.IsNull()) {
234 for (intptr_t i = 0; i < func_array.Length(); ++i) { 238 for (intptr_t i = 0; i < func_array.Length(); ++i) {
235 func ^= func_array.At(i); 239 func ^= func_array.At(i);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 if (obj.IsError()) { 280 if (obj.IsError()) {
277 return target; 281 return target;
278 } 282 }
279 const String& func_name = Api::UnwrapStringHandle(isolate, function_name); 283 const String& func_name = Api::UnwrapStringHandle(isolate, function_name);
280 if (func_name.IsNull()) { 284 if (func_name.IsNull()) {
281 RETURN_TYPE_ERROR(isolate, function_name, String); 285 RETURN_TYPE_ERROR(isolate, function_name, String);
282 } 286 }
283 287
284 Function& func = Function::Handle(isolate); 288 Function& func = Function::Handle(isolate);
285 String& tmp_name = String::Handle(isolate); 289 String& tmp_name = String::Handle(isolate);
286 if (obj.IsClass()) { 290 if (obj.IsType() || obj.IsClass()) {
287 const Class& cls = Class::Cast(obj); 291 // For backwards compatibility we allow class objects to be passed in
292 // for now. This needs to be removed once all code that uses class
293 // objects to invoke Dart_Invoke is removed.
294 const Class& cls = (obj.IsType()) ?
295 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj);
288 296
289 // Case 1. Lookup the unmodified function name. 297 // Case 1. Lookup the unmodified function name.
290 func = cls.LookupFunctionAllowPrivate(func_name); 298 func = cls.LookupFunctionAllowPrivate(func_name);
291 299
292 // Case 2. Lookup the function without the external setter suffix 300 // Case 2. Lookup the function without the external setter suffix
293 // '='. Make sure to do this check after the regular lookup, so 301 // '='. Make sure to do this check after the regular lookup, so
294 // that we don't interfere with operator lookups (like ==). 302 // that we don't interfere with operator lookups (like ==).
295 if (func.IsNull() && HasExternalSetterSuffix(func_name)) { 303 if (func.IsNull() && HasExternalSetterSuffix(func_name)) {
296 tmp_name = RemoveExternalSetterSuffix(func_name); 304 tmp_name = RemoveExternalSetterSuffix(func_name);
297 tmp_name = Field::SetterName(tmp_name); 305 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)); 562 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target));
555 if (obj.IsError()) { 563 if (obj.IsError()) {
556 return target; 564 return target;
557 } 565 }
558 566
559 const GrowableObjectArray& names = 567 const GrowableObjectArray& names =
560 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New()); 568 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New());
561 Field& field = Field::Handle(isolate); 569 Field& field = Field::Handle(isolate);
562 String& name = String::Handle(isolate); 570 String& name = String::Handle(isolate);
563 571
564 if (obj.IsClass()) { 572 if (obj.IsType() || obj.IsClass()) {
565 const Class& cls = Class::Cast(obj); 573 // For backwards compatibility we allow class objects to be passed in
574 // for now. This needs to be removed once all code that uses class
575 // objects to invoke Dart_Invoke is removed.
576 const Class& cls = (obj.IsType()) ?
577 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj);
566 const Error& error = Error::Handle(isolate, cls.EnsureIsFinalized(isolate)); 578 const Error& error = Error::Handle(isolate, cls.EnsureIsFinalized(isolate));
567 if (!error.IsNull()) { 579 if (!error.IsNull()) {
568 return Api::NewHandle(isolate, error.raw()); 580 return Api::NewHandle(isolate, error.raw());
569 } 581 }
570 const Array& field_array = Array::Handle(cls.fields()); 582 const Array& field_array = Array::Handle(cls.fields());
571 583
572 // Some special types like 'dynamic' have a null fields list. 584 // Some special types like 'dynamic' have a null fields list.
573 // 585 //
574 // TODO(turnidge): Fix 'dynamic' so that it does not have a null 586 // 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 587 // 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(); 619 Isolate* isolate = Isolate::Current();
608 DARTSCOPE(isolate); 620 DARTSCOPE(isolate);
609 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); 621 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target));
610 if (obj.IsError()) { 622 if (obj.IsError()) {
611 return target; 623 return target;
612 } 624 }
613 const String& var_name = Api::UnwrapStringHandle(isolate, variable_name); 625 const String& var_name = Api::UnwrapStringHandle(isolate, variable_name);
614 if (var_name.IsNull()) { 626 if (var_name.IsNull()) {
615 RETURN_TYPE_ERROR(isolate, variable_name, String); 627 RETURN_TYPE_ERROR(isolate, variable_name, String);
616 } 628 }
617 if (obj.IsClass()) { 629 if (obj.IsType() || obj.IsClass()) {
618 const Class& cls = Class::Cast(obj); 630 // For backwards compatibility we allow class objects to be passed in
631 // for now. This needs to be removed once all code that uses class
632 // objects to invoke Dart_Invoke is removed.
633 const Class& cls = (obj.IsType()) ?
634 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj);
619 return Api::NewHandle(isolate, cls.LookupField(var_name)); 635 return Api::NewHandle(isolate, cls.LookupField(var_name));
620 } 636 }
621 if (obj.IsLibrary()) { 637 if (obj.IsLibrary()) {
622 const Library& lib = Library::Cast(obj); 638 const Library& lib = Library::Cast(obj);
623 return Api::NewHandle(isolate, lib.LookupFieldAllowPrivate(var_name)); 639 return Api::NewHandle(isolate, lib.LookupFieldAllowPrivate(var_name));
624 } 640 }
625 return Api::NewError( 641 return Api::NewError(
626 "%s expects argument 'target' to be a class or library.", 642 "%s expects argument 'target' to be a class or library.",
627 CURRENT_FUNC); 643 CURRENT_FUNC);
628 } 644 }
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 } else if (obj.IsField()) { 877 } else if (obj.IsField()) {
862 cls = Field::Cast(obj).origin(); 878 cls = Field::Cast(obj).origin();
863 } else { 879 } else {
864 return Api::NewHandle(isolate, Object::empty_array().raw()); 880 return Api::NewHandle(isolate, Object::empty_array().raw());
865 } 881 }
866 const Library& lib = Library::Handle(cls.library()); 882 const Library& lib = Library::Handle(cls.library());
867 return Api::NewHandle(isolate, lib.GetMetadata(obj)); 883 return Api::NewHandle(isolate, lib.GetMetadata(obj));
868 } 884 }
869 885
870 } // namespace dart 886 } // namespace dart
OLDNEW
« runtime/lib/mirrors.cc ('K') | « runtime/lib/mirrors.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698