| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "include/dart_mirrors_api.h" | 5 #include "include/dart_mirrors_api.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/dart.h" | 9 #include "vm/dart.h" |
| 10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 // --- Classes and Interfaces Reflection --- | 26 // --- Classes and Interfaces Reflection --- |
| 27 | 27 |
| 28 DART_EXPORT Dart_Handle Dart_TypeName(Dart_Handle object) { | 28 DART_EXPORT Dart_Handle Dart_TypeName(Dart_Handle object) { |
| 29 DARTSCOPE(Thread::Current()); | 29 DARTSCOPE(Thread::Current()); |
| 30 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); | 30 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); |
| 31 if (obj.IsType()) { | 31 if (obj.IsType()) { |
| 32 const Class& cls = Class::Handle(Type::Cast(obj).type_class()); | 32 const Class& cls = Class::Handle(Type::Cast(obj).type_class()); |
| 33 return Api::NewHandle(T, cls.UserVisibleName()); | 33 return Api::NewHandle(T, cls.UserVisibleName()); |
| 34 } else { | 34 } else { |
| 35 RETURN_TYPE_ERROR(Z, object, Class/Type); | 35 RETURN_TYPE_ERROR(Z, object, Class / Type); |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 | 38 |
| 39 | 39 |
| 40 DART_EXPORT Dart_Handle Dart_QualifiedTypeName(Dart_Handle object) { | 40 DART_EXPORT Dart_Handle Dart_QualifiedTypeName(Dart_Handle object) { |
| 41 DARTSCOPE(Thread::Current()); | 41 DARTSCOPE(Thread::Current()); |
| 42 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); | 42 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); |
| 43 if (obj.IsType() || obj.IsClass()) { | 43 if (obj.IsType() || obj.IsClass()) { |
| 44 const Class& cls = (obj.IsType()) ? | 44 const Class& cls = (obj.IsType()) |
| 45 Class::Handle(Z, Type::Cast(obj).type_class()) : Class::Cast(obj); | 45 ? Class::Handle(Z, Type::Cast(obj).type_class()) |
| 46 : Class::Cast(obj); |
| 46 const char* str = cls.ToCString(); | 47 const char* str = cls.ToCString(); |
| 47 if (str == NULL) { | 48 if (str == NULL) { |
| 48 RETURN_NULL_ERROR(str); | 49 RETURN_NULL_ERROR(str); |
| 49 } | 50 } |
| 50 CHECK_CALLBACK_STATE(T); | 51 CHECK_CALLBACK_STATE(T); |
| 51 return Api::NewHandle(T, String::New(str)); | 52 return Api::NewHandle(T, String::New(str)); |
| 52 } else { | 53 } else { |
| 53 RETURN_TYPE_ERROR(Z, object, Class/Type); | 54 RETURN_TYPE_ERROR(Z, object, Class / Type); |
| 54 } | 55 } |
| 55 } | 56 } |
| 56 | 57 |
| 57 | 58 |
| 58 // --- Function and Variable Reflection --- | 59 // --- Function and Variable Reflection --- |
| 59 | 60 |
| 60 // Outside of the vm, we expose setter names with a trailing '='. | 61 // Outside of the vm, we expose setter names with a trailing '='. |
| 61 static bool HasExternalSetterSuffix(const String& name) { | 62 static bool HasExternalSetterSuffix(const String& name) { |
| 62 return name.CharAt(name.Length() - 1) == '='; | 63 return name.CharAt(name.Length() - 1) == '='; |
| 63 } | 64 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 while (it.HasNext()) { | 115 while (it.HasNext()) { |
| 115 obj = it.GetNext(); | 116 obj = it.GetNext(); |
| 116 if (obj.IsFunction()) { | 117 if (obj.IsFunction()) { |
| 117 func ^= obj.raw(); | 118 func ^= obj.raw(); |
| 118 name = func.UserVisibleName(); | 119 name = func.UserVisibleName(); |
| 119 names.Add(name); | 120 names.Add(name); |
| 120 } | 121 } |
| 121 } | 122 } |
| 122 } else { | 123 } else { |
| 123 return Api::NewError( | 124 return Api::NewError( |
| 124 "%s expects argument 'target' to be a class or library.", | 125 "%s expects argument 'target' to be a class or library.", CURRENT_FUNC); |
| 125 CURRENT_FUNC); | |
| 126 } | 126 } |
| 127 return Api::NewHandle(T, Array::MakeArray(names)); | 127 return Api::NewHandle(T, Array::MakeArray(names)); |
| 128 } | 128 } |
| 129 | 129 |
| 130 | 130 |
| 131 DART_EXPORT Dart_Handle Dart_LookupFunction(Dart_Handle target, | 131 DART_EXPORT Dart_Handle Dart_LookupFunction(Dart_Handle target, |
| 132 Dart_Handle function_name) { | 132 Dart_Handle function_name) { |
| 133 DARTSCOPE(Thread::Current()); | 133 DARTSCOPE(Thread::Current()); |
| 134 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(target)); | 134 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(target)); |
| 135 if (obj.IsError()) { | 135 if (obj.IsError()) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 func = lib.LookupFunctionAllowPrivate(tmp_name); | 184 func = lib.LookupFunctionAllowPrivate(tmp_name); |
| 185 } | 185 } |
| 186 | 186 |
| 187 // Case 3. Lookup the function with the getter prefix prepended. | 187 // Case 3. Lookup the function with the getter prefix prepended. |
| 188 if (func.IsNull()) { | 188 if (func.IsNull()) { |
| 189 tmp_name = Field::GetterName(func_name); | 189 tmp_name = Field::GetterName(func_name); |
| 190 func = lib.LookupFunctionAllowPrivate(tmp_name); | 190 func = lib.LookupFunctionAllowPrivate(tmp_name); |
| 191 } | 191 } |
| 192 } else { | 192 } else { |
| 193 return Api::NewError( | 193 return Api::NewError( |
| 194 "%s expects argument 'target' to be a class or library.", | 194 "%s expects argument 'target' to be a class or library.", CURRENT_FUNC); |
| 195 CURRENT_FUNC); | |
| 196 } | 195 } |
| 197 | 196 |
| 198 #if defined(DEBUG) | 197 #if defined(DEBUG) |
| 199 if (!func.IsNull()) { | 198 if (!func.IsNull()) { |
| 200 // We only provide access to a subset of function kinds. | 199 // We only provide access to a subset of function kinds. |
| 201 RawFunction::Kind func_kind = func.kind(); | 200 RawFunction::Kind func_kind = func.kind(); |
| 202 ASSERT(func_kind == RawFunction::kRegularFunction || | 201 ASSERT(func_kind == RawFunction::kRegularFunction || |
| 203 func_kind == RawFunction::kGetterFunction || | 202 func_kind == RawFunction::kGetterFunction || |
| 204 func_kind == RawFunction::kSetterFunction || | 203 func_kind == RawFunction::kSetterFunction || |
| 205 func_kind == RawFunction::kConstructor); | 204 func_kind == RawFunction::kConstructor); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 225 if (func.IsNull()) { | 224 if (func.IsNull()) { |
| 226 RETURN_TYPE_ERROR(Z, function, Function); | 225 RETURN_TYPE_ERROR(Z, function, Function); |
| 227 } | 226 } |
| 228 if (func.IsNonImplicitClosureFunction()) { | 227 if (func.IsNonImplicitClosureFunction()) { |
| 229 RawFunction* parent_function = func.parent_function(); | 228 RawFunction* parent_function = func.parent_function(); |
| 230 return Api::NewHandle(T, parent_function); | 229 return Api::NewHandle(T, parent_function); |
| 231 } | 230 } |
| 232 const Class& owner = Class::Handle(Z, func.Owner()); | 231 const Class& owner = Class::Handle(Z, func.Owner()); |
| 233 ASSERT(!owner.IsNull()); | 232 ASSERT(!owner.IsNull()); |
| 234 if (owner.IsTopLevel()) { | 233 if (owner.IsTopLevel()) { |
| 235 // Top-level functions are implemented as members of a hidden class. We hide | 234 // Top-level functions are implemented as members of a hidden class. We hide |
| 236 // that class here and instead answer the library. | 235 // that class here and instead answer the library. |
| 237 #if defined(DEBUG) | 236 #if defined(DEBUG) |
| 238 const Library& lib = Library::Handle(Z, owner.library()); | 237 const Library& lib = Library::Handle(Z, owner.library()); |
| 239 if (lib.IsNull()) { | 238 if (lib.IsNull()) { |
| 240 ASSERT(owner.IsDynamicClass() || owner.IsVoidClass()); | 239 ASSERT(owner.IsDynamicClass() || owner.IsVoidClass()); |
| 241 } | 240 } |
| 242 #endif | 241 #endif |
| 243 return Api::NewHandle(T, owner.library()); | 242 return Api::NewHandle(T, owner.library()); |
| 244 } else { | 243 } else { |
| 245 return Api::NewHandle(T, owner.RareType()); | 244 return Api::NewHandle(T, owner.RareType()); |
| 246 } | 245 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 RETURN_TYPE_ERROR(Z, closure, Instance); | 349 RETURN_TYPE_ERROR(Z, closure, Instance); |
| 351 } | 350 } |
| 352 | 351 |
| 353 ASSERT(ClassFinalizer::AllClassesFinalized()); | 352 ASSERT(ClassFinalizer::AllClassesFinalized()); |
| 354 | 353 |
| 355 RawFunction* rf = Closure::Cast(closure_obj).function(); | 354 RawFunction* rf = Closure::Cast(closure_obj).function(); |
| 356 return Api::NewHandle(T, rf); | 355 return Api::NewHandle(T, rf); |
| 357 } | 356 } |
| 358 | 357 |
| 359 } // namespace dart | 358 } // namespace dart |
| OLD | NEW |