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 "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 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 791 Dart_PropagateError(CreateMirroredError(result)); | 799 Dart_PropagateError(CreateMirroredError(result)); |
| 792 } | 800 } |
| 793 | 801 |
| 794 Dart_Handle wrapped_result = CreateInstanceMirror(result); | 802 Dart_Handle wrapped_result = CreateInstanceMirror(result); |
| 795 if (Dart_IsError(wrapped_result)) { | 803 if (Dart_IsError(wrapped_result)) { |
| 796 Dart_PropagateError(wrapped_result); | 804 Dart_PropagateError(wrapped_result); |
| 797 } | 805 } |
| 798 Dart_SetReturnValue(args, wrapped_result); | 806 Dart_SetReturnValue(args, wrapped_result); |
| 799 } | 807 } |
| 800 | 808 |
| 809 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_getField)( | |
| 810 Dart_NativeArguments args) { | |
| 811 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); | |
| 812 Dart_Handle fieldName = Dart_GetNativeArgument(args, 1); | |
| 813 | |
| 814 Dart_Handle reflectee = UnwrapMirror(mirror); | |
| 815 Dart_Handle result = | |
|
turnidge
2012/07/17 23:59:33
Can this fit on one line?
| |
| 816 Dart_GetField(reflectee, fieldName); | |
| 817 if (Dart_IsError(result)) { | |
| 818 // Instead of propagating the error from an invoke directly, we | |
| 819 // provide reflective access to the error. | |
|
turnidge
2012/07/17 23:59:33
Update comment to not refer to invoke.
| |
| 820 Dart_PropagateError(CreateMirroredError(result)); | |
| 821 } | |
| 822 | |
| 823 Dart_Handle wrapped_result = CreateInstanceMirror(result); | |
| 824 if (Dart_IsError(wrapped_result)) { | |
| 825 Dart_PropagateError(wrapped_result); | |
| 826 } | |
| 827 Dart_SetReturnValue(args, wrapped_result); | |
| 828 } | |
| 829 | |
| 830 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_setField)( | |
| 831 Dart_NativeArguments args) { | |
| 832 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); | |
| 833 Dart_Handle fieldName = Dart_GetNativeArgument(args, 1); | |
| 834 Dart_Handle raw_arg = Dart_GetNativeArgument(args, 2); | |
| 835 | |
| 836 Dart_Handle reflectee = UnwrapMirror(mirror); | |
| 837 Dart_Handle set_arg = UnwrapArg(raw_arg); | |
| 838 if (Dart_IsError(set_arg)) { | |
| 839 Dart_PropagateError(set_arg); | |
| 840 } | |
| 841 Dart_Handle result = | |
|
turnidge
2012/07/17 23:59:33
Can this fit on one line?
| |
| 842 Dart_SetField(reflectee, fieldName, set_arg); | |
| 843 if (Dart_IsError(result)) { | |
| 844 // Instead of propagating the error from an invoke directly, we | |
| 845 // provide reflective access to the error. | |
|
turnidge
2012/07/17 23:59:33
Update commentto not refer to invoke.
| |
| 846 Dart_PropagateError(CreateMirroredError(result)); | |
| 847 } | |
| 848 | |
| 849 Dart_Handle wrapped_result = CreateInstanceMirror(result); | |
| 850 if (Dart_IsError(wrapped_result)) { | |
| 851 Dart_PropagateError(wrapped_result); | |
| 852 } | |
| 853 Dart_SetReturnValue(args, wrapped_result); | |
| 854 } | |
| 855 | |
| 801 void HandleMirrorsMessage(Isolate* isolate, | 856 void HandleMirrorsMessage(Isolate* isolate, |
| 802 Dart_Port reply_port, | 857 Dart_Port reply_port, |
| 803 const Instance& message) { | 858 const Instance& message) { |
| 804 UNIMPLEMENTED(); | 859 UNIMPLEMENTED(); |
| 805 } | 860 } |
| 806 | 861 |
| 807 } // namespace dart | 862 } // namespace dart |
| OLD | NEW |