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 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 543 CreateImplementsList(intf), | 543 CreateImplementsList(intf), |
| 544 CreateLazyMirror(default_class), | 544 CreateLazyMirror(default_class), |
| 545 constructor_map, | 545 constructor_map, |
| 546 type_var_map, | 546 type_var_map, |
| 547 }; | 547 }; |
| 548 Dart_Handle mirror = Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); | 548 Dart_Handle mirror = Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); |
| 549 return mirror; | 549 return mirror; |
| 550 } | 550 } |
| 551 | 551 |
| 552 | 552 |
| 553 static RawInstance* CreateMethodMirror(const Function& func, | |
| 554 const Instance& owner_mirror) { | |
| 555 HANDLESCOPE(Isolate::Current()); | |
|
siva
2013/07/25 20:54:40
Is the HANDLESCOPE here needed? Do we have a leak
Michael Lippautz (Google)
2013/07/25 21:06:38
It's not needed anymore. It was needed when the Mi
| |
| 556 const Array& args = Array::Handle(Array::New(11)); | |
| 557 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); | |
| 558 args.SetAt(1, owner_mirror); | |
| 559 args.SetAt(2, func.is_static() ? Bool::True() : Bool::False()); | |
| 560 args.SetAt(3, func.is_abstract() ? Bool::True() : Bool::False()); | |
| 561 args.SetAt(4, func.IsGetterFunction() ? Bool::True() : Bool::False()); | |
| 562 args.SetAt(5, func.IsSetterFunction() ? Bool::True() : Bool::False()); | |
| 563 args.SetAt(6, func.IsConstructor() ? Bool::True() : Bool::False()); | |
| 564 // TODO(mlippautz): Implement different constructor kinds. | |
| 565 args.SetAt(7, Bool::False()); | |
| 566 args.SetAt(8, Bool::False()); | |
| 567 args.SetAt(9, Bool::False()); | |
| 568 args.SetAt(10, Bool::False()); | |
| 569 return CreateMirror(Symbols::_LocalMethodMirrorImpl(), args); | |
| 570 } | |
| 571 | |
| 572 | |
| 553 static Dart_Handle CreateMethodMirrorUsingApi(Dart_Handle func, | 573 static Dart_Handle CreateMethodMirrorUsingApi(Dart_Handle func, |
| 554 Dart_Handle owner_mirror) { | 574 Dart_Handle owner_mirror) { |
| 555 // TODO(11742): Unwrapping is needed until the whole method is converted. | |
| 556 Isolate* isolate = Isolate::Current(); | 575 Isolate* isolate = Isolate::Current(); |
| 557 const Function& func_obj = Api::UnwrapFunctionHandle(isolate, func); | 576 return Api::NewHandle(isolate, CreateMethodMirror( |
| 558 | 577 Api::UnwrapFunctionHandle(isolate, func), |
| 559 Dart_Handle mirror_cls_name = NewString("_LocalMethodMirrorImpl"); | 578 Api::UnwrapInstanceHandle(isolate, owner_mirror))); |
| 560 Dart_Handle mirror_type = Dart_GetType(MirrorLib(), mirror_cls_name, 0, NULL); | |
| 561 if (Dart_IsError(mirror_type)) { | |
| 562 return mirror_type; | |
| 563 } | |
| 564 | |
| 565 // TODO(turnidge): Implement constructor kinds (arguments 7 - 10). | |
| 566 Dart_Handle args[] = { | |
| 567 CreateMirrorReference(func), | |
| 568 owner_mirror, | |
| 569 CreateParameterMirrorListUsingApi(func), | |
| 570 func_obj.is_static() ? Api::True() : Api::False(), | |
| 571 func_obj.is_abstract() ? Api::True() : Api::False(), | |
| 572 func_obj.IsGetterFunction() ? Api::True() : Api::False(), | |
| 573 func_obj.IsSetterFunction() ? Api::True() : Api::False(), | |
| 574 func_obj.IsConstructor() ? Api::True() : Api::False(), | |
| 575 Api::False(), | |
| 576 Api::False(), | |
| 577 Api::False(), | |
| 578 Api::False() | |
| 579 }; | |
| 580 Dart_Handle mirror = | |
| 581 Dart_New(mirror_type, Dart_Null(), ARRAY_SIZE(args), args); | |
| 582 return mirror; | |
| 583 } | 579 } |
| 584 | 580 |
| 585 static RawInstance* CreateVariableMirror(const Field& field, | 581 static RawInstance* CreateVariableMirror(const Field& field, |
| 586 const Instance& owner_mirror) { | 582 const Instance& owner_mirror) { |
| 587 const MirrorReference& field_ref = | 583 const MirrorReference& field_ref = |
| 588 MirrorReference::Handle(MirrorReference::New(field)); | 584 MirrorReference::Handle(MirrorReference::New(field)); |
| 589 | 585 |
| 590 const String& name = String::Handle(field.UserVisibleName()); | 586 const String& name = String::Handle(field.UserVisibleName()); |
| 591 | 587 |
| 592 const Array& args = Array::Handle(Array::New(6)); | 588 const Array& args = Array::Handle(Array::New(6)); |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1022 Dart_Handle result = CreateLibraryMirrorUsingApi(lib_handle); | 1018 Dart_Handle result = CreateLibraryMirrorUsingApi(lib_handle); |
| 1023 if (Dart_IsError(result)) { | 1019 if (Dart_IsError(result)) { |
| 1024 Dart_PropagateError(result); | 1020 Dart_PropagateError(result); |
| 1025 } | 1021 } |
| 1026 retvalue ^= Api::UnwrapHandle(result); | 1022 retvalue ^= Api::UnwrapHandle(result); |
| 1027 Dart_ExitScope(); | 1023 Dart_ExitScope(); |
| 1028 return retvalue.raw(); | 1024 return retvalue.raw(); |
| 1029 } | 1025 } |
| 1030 | 1026 |
| 1031 | 1027 |
| 1032 static RawInstance* CreateMethodMirror(const Function& func, | |
| 1033 const Instance& owner_mirror) { | |
| 1034 Instance& retvalue = Instance::Handle(); | |
| 1035 Dart_EnterScope(); | |
| 1036 Isolate* isolate = Isolate::Current(); | |
| 1037 Dart_Handle func_handle = Api::NewHandle(isolate, func.raw()); | |
| 1038 Dart_Handle owner_handle = Api::NewHandle(isolate, owner_mirror.raw()); | |
| 1039 // TODO(11742): At some point the handle calls will be replaced by inlined | |
| 1040 // functionality. | |
| 1041 Dart_Handle result = CreateMethodMirrorUsingApi(func_handle, owner_handle); | |
| 1042 if (Dart_IsError(result)) { | |
| 1043 Dart_PropagateError(result); | |
| 1044 } | |
| 1045 retvalue ^= Api::UnwrapHandle(result); | |
| 1046 Dart_ExitScope(); | |
| 1047 return retvalue.raw(); | |
| 1048 } | |
| 1049 | |
| 1050 | |
| 1051 static RawInstance* CreateTypeMirror(const AbstractType& type) { | 1028 static RawInstance* CreateTypeMirror(const AbstractType& type) { |
| 1052 ASSERT(!type.IsMalformed()); | 1029 ASSERT(!type.IsMalformed()); |
| 1053 if (type.HasResolvedTypeClass()) { | 1030 if (type.HasResolvedTypeClass()) { |
| 1054 const Class& cls = Class::Handle(type.type_class()); | 1031 const Class& cls = Class::Handle(type.type_class()); |
| 1055 // Handle void and dynamic types. | 1032 // Handle void and dynamic types. |
| 1056 if (cls.IsVoidClass()) { | 1033 if (cls.IsVoidClass()) { |
| 1057 Array& args = Array::Handle(Array::New(1)); | 1034 Array& args = Array::Handle(Array::New(1)); |
| 1058 args.SetAt(0, Symbols::Void()); | 1035 args.SetAt(0, Symbols::Void()); |
| 1059 // TODO(mlippautz): Create once in the VM isolate and retrieve from there. | 1036 // TODO(mlippautz): Create once in the VM isolate and retrieve from there. |
| 1060 return CreateMirror(Symbols::_SpecialTypeMirrorImpl(), args); | 1037 return CreateMirror(Symbols::_SpecialTypeMirrorImpl(), args); |
| (...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1883 func.parent_function()), Object::null_instance()); | 1860 func.parent_function()), Object::null_instance()); |
| 1884 } | 1861 } |
| 1885 const Class& owner = Class::Handle(func.Owner()); | 1862 const Class& owner = Class::Handle(func.Owner()); |
| 1886 if (owner.IsTopLevel()) { | 1863 if (owner.IsTopLevel()) { |
| 1887 return CreateLibraryMirror(Library::Handle(owner.library())); | 1864 return CreateLibraryMirror(Library::Handle(owner.library())); |
| 1888 } | 1865 } |
| 1889 return CreateClassMirror(owner, Object::null_instance()); | 1866 return CreateClassMirror(owner, Object::null_instance()); |
| 1890 } | 1867 } |
| 1891 | 1868 |
| 1892 | 1869 |
| 1870 DEFINE_NATIVE_ENTRY(MethodMirror_parameters, 1) { | |
| 1871 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | |
| 1872 const Function& func = Function::Handle(ref.GetFunctionReferent()); | |
| 1873 return CreateParameterMirrorList(func); | |
| 1874 } | |
| 1875 | |
| 1876 | |
| 1893 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { | 1877 DEFINE_NATIVE_ENTRY(MethodMirror_return_type, 1) { |
| 1894 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1878 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1895 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1879 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1896 // We handle constructors in Dart code. | 1880 // We handle constructors in Dart code. |
| 1897 ASSERT(!func.IsConstructor()); | 1881 ASSERT(!func.IsConstructor()); |
| 1898 const AbstractType& return_type = AbstractType::Handle(func.result_type()); | 1882 const AbstractType& return_type = AbstractType::Handle(func.result_type()); |
| 1899 return CreateTypeMirror(return_type); | 1883 return CreateTypeMirror(return_type); |
| 1900 } | 1884 } |
| 1901 | 1885 |
| 1902 | 1886 |
| 1903 DEFINE_NATIVE_ENTRY(ParameterMirror_type, 2) { | 1887 DEFINE_NATIVE_ENTRY(ParameterMirror_type, 2) { |
| 1904 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1888 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1905 GET_NON_NULL_NATIVE_ARGUMENT(Smi, pos, arguments->NativeArgAt(1)); | 1889 GET_NON_NULL_NATIVE_ARGUMENT(Smi, pos, arguments->NativeArgAt(1)); |
| 1906 const Function& func = Function::Handle(ref.GetFunctionReferent()); | 1890 const Function& func = Function::Handle(ref.GetFunctionReferent()); |
| 1907 const AbstractType& param_type = AbstractType::Handle(func.ParameterTypeAt( | 1891 const AbstractType& param_type = AbstractType::Handle(func.ParameterTypeAt( |
| 1908 func.NumImplicitParameters() + pos.Value())); | 1892 func.NumImplicitParameters() + pos.Value())); |
| 1909 return CreateTypeMirror(param_type); | 1893 return CreateTypeMirror(param_type); |
| 1910 } | 1894 } |
| 1911 | 1895 |
| 1912 | 1896 |
| 1913 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1897 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
| 1914 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1898 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
| 1915 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1899 const Field& field = Field::Handle(ref.GetFieldReferent()); |
| 1916 | 1900 |
| 1917 const AbstractType& type = AbstractType::Handle(field.type()); | 1901 const AbstractType& type = AbstractType::Handle(field.type()); |
| 1918 return CreateTypeMirror(type); | 1902 return CreateTypeMirror(type); |
| 1919 } | 1903 } |
| 1920 | 1904 |
| 1921 } // namespace dart | 1905 } // namespace dart |
| OLD | NEW |