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