| 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" |
| 11 #include "vm/dart_api_state.h" | 11 #include "vm/dart_api_state.h" |
| 12 #include "vm/dart_entry.h" | 12 #include "vm/dart_entry.h" |
| 13 #include "vm/exceptions.h" | 13 #include "vm/exceptions.h" |
| 14 #include "vm/growable_array.h" | 14 #include "vm/growable_array.h" |
| 15 #include "vm/object.h" | 15 #include "vm/object.h" |
| 16 #include "vm/resolver.h" | 16 #include "vm/resolver.h" |
| 17 #include "vm/stack_frame.h" | 17 #include "vm/stack_frame.h" |
| 18 #include "vm/symbols.h" | 18 #include "vm/symbols.h" |
| 19 | 19 |
| 20 namespace dart { | 20 namespace dart { |
| 21 | 21 |
| 22 | 22 |
| 23 // --- Classes and Interfaces Reflection --- | 23 // --- Classes and Interfaces Reflection --- |
| 24 | 24 |
| 25 DART_EXPORT Dart_Handle Dart_ClassName(Dart_Handle object) { | 25 DART_EXPORT Dart_Handle Dart_TypeName(Dart_Handle object) { |
| 26 Isolate* isolate = Isolate::Current(); | 26 Isolate* isolate = Isolate::Current(); |
| 27 DARTSCOPE(isolate); | 27 DARTSCOPE(isolate); |
| 28 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 28 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
| 29 if (obj.IsType() || obj.IsClass()) { | 29 if (obj.IsType()) { |
| 30 const Class& cls = (obj.IsType()) ? | 30 const Class& cls = Class::Handle(Type::Cast(obj).type_class()); |
| 31 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj); | |
| 32 return Api::NewHandle(isolate, cls.UserVisibleName()); | 31 return Api::NewHandle(isolate, cls.UserVisibleName()); |
| 33 } else { | 32 } else { |
| 34 RETURN_TYPE_ERROR(isolate, object, Class/Type); | 33 RETURN_TYPE_ERROR(isolate, object, Class/Type); |
| 35 } | 34 } |
| 36 } | 35 } |
| 37 | 36 |
| 38 DART_EXPORT Dart_Handle Dart_QualifiedClassName(Dart_Handle object) { | 37 DART_EXPORT Dart_Handle Dart_ClassName(Dart_Handle object) { |
| 38 return Dart_TypeName(object); |
| 39 } |
| 40 |
| 41 DART_EXPORT Dart_Handle Dart_QualifiedTypeName(Dart_Handle object) { |
| 39 Isolate* isolate = Isolate::Current(); | 42 Isolate* isolate = Isolate::Current(); |
| 40 DARTSCOPE(isolate); | 43 DARTSCOPE(isolate); |
| 41 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 44 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
| 42 if (obj.IsType() || obj.IsClass()) { | 45 if (obj.IsType() || obj.IsClass()) { |
| 43 const Class& cls = (obj.IsType()) ? | 46 const Class& cls = (obj.IsType()) ? |
| 44 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj); | 47 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj); |
| 45 return Dart_NewStringFromCString(cls.ToCString()); | 48 return Dart_NewStringFromCString(cls.ToCString()); |
| 46 } else { | 49 } else { |
| 47 RETURN_TYPE_ERROR(isolate, object, Class/Type); | 50 RETURN_TYPE_ERROR(isolate, object, Class/Type); |
| 48 } | 51 } |
| 49 } | 52 } |
| 50 | 53 |
| 54 DART_EXPORT Dart_Handle Dart_QualifiedClassName(Dart_Handle object) { |
| 55 return Dart_QualifiedTypeName(object); |
| 56 } |
| 57 |
| 51 // --- Function and Variable Reflection --- | 58 // --- Function and Variable Reflection --- |
| 52 | 59 |
| 53 // Outside of the vm, we expose setter names with a trailing '='. | 60 // Outside of the vm, we expose setter names with a trailing '='. |
| 54 static bool HasExternalSetterSuffix(const String& name) { | 61 static bool HasExternalSetterSuffix(const String& name) { |
| 55 return name.CharAt(name.Length() - 1) == '='; | 62 return name.CharAt(name.Length() - 1) == '='; |
| 56 } | 63 } |
| 57 | 64 |
| 58 | 65 |
| 59 static RawString* RemoveExternalSetterSuffix(const String& name) { | 66 static RawString* RemoveExternalSetterSuffix(const String& name) { |
| 60 ASSERT(HasExternalSetterSuffix(name)); | 67 ASSERT(HasExternalSetterSuffix(name)); |
| 61 return String::SubString(name, 0, name.Length() - 1); | 68 return String::SubString(name, 0, name.Length() - 1); |
| 62 } | 69 } |
| 63 | 70 |
| 64 | 71 |
| 65 DART_EXPORT Dart_Handle Dart_GetFunctionNames(Dart_Handle target) { | 72 DART_EXPORT Dart_Handle Dart_GetFunctionNames(Dart_Handle target) { |
| 66 Isolate* isolate = Isolate::Current(); | 73 Isolate* isolate = Isolate::Current(); |
| 67 DARTSCOPE(isolate); | 74 DARTSCOPE(isolate); |
| 68 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); | 75 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); |
| 69 if (obj.IsError()) { | 76 if (obj.IsError()) { |
| 70 return target; | 77 return target; |
| 71 } | 78 } |
| 72 | 79 |
| 73 const GrowableObjectArray& names = | 80 const GrowableObjectArray& names = |
| 74 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New()); | 81 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New()); |
| 75 Function& func = Function::Handle(); | 82 Function& func = Function::Handle(); |
| 76 String& name = String::Handle(); | 83 String& name = String::Handle(); |
| 77 | 84 |
| 78 if (obj.IsType() || obj.IsClass()) { | 85 if (obj.IsType()) { |
| 79 // For backwards compatibility we allow class objects to be passed in | 86 const Class& cls = Class::Handle(Type::Cast(obj).type_class()); |
| 80 // for now. This needs to be removed once all code that uses class | |
| 81 // objects to invoke Dart_Invoke is removed. | |
| 82 const Class& cls = (obj.IsType()) ? | |
| 83 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj); | |
| 84 const Error& error = Error::Handle(isolate, cls.EnsureIsFinalized(isolate)); | 87 const Error& error = Error::Handle(isolate, cls.EnsureIsFinalized(isolate)); |
| 85 if (!error.IsNull()) { | 88 if (!error.IsNull()) { |
| 86 return Api::NewHandle(isolate, error.raw()); | 89 return Api::NewHandle(isolate, error.raw()); |
| 87 } | 90 } |
| 88 const Array& func_array = Array::Handle(cls.functions()); | 91 const Array& func_array = Array::Handle(cls.functions()); |
| 89 | 92 |
| 90 // Some special types like 'dynamic' have a null functions list. | 93 // Some special types like 'dynamic' have a null functions list. |
| 91 if (!func_array.IsNull()) { | 94 if (!func_array.IsNull()) { |
| 92 for (intptr_t i = 0; i < func_array.Length(); ++i) { | 95 for (intptr_t i = 0; i < func_array.Length(); ++i) { |
| 93 func ^= func_array.At(i); | 96 func ^= func_array.At(i); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 if (obj.IsError()) { | 137 if (obj.IsError()) { |
| 135 return target; | 138 return target; |
| 136 } | 139 } |
| 137 const String& func_name = Api::UnwrapStringHandle(isolate, function_name); | 140 const String& func_name = Api::UnwrapStringHandle(isolate, function_name); |
| 138 if (func_name.IsNull()) { | 141 if (func_name.IsNull()) { |
| 139 RETURN_TYPE_ERROR(isolate, function_name, String); | 142 RETURN_TYPE_ERROR(isolate, function_name, String); |
| 140 } | 143 } |
| 141 | 144 |
| 142 Function& func = Function::Handle(isolate); | 145 Function& func = Function::Handle(isolate); |
| 143 String& tmp_name = String::Handle(isolate); | 146 String& tmp_name = String::Handle(isolate); |
| 144 if (obj.IsType() || obj.IsClass()) { | 147 if (obj.IsType()) { |
| 145 // For backwards compatibility we allow class objects to be passed in | 148 const Class& cls = Class::Handle(Type::Cast(obj).type_class()); |
| 146 // for now. This needs to be removed once all code that uses class | |
| 147 // objects to invoke Dart_Invoke is removed. | |
| 148 const Class& cls = (obj.IsType()) ? | |
| 149 Class::Handle(Type::Cast(obj).type_class()) : Class::Cast(obj); | |
| 150 | 149 |
| 151 // Case 1. Lookup the unmodified function name. | 150 // Case 1. Lookup the unmodified function name. |
| 152 func = cls.LookupFunctionAllowPrivate(func_name); | 151 func = cls.LookupFunctionAllowPrivate(func_name); |
| 153 | 152 |
| 154 // Case 2. Lookup the function without the external setter suffix | 153 // Case 2. Lookup the function without the external setter suffix |
| 155 // '='. Make sure to do this check after the regular lookup, so | 154 // '='. Make sure to do this check after the regular lookup, so |
| 156 // that we don't interfere with operator lookups (like ==). | 155 // that we don't interfere with operator lookups (like ==). |
| 157 if (func.IsNull() && HasExternalSetterSuffix(func_name)) { | 156 if (func.IsNull() && HasExternalSetterSuffix(func_name)) { |
| 158 tmp_name = RemoveExternalSetterSuffix(func_name); | 157 tmp_name = RemoveExternalSetterSuffix(func_name); |
| 159 tmp_name = Field::SetterName(tmp_name); | 158 tmp_name = Field::SetterName(tmp_name); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 RETURN_TYPE_ERROR(isolate, closure, Instance); | 372 RETURN_TYPE_ERROR(isolate, closure, Instance); |
| 374 } | 373 } |
| 375 | 374 |
| 376 ASSERT(ClassFinalizer::AllClassesFinalized()); | 375 ASSERT(ClassFinalizer::AllClassesFinalized()); |
| 377 | 376 |
| 378 RawFunction* rf = Closure::function(closure_obj); | 377 RawFunction* rf = Closure::function(closure_obj); |
| 379 return Api::NewHandle(isolate, rf); | 378 return Api::NewHandle(isolate, rf); |
| 380 } | 379 } |
| 381 | 380 |
| 382 } // namespace dart | 381 } // namespace dart |
| OLD | NEW |