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

Side by Side Diff: runtime/lib/mirrors.cc

Issue 19188004: Make the ClassMirrors created through reflectClass() find their owners (libraries) lazily. (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 | « no previous file | runtime/lib/mirrors_impl.dart » ('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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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_debugger_api.h" 6 #include "include/dart_debugger_api.h"
7 #include "include/dart_mirrors_api.h" 7 #include "include/dart_mirrors_api.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_api_state.h" // TODO(11742): Remove with CreateMirrorRef. 9 #include "vm/dart_api_state.h" // TODO(11742): Remove with CreateMirrorRef.
10 #include "vm/bootstrap_natives.h" 10 #include "vm/bootstrap_natives.h"
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 if (Dart_IsError(result)) { 415 if (Dart_IsError(result)) {
416 return result; 416 return result;
417 } 417 }
418 } 418 }
419 return map; 419 return map;
420 } 420 }
421 421
422 422
423 static Dart_Handle CreateTypedefMirror(Dart_Handle cls, 423 static Dart_Handle CreateTypedefMirror(Dart_Handle cls,
424 Dart_Handle cls_name, 424 Dart_Handle cls_name,
425 Dart_Handle owner,
426 Dart_Handle owner_mirror) { 425 Dart_Handle owner_mirror) {
427 Dart_Handle mirror_cls_name = NewString("_LocalTypedefMirrorImpl"); 426 Dart_Handle mirror_cls_name = NewString("_LocalTypedefMirrorImpl");
428 Dart_Handle mirror_type = Dart_GetType(MirrorLib(), mirror_cls_name, 0, NULL); 427 Dart_Handle mirror_type = Dart_GetType(MirrorLib(), mirror_cls_name, 0, NULL);
429 if (Dart_IsError(mirror_type)) { 428 if (Dart_IsError(mirror_type)) {
430 return mirror_type; 429 return mirror_type;
431 } 430 }
432 431
433 Dart_Handle referent = Dart_ClassGetTypedefReferent(cls); 432 Dart_Handle referent = Dart_ClassGetTypedefReferent(cls);
434 if (Dart_IsError(referent)) { 433 if (Dart_IsError(referent)) {
435 return referent; 434 return referent;
436 } 435 }
437 436
438 Dart_Handle args[] = { 437 Dart_Handle args[] = {
439 CreateMirrorReference(cls), 438 CreateMirrorReference(cls),
440 cls_name, 439 cls_name,
441 owner_mirror, 440 owner_mirror,
442 CreateLazyMirror(referent), 441 CreateLazyMirror(referent),
443 }; 442 };
444 Dart_Handle mirror = 443 Dart_Handle mirror =
445 Dart_New(mirror_type, Dart_Null(), ARRAY_SIZE(args), args); 444 Dart_New(mirror_type, Dart_Null(), ARRAY_SIZE(args), args);
446 return mirror; 445 return mirror;
447 } 446 }
448 447
449 448
450 static Dart_Handle CreateMemberMap(Dart_Handle owner, Dart_Handle owner_mirror); 449 static Dart_Handle CreateMemberMap(Dart_Handle owner, Dart_Handle owner_mirror);
451 static Dart_Handle CreateConstructorMap(Dart_Handle owner, 450 static Dart_Handle CreateConstructorMap(Dart_Handle owner,
452 Dart_Handle owner_mirror); 451 Dart_Handle owner_mirror);
453 452
454
455 static Dart_Handle CreateClassMirrorUsingApi(Dart_Handle intf, 453 static Dart_Handle CreateClassMirrorUsingApi(Dart_Handle intf,
456 Dart_Handle intf_name, 454 Dart_Handle intf_name,
457 Dart_Handle lib,
458 Dart_Handle lib_mirror) { 455 Dart_Handle lib_mirror) {
459 ASSERT(Dart_IsClass(intf)); 456 ASSERT(Dart_IsClass(intf));
460 if (Dart_ClassIsTypedef(intf)) { 457 if (Dart_ClassIsTypedef(intf)) {
461 // This class is actually a typedef. Represent it specially in 458 // This class is actually a typedef. Represent it specially in
462 // reflection. 459 // reflection.
463 return CreateTypedefMirror(intf, intf_name, lib, lib_mirror); 460 return CreateTypedefMirror(intf, intf_name, lib_mirror);
464 } 461 }
465 462
466 Dart_Handle cls_name = NewString("_LocalClassMirrorImpl"); 463 Dart_Handle cls_name = NewString("_LocalClassMirrorImpl");
467 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); 464 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL);
468 if (Dart_IsError(type)) { 465 if (Dart_IsError(type)) {
469 return type; 466 return type;
470 } 467 }
471 468
472 // TODO(turnidge): Why am I getting Null when I expect Object? 469 // TODO(turnidge): Why am I getting Null when I expect Object?
473 // TODO(gbracha): this is probably the root of bug 7868 470 // TODO(gbracha): this is probably the root of bug 7868
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 if (Dart_IsError(result)) { 603 if (Dart_IsError(result)) {
607 return result; 604 return result;
608 } 605 }
609 for (intptr_t i = 0; i < len; i++) { 606 for (intptr_t i = 0; i < len; i++) {
610 Dart_Handle intf_name = Dart_ListGetAt(names, i); 607 Dart_Handle intf_name = Dart_ListGetAt(names, i);
611 Dart_Handle intf = Dart_GetClass(owner, intf_name); 608 Dart_Handle intf = Dart_GetClass(owner, intf_name);
612 if (Dart_IsError(intf)) { 609 if (Dart_IsError(intf)) {
613 return intf; 610 return intf;
614 } 611 }
615 Dart_Handle intf_mirror = 612 Dart_Handle intf_mirror =
616 CreateClassMirrorUsingApi(intf, intf_name, owner, owner_mirror); 613 CreateClassMirrorUsingApi(intf, intf_name, owner_mirror);
617 if (Dart_IsError(intf_mirror)) { 614 if (Dart_IsError(intf_mirror)) {
618 return intf_mirror; 615 return intf_mirror;
619 } 616 }
620 result = MapAdd(map, intf_name, intf_mirror); 617 result = MapAdd(map, intf_name, intf_mirror);
621 if (Dart_IsError(result)) { 618 if (Dart_IsError(result)) {
622 return result; 619 return result;
623 } 620 }
624 } 621 }
625 return Dart_True(); 622 return Dart_True();
626 } 623 }
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 CreateLazyMirror(instance_cls), 962 CreateLazyMirror(instance_cls),
966 instance, 963 instance,
967 }; 964 };
968 return Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); 965 return Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args);
969 } 966 }
970 } 967 }
971 968
972 969
973 static RawInstance* CreateClassMirror(const Class& cls, 970 static RawInstance* CreateClassMirror(const Class& cls,
974 const Instance& owner_mirror) { 971 const Instance& owner_mirror) {
972 Instance& retvalue = Instance::Handle();
rmacnak 2013/07/18 22:55:00 Merging with Michael's changes, we discovered it i
975 Dart_EnterScope(); 973 Dart_EnterScope();
976 Isolate* isolate = Isolate::Current(); 974 Isolate* isolate = Isolate::Current();
977 Dart_Handle cls_handle = Api::NewHandle(isolate, cls.raw()); 975 Dart_Handle cls_handle = Api::NewHandle(isolate, cls.raw());
978 if (Dart_IsError(cls_handle)) { 976 if (Dart_IsError(cls_handle)) {
979 Dart_PropagateError(cls_handle); 977 Dart_PropagateError(cls_handle);
980 } 978 }
981 Dart_Handle name_handle = Api::NewHandle(isolate, cls.Name()); 979 Dart_Handle name_handle = Api::NewHandle(isolate, cls.Name());
982 if (Dart_IsError(name_handle)) { 980 if (Dart_IsError(name_handle)) {
983 Dart_PropagateError(name_handle); 981 Dart_PropagateError(name_handle);
984 } 982 }
985 Dart_Handle lib_handle = Api::NewHandle(isolate, cls.library()); 983 Dart_Handle lib_mirror = Api::NewHandle(isolate, owner_mirror.raw());
986 if (Dart_IsError(lib_handle)) {
987 Dart_PropagateError(lib_handle);
988 }
989 Dart_Handle lib_mirror = CreateLibraryMirrorUsingApi(lib_handle);
990 if (Dart_IsError(lib_mirror)) {
991 Dart_PropagateError(lib_mirror);
992 }
993 // TODO(11742): At some point the handle calls will be replaced by inlined 984 // TODO(11742): At some point the handle calls will be replaced by inlined
994 // functionality. 985 // functionality.
995 Dart_Handle result = CreateClassMirrorUsingApi(cls_handle, 986 Dart_Handle result = CreateClassMirrorUsingApi(cls_handle,
996 name_handle, 987 name_handle,
997 lib_handle,
998 lib_mirror); 988 lib_mirror);
999 if (Dart_IsError(result)) { 989 if (Dart_IsError(result)) {
1000 Dart_PropagateError(result); 990 Dart_PropagateError(result);
1001 } 991 }
1002 const Instance& retvalue = Api::UnwrapInstanceHandle(isolate, result); 992 retvalue ^= Api::UnwrapHandle(result);
1003 Dart_ExitScope(); 993 Dart_ExitScope();
1004 return retvalue.raw(); 994 return retvalue.raw();
1005 } 995 }
1006 996
1007 997
1008 static RawInstance* CreateLibraryMirror(const Library& lib) { 998 static RawInstance* CreateLibraryMirror(const Library& lib) {
999 Instance& retvalue = Instance::Handle();
1009 Dart_EnterScope(); 1000 Dart_EnterScope();
1010 Isolate* isolate = Isolate::Current(); 1001 Isolate* isolate = Isolate::Current();
1011 Dart_Handle lib_handle = Api::NewHandle(isolate, lib.raw()); 1002 Dart_Handle lib_handle = Api::NewHandle(isolate, lib.raw());
1012 // TODO(11742): At some point the handle calls will be replaced by inlined 1003 // TODO(11742): At some point the handle calls will be replaced by inlined
1013 // functionality. 1004 // functionality.
1014 Dart_Handle result = CreateLibraryMirrorUsingApi(lib_handle); 1005 Dart_Handle result = CreateLibraryMirrorUsingApi(lib_handle);
1015 if (Dart_IsError(result)) { 1006 if (Dart_IsError(result)) {
1016 Dart_PropagateError(result); 1007 Dart_PropagateError(result);
1017 } 1008 }
1018 const Instance& retvalue = Api::UnwrapInstanceHandle(isolate, result); 1009 retvalue ^= Api::UnwrapHandle(result);
1019 Dart_ExitScope(); 1010 Dart_ExitScope();
1020 return retvalue.raw(); 1011 return retvalue.raw();
1021 } 1012 }
1022 1013
1023 1014
1024 static RawInstance* CreateMethodMirror(const Function& func, 1015 static RawInstance* CreateMethodMirror(const Function& func,
1025 const Instance& owner_mirror) { 1016 const Instance& owner_mirror) {
1017 Instance& retvalue = Instance::Handle();
1026 Dart_EnterScope(); 1018 Dart_EnterScope();
1027 Isolate* isolate = Isolate::Current(); 1019 Isolate* isolate = Isolate::Current();
1028 Dart_Handle func_handle = Api::NewHandle(isolate, func.raw()); 1020 Dart_Handle func_handle = Api::NewHandle(isolate, func.raw());
1029 Dart_Handle owner_handle = Api::NewHandle(isolate, owner_mirror.raw()); 1021 Dart_Handle owner_handle = Api::NewHandle(isolate, owner_mirror.raw());
1030 // TODO(11742): At some point the handle calls will be replaced by inlined 1022 // TODO(11742): At some point the handle calls will be replaced by inlined
1031 // functionality. 1023 // functionality.
1032 Dart_Handle result = CreateMethodMirrorUsingApi(func_handle, owner_handle); 1024 Dart_Handle result = CreateMethodMirrorUsingApi(func_handle, owner_handle);
1033 if (Dart_IsError(result)) { 1025 if (Dart_IsError(result)) {
1034 Dart_PropagateError(result); 1026 Dart_PropagateError(result);
1035 } 1027 }
1036 const Instance& retvalue = Api::UnwrapInstanceHandle(isolate, result); 1028 retvalue ^= Api::UnwrapHandle(result);
1037 Dart_ExitScope(); 1029 Dart_ExitScope();
1038 return retvalue.raw(); 1030 return retvalue.raw();
1039 } 1031 }
1040 1032
1041 1033
1042 void NATIVE_ENTRY_FUNCTION(Mirrors_makeLocalMirrorSystem)( 1034 void NATIVE_ENTRY_FUNCTION(Mirrors_makeLocalMirrorSystem)(
1043 Dart_NativeArguments args) { 1035 Dart_NativeArguments args) {
1044 Dart_EnterScope(); 1036 Dart_EnterScope();
1045 Dart_Handle mirrors = CreateMirrorSystem(); 1037 Dart_Handle mirrors = CreateMirrorSystem();
1046 if (Dart_IsError(mirrors)) { 1038 if (Dart_IsError(mirrors)) {
(...skipping 28 matching lines...) Expand all
1075 const Type& type = Api::UnwrapTypeHandle(isolate, key); 1067 const Type& type = Api::UnwrapTypeHandle(isolate, key);
1076 const Class& cls = Class::Handle(type.type_class()); 1068 const Class& cls = Class::Handle(type.type_class());
1077 Dart_Handle cls_handle = Api::NewHandle(isolate, cls.raw()); 1069 Dart_Handle cls_handle = Api::NewHandle(isolate, cls.raw());
1078 if (Dart_IsError(cls_handle)) { 1070 if (Dart_IsError(cls_handle)) {
1079 Dart_PropagateError(cls_handle); 1071 Dart_PropagateError(cls_handle);
1080 } 1072 }
1081 Dart_Handle name_handle = Api::NewHandle(isolate, cls.Name()); 1073 Dart_Handle name_handle = Api::NewHandle(isolate, cls.Name());
1082 if (Dart_IsError(name_handle)) { 1074 if (Dart_IsError(name_handle)) {
1083 Dart_PropagateError(name_handle); 1075 Dart_PropagateError(name_handle);
1084 } 1076 }
1085 Dart_Handle lib_handle = Api::NewHandle(isolate, cls.library()); 1077 Dart_Handle lib_mirror = Dart_Null();
1086 if (Dart_IsError(lib_handle)) {
1087 Dart_PropagateError(lib_handle);
1088 }
1089 Dart_Handle lib_mirror = CreateLibraryMirrorUsingApi(lib_handle);
1090 if (Dart_IsError(lib_mirror)) {
1091 Dart_PropagateError(lib_mirror);
1092 }
1093 Dart_Handle result = CreateClassMirrorUsingApi(cls_handle, 1078 Dart_Handle result = CreateClassMirrorUsingApi(cls_handle,
1094 name_handle, 1079 name_handle,
1095 lib_handle,
1096 lib_mirror); 1080 lib_mirror);
1097 if (Dart_IsError(result)) { 1081 if (Dart_IsError(result)) {
1098 Dart_PropagateError(result); 1082 Dart_PropagateError(result);
1099 } 1083 }
1100 Dart_SetReturnValue(args, result); 1084 Dart_SetReturnValue(args, result);
1101 Dart_ExitScope(); 1085 Dart_ExitScope();
1102 } 1086 }
1103 1087
1104 1088
1105 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) { 1089 DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 1240
1257 DEFINE_NATIVE_ENTRY(ClassMirror_name, 1) { 1241 DEFINE_NATIVE_ENTRY(ClassMirror_name, 1) {
1258 const MirrorReference& klass_ref = 1242 const MirrorReference& klass_ref =
1259 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); 1243 MirrorReference::CheckedHandle(arguments->NativeArgAt(0));
1260 Class& klass = Class::Handle(); 1244 Class& klass = Class::Handle();
1261 klass ^= klass_ref.referent(); 1245 klass ^= klass_ref.referent();
1262 return klass.Name(); 1246 return klass.Name();
1263 } 1247 }
1264 1248
1265 1249
1250 DEFINE_NATIVE_ENTRY(ClassMirror_library, 1) {
1251 const MirrorReference& klass_ref =
1252 MirrorReference::CheckedHandle(arguments->NativeArgAt(0));
1253 Class& klass = Class::Handle();
1254 klass ^= klass_ref.referent();
1255
1256 const Library& library = Library::Handle(klass.library());
1257 return CreateLibraryMirror(library);
1258 }
1259
1260
1266 // Invoke the function, or noSuchMethod if it is null. Propagate any unhandled 1261 // Invoke the function, or noSuchMethod if it is null. Propagate any unhandled
1267 // exceptions. Wrap and propagate any compilation errors. 1262 // exceptions. Wrap and propagate any compilation errors.
1268 static RawObject* ReflectivelyInvokeDynamicFunction(const Instance& receiver, 1263 static RawObject* ReflectivelyInvokeDynamicFunction(const Instance& receiver,
1269 const Function& function, 1264 const Function& function,
1270 const String& target_name, 1265 const String& target_name,
1271 const Array& arguments) { 1266 const Array& arguments) {
1272 // Note "arguments" is already the internal arguments with the receiver as 1267 // Note "arguments" is already the internal arguments with the receiver as
1273 // the first element. 1268 // the first element.
1274 Object& result = Object::Handle(); 1269 Object& result = Object::Handle();
1275 if (function.IsNull()) { 1270 if (function.IsNull()) {
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
1830 func.parent_function()), Instance::Handle()); 1825 func.parent_function()), Instance::Handle());
1831 } 1826 }
1832 const Class& owner = Class::Handle(func.Owner()); 1827 const Class& owner = Class::Handle(func.Owner());
1833 if (owner.IsTopLevel()) { 1828 if (owner.IsTopLevel()) {
1834 return CreateLibraryMirror(Library::Handle(owner.library())); 1829 return CreateLibraryMirror(Library::Handle(owner.library()));
1835 } 1830 }
1836 return CreateClassMirror(owner, Instance::Handle()); 1831 return CreateClassMirror(owner, Instance::Handle());
1837 } 1832 }
1838 1833
1839 } // namespace dart 1834 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698