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 RawObject* CreateClassMirror(const Class& cls); | |
|
rmacnak
2013/07/17 22:27:50
RawInstance* --- we know they will be mirrors
Michael Lippautz (Google)
2013/07/17 22:43:19
Done.
| |
| 21 static RawObject* CreateLibraryMirror(const Library& lib); | |
| 22 static RawObject* CreateMethodMirror(const Function& func, | |
| 23 const Instance& owner); | |
|
rmacnak
2013/07/17 22:27:50
owner_mirror, no?
Michael Lippautz (Google)
2013/07/17 22:43:19
Done.
| |
| 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 get | |
| 1027 // default and one using Dart_Handles will disappear. | |
|
rmacnak
2013/07/17 22:27:50
will get default ... => will replace the version t
Michael Lippautz (Google)
2013/07/17 22:43:19
Done.
| |
| 1028 static RawObject* CreateClassMirror(const Class& cls) { | |
| 1029 Isolate* isolate = Isolate::Current(); | |
| 1030 DARTSCOPE(isolate); | |
| 1031 Dart_Handle cls_handle = Api::NewHandle(isolate, cls.raw()); | |
| 1032 if (Dart_IsError(cls_handle)) { | |
| 1033 Dart_PropagateError(cls_handle); | |
| 1034 } | |
| 1035 Dart_Handle name_handle = Api::NewHandle(isolate, cls.Name()); | |
| 1036 if (Dart_IsError(name_handle)) { | |
| 1037 Dart_PropagateError(name_handle); | |
| 1038 } | |
| 1039 Dart_Handle lib_handle = Api::NewHandle(isolate, cls.library()); | |
| 1040 if (Dart_IsError(lib_handle)) { | |
| 1041 Dart_PropagateError(lib_handle); | |
| 1042 } | |
| 1043 Dart_Handle lib_mirror = CreateLibraryMirror(lib_handle); | |
| 1044 if (Dart_IsError(lib_mirror)) { | |
| 1045 Dart_PropagateError(lib_mirror); | |
| 1046 } | |
| 1047 Dart_Handle result = CreateClassMirror(cls_handle, | |
| 1048 name_handle, | |
| 1049 lib_handle, | |
| 1050 lib_mirror); | |
| 1051 if (Dart_IsError(result)) { | |
| 1052 Dart_PropagateError(result); | |
| 1053 } | |
| 1054 return Api::UnwrapHandle(result); | |
| 1055 } | |
| 1056 | |
| 1057 | |
| 1058 // TODO(11742): At some point the function taking native parameters will get | |
| 1059 // default and one using Dart_Handles will disappear. | |
|
rmacnak
2013/07/17 22:27:50
will replace
Michael Lippautz (Google)
2013/07/17 22:43:19
Done.
| |
| 1060 static RawObject* CreateLibraryMirror(const Library& lib) { | |
| 1061 Isolate* isolate = Isolate::Current(); | |
| 1062 DARTSCOPE(isolate); | |
| 1063 Dart_Handle lib_handle = Api::NewHandle(isolate, lib.raw()); | |
| 1064 Dart_Handle result = CreateLibraryMirror(lib_handle); | |
| 1065 if (Dart_IsError(result)) { | |
| 1066 Dart_PropagateError(result); | |
| 1067 } | |
| 1068 return Api::UnwrapHandle(result); | |
| 1069 } | |
| 1070 | |
| 1071 | |
| 1072 // TODO(11742): At some point the function taking native parameters will get | |
| 1073 // default and one using Dart_Handles will disappear. | |
|
rmacnak
2013/07/17 22:27:50
will replace
Michael Lippautz (Google)
2013/07/17 22:43:19
Done.
| |
| 1074 static RawObject* CreateMethodMirror(const Function& func, | |
| 1075 const Instance& owner) { | |
| 1076 Isolate* isolate = Isolate::Current(); | |
| 1077 DARTSCOPE(isolate); | |
| 1078 Dart_Handle func_handle = Api::NewHandle(isolate, func.raw()); | |
| 1079 Dart_Handle result = CreateMethodMirror(func_handle, Dart_Null()); | |
| 1080 if (Dart_IsError(result)) { | |
| 1081 Dart_PropagateError(result); | |
| 1082 } | |
| 1083 return Api::UnwrapHandle(result); | |
| 1084 } | |
| 1085 | |
| 1086 | |
| 1021 void NATIVE_ENTRY_FUNCTION(Mirrors_makeLocalMirrorSystem)( | 1087 void NATIVE_ENTRY_FUNCTION(Mirrors_makeLocalMirrorSystem)( |
| 1022 Dart_NativeArguments args) { | 1088 Dart_NativeArguments args) { |
| 1023 Dart_EnterScope(); | 1089 Dart_EnterScope(); |
| 1024 Dart_Handle mirrors = CreateMirrorSystem(); | 1090 Dart_Handle mirrors = CreateMirrorSystem(); |
| 1025 if (Dart_IsError(mirrors)) { | 1091 if (Dart_IsError(mirrors)) { |
| 1026 Dart_PropagateError(mirrors); | 1092 Dart_PropagateError(mirrors); |
| 1027 } | 1093 } |
| 1028 Dart_SetReturnValue(args, mirrors); | 1094 Dart_SetReturnValue(args, mirrors); |
| 1029 Dart_ExitScope(); | 1095 Dart_ExitScope(); |
| 1030 } | 1096 } |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1784 | 1850 |
| 1785 | 1851 |
| 1786 DEFINE_NATIVE_ENTRY(MethodMirror_name, 1) { | 1852 DEFINE_NATIVE_ENTRY(MethodMirror_name, 1) { |
| 1787 const MirrorReference& func_ref = | 1853 const MirrorReference& func_ref = |
| 1788 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); | 1854 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); |
| 1789 Function& func = Function::Handle(); | 1855 Function& func = Function::Handle(); |
| 1790 func ^= func_ref.referent(); | 1856 func ^= func_ref.referent(); |
| 1791 return func.UserVisibleName(); | 1857 return func.UserVisibleName(); |
| 1792 } | 1858 } |
| 1793 | 1859 |
| 1860 | |
| 1861 DEFINE_NATIVE_ENTRY(MethodMirror_owner, 1) { | |
| 1862 const MirrorReference& func_ref = | |
| 1863 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); | |
| 1864 Function& func = Function::Handle(); | |
| 1865 func ^= func_ref.referent(); | |
| 1866 if (func.IsNonImplicitClosureFunction()) { | |
| 1867 return CreateMethodMirror(Function::Handle( | |
| 1868 func.parent_function()), Instance::Handle(Instance::null())); | |
| 1869 } | |
| 1870 const Class& owner = Class::Handle(func.Owner()); | |
| 1871 if (owner.IsTopLevel()) { | |
| 1872 return CreateLibraryMirror(Library::Handle(owner.library())); | |
| 1873 } | |
| 1874 return CreateClassMirror(owner); | |
| 1875 } | |
| 1876 | |
| 1794 } // namespace dart | 1877 } // namespace dart |
| OLD | NEW |