Chromium Code Reviews| 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 |
| 260 for (int64_t i = 0; i < param_count; i++) { | 261 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[] = { | 262 Dart_Handle args[] = { |
| 266 CreateLazyMirror(arg_type), | 263 CreateMirrorReference(func), |
|
siva
2013/07/22 22:54:31
Why do we have to create a mirror reference for 'f
Michael Lippautz (Google)
2013/07/22 23:13:37
Done. However, this function will be inlined with
| |
| 264 Dart_NewInteger(i), | |
| 267 Dart_NewBoolean(i >= fixed_param_count), // optional param? | 265 Dart_NewBoolean(i >= fixed_param_count), // optional param? |
| 268 }; | 266 }; |
| 269 Dart_Handle param = | 267 Dart_Handle param = |
| 270 Dart_New(param_type, Dart_Null(), ARRAY_SIZE(args), args); | 268 Dart_New(param_type, Dart_Null(), ARRAY_SIZE(args), args); |
| 271 if (Dart_IsError(param)) { | 269 if (Dart_IsError(param)) { |
| 272 return param; | 270 return param; |
| 273 } | 271 } |
| 274 result = Dart_ListSetAt(parameter_list, i, param); | 272 result = Dart_ListSetAt(parameter_list, i, param); |
| 275 if (Dart_IsError(result)) { | 273 if (Dart_IsError(result)) { |
| 276 return result; | 274 return result; |
| (...skipping 1634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1911 | 1909 |
| 1912 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { | 1910 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { |
| 1913 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1911 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1914 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1912 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1915 // We handle constructors in Dart code. | 1913 // We handle constructors in Dart code. |
| 1916 ASSERT(!func.IsConstructor()); | 1914 ASSERT(!func.IsConstructor()); |
| 1917 const AbstractType& return_type = AbstractType::Handle(func.result_type()); | 1915 const AbstractType& return_type = AbstractType::Handle(func.result_type()); |
| 1918 return CreateTypeMirror(return_type); | 1916 return CreateTypeMirror(return_type); |
| 1919 } | 1917 } |
| 1920 | 1918 |
| 1919 | |
| 1920 DEFINE_NATIVE_ENTRY(ParameterMirror_type, 2) { | |
| 1921 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | |
| 1922 GET_NON_NULL_NATIVE_ARGUMENT(Smi, pos, arguments->NativeArgAt(1)); | |
| 1923 const Function& func = Function::Handle(ref.GetFunctionReferent()); | |
| 1924 const AbstractType& param_type = AbstractType::Handle(func.ParameterTypeAt( | |
| 1925 func.NumImplicitParameters() + pos.Value())); | |
| 1926 return CreateTypeMirror(param_type); | |
| 1927 } | |
| 1928 | |
| 1921 } // namespace dart | 1929 } // namespace dart |
| OLD | NEW |