Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1475)

Unified Diff: runtime/lib/mirrors.cc

Issue 19579006: Adding proper handling for MethodMirror.owner (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698