Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" |
| 11 #include "vm/dart_entry.h" | 11 #include "vm/dart_entry.h" |
| 12 #include "vm/exceptions.h" | 12 #include "vm/exceptions.h" |
| 13 #include "vm/message.h" | 13 #include "vm/message.h" |
| 14 #include "vm/port.h" | 14 #include "vm/port.h" |
| 15 #include "vm/resolver.h" | 15 #include "vm/resolver.h" |
| 16 #include "vm/symbols.h" | 16 #include "vm/symbols.h" |
| 17 | 17 |
| 18 namespace dart { | 18 namespace dart { |
| 19 | 19 |
| 20 static RawInstance* CreateClassMirror(const Class& cls); | |
| 21 static RawInstance* CreateLibraryMirror(const Library& lib); | |
| 22 static RawInstance* CreateMethodMirror(const Function& func, | |
| 23 const Instance& owner_mirror); | |
| 24 | |
| 20 inline Dart_Handle NewString(const char* str) { | 25 inline Dart_Handle NewString(const char* str) { |
| 21 return Dart_NewStringFromCString(str); | 26 return Dart_NewStringFromCString(str); |
| 22 } | 27 } |
| 23 | 28 |
| 24 | 29 |
| 25 DEFINE_NATIVE_ENTRY(Mirrors_isLocalPort, 1) { | 30 DEFINE_NATIVE_ENTRY(Mirrors_isLocalPort, 1) { |
| 26 GET_NON_NULL_NATIVE_ARGUMENT(Instance, port, arguments->NativeArgAt(0)); | 31 GET_NON_NULL_NATIVE_ARGUMENT(Instance, port, arguments->NativeArgAt(0)); |
| 27 | 32 |
| 28 // Get the port id from the SendPort instance. | 33 // Get the port id from the SendPort instance. |
| 29 const Object& id_obj = Object::Handle(DartLibraryCalls::PortGetId(port)); | 34 const Object& id_obj = Object::Handle(DartLibraryCalls::PortGetId(port)); |
| (...skipping 981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1011 Dart_Handle args[] = { | 1016 Dart_Handle args[] = { |
| 1012 CreateVMReference(instance), | 1017 CreateVMReference(instance), |
| 1013 CreateLazyMirror(instance_cls), | 1018 CreateLazyMirror(instance_cls), |
| 1014 instance, | 1019 instance, |
| 1015 }; | 1020 }; |
| 1016 return Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); | 1021 return Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); |
| 1017 } | 1022 } |
| 1018 } | 1023 } |
| 1019 | 1024 |
| 1020 | 1025 |
| 1026 // TODO(11742): At some point the function taking native parameters will replace | |
| 1027 // the version that uses API handles. | |
| 1028 static RawInstance* CreateClassMirror(const Class& cls) { | |
|
siva
2013/07/18 20:32:34
Change the signature of the method to the final fo
Michael Lippautz (Google)
2013/07/18 22:01:23
Done.
| |
| 1029 Dart_EnterScope(); | |
| 1030 Isolate* isolate = Isolate::Current(); | |
| 1031 DARTSCOPE(isolate); | |
|
siva
2013/07/18 20:32:34
As discussed it is not necessary to have this DART
Michael Lippautz (Google)
2013/07/18 22:01:23
Done.
| |
| 1032 Dart_Handle cls_handle = Api::NewHandle(isolate, cls.raw()); | |
| 1033 if (Dart_IsError(cls_handle)) { | |
| 1034 Dart_PropagateError(cls_handle); | |
| 1035 } | |
| 1036 Dart_Handle name_handle = Api::NewHandle(isolate, cls.Name()); | |
| 1037 if (Dart_IsError(name_handle)) { | |
| 1038 Dart_PropagateError(name_handle); | |
| 1039 } | |
| 1040 Dart_Handle lib_handle = Api::NewHandle(isolate, cls.library()); | |
| 1041 if (Dart_IsError(lib_handle)) { | |
| 1042 Dart_PropagateError(lib_handle); | |
| 1043 } | |
| 1044 Dart_Handle lib_mirror = CreateLibraryMirror(lib_handle); | |
| 1045 if (Dart_IsError(lib_mirror)) { | |
| 1046 Dart_PropagateError(lib_mirror); | |
| 1047 } | |
|
siva
2013/07/18 20:32:34
I think the TODO comment above should end up here
Michael Lippautz (Google)
2013/07/18 22:01:23
Done.
| |
| 1048 Dart_Handle result = CreateClassMirror(cls_handle, | |
| 1049 name_handle, | |
| 1050 lib_handle, | |
| 1051 lib_mirror); | |
|
siva
2013/07/18 20:32:34
As discussed offline we should probably call this
Michael Lippautz (Google)
2013/07/18 22:01:23
Done.
| |
| 1052 if (Dart_IsError(result)) { | |
| 1053 Dart_PropagateError(result); | |
| 1054 } | |
| 1055 const Instance& retvalue = Api::UnwrapInstanceHandle(isolate, result); | |
| 1056 Dart_ExitScope(); | |
| 1057 return retvalue.raw(); | |
| 1058 } | |
| 1059 | |
| 1060 | |
| 1061 // TODO(11742): At some point the function taking native parameters will replace | |
| 1062 // the version that uses API handles. | |
| 1063 static RawInstance* CreateLibraryMirror(const Library& lib) { | |
|
siva
2013/07/18 20:32:34
Ditto comment about the signature here, you want i
Michael Lippautz (Google)
2013/07/18 22:01:23
Done.
| |
| 1064 Dart_EnterScope(); | |
| 1065 Isolate* isolate = Isolate::Current(); | |
| 1066 DARTSCOPE(isolate); | |
| 1067 Dart_Handle lib_handle = Api::NewHandle(isolate, lib.raw()); | |
| 1068 Dart_Handle result = CreateLibraryMirror(lib_handle); | |
| 1069 if (Dart_IsError(result)) { | |
| 1070 Dart_PropagateError(result); | |
| 1071 } | |
| 1072 const Instance& retvalue = Api::UnwrapInstanceHandle(isolate, result); | |
| 1073 Dart_ExitScope(); | |
| 1074 return retvalue.raw(); | |
| 1075 } | |
| 1076 | |
| 1077 | |
| 1078 // TODO(11742): At some point the function taking native parameters will replace | |
| 1079 // the version that uses API handles. | |
| 1080 static RawInstance* CreateMethodMirror(const Function& func, | |
| 1081 const Instance& owner_mirror) { | |
| 1082 Dart_EnterScope(); | |
| 1083 Isolate* isolate = Isolate::Current(); | |
| 1084 DARTSCOPE(isolate); | |
| 1085 Dart_Handle func_handle = Api::NewHandle(isolate, func.raw()); | |
| 1086 Dart_Handle owner_handle = Api::NewHandle(isolate, owner_mirror.raw()); | |
| 1087 Dart_Handle result = CreateMethodMirror(func_handle, owner_handle); | |
| 1088 if (Dart_IsError(result)) { | |
| 1089 Dart_PropagateError(result); | |
| 1090 } | |
| 1091 const Instance& retvalue = Api::UnwrapInstanceHandle(isolate, result); | |
| 1092 Dart_ExitScope(); | |
| 1093 return retvalue.raw(); | |
| 1094 } | |
| 1095 | |
| 1096 | |
| 1021 void NATIVE_ENTRY_FUNCTION(Mirrors_makeLocalMirrorSystem)( | 1097 void NATIVE_ENTRY_FUNCTION(Mirrors_makeLocalMirrorSystem)( |
| 1022 Dart_NativeArguments args) { | 1098 Dart_NativeArguments args) { |
| 1023 Dart_EnterScope(); | 1099 Dart_EnterScope(); |
| 1024 Dart_Handle mirrors = CreateMirrorSystem(); | 1100 Dart_Handle mirrors = CreateMirrorSystem(); |
| 1025 if (Dart_IsError(mirrors)) { | 1101 if (Dart_IsError(mirrors)) { |
| 1026 Dart_PropagateError(mirrors); | 1102 Dart_PropagateError(mirrors); |
| 1027 } | 1103 } |
| 1028 Dart_SetReturnValue(args, mirrors); | 1104 Dart_SetReturnValue(args, mirrors); |
| 1029 Dart_ExitScope(); | 1105 Dart_ExitScope(); |
| 1030 } | 1106 } |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1784 | 1860 |
| 1785 | 1861 |
| 1786 DEFINE_NATIVE_ENTRY(MethodMirror_name, 1) { | 1862 DEFINE_NATIVE_ENTRY(MethodMirror_name, 1) { |
| 1787 const MirrorReference& func_ref = | 1863 const MirrorReference& func_ref = |
| 1788 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); | 1864 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); |
| 1789 Function& func = Function::Handle(); | 1865 Function& func = Function::Handle(); |
| 1790 func ^= func_ref.referent(); | 1866 func ^= func_ref.referent(); |
| 1791 return func.UserVisibleName(); | 1867 return func.UserVisibleName(); |
| 1792 } | 1868 } |
| 1793 | 1869 |
| 1870 | |
| 1871 DEFINE_NATIVE_ENTRY(MethodMirror_owner, 1) { | |
| 1872 const MirrorReference& func_ref = | |
| 1873 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); | |
| 1874 Function& func = Function::Handle(); | |
| 1875 func ^= func_ref.referent(); | |
|
siva
2013/07/18 20:32:34
I see this pattern a lot I am wondering if it make
Michael Lippautz (Google)
2013/07/18 22:01:23
Will try to incorporate in another CL.
| |
| 1876 if (func.IsNonImplicitClosureFunction()) { | |
| 1877 return CreateMethodMirror(Function::Handle( | |
| 1878 func.parent_function()), Instance::Handle(Instance::null())); | |
| 1879 } | |
| 1880 const Class& owner = Class::Handle(func.Owner()); | |
| 1881 if (owner.IsTopLevel()) { | |
| 1882 return CreateLibraryMirror(Library::Handle(owner.library())); | |
| 1883 } | |
| 1884 return CreateClassMirror(owner); | |
| 1885 } | |
| 1886 | |
| 1794 } // namespace dart | 1887 } // namespace dart |
| OLD | NEW |