| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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_api.h" | 5 #include "include/dart_api.h" |
| 6 #include "include/dart_debugger_api.h" | 6 #include "include/dart_debugger_api.h" |
| 7 #include "include/dart_mirrors_api.h" | 7 #include "include/dart_mirrors_api.h" |
| 8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
| 9 #include "vm/dart_api_state.h" // TODO(11742): Remove with CreateMirrorRef. | 9 #include "vm/dart_api_state.h" // TODO(11742): Remove with CreateMirrorRef. |
| 10 #include "vm/bootstrap_natives.h" | 10 #include "vm/bootstrap_natives.h" |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 } | 229 } |
| 230 return UnwrapObjectMirror(mirror); | 230 return UnwrapObjectMirror(mirror); |
| 231 // will return nonsense if mirror is not an ObjectMirror | 231 // will return nonsense if mirror is not an ObjectMirror |
| 232 } | 232 } |
| 233 | 233 |
| 234 | 234 |
| 235 static Dart_Handle CreateLazyMirror(Dart_Handle target); | 235 static Dart_Handle CreateLazyMirror(Dart_Handle target); |
| 236 | 236 |
| 237 | 237 |
| 238 static Dart_Handle CreateParameterMirrorList(Dart_Handle func) { | 238 static Dart_Handle CreateParameterMirrorList(Dart_Handle func) { |
| 239 ASSERT(Dart_IsFunction(func)); |
| 239 int64_t fixed_param_count; | 240 int64_t fixed_param_count; |
| 240 int64_t opt_param_count; | 241 int64_t opt_param_count; |
| 241 Dart_Handle result = Dart_FunctionParameterCounts(func, | 242 Dart_Handle result = Dart_FunctionParameterCounts(func, |
| 242 &fixed_param_count, | 243 &fixed_param_count, |
| 243 &opt_param_count); | 244 &opt_param_count); |
| 244 if (Dart_IsError(result)) { | 245 if (Dart_IsError(result)) { |
| 245 return result; | 246 return result; |
| 246 } | 247 } |
| 247 | 248 |
| 248 int64_t param_count = fixed_param_count + opt_param_count; | 249 int64_t param_count = fixed_param_count + opt_param_count; |
| 249 Dart_Handle parameter_list = Dart_NewList(param_count); | 250 Dart_Handle parameter_list = Dart_NewList(param_count); |
| 250 if (Dart_IsError(parameter_list)) { | 251 if (Dart_IsError(parameter_list)) { |
| 251 return result; | 252 return result; |
| 252 } | 253 } |
| 253 | 254 |
| 254 Dart_Handle param_cls_name = NewString("_LocalParameterMirrorImpl"); | 255 Dart_Handle param_cls_name = NewString("_LocalParameterMirrorImpl"); |
| 255 Dart_Handle param_type = Dart_GetType(MirrorLib(), param_cls_name, 0, NULL); | 256 Dart_Handle param_type = Dart_GetType(MirrorLib(), param_cls_name, 0, NULL); |
| 256 if (Dart_IsError(param_type)) { | 257 if (Dart_IsError(param_type)) { |
| 257 return param_type; | 258 return param_type; |
| 258 } | 259 } |
| 259 | 260 |
| 261 Dart_Handle reflectee = CreateMirrorReference(func); |
| 260 for (int64_t i = 0; i < param_count; i++) { | 262 for (int64_t i = 0; i < param_count; i++) { |
| 261 Dart_Handle arg_type = Dart_FunctionParameterType(func, i); | |
| 262 if (Dart_IsError(arg_type)) { | |
| 263 return arg_type; | |
| 264 } | |
| 265 Dart_Handle args[] = { | 263 Dart_Handle args[] = { |
| 266 CreateLazyMirror(arg_type), | 264 reflectee, |
| 267 Dart_NewBoolean(i >= fixed_param_count), // optional param? | 265 Dart_NewInteger(i), |
| 266 (i >= fixed_param_count) ? Api::True() : Api::False(), |
| 268 }; | 267 }; |
| 269 Dart_Handle param = | 268 Dart_Handle param = |
| 270 Dart_New(param_type, Dart_Null(), ARRAY_SIZE(args), args); | 269 Dart_New(param_type, Dart_Null(), ARRAY_SIZE(args), args); |
| 271 if (Dart_IsError(param)) { | 270 if (Dart_IsError(param)) { |
| 272 return param; | 271 return param; |
| 273 } | 272 } |
| 274 result = Dart_ListSetAt(parameter_list, i, param); | 273 result = Dart_ListSetAt(parameter_list, i, param); |
| 275 if (Dart_IsError(result)) { | 274 if (Dart_IsError(result)) { |
| 276 return result; | 275 return result; |
| 277 } | 276 } |
| (...skipping 1579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1857 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { | 1856 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { |
| 1858 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1857 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1859 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1858 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1860 // We handle constructors in Dart code. | 1859 // We handle constructors in Dart code. |
| 1861 ASSERT(!func.IsConstructor()); | 1860 ASSERT(!func.IsConstructor()); |
| 1862 const AbstractType& return_type = AbstractType::Handle(func.result_type()); | 1861 const AbstractType& return_type = AbstractType::Handle(func.result_type()); |
| 1863 return CreateTypeMirror(return_type); | 1862 return CreateTypeMirror(return_type); |
| 1864 } | 1863 } |
| 1865 | 1864 |
| 1866 | 1865 |
| 1866 DEFINE_NATIVE_ENTRY(ParameterMirror_type, 2) { |
| 1867 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1868 GET_NON_NULL_NATIVE_ARGUMENT(Smi, pos, arguments->NativeArgAt(1)); |
| 1869 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1870 const AbstractType& param_type = AbstractType::Handle(func.ParameterTypeAt( |
| 1871 func.NumImplicitParameters() + pos.Value())); |
| 1872 return CreateTypeMirror(param_type); |
| 1873 } |
| 1874 |
| 1875 |
| 1867 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1876 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
| 1868 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1877 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1869 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1878 const Field& field = Field::Handle(ref.GetFieldReferent()); |
| 1870 | 1879 |
| 1871 const AbstractType& type = AbstractType::Handle(field.type()); | 1880 const AbstractType& type = AbstractType::Handle(field.type()); |
| 1872 return CreateTypeMirror(type); | 1881 return CreateTypeMirror(type); |
| 1873 } | 1882 } |
| 1874 | 1883 |
| 1875 } // namespace dart | 1884 } // namespace dart |
| OLD | NEW |