Chromium Code Reviews| Index: runtime/lib/mirrors.cc |
| diff --git a/runtime/lib/mirrors.cc b/runtime/lib/mirrors.cc |
| index 1cb1c748c48bd91f39c824440b14fdc3cab93de1..338f5db8cc12f2ed1853f15c5f7dddada0da5703 100644 |
| --- a/runtime/lib/mirrors.cc |
| +++ b/runtime/lib/mirrors.cc |
| @@ -17,6 +17,12 @@ |
| namespace dart { |
| +static RawInstance* CreateClassMirror(const Class& cls, |
| + const Instance& owner_mirror); |
| +static RawInstance* CreateLibraryMirror(const Library& lib); |
| +static RawInstance* CreateMethodMirror(const Function& func, |
| + const Instance& owner_mirror); |
|
siva
2013/07/18 20:38:45
Why are these forward declarations needed?
Michael Lippautz (Google)
2013/07/18 22:01:23
Are not needed anymore. (At some point code was or
|
| + |
| inline Dart_Handle NewString(const char* str) { |
| return Dart_NewStringFromCString(str); |
| } |
| @@ -496,10 +502,10 @@ static Dart_Handle CreateConstructorMap(Dart_Handle owner, |
| Dart_Handle owner_mirror); |
| -static Dart_Handle CreateClassMirror(Dart_Handle intf, |
| - Dart_Handle intf_name, |
| - Dart_Handle lib, |
| - Dart_Handle lib_mirror) { |
| +static Dart_Handle CreateClassMirrorUsingApi(Dart_Handle intf, |
| + Dart_Handle intf_name, |
| + Dart_Handle lib, |
| + Dart_Handle lib_mirror) { |
| ASSERT(Dart_IsClass(intf)); |
| if (Dart_ClassIsTypedef(intf)) { |
| // This class is actually a typedef. Represent it specially in |
| @@ -557,8 +563,8 @@ static Dart_Handle CreateClassMirror(Dart_Handle intf, |
| } |
| -static Dart_Handle CreateMethodMirror(Dart_Handle func, |
| - Dart_Handle owner_mirror) { |
| +static Dart_Handle CreateMethodMirrorUsingApi(Dart_Handle func, |
| + Dart_Handle owner_mirror) { |
| // TODO(11742): Unwrapping is needed until the whole method is converted. |
| Isolate* isolate = Isolate::Current(); |
| DARTSCOPE(isolate); |
| @@ -657,7 +663,7 @@ static Dart_Handle AddMemberClasses(Dart_Handle map, |
| return intf; |
| } |
| Dart_Handle intf_mirror = |
| - CreateClassMirror(intf, intf_name, owner, owner_mirror); |
| + CreateClassMirrorUsingApi(intf, intf_name, owner, owner_mirror); |
| if (Dart_IsError(intf_mirror)) { |
| return intf_mirror; |
| } |
| @@ -701,7 +707,7 @@ static Dart_Handle AddMemberFunctions(Dart_Handle map, |
| continue; |
| } |
| - Dart_Handle func_mirror = CreateMethodMirror(func, owner_mirror); |
| + Dart_Handle func_mirror = CreateMethodMirrorUsingApi(func, owner_mirror); |
| if (Dart_IsError(func_mirror)) { |
| return func_mirror; |
| } |
| @@ -745,7 +751,7 @@ static Dart_Handle AddConstructors(Dart_Handle map, |
| continue; |
| } |
| - Dart_Handle func_mirror = CreateMethodMirror(func, owner_mirror); |
| + Dart_Handle func_mirror = CreateMethodMirrorUsingApi(func, owner_mirror); |
| if (Dart_IsError(func_mirror)) { |
| return func_mirror; |
| } |
| @@ -833,7 +839,7 @@ static Dart_Handle CreateConstructorMap(Dart_Handle owner, |
| } |
| -static Dart_Handle CreateLibraryMirror(Dart_Handle lib) { |
| +static Dart_Handle CreateLibraryMirrorUsingApi(Dart_Handle lib) { |
| Dart_Handle cls_name = NewString("_LocalLibraryMirrorImpl"); |
| Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); |
| if (Dart_IsError(type)) { |
| @@ -888,7 +894,7 @@ static Dart_Handle CreateLibrariesMap() { |
| if (Dart_IsError(lib)) { |
| return lib; |
| } |
| - Dart_Handle lib_mirror = CreateLibraryMirror(lib); |
| + Dart_Handle lib_mirror = CreateLibraryMirrorUsingApi(lib); |
| if (Dart_IsError(lib_mirror)) { |
| return lib_mirror; |
| } |
| @@ -990,7 +996,7 @@ static Dart_Handle CreateInstanceMirror(Dart_Handle instance) { |
| // TODO(turnidge): Pass the function owner here. This will require |
| // us to support functions in CreateLazyMirror. |
| Dart_Handle func_mirror = |
| - CreateMethodMirror(func, Dart_Null()); |
| + CreateMethodMirrorUsingApi(func, Dart_Null()); |
| if (Dart_IsError(func_mirror)) { |
| return func_mirror; |
| } |
| @@ -1018,6 +1024,75 @@ 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. |
|
siva
2013/07/18 20:38:45
This comment here is misleading it seems to imply
Michael Lippautz (Google)
2013/07/18 22:01:23
Done.
|
| +static RawInstance* CreateClassMirror(const Class& cls, |
| + const Instance& owner_mirror) { |
| + Dart_EnterScope(); |
| + Isolate* isolate = Isolate::Current(); |
| + 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 = CreateLibraryMirrorUsingApi(lib_handle); |
| + if (Dart_IsError(lib_mirror)) { |
| + Dart_PropagateError(lib_mirror); |
| + } |
| + Dart_Handle result = CreateClassMirrorUsingApi(cls_handle, |
| + name_handle, |
| + lib_handle, |
| + lib_mirror); |
| + 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) { |
| + Dart_EnterScope(); |
| + Isolate* isolate = Isolate::Current(); |
| + Dart_Handle lib_handle = Api::NewHandle(isolate, lib.raw()); |
| + Dart_Handle result = CreateLibraryMirrorUsingApi(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(); |
| + Dart_Handle func_handle = Api::NewHandle(isolate, func.raw()); |
| + Dart_Handle owner_handle = Api::NewHandle(isolate, owner_mirror.raw()); |
| + Dart_Handle result = CreateMethodMirrorUsingApi(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(); |
| @@ -1065,14 +1140,14 @@ void NATIVE_ENTRY_FUNCTION(Mirrors_makeLocalClassMirror)( |
| if (Dart_IsError(lib_handle)) { |
| Dart_PropagateError(lib_handle); |
| } |
| - Dart_Handle lib_mirror = CreateLibraryMirror(lib_handle); |
| + Dart_Handle lib_mirror = CreateLibraryMirrorUsingApi(lib_handle); |
| if (Dart_IsError(lib_mirror)) { |
| Dart_PropagateError(lib_mirror); |
| } |
| - Dart_Handle result = CreateClassMirror(cls_handle, |
| - name_handle, |
| - lib_handle, |
| - lib_mirror); |
| + Dart_Handle result = CreateClassMirrorUsingApi(cls_handle, |
| + name_handle, |
| + lib_handle, |
| + lib_mirror); |
| if (Dart_IsError(result)) { |
| Dart_PropagateError(result); |
| } |
| @@ -1791,4 +1866,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()); |
| + } |
| + const Class& owner = Class::Handle(func.Owner()); |
| + if (owner.IsTopLevel()) { |
| + return CreateLibraryMirror(Library::Handle(owner.library())); |
| + } |
| + return CreateClassMirror(owner, Instance::Handle()); |
| +} |
| + |
| } // namespace dart |