| 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 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 member_map, | 623 member_map, |
| 624 constructor_map, | 624 constructor_map, |
| 625 type_var_map, | 625 type_var_map, |
| 626 }; | 626 }; |
| 627 Dart_Handle mirror = Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); | 627 Dart_Handle mirror = Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); |
| 628 return mirror; | 628 return mirror; |
| 629 } | 629 } |
| 630 | 630 |
| 631 | 631 |
| 632 static Dart_Handle CreateMethodMirror(Dart_Handle func, | 632 static Dart_Handle CreateMethodMirror(Dart_Handle func, |
| 633 Dart_Handle func_name, | |
| 634 Dart_Handle owner_mirror) { | 633 Dart_Handle owner_mirror) { |
| 635 ASSERT(Dart_IsFunction(func)); | 634 ASSERT(Dart_IsFunction(func)); |
| 636 Dart_Handle mirror_cls_name = NewString("_LocalMethodMirrorImpl"); | 635 Dart_Handle mirror_cls_name = NewString("_LocalMethodMirrorImpl"); |
| 637 Dart_Handle mirror_type = Dart_GetType(MirrorLib(), mirror_cls_name, 0, NULL); | 636 Dart_Handle mirror_type = Dart_GetType(MirrorLib(), mirror_cls_name, 0, NULL); |
| 638 if (Dart_IsError(mirror_type)) { | 637 if (Dart_IsError(mirror_type)) { |
| 639 return mirror_type; | 638 return mirror_type; |
| 640 } | 639 } |
| 641 | 640 |
| 642 bool is_static = false; | 641 bool is_static = false; |
| 643 bool is_abstract = false; | 642 bool is_abstract = false; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 int64_t opt_param_count; | 674 int64_t opt_param_count; |
| 676 result = Dart_FunctionParameterCounts(func, | 675 result = Dart_FunctionParameterCounts(func, |
| 677 &fixed_param_count, | 676 &fixed_param_count, |
| 678 &opt_param_count); | 677 &opt_param_count); |
| 679 if (Dart_IsError(result)) { | 678 if (Dart_IsError(result)) { |
| 680 return result; | 679 return result; |
| 681 } | 680 } |
| 682 | 681 |
| 683 // TODO(turnidge): Implement constructor kinds (arguments 7 - 10). | 682 // TODO(turnidge): Implement constructor kinds (arguments 7 - 10). |
| 684 Dart_Handle args[] = { | 683 Dart_Handle args[] = { |
| 685 func_name, | 684 CreateMirrorReference(func), |
| 686 owner_mirror, | 685 owner_mirror, |
| 687 CreateParameterMirrorList(func), | 686 CreateParameterMirrorList(func), |
| 688 CreateLazyMirror(return_type), | 687 CreateLazyMirror(return_type), |
| 689 Dart_NewBoolean(is_static), | 688 Dart_NewBoolean(is_static), |
| 690 Dart_NewBoolean(is_abstract), | 689 Dart_NewBoolean(is_abstract), |
| 691 Dart_NewBoolean(is_getter), | 690 Dart_NewBoolean(is_getter), |
| 692 Dart_NewBoolean(is_setter), | 691 Dart_NewBoolean(is_setter), |
| 693 Dart_NewBoolean(is_constructor), | 692 Dart_NewBoolean(is_constructor), |
| 694 Dart_False(), | 693 Dart_False(), |
| 695 Dart_False(), | 694 Dart_False(), |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 bool is_constructor = false; | 798 bool is_constructor = false; |
| 800 result = Dart_FunctionIsConstructor(func, &is_constructor); | 799 result = Dart_FunctionIsConstructor(func, &is_constructor); |
| 801 if (Dart_IsError(result)) { | 800 if (Dart_IsError(result)) { |
| 802 return result; | 801 return result; |
| 803 } | 802 } |
| 804 if (is_constructor) { | 803 if (is_constructor) { |
| 805 // Skip constructors. | 804 // Skip constructors. |
| 806 continue; | 805 continue; |
| 807 } | 806 } |
| 808 | 807 |
| 809 Dart_Handle func_mirror = CreateMethodMirror(func, func_name, owner_mirror); | 808 Dart_Handle func_mirror = CreateMethodMirror(func, owner_mirror); |
| 810 if (Dart_IsError(func_mirror)) { | 809 if (Dart_IsError(func_mirror)) { |
| 811 return func_mirror; | 810 return func_mirror; |
| 812 } | 811 } |
| 813 result = MapAdd(map, func_name, func_mirror); | 812 result = MapAdd(map, func_name, func_mirror); |
| 814 if (Dart_IsError(result)) { | 813 if (Dart_IsError(result)) { |
| 815 return result; | 814 return result; |
| 816 } | 815 } |
| 817 } | 816 } |
| 818 return Dart_True(); | 817 return Dart_True(); |
| 819 } | 818 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 843 bool is_constructor = false; | 842 bool is_constructor = false; |
| 844 result = Dart_FunctionIsConstructor(func, &is_constructor); | 843 result = Dart_FunctionIsConstructor(func, &is_constructor); |
| 845 if (Dart_IsError(result)) { | 844 if (Dart_IsError(result)) { |
| 846 return result; | 845 return result; |
| 847 } | 846 } |
| 848 if (!is_constructor) { | 847 if (!is_constructor) { |
| 849 // Skip non-constructors. | 848 // Skip non-constructors. |
| 850 continue; | 849 continue; |
| 851 } | 850 } |
| 852 | 851 |
| 853 Dart_Handle func_mirror = CreateMethodMirror(func, func_name, owner_mirror); | 852 Dart_Handle func_mirror = CreateMethodMirror(func, owner_mirror); |
| 854 if (Dart_IsError(func_mirror)) { | 853 if (Dart_IsError(func_mirror)) { |
| 855 return func_mirror; | 854 return func_mirror; |
| 856 } | 855 } |
| 857 result = MapAdd(map, func_name, func_mirror); | 856 result = MapAdd(map, func_name, func_mirror); |
| 858 if (Dart_IsError(result)) { | 857 if (Dart_IsError(result)) { |
| 859 return result; | 858 return result; |
| 860 } | 859 } |
| 861 } | 860 } |
| 862 return Dart_True(); | 861 return Dart_True(); |
| 863 } | 862 } |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1079 return type; | 1078 return type; |
| 1080 } | 1079 } |
| 1081 // We set the function field of ClosureMirrors outside of the constructor | 1080 // We set the function field of ClosureMirrors outside of the constructor |
| 1082 // to break the mutual recursion. | 1081 // to break the mutual recursion. |
| 1083 Dart_Handle func = Dart_ClosureFunction(instance); | 1082 Dart_Handle func = Dart_ClosureFunction(instance); |
| 1084 if (Dart_IsError(func)) { | 1083 if (Dart_IsError(func)) { |
| 1085 return func; | 1084 return func; |
| 1086 } | 1085 } |
| 1087 | 1086 |
| 1088 // TODO(turnidge): Why not use the real function name here? | 1087 // TODO(turnidge): Why not use the real function name here? |
| 1089 Dart_Handle func_name = NewString("call"); | |
| 1090 Dart_Handle func_owner = Dart_FunctionOwner(func); | 1088 Dart_Handle func_owner = Dart_FunctionOwner(func); |
| 1091 if (Dart_IsError(func_owner)) { | 1089 if (Dart_IsError(func_owner)) { |
| 1092 return func_owner; | 1090 return func_owner; |
| 1093 } | 1091 } |
| 1094 | 1092 |
| 1095 // TODO(turnidge): Pass the function owner here. This will require | 1093 // TODO(turnidge): Pass the function owner here. This will require |
| 1096 // us to support functions in CreateLazyMirror. | 1094 // us to support functions in CreateLazyMirror. |
| 1097 Dart_Handle func_mirror = | 1095 Dart_Handle func_mirror = |
| 1098 CreateMethodMirror(func, func_name, Dart_Null()); | 1096 CreateMethodMirror(func, Dart_Null()); |
| 1099 if (Dart_IsError(func_mirror)) { | 1097 if (Dart_IsError(func_mirror)) { |
| 1100 return func_mirror; | 1098 return func_mirror; |
| 1101 } | 1099 } |
| 1102 Dart_Handle args[] = { | 1100 Dart_Handle args[] = { |
| 1103 CreateVMReference(instance), | 1101 CreateVMReference(instance), |
| 1104 CreateLazyMirror(instance_cls), | 1102 CreateLazyMirror(instance_cls), |
| 1105 instance, | 1103 instance, |
| 1106 func_mirror, | 1104 func_mirror, |
| 1107 }; | 1105 }; |
| 1108 return Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); | 1106 return Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1423 | 1421 |
| 1424 | 1422 |
| 1425 DEFINE_NATIVE_ENTRY(ClassMirror_name, 1) { | 1423 DEFINE_NATIVE_ENTRY(ClassMirror_name, 1) { |
| 1426 const MirrorReference& klass_ref = | 1424 const MirrorReference& klass_ref = |
| 1427 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); | 1425 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); |
| 1428 Class& klass = Class::Handle(); | 1426 Class& klass = Class::Handle(); |
| 1429 klass ^= klass_ref.referent(); | 1427 klass ^= klass_ref.referent(); |
| 1430 return klass.Name(); | 1428 return klass.Name(); |
| 1431 } | 1429 } |
| 1432 | 1430 |
| 1431 DEFINE_NATIVE_ENTRY(MethodMirror_name, 1) { |
| 1432 const MirrorReference& func_ref = |
| 1433 MirrorReference::CheckedHandle(arguments->NativeArgAt(0)); |
| 1434 Function& func = Function::Handle(); |
| 1435 func ^= func_ref.referent(); |
| 1436 return func.UserVisibleName(); |
| 1437 } |
| 1438 |
| 1433 } // namespace dart | 1439 } // namespace dart |
| OLD | NEW |