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

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

Issue 19579006: Adding proper handling for MethodMirror.owner (Closed) Base URL: https://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 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 Dart_New(mirror_type, Dart_Null(), ARRAY_SIZE(args), args); 489 Dart_New(mirror_type, Dart_Null(), ARRAY_SIZE(args), args);
490 return mirror; 490 return mirror;
491 } 491 }
492 492
493 493
494 static Dart_Handle CreateMemberMap(Dart_Handle owner, Dart_Handle owner_mirror); 494 static Dart_Handle CreateMemberMap(Dart_Handle owner, Dart_Handle owner_mirror);
495 static Dart_Handle CreateConstructorMap(Dart_Handle owner, 495 static Dart_Handle CreateConstructorMap(Dart_Handle owner,
496 Dart_Handle owner_mirror); 496 Dart_Handle owner_mirror);
497 497
498 498
499 static Dart_Handle CreateClassMirror(Dart_Handle intf, 499 static Dart_Handle CreateClassMirrorUsingApi(Dart_Handle intf,
500 Dart_Handle intf_name, 500 Dart_Handle intf_name,
501 Dart_Handle lib, 501 Dart_Handle lib,
502 Dart_Handle lib_mirror) { 502 Dart_Handle lib_mirror) {
503 ASSERT(Dart_IsClass(intf)); 503 ASSERT(Dart_IsClass(intf));
504 if (Dart_ClassIsTypedef(intf)) { 504 if (Dart_ClassIsTypedef(intf)) {
505 // This class is actually a typedef. Represent it specially in 505 // This class is actually a typedef. Represent it specially in
506 // reflection. 506 // reflection.
507 return CreateTypedefMirror(intf, intf_name, lib, lib_mirror); 507 return CreateTypedefMirror(intf, intf_name, lib, lib_mirror);
508 } 508 }
509 509
510 Dart_Handle cls_name = NewString("_LocalClassMirrorImpl"); 510 Dart_Handle cls_name = NewString("_LocalClassMirrorImpl");
511 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); 511 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL);
512 if (Dart_IsError(type)) { 512 if (Dart_IsError(type)) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 CreateLazyMirror(default_class), 550 CreateLazyMirror(default_class),
551 member_map, 551 member_map,
552 constructor_map, 552 constructor_map,
553 type_var_map, 553 type_var_map,
554 }; 554 };
555 Dart_Handle mirror = Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); 555 Dart_Handle mirror = Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args);
556 return mirror; 556 return mirror;
557 } 557 }
558 558
559 559
560 static Dart_Handle CreateMethodMirror(Dart_Handle func, 560 static Dart_Handle CreateMethodMirrorUsingApi(Dart_Handle func,
561 Dart_Handle owner_mirror) { 561 Dart_Handle owner_mirror) {
562 // TODO(11742): Unwrapping is needed until the whole method is converted. 562 // TODO(11742): Unwrapping is needed until the whole method is converted.
563 Isolate* isolate = Isolate::Current(); 563 Isolate* isolate = Isolate::Current();
564 DARTSCOPE(isolate); 564 DARTSCOPE(isolate);
565 const Function& func_obj = Api::UnwrapFunctionHandle(isolate, func); 565 const Function& func_obj = Api::UnwrapFunctionHandle(isolate, func);
566 566
567 Dart_Handle mirror_cls_name = NewString("_LocalMethodMirrorImpl"); 567 Dart_Handle mirror_cls_name = NewString("_LocalMethodMirrorImpl");
568 Dart_Handle mirror_type = Dart_GetType(MirrorLib(), mirror_cls_name, 0, NULL); 568 Dart_Handle mirror_type = Dart_GetType(MirrorLib(), mirror_cls_name, 0, NULL);
569 if (Dart_IsError(mirror_type)) { 569 if (Dart_IsError(mirror_type)) {
570 return mirror_type; 570 return mirror_type;
571 } 571 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 if (Dart_IsError(result)) { 650 if (Dart_IsError(result)) {
651 return result; 651 return result;
652 } 652 }
653 for (intptr_t i = 0; i < len; i++) { 653 for (intptr_t i = 0; i < len; i++) {
654 Dart_Handle intf_name = Dart_ListGetAt(names, i); 654 Dart_Handle intf_name = Dart_ListGetAt(names, i);
655 Dart_Handle intf = Dart_GetClass(owner, intf_name); 655 Dart_Handle intf = Dart_GetClass(owner, intf_name);
656 if (Dart_IsError(intf)) { 656 if (Dart_IsError(intf)) {
657 return intf; 657 return intf;
658 } 658 }
659 Dart_Handle intf_mirror = 659 Dart_Handle intf_mirror =
660 CreateClassMirror(intf, intf_name, owner, owner_mirror); 660 CreateClassMirrorUsingApi(intf, intf_name, owner, owner_mirror);
661 if (Dart_IsError(intf_mirror)) { 661 if (Dart_IsError(intf_mirror)) {
662 return intf_mirror; 662 return intf_mirror;
663 } 663 }
664 result = MapAdd(map, intf_name, intf_mirror); 664 result = MapAdd(map, intf_name, intf_mirror);
665 if (Dart_IsError(result)) { 665 if (Dart_IsError(result)) {
666 return result; 666 return result;
667 } 667 }
668 } 668 }
669 return Dart_True(); 669 return Dart_True();
670 } 670 }
(...skipping 23 matching lines...) Expand all
694 bool is_constructor = false; 694 bool is_constructor = false;
695 result = Dart_FunctionIsConstructor(func, &is_constructor); 695 result = Dart_FunctionIsConstructor(func, &is_constructor);
696 if (Dart_IsError(result)) { 696 if (Dart_IsError(result)) {
697 return result; 697 return result;
698 } 698 }
699 if (is_constructor) { 699 if (is_constructor) {
700 // Skip constructors. 700 // Skip constructors.
701 continue; 701 continue;
702 } 702 }
703 703
704 Dart_Handle func_mirror = CreateMethodMirror(func, owner_mirror); 704 Dart_Handle func_mirror = CreateMethodMirrorUsingApi(func, owner_mirror);
705 if (Dart_IsError(func_mirror)) { 705 if (Dart_IsError(func_mirror)) {
706 return func_mirror; 706 return func_mirror;
707 } 707 }
708 result = MapAdd(map, func_name, func_mirror); 708 result = MapAdd(map, func_name, func_mirror);
709 if (Dart_IsError(result)) { 709 if (Dart_IsError(result)) {
710 return result; 710 return result;
711 } 711 }
712 } 712 }
713 return Dart_True(); 713 return Dart_True();
714 } 714 }
(...skipping 23 matching lines...) Expand all
738 bool is_constructor = false; 738 bool is_constructor = false;
739 result = Dart_FunctionIsConstructor(func, &is_constructor); 739 result = Dart_FunctionIsConstructor(func, &is_constructor);
740 if (Dart_IsError(result)) { 740 if (Dart_IsError(result)) {
741 return result; 741 return result;
742 } 742 }
743 if (!is_constructor) { 743 if (!is_constructor) {
744 // Skip non-constructors. 744 // Skip non-constructors.
745 continue; 745 continue;
746 } 746 }
747 747
748 Dart_Handle func_mirror = CreateMethodMirror(func, owner_mirror); 748 Dart_Handle func_mirror = CreateMethodMirrorUsingApi(func, owner_mirror);
749 if (Dart_IsError(func_mirror)) { 749 if (Dart_IsError(func_mirror)) {
750 return func_mirror; 750 return func_mirror;
751 } 751 }
752 result = MapAdd(map, func_name, func_mirror); 752 result = MapAdd(map, func_name, func_mirror);
753 if (Dart_IsError(result)) { 753 if (Dart_IsError(result)) {
754 return result; 754 return result;
755 } 755 }
756 } 756 }
757 return Dart_True(); 757 return Dart_True();
758 } 758 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 Dart_Handle result; 826 Dart_Handle result;
827 Dart_Handle map = MapNew(); 827 Dart_Handle map = MapNew();
828 result = AddConstructors(map, owner, owner_mirror); 828 result = AddConstructors(map, owner, owner_mirror);
829 if (Dart_IsError(result)) { 829 if (Dart_IsError(result)) {
830 return result; 830 return result;
831 } 831 }
832 return map; 832 return map;
833 } 833 }
834 834
835 835
836 static Dart_Handle CreateLibraryMirror(Dart_Handle lib) { 836 static Dart_Handle CreateLibraryMirrorUsingApi(Dart_Handle lib) {
837 Dart_Handle cls_name = NewString("_LocalLibraryMirrorImpl"); 837 Dart_Handle cls_name = NewString("_LocalLibraryMirrorImpl");
838 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); 838 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL);
839 if (Dart_IsError(type)) { 839 if (Dart_IsError(type)) {
840 return type; 840 return type;
841 } 841 }
842 Dart_Handle lazy_lib_mirror = CreateLazyMirror(lib); 842 Dart_Handle lazy_lib_mirror = CreateLazyMirror(lib);
843 if (Dart_IsError(lazy_lib_mirror)) { 843 if (Dart_IsError(lazy_lib_mirror)) {
844 return lazy_lib_mirror; 844 return lazy_lib_mirror;
845 } 845 }
846 Dart_Handle member_map = CreateMemberMap(lib, lazy_lib_mirror); 846 Dart_Handle member_map = CreateMemberMap(lib, lazy_lib_mirror);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 int64_t id64; 881 int64_t id64;
882 Dart_IntegerToInt64(lib_id, &id64); 882 Dart_IntegerToInt64(lib_id, &id64);
883 Dart_Handle lib_url = Dart_GetLibraryURL(id64); 883 Dart_Handle lib_url = Dart_GetLibraryURL(id64);
884 if (Dart_IsError(lib_url)) { 884 if (Dart_IsError(lib_url)) {
885 return lib_url; 885 return lib_url;
886 } 886 }
887 Dart_Handle lib = Dart_LookupLibrary(lib_url); 887 Dart_Handle lib = Dart_LookupLibrary(lib_url);
888 if (Dart_IsError(lib)) { 888 if (Dart_IsError(lib)) {
889 return lib; 889 return lib;
890 } 890 }
891 Dart_Handle lib_mirror = CreateLibraryMirror(lib); 891 Dart_Handle lib_mirror = CreateLibraryMirrorUsingApi(lib);
892 if (Dart_IsError(lib_mirror)) { 892 if (Dart_IsError(lib_mirror)) {
893 return lib_mirror; 893 return lib_mirror;
894 } 894 }
895 result = MapAdd(map, lib_url, lib_mirror); 895 result = MapAdd(map, lib_url, lib_mirror);
896 } 896 }
897 return map; 897 return map;
898 } 898 }
899 899
900 900
901 static Dart_Handle CreateIsolateMirror() { 901 static Dart_Handle CreateIsolateMirror() {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 983
984 // TODO(turnidge): Why not use the real function name here? 984 // TODO(turnidge): Why not use the real function name here?
985 Dart_Handle func_owner = Dart_FunctionOwner(func); 985 Dart_Handle func_owner = Dart_FunctionOwner(func);
986 if (Dart_IsError(func_owner)) { 986 if (Dart_IsError(func_owner)) {
987 return func_owner; 987 return func_owner;
988 } 988 }
989 989
990 // TODO(turnidge): Pass the function owner here. This will require 990 // TODO(turnidge): Pass the function owner here. This will require
991 // us to support functions in CreateLazyMirror. 991 // us to support functions in CreateLazyMirror.
992 Dart_Handle func_mirror = 992 Dart_Handle func_mirror =
993 CreateMethodMirror(func, Dart_Null()); 993 CreateMethodMirrorUsingApi(func, Dart_Null());
994 if (Dart_IsError(func_mirror)) { 994 if (Dart_IsError(func_mirror)) {
995 return func_mirror; 995 return func_mirror;
996 } 996 }
997 Dart_Handle args[] = { 997 Dart_Handle args[] = {
998 CreateVMReference(instance), 998 CreateVMReference(instance),
999 CreateLazyMirror(instance_cls), 999 CreateLazyMirror(instance_cls),
1000 instance, 1000 instance,
1001 func_mirror, 1001 func_mirror,
1002 }; 1002 };
1003 return Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); 1003 return Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args);
1004 1004
1005 } else { 1005 } else {
1006 Dart_Handle cls_name = NewString("_LocalInstanceMirrorImpl"); 1006 Dart_Handle cls_name = NewString("_LocalInstanceMirrorImpl");
1007 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); 1007 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL);
1008 if (Dart_IsError(type)) { 1008 if (Dart_IsError(type)) {
1009 return type; 1009 return type;
1010 } 1010 }
1011 Dart_Handle args[] = { 1011 Dart_Handle args[] = {
1012 CreateVMReference(instance), 1012 CreateVMReference(instance),
1013 CreateLazyMirror(instance_cls), 1013 CreateLazyMirror(instance_cls),
1014 instance, 1014 instance,
1015 }; 1015 };
1016 return Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); 1016 return Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args);
1017 } 1017 }
1018 } 1018 }
1019 1019
1020 1020
1021 static RawInstance* CreateClassMirror(const Class& cls,
1022 const Instance& owner_mirror) {
1023 Dart_EnterScope();
1024 Isolate* isolate = Isolate::Current();
1025 Dart_Handle cls_handle = Api::NewHandle(isolate, cls.raw());
1026 if (Dart_IsError(cls_handle)) {
1027 Dart_PropagateError(cls_handle);
1028 }
1029 Dart_Handle name_handle = Api::NewHandle(isolate, cls.Name());
1030 if (Dart_IsError(name_handle)) {
1031 Dart_PropagateError(name_handle);
1032 }
1033 Dart_Handle lib_handle = Api::NewHandle(isolate, cls.library());
1034 if (Dart_IsError(lib_handle)) {
1035 Dart_PropagateError(lib_handle);
1036 }
1037 Dart_Handle lib_mirror = CreateLibraryMirrorUsingApi(lib_handle);
1038 if (Dart_IsError(lib_mirror)) {
1039 Dart_PropagateError(lib_mirror);
1040 }
1041 // TODO(11742): At some point the handle calls will be replaced by inlined
1042 // functionality.
1043 Dart_Handle result = CreateClassMirrorUsingApi(cls_handle,
1044 name_handle,
1045 lib_handle,
1046 lib_mirror);
1047 if (Dart_IsError(result)) {
1048 Dart_PropagateError(result);
1049 }
1050 const Instance& retvalue = Api::UnwrapInstanceHandle(isolate, result);
1051 Dart_ExitScope();
1052 return retvalue.raw();
1053 }
1054
1055
1056 static RawInstance* CreateLibraryMirror(const Library& lib) {
1057 Dart_EnterScope();
1058 Isolate* isolate = Isolate::Current();
1059 Dart_Handle lib_handle = Api::NewHandle(isolate, lib.raw());
1060 // TODO(11742): At some point the handle calls will be replaced by inlined
1061 // functionality.
1062 Dart_Handle result = CreateLibraryMirrorUsingApi(lib_handle);
1063 if (Dart_IsError(result)) {
1064 Dart_PropagateError(result);
1065 }
1066 const Instance& retvalue = Api::UnwrapInstanceHandle(isolate, result);
1067 Dart_ExitScope();
1068 return retvalue.raw();
1069 }
1070
1071
1072 static RawInstance* CreateMethodMirror(const Function& func,
1073 const Instance& owner_mirror) {
1074 Dart_EnterScope();
1075 Isolate* isolate = Isolate::Current();
1076 Dart_Handle func_handle = Api::NewHandle(isolate, func.raw());
1077 Dart_Handle owner_handle = Api::NewHandle(isolate, owner_mirror.raw());
1078 // TODO(11742): At some point the handle calls will be replaced by inlined
1079 // functionality.
1080 Dart_Handle result = CreateMethodMirrorUsingApi(func_handle, owner_handle);
1081 if (Dart_IsError(result)) {
1082 Dart_PropagateError(result);
1083 }
1084 const Instance& retvalue = Api::UnwrapInstanceHandle(isolate, result);
1085 Dart_ExitScope();
1086 return retvalue.raw();
1087 }
1088
1089
1021 void NATIVE_ENTRY_FUNCTION(Mirrors_makeLocalMirrorSystem)( 1090 void NATIVE_ENTRY_FUNCTION(Mirrors_makeLocalMirrorSystem)(
1022 Dart_NativeArguments args) { 1091 Dart_NativeArguments args) {
1023 Dart_EnterScope(); 1092 Dart_EnterScope();
1024 Dart_Handle mirrors = CreateMirrorSystem(); 1093 Dart_Handle mirrors = CreateMirrorSystem();
1025 if (Dart_IsError(mirrors)) { 1094 if (Dart_IsError(mirrors)) {
1026 Dart_PropagateError(mirrors); 1095 Dart_PropagateError(mirrors);
1027 } 1096 }
1028 Dart_SetReturnValue(args, mirrors); 1097 Dart_SetReturnValue(args, mirrors);
1029 Dart_ExitScope(); 1098 Dart_ExitScope();
1030 } 1099 }
(...skipping 27 matching lines...) Expand all
1058 Dart_PropagateError(cls_handle); 1127 Dart_PropagateError(cls_handle);
1059 } 1128 }
1060 Dart_Handle name_handle = Api::NewHandle(isolate, cls.Name()); 1129 Dart_Handle name_handle = Api::NewHandle(isolate, cls.Name());
1061 if (Dart_IsError(name_handle)) { 1130 if (Dart_IsError(name_handle)) {
1062 Dart_PropagateError(name_handle); 1131 Dart_PropagateError(name_handle);
1063 } 1132 }
1064 Dart_Handle lib_handle = Api::NewHandle(isolate, cls.library()); 1133 Dart_Handle lib_handle = Api::NewHandle(isolate, cls.library());
1065 if (Dart_IsError(lib_handle)) { 1134 if (Dart_IsError(lib_handle)) {
1066 Dart_PropagateError(lib_handle); 1135 Dart_PropagateError(lib_handle);
1067 } 1136 }
1068 Dart_Handle lib_mirror = CreateLibraryMirror(lib_handle); 1137 Dart_Handle lib_mirror = CreateLibraryMirrorUsingApi(lib_handle);
1069 if (Dart_IsError(lib_mirror)) { 1138 if (Dart_IsError(lib_mirror)) {
1070 Dart_PropagateError(lib_mirror); 1139 Dart_PropagateError(lib_mirror);
1071 } 1140 }
1072 Dart_Handle result = CreateClassMirror(cls_handle, 1141 Dart_Handle result = CreateClassMirrorUsingApi(cls_handle,
1073 name_handle, 1142 name_handle,
1074 lib_handle, 1143 lib_handle,
1075 lib_mirror); 1144 lib_mirror);
1076 if (Dart_IsError(result)) { 1145 if (Dart_IsError(result)) {
1077 Dart_PropagateError(result); 1146 Dart_PropagateError(result);
1078 } 1147 }
1079 Dart_SetReturnValue(args, result); 1148 Dart_SetReturnValue(args, result);
1080 Dart_ExitScope(); 1149 Dart_ExitScope();
1081 } 1150 }
1082 1151
1083 void NATIVE_ENTRY_FUNCTION(Mirrors_metadata)(Dart_NativeArguments args) { 1152 void NATIVE_ENTRY_FUNCTION(Mirrors_metadata)(Dart_NativeArguments args) {
1084 Dart_EnterScope(); 1153 Dart_EnterScope();
1085 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); 1154 Dart_Handle mirror = Dart_GetNativeArgument(args, 0);
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after
1784 1853
1785 1854
1786 DEFINE_NATIVE_ENTRY(MethodMirror_name, 1) { 1855 DEFINE_NATIVE_ENTRY(MethodMirror_name, 1) {
1787 const MirrorReference& func_ref = 1856 const MirrorReference& func_ref =
1788 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); 1857 MirrorReference::CheckedHandle(arguments->NativeArgAt(0));
1789 Function& func = Function::Handle(); 1858 Function& func = Function::Handle();
1790 func ^= func_ref.referent(); 1859 func ^= func_ref.referent();
1791 return func.UserVisibleName(); 1860 return func.UserVisibleName();
1792 } 1861 }
1793 1862
1863
1864 DEFINE_NATIVE_ENTRY(MethodMirror_owner, 1) {
1865 const MirrorReference& func_ref =
1866 MirrorReference::CheckedHandle(arguments->NativeArgAt(0));
1867 Function& func = Function::Handle();
1868 func ^= func_ref.referent();
1869 if (func.IsNonImplicitClosureFunction()) {
1870 return CreateMethodMirror(Function::Handle(
1871 func.parent_function()), Instance::Handle());
1872 }
1873 const Class& owner = Class::Handle(func.Owner());
1874 if (owner.IsTopLevel()) {
1875 return CreateLibraryMirror(Library::Handle(owner.library()));
1876 }
1877 return CreateClassMirror(owner, Instance::Handle());
1878 }
1879
1794 } // namespace dart 1880 } // 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