| 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 "vm/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
| 6 | 6 |
| 7 #include "platform/json.h" | 7 #include "platform/json.h" |
| 8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 #include "include/dart_debugger_api.h" | 9 #include "include/dart_debugger_api.h" |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 static Dart_Handle UnwrapMirror(Dart_Handle mirror) { | 157 static Dart_Handle UnwrapMirror(Dart_Handle mirror) { |
| 158 Dart_Handle field_name = Dart_NewString("_reference"); | 158 Dart_Handle field_name = Dart_NewString("_reference"); |
| 159 Dart_Handle vm_ref = Dart_GetField(mirror, field_name); | 159 Dart_Handle vm_ref = Dart_GetField(mirror, field_name); |
| 160 if (Dart_IsError(vm_ref)) { | 160 if (Dart_IsError(vm_ref)) { |
| 161 return vm_ref; | 161 return vm_ref; |
| 162 } | 162 } |
| 163 return UnwrapVMReference(vm_ref); | 163 return UnwrapVMReference(vm_ref); |
| 164 } | 164 } |
| 165 | 165 |
| 166 | 166 |
| 167 static Dart_Handle UnwrapArg(Dart_Handle arg) { |
| 168 if (Dart_IsError(arg)) { |
| 169 return arg; |
| 170 } |
| 171 bool is_mirror = false; |
| 172 Dart_Handle result = IsMirror(arg, &is_mirror); |
| 173 if (Dart_IsError(result)) { |
| 174 return result; |
| 175 } |
| 176 if (is_mirror) { |
| 177 return UnwrapMirror(arg); |
| 178 } else { |
| 179 // Simple value. |
| 180 ASSERT(IsSimpleValue(arg)); |
| 181 return arg; |
| 182 } |
| 183 } |
| 184 |
| 167 static Dart_Handle UnwrapArgList(Dart_Handle arg_list, | 185 static Dart_Handle UnwrapArgList(Dart_Handle arg_list, |
| 168 GrowableArray<Dart_Handle>* arg_array) { | 186 GrowableArray<Dart_Handle>* arg_array) { |
| 169 intptr_t len = 0; | 187 intptr_t len = 0; |
| 170 Dart_Handle result = Dart_ListLength(arg_list, &len); | 188 Dart_Handle result = Dart_ListLength(arg_list, &len); |
| 171 if (Dart_IsError(result)) { | 189 if (Dart_IsError(result)) { |
| 172 return result; | 190 return result; |
| 173 } | 191 } |
| 174 for (int i = 0; i < len; i++) { | 192 for (int i = 0; i < len; i++) { |
| 175 Dart_Handle arg = Dart_ListGetAt(arg_list, i); | 193 Dart_Handle arg = Dart_ListGetAt(arg_list, i); |
| 176 if (Dart_IsError(arg)) { | 194 Dart_Handle unwrapped_arg = UnwrapArg(arg); |
| 177 return arg; | 195 if (Dart_IsError(unwrapped_arg)) { |
| 196 return unwrapped_arg; |
| 178 } | 197 } |
| 179 bool is_mirror = false; | 198 arg_array->Add(unwrapped_arg); |
| 180 result = IsMirror(arg, &is_mirror); | |
| 181 if (Dart_IsError(result)) { | |
| 182 return result; | |
| 183 } | |
| 184 if (is_mirror) { | |
| 185 arg_array->Add(UnwrapMirror(arg)); | |
| 186 } else { | |
| 187 // Simple value. | |
| 188 ASSERT(IsSimpleValue(arg)); | |
| 189 arg_array->Add(arg); | |
| 190 } | |
| 191 } | 199 } |
| 192 return Dart_True(); | 200 return Dart_True(); |
| 193 } | 201 } |
| 194 | 202 |
| 195 | 203 |
| 196 static Dart_Handle CreateLazyMirror(Dart_Handle target) { | 204 static Dart_Handle CreateLazyMirror(Dart_Handle target) { |
| 197 if (Dart_IsNull(target)) { | 205 if (Dart_IsNull(target)) { |
| 198 return target; | 206 return target; |
| 199 } | 207 } |
| 200 if (Dart_IsLibrary(target)) { | 208 if (Dart_IsLibrary(target)) { |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 | 762 |
| 755 void NATIVE_ENTRY_FUNCTION(Mirrors_makeLocalMirrorSystem)( | 763 void NATIVE_ENTRY_FUNCTION(Mirrors_makeLocalMirrorSystem)( |
| 756 Dart_NativeArguments args) { | 764 Dart_NativeArguments args) { |
| 757 Dart_Handle mirrors = CreateMirrorSystem(); | 765 Dart_Handle mirrors = CreateMirrorSystem(); |
| 758 if (Dart_IsError(mirrors)) { | 766 if (Dart_IsError(mirrors)) { |
| 759 Dart_PropagateError(mirrors); | 767 Dart_PropagateError(mirrors); |
| 760 } | 768 } |
| 761 Dart_SetReturnValue(args, mirrors); | 769 Dart_SetReturnValue(args, mirrors); |
| 762 } | 770 } |
| 763 | 771 |
| 772 |
| 764 void NATIVE_ENTRY_FUNCTION(Mirrors_makeLocalInstanceMirror)( | 773 void NATIVE_ENTRY_FUNCTION(Mirrors_makeLocalInstanceMirror)( |
| 765 Dart_NativeArguments args) { | 774 Dart_NativeArguments args) { |
| 766 Dart_Handle reflectee = Dart_GetNativeArgument(args, 0); | 775 Dart_Handle reflectee = Dart_GetNativeArgument(args, 0); |
| 767 Dart_Handle mirror = CreateInstanceMirror(reflectee); | 776 Dart_Handle mirror = CreateInstanceMirror(reflectee); |
| 768 if (Dart_IsError(mirror)) { | 777 if (Dart_IsError(mirror)) { |
| 769 Dart_PropagateError(mirror); | 778 Dart_PropagateError(mirror); |
| 770 } | 779 } |
| 771 Dart_SetReturnValue(args, mirror); | 780 Dart_SetReturnValue(args, mirror); |
| 772 } | 781 } |
| 773 | 782 |
| 783 |
| 774 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_invoke)( | 784 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_invoke)( |
| 775 Dart_NativeArguments args) { | 785 Dart_NativeArguments args) { |
| 776 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); | 786 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); |
| 777 Dart_Handle member = Dart_GetNativeArgument(args, 1); | 787 Dart_Handle member = Dart_GetNativeArgument(args, 1); |
| 778 Dart_Handle raw_invoke_args = Dart_GetNativeArgument(args, 2); | 788 Dart_Handle raw_invoke_args = Dart_GetNativeArgument(args, 2); |
| 779 | 789 |
| 780 Dart_Handle reflectee = UnwrapMirror(mirror); | 790 Dart_Handle reflectee = UnwrapMirror(mirror); |
| 781 GrowableArray<Dart_Handle> invoke_args; | 791 GrowableArray<Dart_Handle> invoke_args; |
| 782 Dart_Handle result = UnwrapArgList(raw_invoke_args, &invoke_args); | 792 Dart_Handle result = UnwrapArgList(raw_invoke_args, &invoke_args); |
| 783 if (Dart_IsError(result)) { | 793 if (Dart_IsError(result)) { |
| 784 Dart_PropagateError(result); | 794 Dart_PropagateError(result); |
| 785 } | 795 } |
| 786 result = | 796 result = |
| 787 Dart_Invoke(reflectee, member, invoke_args.length(), invoke_args.data()); | 797 Dart_Invoke(reflectee, member, invoke_args.length(), invoke_args.data()); |
| 788 if (Dart_IsError(result)) { | 798 if (Dart_IsError(result)) { |
| 789 // Instead of propagating the error from an invoke directly, we | 799 // Instead of propagating the error from an invoke directly, we |
| 790 // provide reflective access to the error. | 800 // provide reflective access to the error. |
| 791 Dart_PropagateError(CreateMirroredError(result)); | 801 Dart_PropagateError(CreateMirroredError(result)); |
| 792 } | 802 } |
| 793 | 803 |
| 794 Dart_Handle wrapped_result = CreateInstanceMirror(result); | 804 Dart_Handle wrapped_result = CreateInstanceMirror(result); |
| 795 if (Dart_IsError(wrapped_result)) { | 805 if (Dart_IsError(wrapped_result)) { |
| 796 Dart_PropagateError(wrapped_result); | 806 Dart_PropagateError(wrapped_result); |
| 797 } | 807 } |
| 798 Dart_SetReturnValue(args, wrapped_result); | 808 Dart_SetReturnValue(args, wrapped_result); |
| 799 } | 809 } |
| 800 | 810 |
| 811 |
| 812 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_getField)( |
| 813 Dart_NativeArguments args) { |
| 814 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); |
| 815 Dart_Handle fieldName = Dart_GetNativeArgument(args, 1); |
| 816 |
| 817 Dart_Handle reflectee = UnwrapMirror(mirror); |
| 818 Dart_Handle result = Dart_GetField(reflectee, fieldName); |
| 819 if (Dart_IsError(result)) { |
| 820 // Instead of propagating the error from a GetField directly, we |
| 821 // provide reflective access to the error. |
| 822 Dart_PropagateError(CreateMirroredError(result)); |
| 823 } |
| 824 |
| 825 Dart_Handle wrapped_result = CreateInstanceMirror(result); |
| 826 if (Dart_IsError(wrapped_result)) { |
| 827 Dart_PropagateError(wrapped_result); |
| 828 } |
| 829 Dart_SetReturnValue(args, wrapped_result); |
| 830 } |
| 831 |
| 832 |
| 833 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_setField)( |
| 834 Dart_NativeArguments args) { |
| 835 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); |
| 836 Dart_Handle fieldName = Dart_GetNativeArgument(args, 1); |
| 837 Dart_Handle raw_arg = Dart_GetNativeArgument(args, 2); |
| 838 |
| 839 Dart_Handle reflectee = UnwrapMirror(mirror); |
| 840 Dart_Handle set_arg = UnwrapArg(raw_arg); |
| 841 if (Dart_IsError(set_arg)) { |
| 842 Dart_PropagateError(set_arg); |
| 843 } |
| 844 Dart_Handle result = Dart_SetField(reflectee, fieldName, set_arg); |
| 845 if (Dart_IsError(result)) { |
| 846 // Instead of propagating the error from a SetField directly, we |
| 847 // provide reflective access to the error. |
| 848 Dart_PropagateError(CreateMirroredError(result)); |
| 849 } |
| 850 |
| 851 Dart_Handle wrapped_result = CreateInstanceMirror(result); |
| 852 if (Dart_IsError(wrapped_result)) { |
| 853 Dart_PropagateError(wrapped_result); |
| 854 } |
| 855 Dart_SetReturnValue(args, wrapped_result); |
| 856 } |
| 857 |
| 858 |
| 801 void HandleMirrorsMessage(Isolate* isolate, | 859 void HandleMirrorsMessage(Isolate* isolate, |
| 802 Dart_Port reply_port, | 860 Dart_Port reply_port, |
| 803 const Instance& message) { | 861 const Instance& message) { |
| 804 UNIMPLEMENTED(); | 862 UNIMPLEMENTED(); |
| 805 } | 863 } |
| 806 | 864 |
| 807 } // namespace dart | 865 } // namespace dart |
| OLD | NEW |