Chromium Code Reviews| Index: runtime/lib/mirrors.cc |
| diff --git a/runtime/lib/mirrors.cc b/runtime/lib/mirrors.cc |
| index 1cb1c748c48bd91f39c824440b14fdc3cab93de1..ec55a8695cc6f7ac3bf2cc571a099a26231ace7b 100644 |
| --- a/runtime/lib/mirrors.cc |
| +++ b/runtime/lib/mirrors.cc |
| @@ -17,6 +17,11 @@ |
| namespace dart { |
| +static RawInstance* CreateClassMirror(const Class& cls); |
| +static RawInstance* CreateLibraryMirror(const Library& lib); |
| +static RawInstance* CreateMethodMirror(const Function& func, |
| + const Instance& owner_mirror); |
| + |
| inline Dart_Handle NewString(const char* str) { |
| return Dart_NewStringFromCString(str); |
| } |
| @@ -1018,6 +1023,77 @@ static Dart_Handle CreateInstanceMirror(Dart_Handle instance) { |
| } |
| +// TODO(11742): At some point the function taking native parameters will replace |
| +// the version that uses API handles. |
| +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.
|
| + Dart_EnterScope(); |
| + Isolate* isolate = Isolate::Current(); |
| + 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.
|
| + 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); |
| + } |
|
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.
|
| + Dart_Handle result = CreateClassMirror(cls_handle, |
| + name_handle, |
| + lib_handle, |
| + 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.
|
| + if (Dart_IsError(result)) { |
| + Dart_PropagateError(result); |
| + } |
| + const Instance& retvalue = Api::UnwrapInstanceHandle(isolate, result); |
| + Dart_ExitScope(); |
| + return retvalue.raw(); |
| +} |
| + |
| + |
| +// TODO(11742): At some point the function taking native parameters will replace |
| +// the version that uses API handles. |
| +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.
|
| + Dart_EnterScope(); |
| + 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); |
| + } |
| + const Instance& retvalue = Api::UnwrapInstanceHandle(isolate, result); |
| + Dart_ExitScope(); |
| + return retvalue.raw(); |
| +} |
| + |
| + |
| +// TODO(11742): At some point the function taking native parameters will replace |
| +// the version that uses API handles. |
| +static RawInstance* CreateMethodMirror(const Function& func, |
| + const Instance& owner_mirror) { |
| + Dart_EnterScope(); |
| + Isolate* isolate = Isolate::Current(); |
| + DARTSCOPE(isolate); |
| + Dart_Handle func_handle = Api::NewHandle(isolate, func.raw()); |
| + Dart_Handle owner_handle = Api::NewHandle(isolate, owner_mirror.raw()); |
| + Dart_Handle result = CreateMethodMirror(func_handle, owner_handle); |
| + if (Dart_IsError(result)) { |
| + Dart_PropagateError(result); |
| + } |
| + const Instance& retvalue = Api::UnwrapInstanceHandle(isolate, result); |
| + Dart_ExitScope(); |
| + return retvalue.raw(); |
| +} |
| + |
| + |
| void NATIVE_ENTRY_FUNCTION(Mirrors_makeLocalMirrorSystem)( |
| Dart_NativeArguments args) { |
| Dart_EnterScope(); |
| @@ -1791,4 +1867,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(); |
|
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.
|
| + 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 |