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

Unified Diff: runtime/lib/mirrors.cc

Issue 22625003: Make ClosureMirror handle instances of user-defined classes that implement call. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase Created 7 years, 4 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 f2171835cda5fe0eb84b591598adcba0e1eb41df..d0e4524e01cac94453ac7a1f6c78580271a715f7 100644
--- a/runtime/lib/mirrors.cc
+++ b/runtime/lib/mirrors.cc
@@ -156,6 +156,22 @@ static RawInstance* CreateVariableMirror(const Field& field,
return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args);
}
+static RawFunction* CallMethod(const Class& cls) {
+ if (cls.IsSignatureClass()) {
+ return cls.signature_function();
+ }
+
+ Class& lookup_cls = Class::Handle(cls.raw());
+ Function& call_function = Function::Handle();
+ do {
+ call_function = lookup_cls.LookupDynamicFunction(Symbols::Call());
+ if (!call_function.IsNull()) {
+ return call_function.raw();
+ }
+ lookup_cls = lookup_cls.SuperClass();
+ } while (!lookup_cls.IsNull());
+ return Function::null();
+}
static RawInstance* CreateClassMirror(const Class& cls,
const AbstractType& type,
@@ -350,10 +366,23 @@ DEFINE_NATIVE_ENTRY(DeclarationMirror_metadata, 1) {
}
+DEFINE_NATIVE_ENTRY(FunctionTypeMirror_call_method, 2) {
+ GET_NON_NULL_NATIVE_ARGUMENT(Instance,
+ owner_mirror,
+ arguments->NativeArgAt(0));
+ GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(1));
+ const Class& cls = Class::Handle(ref.GetClassReferent());
+ const Function& func = Function::Handle(CallMethod(cls));
+ ASSERT(!func.IsNull());
+ return CreateMethodMirror(func, owner_mirror);
+}
+
+
DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 1) {
GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
const Class& cls = Class::Handle(ref.GetClassReferent());
- const Function& func = Function::Handle(cls.signature_function());
+ const Function& func = Function::Handle(CallMethod(cls));
+ ASSERT(!func.IsNull());
return CreateParameterMirrorList(func);
}
@@ -361,7 +390,8 @@ DEFINE_NATIVE_ENTRY(FunctionTypeMirror_parameters, 1) {
DEFINE_NATIVE_ENTRY(FunctionTypeMirror_return_type, 1) {
GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0));
const Class& cls = Class::Handle(ref.GetClassReferent());
- const Function& func = Function::Handle(cls.signature_function());
+ const Function& func = Function::Handle(CallMethod(cls));
+ ASSERT(!func.IsNull());
return func.result_type();
}
@@ -777,10 +807,13 @@ DEFINE_NATIVE_ENTRY(ClosureMirror_apply, 2) {
DEFINE_NATIVE_ENTRY(ClosureMirror_function, 1) {
GET_NON_NULL_NATIVE_ARGUMENT(Instance, closure, arguments->NativeArgAt(0));
- ASSERT(closure.IsClosure());
+ ASSERT(!closure.IsNull());
+
+ Function& function = Function::Handle();
+ bool callable = closure.IsCallable(&function, NULL);
+ ASSERT(callable);
- const Function& func = Function::Handle(Closure::function(closure));
- return CreateMethodMirror(func, Instance::null_instance());
+ return CreateMethodMirror(function, Instance::null_instance());
}
« 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