Chromium Code Reviews| Index: runtime/lib/mirrors.cc |
| diff --git a/runtime/lib/mirrors.cc b/runtime/lib/mirrors.cc |
| index 1cb1c748c48bd91f39c824440b14fdc3cab93de1..012e128c55c88fc248f580edaeccc56f28de1072 100644 |
| --- a/runtime/lib/mirrors.cc |
| +++ b/runtime/lib/mirrors.cc |
| @@ -17,6 +17,11 @@ |
| namespace dart { |
| +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.
|
| +static RawObject* CreateLibraryMirror(const Library& lib); |
| +static RawObject* CreateMethodMirror(const Function& func, |
| + const Instance& owner); |
|
rmacnak
2013/07/17 22:27:50
owner_mirror, no?
Michael Lippautz (Google)
2013/07/17 22:43:19
Done.
|
| + |
| inline Dart_Handle NewString(const char* str) { |
| return Dart_NewStringFromCString(str); |
| } |
| @@ -1018,6 +1023,67 @@ static Dart_Handle CreateInstanceMirror(Dart_Handle instance) { |
| } |
| +// TODO(11742): At some point the function taking native parameters will get |
| +// 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.
|
| +static RawObject* CreateClassMirror(const Class& cls) { |
| + Isolate* isolate = Isolate::Current(); |
| + DARTSCOPE(isolate); |
| + Dart_Handle cls_handle = Api::NewHandle(isolate, cls.raw()); |
| + if (Dart_IsError(cls_handle)) { |
| + Dart_PropagateError(cls_handle); |
| + } |
| + Dart_Handle name_handle = Api::NewHandle(isolate, cls.Name()); |
| + if (Dart_IsError(name_handle)) { |
| + Dart_PropagateError(name_handle); |
| + } |
| + Dart_Handle lib_handle = Api::NewHandle(isolate, cls.library()); |
| + if (Dart_IsError(lib_handle)) { |
| + Dart_PropagateError(lib_handle); |
| + } |
| + Dart_Handle lib_mirror = CreateLibraryMirror(lib_handle); |
| + if (Dart_IsError(lib_mirror)) { |
| + Dart_PropagateError(lib_mirror); |
| + } |
| + Dart_Handle result = CreateClassMirror(cls_handle, |
| + name_handle, |
| + lib_handle, |
| + lib_mirror); |
| + if (Dart_IsError(result)) { |
| + Dart_PropagateError(result); |
| + } |
| + return Api::UnwrapHandle(result); |
| +} |
| + |
| + |
| +// TODO(11742): At some point the function taking native parameters will get |
| +// 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.
|
| +static RawObject* CreateLibraryMirror(const Library& lib) { |
| + Isolate* isolate = Isolate::Current(); |
| + DARTSCOPE(isolate); |
| + Dart_Handle lib_handle = Api::NewHandle(isolate, lib.raw()); |
| + Dart_Handle result = CreateLibraryMirror(lib_handle); |
| + if (Dart_IsError(result)) { |
| + Dart_PropagateError(result); |
| + } |
| + return Api::UnwrapHandle(result); |
| +} |
| + |
| + |
| +// TODO(11742): At some point the function taking native parameters will get |
| +// 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.
|
| +static RawObject* CreateMethodMirror(const Function& func, |
| + const Instance& owner) { |
| + Isolate* isolate = Isolate::Current(); |
| + DARTSCOPE(isolate); |
| + Dart_Handle func_handle = Api::NewHandle(isolate, func.raw()); |
| + Dart_Handle result = CreateMethodMirror(func_handle, Dart_Null()); |
| + if (Dart_IsError(result)) { |
| + Dart_PropagateError(result); |
| + } |
| + return Api::UnwrapHandle(result); |
| +} |
| + |
| + |
| void NATIVE_ENTRY_FUNCTION(Mirrors_makeLocalMirrorSystem)( |
| Dart_NativeArguments args) { |
| Dart_EnterScope(); |
| @@ -1791,4 +1857,21 @@ DEFINE_NATIVE_ENTRY(MethodMirror_name, 1) { |
| return func.UserVisibleName(); |
| } |
| + |
| +DEFINE_NATIVE_ENTRY(MethodMirror_owner, 1) { |
| + const MirrorReference& func_ref = |
| + MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); |
| + Function& func = Function::Handle(); |
| + func ^= func_ref.referent(); |
| + if (func.IsNonImplicitClosureFunction()) { |
| + return CreateMethodMirror(Function::Handle( |
| + func.parent_function()), Instance::Handle(Instance::null())); |
| + } |
| + const Class& owner = Class::Handle(func.Owner()); |
| + if (owner.IsTopLevel()) { |
| + return CreateLibraryMirror(Library::Handle(owner.library())); |
| + } |
| + return CreateClassMirror(owner); |
| +} |
| + |
| } // namespace dart |