| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 112 } |
| 113 | 113 |
| 114 | 114 |
| 115 // TODO(11742): Remove once there are no more users of the Dart_Handle-based | 115 // TODO(11742): Remove once there are no more users of the Dart_Handle-based |
| 116 // VMReferences. | 116 // VMReferences. |
| 117 static Dart_Handle CreateMirrorReference(Dart_Handle handle) { | 117 static Dart_Handle CreateMirrorReference(Dart_Handle handle) { |
| 118 Isolate* isolate = Isolate::Current(); | 118 Isolate* isolate = Isolate::Current(); |
| 119 DARTSCOPE(isolate); | 119 DARTSCOPE(isolate); |
| 120 const Object& referent = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 120 const Object& referent = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
| 121 const MirrorReference& reference = | 121 const MirrorReference& reference = |
| 122 MirrorReference::Handle(MirrorReference::New()); | 122 MirrorReference::Handle(MirrorReference::New(referent)); |
| 123 reference.set_referent(referent); | |
| 124 return Api::NewHandle(isolate, reference.raw()); | 123 return Api::NewHandle(isolate, reference.raw()); |
| 125 } | 124 } |
| 126 | 125 |
| 127 | 126 |
| 128 static Dart_Handle StringFromSymbol(Dart_Handle symbol) { | 127 static Dart_Handle StringFromSymbol(Dart_Handle symbol) { |
| 129 Dart_Handle result = Dart_Invoke(MirrorLib(), NewString("_n"), 1, &symbol); | 128 Dart_Handle result = Dart_Invoke(MirrorLib(), NewString("_n"), 1, &symbol); |
| 130 return result; | 129 return result; |
| 131 } | 130 } |
| 132 | 131 |
| 133 | 132 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 return UnwrapVariableMirror(mirror); | 228 return UnwrapVariableMirror(mirror); |
| 230 } | 229 } |
| 231 return UnwrapObjectMirror(mirror); | 230 return UnwrapObjectMirror(mirror); |
| 232 // will return nonsense if mirror is not an ObjectMirror | 231 // will return nonsense if mirror is not an ObjectMirror |
| 233 } | 232 } |
| 234 | 233 |
| 235 | 234 |
| 236 static Dart_Handle CreateLazyMirror(Dart_Handle target); | 235 static Dart_Handle CreateLazyMirror(Dart_Handle target); |
| 237 | 236 |
| 238 | 237 |
| 239 static Dart_Handle CreateParameterMirrorList(Dart_Handle func) { | 238 static RawInstance* CreateParameterMirrorList(const Function& func) { |
| 240 ASSERT(Dart_IsFunction(func)); | 239 HANDLESCOPE(Isolate::Current()); |
| 241 int64_t fixed_param_count; | 240 const intptr_t param_cnt = func.num_fixed_parameters() - |
| 242 int64_t opt_param_count; | 241 func.NumImplicitParameters() + |
| 243 Dart_Handle result = Dart_FunctionParameterCounts(func, | 242 func.NumOptionalParameters(); |
| 244 &fixed_param_count, | 243 const Array& results = Array::Handle(Array::New(param_cnt)); |
| 245 &opt_param_count); | 244 const Array& args = Array::Handle(Array::New(3)); |
| 246 if (Dart_IsError(result)) { | 245 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); |
| 247 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(1, pos); |
| 251 args.SetAt(2, (i >= func.num_fixed_parameters()) ? |
| 252 Bool::True() : Bool::False()); |
| 253 param ^= CreateMirror(Symbols::_LocalParameterMirrorImpl(), args); |
| 254 results.SetAt(i, param); |
| 248 } | 255 } |
| 249 | 256 results.MakeImmutable(); |
| 250 int64_t param_count = fixed_param_count + opt_param_count; | 257 return results.raw(); |
| 251 Dart_Handle parameter_list = Dart_NewList(param_count); | |
| 252 if (Dart_IsError(parameter_list)) { | |
| 253 return result; | |
| 254 } | |
| 255 | |
| 256 Dart_Handle param_cls_name = NewString("_LocalParameterMirrorImpl"); | |
| 257 Dart_Handle param_type = Dart_GetType(MirrorLib(), param_cls_name, 0, NULL); | |
| 258 if (Dart_IsError(param_type)) { | |
| 259 return param_type; | |
| 260 } | |
| 261 | |
| 262 Dart_Handle reflectee = CreateMirrorReference(func); | |
| 263 for (int64_t i = 0; i < param_count; i++) { | |
| 264 Dart_Handle args[] = { | |
| 265 reflectee, | |
| 266 Dart_NewInteger(i), | |
| 267 (i >= fixed_param_count) ? Api::True() : Api::False(), | |
| 268 }; | |
| 269 Dart_Handle param = | |
| 270 Dart_New(param_type, Dart_Null(), ARRAY_SIZE(args), args); | |
| 271 if (Dart_IsError(param)) { | |
| 272 return param; | |
| 273 } | |
| 274 result = Dart_ListSetAt(parameter_list, i, param); | |
| 275 if (Dart_IsError(result)) { | |
| 276 return result; | |
| 277 } | |
| 278 } | |
| 279 return parameter_list; | |
| 280 } | 258 } |
| 281 | 259 |
| 282 | 260 |
| 261 static Dart_Handle CreateParameterMirrorListUsingApi(Dart_Handle func) { |
| 262 ASSERT(Dart_IsFunction(func)); |
| 263 Isolate* isolate = Isolate::Current(); |
| 264 return Api::NewHandle( |
| 265 isolate, CreateParameterMirrorList(Api::UnwrapFunctionHandle( |
| 266 isolate, func))); |
| 267 } |
| 268 |
| 269 |
| 283 static Dart_Handle CreateLazyMirror(Dart_Handle target) { | 270 static Dart_Handle CreateLazyMirror(Dart_Handle target) { |
| 284 if (Dart_IsNull(target) || Dart_IsError(target)) { | 271 if (Dart_IsNull(target) || Dart_IsError(target)) { |
| 285 return target; | 272 return target; |
| 286 } | 273 } |
| 287 | 274 |
| 288 if (Dart_IsLibrary(target)) { | 275 if (Dart_IsLibrary(target)) { |
| 289 Dart_Handle cls_name = NewString("_LazyLibraryMirror"); | 276 Dart_Handle cls_name = NewString("_LazyLibraryMirror"); |
| 290 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); | 277 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); |
| 291 Dart_Handle args[] = { Dart_LibraryUrl(target) }; | 278 Dart_Handle args[] = { Dart_LibraryUrl(target) }; |
| 292 return Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); | 279 return Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); |
| 293 } | 280 } |
| 294 | 281 |
| 295 if (Dart_IsClass(target)) { | 282 if (Dart_IsClass(target)) { |
| 296 if (Dart_ClassIsFunctionType(target)) { | 283 if (Dart_ClassIsFunctionType(target)) { |
| 297 Dart_Handle cls_name = NewString("_LazyFunctionTypeMirror"); | 284 Dart_Handle cls_name = NewString("_LazyFunctionTypeMirror"); |
| 298 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); | 285 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); |
| 299 | 286 |
| 300 Dart_Handle sig = Dart_ClassGetFunctionTypeSignature(target); | 287 Dart_Handle sig = Dart_ClassGetFunctionTypeSignature(target); |
| 301 Dart_Handle return_type = Dart_FunctionReturnType(sig); | 288 Dart_Handle return_type = Dart_FunctionReturnType(sig); |
| 302 if (Dart_IsError(return_type)) { | 289 if (Dart_IsError(return_type)) { |
| 303 return return_type; | 290 return return_type; |
| 304 } | 291 } |
| 305 | 292 |
| 306 Dart_Handle args[] = { | 293 Dart_Handle args[] = { |
| 307 CreateLazyMirror(return_type), | 294 CreateLazyMirror(return_type), |
| 308 CreateParameterMirrorList(sig), | 295 CreateParameterMirrorListUsingApi(sig), |
| 309 }; | 296 }; |
| 310 return Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); | 297 return Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); |
| 311 } else { | 298 } else { |
| 312 Dart_Handle cls_name = NewString("_LazyTypeMirror"); | 299 Dart_Handle cls_name = NewString("_LazyTypeMirror"); |
| 313 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); | 300 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); |
| 314 Dart_Handle lib = Dart_ClassGetLibrary(target); | 301 Dart_Handle lib = Dart_ClassGetLibrary(target); |
| 315 Dart_Handle lib_url; | 302 Dart_Handle lib_url; |
| 316 if (Dart_IsNull(lib)) { | 303 if (Dart_IsNull(lib)) { |
| 317 lib_url = Dart_Null(); | 304 lib_url = Dart_Null(); |
| 318 } else { | 305 } else { |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 Dart_Handle mirror_cls_name = NewString("_LocalMethodMirrorImpl"); | 559 Dart_Handle mirror_cls_name = NewString("_LocalMethodMirrorImpl"); |
| 573 Dart_Handle mirror_type = Dart_GetType(MirrorLib(), mirror_cls_name, 0, NULL); | 560 Dart_Handle mirror_type = Dart_GetType(MirrorLib(), mirror_cls_name, 0, NULL); |
| 574 if (Dart_IsError(mirror_type)) { | 561 if (Dart_IsError(mirror_type)) { |
| 575 return mirror_type; | 562 return mirror_type; |
| 576 } | 563 } |
| 577 | 564 |
| 578 // TODO(turnidge): Implement constructor kinds (arguments 7 - 10). | 565 // TODO(turnidge): Implement constructor kinds (arguments 7 - 10). |
| 579 Dart_Handle args[] = { | 566 Dart_Handle args[] = { |
| 580 CreateMirrorReference(func), | 567 CreateMirrorReference(func), |
| 581 owner_mirror, | 568 owner_mirror, |
| 582 CreateParameterMirrorList(func), | 569 CreateParameterMirrorListUsingApi(func), |
| 583 func_obj.is_static() ? Api::True() : Api::False(), | 570 func_obj.is_static() ? Api::True() : Api::False(), |
| 584 func_obj.is_abstract() ? Api::True() : Api::False(), | 571 func_obj.is_abstract() ? Api::True() : Api::False(), |
| 585 func_obj.IsGetterFunction() ? Api::True() : Api::False(), | 572 func_obj.IsGetterFunction() ? Api::True() : Api::False(), |
| 586 func_obj.IsSetterFunction() ? Api::True() : Api::False(), | 573 func_obj.IsSetterFunction() ? Api::True() : Api::False(), |
| 587 func_obj.IsConstructor() ? Api::True() : Api::False(), | 574 func_obj.IsConstructor() ? Api::True() : Api::False(), |
| 588 Api::False(), | 575 Api::False(), |
| 589 Api::False(), | 576 Api::False(), |
| 590 Api::False(), | 577 Api::False(), |
| 591 Api::False() | 578 Api::False() |
| 592 }; | 579 }; |
| 593 Dart_Handle mirror = | 580 Dart_Handle mirror = |
| 594 Dart_New(mirror_type, Dart_Null(), ARRAY_SIZE(args), args); | 581 Dart_New(mirror_type, Dart_Null(), ARRAY_SIZE(args), args); |
| 595 return mirror; | 582 return mirror; |
| 596 } | 583 } |
| 597 | 584 |
| 598 static RawInstance* CreateVariableMirror(const Field& field, | 585 static RawInstance* CreateVariableMirror(const Field& field, |
| 599 const Instance& owner_mirror) { | 586 const Instance& owner_mirror) { |
| 600 const MirrorReference& field_ref = | 587 const MirrorReference& field_ref = |
| 601 MirrorReference::Handle(MirrorReference::New()); | 588 MirrorReference::Handle(MirrorReference::New(field)); |
| 602 field_ref.set_referent(field); | |
| 603 | 589 |
| 604 const String& name = String::Handle(field.UserVisibleName()); | 590 const String& name = String::Handle(field.UserVisibleName()); |
| 605 | 591 |
| 606 const Array& args = Array::Handle(Array::New(6)); | 592 const Array& args = Array::Handle(Array::New(6)); |
| 607 args.SetAt(0, field_ref); | 593 args.SetAt(0, field_ref); |
| 608 args.SetAt(1, name); | 594 args.SetAt(1, name); |
| 609 args.SetAt(2, owner_mirror); | 595 args.SetAt(2, owner_mirror); |
| 610 args.SetAt(3, Instance::Handle()); // Null for type. | 596 args.SetAt(3, Instance::Handle()); // Null for type. |
| 611 args.SetAt(4, field.is_static() ? Bool::True() : Bool::False()); | 597 args.SetAt(4, field.is_static() ? Bool::True() : Bool::False()); |
| 612 args.SetAt(5, field.is_final() ? Bool::True() : Bool::False()); | 598 args.SetAt(5, field.is_final() ? Bool::True() : Bool::False()); |
| (...skipping 1313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1926 | 1912 |
| 1927 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1913 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
| 1928 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1914 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1929 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1915 const Field& field = Field::Handle(ref.GetFieldReferent()); |
| 1930 | 1916 |
| 1931 const AbstractType& type = AbstractType::Handle(field.type()); | 1917 const AbstractType& type = AbstractType::Handle(field.type()); |
| 1932 return CreateTypeMirror(type); | 1918 return CreateTypeMirror(type); |
| 1933 } | 1919 } |
| 1934 | 1920 |
| 1935 } // namespace dart | 1921 } // namespace dart |
| OLD | NEW |