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 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 args.SetAt(1, name); | 395 args.SetAt(1, name); |
| 396 args.SetAt(2, owner_mirror); | 396 args.SetAt(2, owner_mirror); |
| 397 args.SetAt(3, Instance::Handle()); // Null for type. | 397 args.SetAt(3, Instance::Handle()); // Null for type. |
| 398 args.SetAt(4, field.is_static() ? Bool::True() : Bool::False()); | 398 args.SetAt(4, field.is_static() ? Bool::True() : Bool::False()); |
| 399 args.SetAt(5, field.is_final() ? Bool::True() : Bool::False()); | 399 args.SetAt(5, field.is_final() ? Bool::True() : Bool::False()); |
| 400 | 400 |
| 401 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); | 401 return CreateMirror(Symbols::_LocalVariableMirrorImpl(), args); |
| 402 } | 402 } |
| 403 | 403 |
| 404 | 404 |
| 405 static Dart_Handle CreateLibraryMirrorUsingApi(Dart_Handle lib) { | |
| 406 Dart_Handle cls_name = NewString("_LocalLibraryMirrorImpl"); | |
| 407 Dart_Handle type = Dart_GetType(MirrorLib(), cls_name, 0, NULL); | |
| 408 if (Dart_IsError(type)) { | |
| 409 return type; | |
| 410 } | |
| 411 Dart_Handle lazy_lib_mirror = CreateLazyMirror(lib); | |
| 412 if (Dart_IsError(lazy_lib_mirror)) { | |
| 413 return lazy_lib_mirror; | |
| 414 } | |
| 415 Dart_Handle args[] = { | |
| 416 CreateMirrorReference(lib), | |
| 417 Dart_LibraryName(lib), | |
| 418 Dart_LibraryUrl(lib), | |
| 419 }; | |
| 420 Dart_Handle lib_mirror = Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); | |
| 421 if (Dart_IsError(lib_mirror)) { | |
| 422 return lib_mirror; | |
| 423 } | |
| 424 | |
| 425 return lib_mirror; | |
| 426 } | |
| 427 | |
| 428 | |
| 429 static RawInstance* CreateClassMirror(const Class& cls, | 405 static RawInstance* CreateClassMirror(const Class& cls, |
| 430 const Instance& owner_mirror) { | 406 const Instance& owner_mirror) { |
| 431 Instance& retvalue = Instance::Handle(); | 407 Instance& retvalue = Instance::Handle(); |
| 432 Dart_EnterScope(); | 408 Dart_EnterScope(); |
| 433 Isolate* isolate = Isolate::Current(); | 409 Isolate* isolate = Isolate::Current(); |
| 434 Dart_Handle cls_handle = Api::NewHandle(isolate, cls.raw()); | 410 Dart_Handle cls_handle = Api::NewHandle(isolate, cls.raw()); |
| 435 if (Dart_IsError(cls_handle)) { | 411 if (Dart_IsError(cls_handle)) { |
| 436 Dart_PropagateError(cls_handle); | 412 Dart_PropagateError(cls_handle); |
| 437 } | 413 } |
| 438 Dart_Handle name_handle = Api::NewHandle(isolate, cls.Name()); | 414 Dart_Handle name_handle = Api::NewHandle(isolate, cls.Name()); |
| 439 if (Dart_IsError(name_handle)) { | 415 if (Dart_IsError(name_handle)) { |
| 440 Dart_PropagateError(name_handle); | 416 Dart_PropagateError(name_handle); |
| 441 } | 417 } |
| 442 Dart_Handle lib_mirror = Api::NewHandle(isolate, owner_mirror.raw()); | 418 Dart_Handle lib_mirror = Api::NewHandle(isolate, owner_mirror.raw()); |
| 443 // TODO(11742): At some point the handle calls will be replaced by inlined | 419 // TODO(11742): At some point the handle calls will be replaced by inlined |
| 444 // functionality. | 420 // functionality. |
| 445 Dart_Handle result = CreateClassMirrorUsingApi(cls_handle, | 421 Dart_Handle result = CreateClassMirrorUsingApi(cls_handle, |
| 446 name_handle, | 422 name_handle, |
| 447 lib_mirror); | 423 lib_mirror); |
| 448 if (Dart_IsError(result)) { | 424 if (Dart_IsError(result)) { |
| 449 Dart_PropagateError(result); | 425 Dart_PropagateError(result); |
| 450 } | 426 } |
| 451 retvalue ^= Api::UnwrapHandle(result); | 427 retvalue ^= Api::UnwrapHandle(result); |
| 452 Dart_ExitScope(); | 428 Dart_ExitScope(); |
| 453 return retvalue.raw(); | 429 return retvalue.raw(); |
| 454 } | 430 } |
| 455 | 431 |
| 456 | 432 |
| 457 static RawInstance* CreateLibraryMirror(const Library& lib) { | 433 static RawInstance* CreateLibraryMirror(const Library& lib) { |
| 458 Instance& retvalue = Instance::Handle(); | 434 const Array& args = Array::Handle(Array::New(3)); |
| 459 Dart_EnterScope(); | 435 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(lib))); |
| 460 Isolate* isolate = Isolate::Current(); | 436 args.SetAt(1, String::Handle(lib.name())); |
| 461 Dart_Handle lib_handle = Api::NewHandle(isolate, lib.raw()); | 437 args.SetAt(2, String::Handle(lib.url())); |
|
siva
2013/07/30 20:42:27
Small nit, you could save one Handle here by doing
Michael Lippautz (Google)
2013/07/30 20:52:14
Done.
| |
| 462 // TODO(11742): At some point the handle calls will be replaced by inlined | 438 return CreateMirror(Symbols::_LocalLibraryMirrorImpl(), args); |
| 463 // functionality. | |
| 464 Dart_Handle result = CreateLibraryMirrorUsingApi(lib_handle); | |
| 465 if (Dart_IsError(result)) { | |
| 466 Dart_PropagateError(result); | |
| 467 } | |
| 468 retvalue ^= Api::UnwrapHandle(result); | |
| 469 Dart_ExitScope(); | |
| 470 return retvalue.raw(); | |
| 471 } | 439 } |
| 472 | 440 |
| 473 | 441 |
| 474 static RawInstance* CreateTypeMirror(const AbstractType& type) { | 442 static RawInstance* CreateTypeMirror(const AbstractType& type) { |
| 475 ASSERT(!type.IsMalformed()); | 443 ASSERT(!type.IsMalformed()); |
| 476 if (type.HasResolvedTypeClass()) { | 444 if (type.HasResolvedTypeClass()) { |
| 477 const Class& cls = Class::Handle(type.type_class()); | 445 const Class& cls = Class::Handle(type.type_class()); |
| 478 // Handle void and dynamic types. | 446 // Handle void and dynamic types. |
| 479 if (cls.IsVoidClass()) { | 447 if (cls.IsVoidClass()) { |
| 480 Array& args = Array::Handle(Array::New(1)); | 448 Array& args = Array::Handle(Array::New(1)); |
| (...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1441 | 1409 |
| 1442 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1410 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
| 1443 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1411 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1444 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1412 const Field& field = Field::Handle(ref.GetFieldReferent()); |
| 1445 | 1413 |
| 1446 const AbstractType& type = AbstractType::Handle(field.type()); | 1414 const AbstractType& type = AbstractType::Handle(field.type()); |
| 1447 return CreateTypeMirror(type); | 1415 return CreateTypeMirror(type); |
| 1448 } | 1416 } |
| 1449 | 1417 |
| 1450 } // namespace dart | 1418 } // namespace dart |
| OLD | NEW |