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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 return UnwrapVariableMirror(mirror); | 228 return UnwrapVariableMirror(mirror); |
| 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 RawInstance* CreateParameterMirrorList(const Function& func) { |
| 239 ASSERT(Dart_IsFunction(func)); | 239 const intptr_t param_cnt = func.num_fixed_parameters() - |
|
Michael Lippautz (Google)
2013/07/23 18:41:46
num_fixed_parameters() includes the implicit ones
| |
| 240 int64_t fixed_param_count; | 240 func.NumImplicitParameters() + |
| 241 int64_t opt_param_count; | 241 func.NumOptionalParameters(); |
| 242 Dart_Handle result = Dart_FunctionParameterCounts(func, | 242 const Array& results = Array::Handle(Array::New(param_cnt)); |
| 243 &fixed_param_count, | 243 const Array& args = Array::Handle(Array::New(3)); |
| 244 &opt_param_count); | 244 const MirrorReference& reflectee = MirrorReference::Handle( |
| 245 if (Dart_IsError(result)) { | 245 MirrorReference::New(func)); |
| 246 return result; | 246 Smi& pos = Smi::Handle(); |
| 247 Instance& param = Instance::Handle(); | |
| 248 for (intptr_t i = 0; i < param_cnt; ++i) { | |
| 249 pos ^= Smi::New(i); | |
| 250 args.SetAt(0, reflectee); | |
|
siva
2013/07/23 21:44:58
This line can be hoisted out of the loop.
Michael Lippautz (Google)
2013/07/23 23:18:13
Done.
| |
| 251 args.SetAt(1, pos); | |
| 252 args.SetAt(2, (i >= func.num_fixed_parameters()) ? | |
| 253 Bool::True() : Bool::False()); | |
| 254 param ^= CreateMirror(Symbols::_LocalParameterMirrorImpl(), args); | |
|
Michael Lippautz (Google)
2013/07/23 18:41:46
This looks up the class each time it is invoked (l
| |
| 255 results.SetAt(i, param); | |
| 247 } | 256 } |
| 248 | 257 results.MakeImmutable(); |
| 249 int64_t param_count = fixed_param_count + opt_param_count; | 258 return results.raw(); |
| 250 Dart_Handle parameter_list = Dart_NewList(param_count); | |
| 251 if (Dart_IsError(parameter_list)) { | |
| 252 return result; | |
| 253 } | |
| 254 | |
| 255 Dart_Handle param_cls_name = NewString("_LocalParameterMirrorImpl"); | |
| 256 Dart_Handle param_type = Dart_GetType(MirrorLib(), param_cls_name, 0, NULL); | |
| 257 if (Dart_IsError(param_type)) { | |
| 258 return param_type; | |
| 259 } | |
| 260 | |
| 261 Dart_Handle reflectee = CreateMirrorReference(func); | |
| 262 for (int64_t i = 0; i < param_count; i++) { | |
| 263 Dart_Handle args[] = { | |
| 264 reflectee, | |
| 265 Dart_NewInteger(i), | |
| 266 (i >= fixed_param_count) ? Api::True() : Api::False(), | |
| 267 }; | |
| 268 Dart_Handle param = | |
| 269 Dart_New(param_type, Dart_Null(), ARRAY_SIZE(args), args); | |
| 270 if (Dart_IsError(param)) { | |
| 271 return param; | |
| 272 } | |
| 273 result = Dart_ListSetAt(parameter_list, i, param); | |
| 274 if (Dart_IsError(result)) { | |
| 275 return result; | |
| 276 } | |
| 277 } | |
| 278 return parameter_list; | |
| 279 } | 259 } |
| 280 | 260 |
| 281 | 261 |
| 262 static Dart_Handle CreateParameterMirrorListUsingApi(Dart_Handle func) { | |
| 263 ASSERT(Dart_IsFunction(func)); | |
| 264 Isolate* isolate = Isolate::Current(); | |
| 265 Instance& retvalue = Instance::Handle(); | |
| 266 Dart_EnterScope(); | |
|
Michael Lippautz (Google)
2013/07/23 18:41:46
Right now the parameter list is created eagerly wh
| |
| 267 const Function& func_obj = Api::UnwrapFunctionHandle(isolate, func); | |
| 268 retvalue ^= CreateParameterMirrorList(func_obj); | |
| 269 Dart_ExitScope(); | |
|
siva
2013/07/23 21:44:58
why do you need a Dart_EnterScope() / Dart_ExitSco
Michael Lippautz (Google)
2013/07/23 23:18:13
As discussed offline, we rather use a HANDLESCOPE
| |
| 270 return Api::NewHandle(isolate, retvalue.raw()); | |
| 271 } | |
| 272 | |
| 273 | |
| 282 static Dart_Handle CreateLazyMirror(Dart_Handle target) { | 274 static Dart_Handle CreateLazyMirror(Dart_Handle target) { |
| 283 if (Dart_IsNull(target) || Dart_IsError(target)) { | 275 if (Dart_IsNull(target) || Dart_IsError(target)) { |
| 284 return target; | 276 return target; |
| 285 } | 277 } |
| 286 | 278 |
| 287 if (Dart_IsLibrary(target)) { | 279 if (Dart_IsLibrary(target)) { |
| 288 Dart_Handle cls_name = NewString("_LazyLibraryMirror"); | 280 Dart_Handle cls_name = NewString("_LazyLibraryMirror"); |
| 289 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); | 281 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); |
| 290 Dart_Handle args[] = { Dart_LibraryUrl(target) }; | 282 Dart_Handle args[] = { Dart_LibraryUrl(target) }; |
| 291 return Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); | 283 return Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); |
| 292 } | 284 } |
| 293 | 285 |
| 294 if (Dart_IsClass(target)) { | 286 if (Dart_IsClass(target)) { |
| 295 if (Dart_ClassIsFunctionType(target)) { | 287 if (Dart_ClassIsFunctionType(target)) { |
| 296 Dart_Handle cls_name = NewString("_LazyFunctionTypeMirror"); | 288 Dart_Handle cls_name = NewString("_LazyFunctionTypeMirror"); |
| 297 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); | 289 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); |
| 298 | 290 |
| 299 Dart_Handle sig = Dart_ClassGetFunctionTypeSignature(target); | 291 Dart_Handle sig = Dart_ClassGetFunctionTypeSignature(target); |
| 300 Dart_Handle return_type = Dart_FunctionReturnType(sig); | 292 Dart_Handle return_type = Dart_FunctionReturnType(sig); |
| 301 if (Dart_IsError(return_type)) { | 293 if (Dart_IsError(return_type)) { |
| 302 return return_type; | 294 return return_type; |
| 303 } | 295 } |
| 304 | 296 |
| 305 Dart_Handle args[] = { | 297 Dart_Handle args[] = { |
| 306 CreateLazyMirror(return_type), | 298 CreateLazyMirror(return_type), |
| 307 CreateParameterMirrorList(sig), | 299 CreateParameterMirrorListUsingApi(sig), |
| 308 }; | 300 }; |
| 309 return Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); | 301 return Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); |
| 310 } else { | 302 } else { |
| 311 Dart_Handle cls_name = NewString("_LazyTypeMirror"); | 303 Dart_Handle cls_name = NewString("_LazyTypeMirror"); |
| 312 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); | 304 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); |
| 313 Dart_Handle lib = Dart_ClassGetLibrary(target); | 305 Dart_Handle lib = Dart_ClassGetLibrary(target); |
| 314 Dart_Handle lib_url; | 306 Dart_Handle lib_url; |
| 315 if (Dart_IsNull(lib)) { | 307 if (Dart_IsNull(lib)) { |
| 316 lib_url = Dart_Null(); | 308 lib_url = Dart_Null(); |
| 317 } else { | 309 } else { |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 576 Dart_Handle mirror_cls_name = NewString("_LocalMethodMirrorImpl"); | 568 Dart_Handle mirror_cls_name = NewString("_LocalMethodMirrorImpl"); |
| 577 Dart_Handle mirror_type = Dart_GetType(MirrorLib(), mirror_cls_name, 0, NULL); | 569 Dart_Handle mirror_type = Dart_GetType(MirrorLib(), mirror_cls_name, 0, NULL); |
| 578 if (Dart_IsError(mirror_type)) { | 570 if (Dart_IsError(mirror_type)) { |
| 579 return mirror_type; | 571 return mirror_type; |
| 580 } | 572 } |
| 581 | 573 |
| 582 // TODO(turnidge): Implement constructor kinds (arguments 7 - 10). | 574 // TODO(turnidge): Implement constructor kinds (arguments 7 - 10). |
| 583 Dart_Handle args[] = { | 575 Dart_Handle args[] = { |
| 584 CreateMirrorReference(func), | 576 CreateMirrorReference(func), |
| 585 owner_mirror, | 577 owner_mirror, |
| 586 CreateParameterMirrorList(func), | 578 CreateParameterMirrorListUsingApi(func), |
| 587 func_obj.is_static() ? Api::True() : Api::False(), | 579 func_obj.is_static() ? Api::True() : Api::False(), |
| 588 func_obj.is_abstract() ? Api::True() : Api::False(), | 580 func_obj.is_abstract() ? Api::True() : Api::False(), |
| 589 func_obj.IsGetterFunction() ? Api::True() : Api::False(), | 581 func_obj.IsGetterFunction() ? Api::True() : Api::False(), |
| 590 func_obj.IsSetterFunction() ? Api::True() : Api::False(), | 582 func_obj.IsSetterFunction() ? Api::True() : Api::False(), |
| 591 func_obj.IsConstructor() ? Api::True() : Api::False(), | 583 func_obj.IsConstructor() ? Api::True() : Api::False(), |
| 592 Api::False(), | 584 Api::False(), |
| 593 Api::False(), | 585 Api::False(), |
| 594 Api::False(), | 586 Api::False(), |
| 595 Api::False() | 587 Api::False() |
| 596 }; | 588 }; |
| (...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1875 | 1867 |
| 1876 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1868 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
| 1877 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1869 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1878 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1870 const Field& field = Field::Handle(ref.GetFieldReferent()); |
| 1879 | 1871 |
| 1880 const AbstractType& type = AbstractType::Handle(field.type()); | 1872 const AbstractType& type = AbstractType::Handle(field.type()); |
| 1881 return CreateTypeMirror(type); | 1873 return CreateTypeMirror(type); |
| 1882 } | 1874 } |
| 1883 | 1875 |
| 1884 } // namespace dart | 1876 } // namespace dart |
| OLD | NEW |