Chromium Code Reviews| 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_ClassName(Dart_Handle object) { |
|
siva
2013/09/19 03:16:58
We should change the name of this function to Dart
rmacnak
2013/09/19 17:45:53
Makes sense. I have renamed this Dart_TypeName and
| |
| 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)); |
|
siva
2013/09/19 03:16:58
Ditto comment about using
const Type& type_obj = .
rmacnak
2013/09/19 17:45:53
Got 'em.
| |
| 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_QualifiedClassName(Dart_Handle object) { |
| 39 Isolate* isolate = Isolate::Current(); | 38 Isolate* isolate = Isolate::Current(); |
| 40 DARTSCOPE(isolate); | 39 DARTSCOPE(isolate); |
| 41 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 40 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 68 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); | 67 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); |
| 69 if (obj.IsError()) { | 68 if (obj.IsError()) { |
| 70 return target; | 69 return target; |
| 71 } | 70 } |
| 72 | 71 |
| 73 const GrowableObjectArray& names = | 72 const GrowableObjectArray& names = |
| 74 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New()); | 73 GrowableObjectArray::Handle(isolate, GrowableObjectArray::New()); |
| 75 Function& func = Function::Handle(); | 74 Function& func = Function::Handle(); |
| 76 String& name = String::Handle(); | 75 String& name = String::Handle(); |
| 77 | 76 |
| 78 if (obj.IsType() || obj.IsClass()) { | 77 if (obj.IsType()) { |
| 79 // For backwards compatibility we allow class objects to be passed in | 78 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)); | 79 const Error& error = Error::Handle(isolate, cls.EnsureIsFinalized(isolate)); |
| 85 if (!error.IsNull()) { | 80 if (!error.IsNull()) { |
| 86 return Api::NewHandle(isolate, error.raw()); | 81 return Api::NewHandle(isolate, error.raw()); |
| 87 } | 82 } |
| 88 const Array& func_array = Array::Handle(cls.functions()); | 83 const Array& func_array = Array::Handle(cls.functions()); |
| 89 | 84 |
| 90 // Some special types like 'dynamic' have a null functions list. | 85 // Some special types like 'dynamic' have a null functions list. |
| 91 if (!func_array.IsNull()) { | 86 if (!func_array.IsNull()) { |
| 92 for (intptr_t i = 0; i < func_array.Length(); ++i) { | 87 for (intptr_t i = 0; i < func_array.Length(); ++i) { |
| 93 func ^= func_array.At(i); | 88 func ^= func_array.At(i); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 if (obj.IsError()) { | 129 if (obj.IsError()) { |
| 135 return target; | 130 return target; |
| 136 } | 131 } |
| 137 const String& func_name = Api::UnwrapStringHandle(isolate, function_name); | 132 const String& func_name = Api::UnwrapStringHandle(isolate, function_name); |
| 138 if (func_name.IsNull()) { | 133 if (func_name.IsNull()) { |
| 139 RETURN_TYPE_ERROR(isolate, function_name, String); | 134 RETURN_TYPE_ERROR(isolate, function_name, String); |
| 140 } | 135 } |
| 141 | 136 |
| 142 Function& func = Function::Handle(isolate); | 137 Function& func = Function::Handle(isolate); |
| 143 String& tmp_name = String::Handle(isolate); | 138 String& tmp_name = String::Handle(isolate); |
| 144 if (obj.IsType() || obj.IsClass()) { | 139 if (obj.IsType()) { |
| 145 // For backwards compatibility we allow class objects to be passed in | 140 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 | 141 |
| 151 // Case 1. Lookup the unmodified function name. | 142 // Case 1. Lookup the unmodified function name. |
| 152 func = cls.LookupFunctionAllowPrivate(func_name); | 143 func = cls.LookupFunctionAllowPrivate(func_name); |
| 153 | 144 |
| 154 // Case 2. Lookup the function without the external setter suffix | 145 // Case 2. Lookup the function without the external setter suffix |
| 155 // '='. Make sure to do this check after the regular lookup, so | 146 // '='. Make sure to do this check after the regular lookup, so |
| 156 // that we don't interfere with operator lookups (like ==). | 147 // that we don't interfere with operator lookups (like ==). |
| 157 if (func.IsNull() && HasExternalSetterSuffix(func_name)) { | 148 if (func.IsNull() && HasExternalSetterSuffix(func_name)) { |
| 158 tmp_name = RemoveExternalSetterSuffix(func_name); | 149 tmp_name = RemoveExternalSetterSuffix(func_name); |
| 159 tmp_name = Field::SetterName(tmp_name); | 150 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); | 364 RETURN_TYPE_ERROR(isolate, closure, Instance); |
| 374 } | 365 } |
| 375 | 366 |
| 376 ASSERT(ClassFinalizer::AllClassesFinalized()); | 367 ASSERT(ClassFinalizer::AllClassesFinalized()); |
| 377 | 368 |
| 378 RawFunction* rf = Closure::function(closure_obj); | 369 RawFunction* rf = Closure::function(closure_obj); |
| 379 return Api::NewHandle(isolate, rf); | 370 return Api::NewHandle(isolate, rf); |
| 380 } | 371 } |
| 381 | 372 |
| 382 } // namespace dart | 373 } // namespace dart |
| OLD | NEW |