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 "platform/json.h" | 7 #include "platform/json.h" |
8 #include "vm/bootstrap_natives.h" | 8 #include "vm/bootstrap_natives.h" |
9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
10 #include "vm/exceptions.h" | 10 #include "vm/exceptions.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 Dart_Handle arg = Dart_ListGetAt(arg_list, i); | 191 Dart_Handle arg = Dart_ListGetAt(arg_list, i); |
192 Dart_Handle unwrapped_arg = UnwrapArg(arg); | 192 Dart_Handle unwrapped_arg = UnwrapArg(arg); |
193 if (Dart_IsError(unwrapped_arg)) { | 193 if (Dart_IsError(unwrapped_arg)) { |
194 return unwrapped_arg; | 194 return unwrapped_arg; |
195 } | 195 } |
196 arg_array->Add(unwrapped_arg); | 196 arg_array->Add(unwrapped_arg); |
197 } | 197 } |
198 return Dart_True(); | 198 return Dart_True(); |
199 } | 199 } |
200 | 200 |
| 201 static Dart_Handle UnpackLocalArgList(Dart_Handle arg_list, |
| 202 GrowableArray<Dart_Handle>* arg_array) { |
| 203 intptr_t len = 0; |
| 204 Dart_Handle result = Dart_ListLength(arg_list, &len); |
| 205 if (Dart_IsError(result)) { |
| 206 return result; |
| 207 } |
| 208 for (intptr_t i = 0; i < len; i++) { |
| 209 Dart_Handle arg = Dart_ListGetAt(arg_list, i); |
| 210 if (Dart_IsError(arg)) { |
| 211 return arg; |
| 212 } |
| 213 arg_array->Add(arg); |
| 214 } |
| 215 return Dart_True(); |
| 216 } |
201 | 217 |
202 static Dart_Handle CreateLazyMirror(Dart_Handle target); | 218 static Dart_Handle CreateLazyMirror(Dart_Handle target); |
203 | 219 |
204 | 220 |
205 static Dart_Handle CreateParameterMirrorList(Dart_Handle func) { | 221 static Dart_Handle CreateParameterMirrorList(Dart_Handle func) { |
206 int64_t fixed_param_count; | 222 int64_t fixed_param_count; |
207 int64_t opt_param_count; | 223 int64_t opt_param_count; |
208 Dart_Handle result = Dart_FunctionParameterCounts(func, | 224 Dart_Handle result = Dart_FunctionParameterCounts(func, |
209 &fixed_param_count, | 225 &fixed_param_count, |
210 &opt_param_count); | 226 &opt_param_count); |
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 } | 1067 } |
1052 | 1068 |
1053 | 1069 |
1054 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_invoke)( | 1070 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_invoke)( |
1055 Dart_NativeArguments args) { | 1071 Dart_NativeArguments args) { |
1056 Dart_EnterScope(); | 1072 Dart_EnterScope(); |
1057 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); | 1073 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); |
1058 Dart_Handle member = Dart_GetNativeArgument(args, 1); | 1074 Dart_Handle member = Dart_GetNativeArgument(args, 1); |
1059 // The wrapped arguments are either simple values or instance mirrors. | 1075 // The wrapped arguments are either simple values or instance mirrors. |
1060 Dart_Handle wrapped_invoke_args = Dart_GetNativeArgument(args, 2); | 1076 Dart_Handle wrapped_invoke_args = Dart_GetNativeArgument(args, 2); |
| 1077 Dart_Handle isAsync = Dart_GetNativeArgument(args, 3); |
1061 | 1078 |
1062 Dart_Handle reflectee = UnwrapMirror(mirror); | 1079 Dart_Handle reflectee = UnwrapMirror(mirror); |
| 1080 Dart_Handle result; |
1063 GrowableArray<Dart_Handle> invoke_args; | 1081 GrowableArray<Dart_Handle> invoke_args; |
1064 Dart_Handle result = UnwrapArgList(wrapped_invoke_args, &invoke_args); | 1082 if (isAsync) { |
1065 if (Dart_IsError(result)) { | 1083 result = UnwrapArgList(wrapped_invoke_args, &invoke_args); |
1066 Dart_PropagateError(result); | 1084 if (Dart_IsError(result)) { |
1067 } | 1085 Dart_PropagateError(result); |
| 1086 } |
| 1087 } else {result = UnpackLocalArgList(wrapped_invoke_args, &invoke_args);} |
1068 result = | 1088 result = |
1069 Dart_Invoke(reflectee, member, invoke_args.length(), invoke_args.data()); | 1089 Dart_Invoke(reflectee, member, invoke_args.length(), invoke_args.data()); |
1070 if (Dart_IsError(result)) { | 1090 if (Dart_IsError(result)) { |
1071 // Instead of propagating the error from an invoke directly, we | 1091 // Instead of propagating the error from an invoke directly, we |
1072 // provide reflective access to the error. | 1092 // provide reflective access to the error. |
1073 Dart_PropagateError(CreateMirroredError(result)); | 1093 Dart_PropagateError(CreateMirroredError(result)); |
1074 } | 1094 } |
1075 | 1095 |
1076 Dart_Handle wrapped_result = CreateInstanceMirror(result); | 1096 Dart_Handle wrapped_result = CreateInstanceMirror(result); |
1077 if (Dart_IsError(wrapped_result)) { | 1097 if (Dart_IsError(wrapped_result)) { |
(...skipping 25 matching lines...) Expand all Loading... |
1103 Dart_SetReturnValue(args, wrapped_result); | 1123 Dart_SetReturnValue(args, wrapped_result); |
1104 Dart_ExitScope(); | 1124 Dart_ExitScope(); |
1105 } | 1125 } |
1106 | 1126 |
1107 | 1127 |
1108 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_setField)( | 1128 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_setField)( |
1109 Dart_NativeArguments args) { | 1129 Dart_NativeArguments args) { |
1110 Dart_EnterScope(); | 1130 Dart_EnterScope(); |
1111 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); | 1131 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); |
1112 Dart_Handle fieldName = Dart_GetNativeArgument(args, 1); | 1132 Dart_Handle fieldName = Dart_GetNativeArgument(args, 1); |
| 1133 Dart_Handle isAsync = Dart_GetNativeArgument(args, 2); |
1113 // The wrapped argument is either a simple value or instance mirror. | 1134 // The wrapped argument is either a simple value or instance mirror. |
1114 Dart_Handle wrapped_arg = Dart_GetNativeArgument(args, 2); | 1135 Dart_Handle wrapped_arg = Dart_GetNativeArgument(args, 2); |
1115 | 1136 |
1116 Dart_Handle reflectee = UnwrapMirror(mirror); | 1137 Dart_Handle reflectee = UnwrapMirror(mirror); |
1117 Dart_Handle set_arg = UnwrapArg(wrapped_arg); | 1138 Dart_Handle set_arg; |
| 1139 if (isAsync == DART_TRUE) set_arg = UnwrapArg(wrapped_arg); |
| 1140 }; |
1118 if (Dart_IsError(set_arg)) { | 1141 if (Dart_IsError(set_arg)) { |
1119 Dart_PropagateError(set_arg); | 1142 Dart_PropagateError(set_arg); |
1120 } | 1143 } |
1121 Dart_Handle result = Dart_SetField(reflectee, fieldName, set_arg); | 1144 Dart_Handle result = Dart_SetField(reflectee, fieldName, set_arg); |
1122 if (Dart_IsError(result)) { | 1145 if (Dart_IsError(result)) { |
1123 // Instead of propagating the error from a SetField directly, we | 1146 // Instead of propagating the error from a SetField directly, we |
1124 // provide reflective access to the error. | 1147 // provide reflective access to the error. |
1125 Dart_PropagateError(CreateMirroredError(result)); | 1148 Dart_PropagateError(CreateMirroredError(result)); |
1126 } | 1149 } |
1127 | 1150 |
1128 Dart_Handle wrapped_result = CreateInstanceMirror(result); | 1151 Dart_Handle wrapped_result = CreateInstanceMirror(result); |
1129 if (Dart_IsError(wrapped_result)) { | 1152 if (Dart_IsError(wrapped_result)) { |
1130 Dart_PropagateError(wrapped_result); | 1153 Dart_PropagateError(wrapped_result); |
1131 } | 1154 } |
1132 Dart_SetReturnValue(args, wrapped_result); | 1155 Dart_SetReturnValue(args, wrapped_result); |
1133 Dart_ExitScope(); | 1156 Dart_ExitScope(); |
1134 } | 1157 } |
1135 | 1158 |
1136 | 1159 |
1137 void NATIVE_ENTRY_FUNCTION(LocalClosureMirrorImpl_apply)( | 1160 void NATIVE_ENTRY_FUNCTION(LocalClosureMirrorImpl_apply)( |
1138 Dart_NativeArguments args) { | 1161 Dart_NativeArguments args) { |
1139 Dart_EnterScope(); | 1162 Dart_EnterScope(); |
1140 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); | 1163 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); |
1141 // The wrapped arguments are either simple values or instance mirrors. | 1164 // The wrapped arguments are either simple values or instance mirrors. |
1142 Dart_Handle wrapped_invoke_args = Dart_GetNativeArgument(args, 1); | 1165 Dart_Handle wrapped_invoke_args = Dart_GetNativeArgument(args, 1); |
| 1166 Dart_Handle isAsync = Dart_GetNativeArgument(args, 2); |
1143 | 1167 |
1144 Dart_Handle reflectee = UnwrapMirror(mirror); | 1168 Dart_Handle reflectee = UnwrapMirror(mirror); |
1145 GrowableArray<Dart_Handle> invoke_args; | 1169 GrowableArray<Dart_Handle> invoke_args; |
1146 Dart_Handle result = UnwrapArgList(wrapped_invoke_args, &invoke_args); | 1170 Dart_Handle result; |
| 1171 if (isAsync) { |
| 1172 result = UnwrapArgList(wrapped_invoke_args, &invoke_args); |
| 1173 if (Dart_IsError(result)) { |
| 1174 Dart_PropagateError(result); |
| 1175 } |
| 1176 } else {result = UnpackLocalArgList(wrapped_invoke_args, &invoke_args);} |
1147 if (Dart_IsError(result)) { | 1177 if (Dart_IsError(result)) { |
1148 Dart_PropagateError(result); | 1178 Dart_PropagateError(result); |
1149 } | 1179 } |
1150 result = | 1180 result = |
1151 Dart_InvokeClosure(reflectee, invoke_args.length(), invoke_args.data()); | 1181 Dart_InvokeClosure(reflectee, invoke_args.length(), invoke_args.data()); |
1152 if (Dart_IsError(result)) { | 1182 if (Dart_IsError(result)) { |
1153 // Instead of propagating the error from an apply directly, we | 1183 // Instead of propagating the error from an apply directly, we |
1154 // provide reflective access to the error. | 1184 // provide reflective access to the error. |
1155 Dart_PropagateError(CreateMirroredError(result)); | 1185 Dart_PropagateError(CreateMirroredError(result)); |
1156 } | 1186 } |
1157 | 1187 |
1158 Dart_Handle wrapped_result = CreateInstanceMirror(result); | 1188 Dart_Handle wrapped_result = CreateInstanceMirror(result); |
1159 if (Dart_IsError(wrapped_result)) { | 1189 if (Dart_IsError(wrapped_result)) { |
1160 Dart_PropagateError(wrapped_result); | 1190 Dart_PropagateError(wrapped_result); |
1161 } | 1191 } |
1162 Dart_SetReturnValue(args, wrapped_result); | 1192 Dart_SetReturnValue(args, wrapped_result); |
1163 Dart_ExitScope(); | 1193 Dart_ExitScope(); |
1164 } | 1194 } |
1165 | 1195 |
1166 | 1196 |
1167 void NATIVE_ENTRY_FUNCTION(LocalClassMirrorImpl_invokeConstructor)( | 1197 void NATIVE_ENTRY_FUNCTION(LocalClassMirrorImpl_invokeConstructor)( |
1168 Dart_NativeArguments args) { | 1198 Dart_NativeArguments args) { |
1169 Dart_EnterScope(); | 1199 Dart_EnterScope(); |
1170 Dart_Handle klass_mirror = Dart_GetNativeArgument(args, 0); | 1200 Dart_Handle klass_mirror = Dart_GetNativeArgument(args, 0); |
1171 Dart_Handle constructor_name = Dart_GetNativeArgument(args, 1); | 1201 Dart_Handle constructor_name = Dart_GetNativeArgument(args, 1); |
1172 // The wrapped arguments are either simple values or instance mirrors. | 1202 // The wrapped arguments are either simple values or instance mirrors. |
1173 Dart_Handle wrapped_invoke_args = Dart_GetNativeArgument(args, 2); | 1203 Dart_Handle wrapped_invoke_args = Dart_GetNativeArgument(args, 2); |
| 1204 Dart_Handle isAsync = Dart_GetNativeArgument(args, 3); |
1174 | 1205 |
1175 Dart_Handle klass = UnwrapMirror(klass_mirror); | 1206 Dart_Handle klass = UnwrapMirror(klass_mirror); |
1176 GrowableArray<Dart_Handle> invoke_args; | 1207 GrowableArray<Dart_Handle> invoke_args; |
1177 Dart_Handle result = UnwrapArgList(wrapped_invoke_args, &invoke_args); | 1208 Dart_Handle result; |
| 1209 if (isAsync) { |
| 1210 result = UnwrapArgList(wrapped_invoke_args, &invoke_args); |
| 1211 if (Dart_IsError(result)) { |
| 1212 Dart_PropagateError(result); |
| 1213 } |
| 1214 } else {result = UnpackLocalArgList(wrapped_invoke_args, &invoke_args);} |
1178 if (Dart_IsError(result)) { | 1215 if (Dart_IsError(result)) { |
1179 Dart_PropagateError(result); | 1216 Dart_PropagateError(result); |
1180 } | 1217 } |
1181 result = Dart_New(klass, | 1218 result = Dart_New(klass, |
1182 constructor_name, | 1219 constructor_name, |
1183 invoke_args.length(), | 1220 invoke_args.length(), |
1184 invoke_args.data()); | 1221 invoke_args.data()); |
1185 if (Dart_IsError(result)) { | 1222 if (Dart_IsError(result)) { |
1186 // Instead of propagating the error from an invoke directly, we | 1223 // Instead of propagating the error from an invoke directly, we |
1187 // provide reflective access to the error. | 1224 // provide reflective access to the error. |
1188 Dart_PropagateError(CreateMirroredError(result)); | 1225 Dart_PropagateError(CreateMirroredError(result)); |
1189 } | 1226 } |
1190 | 1227 |
1191 Dart_Handle wrapped_result = CreateInstanceMirror(result); | 1228 Dart_Handle wrapped_result = CreateInstanceMirror(result); |
1192 if (Dart_IsError(wrapped_result)) { | 1229 if (Dart_IsError(wrapped_result)) { |
1193 Dart_PropagateError(wrapped_result); | 1230 Dart_PropagateError(wrapped_result); |
1194 } | 1231 } |
1195 Dart_SetReturnValue(args, wrapped_result); | 1232 Dart_SetReturnValue(args, wrapped_result); |
1196 Dart_ExitScope(); | 1233 Dart_ExitScope(); |
1197 } | 1234 } |
1198 | 1235 |
1199 | 1236 |
1200 void HandleMirrorsMessage(Isolate* isolate, | 1237 void HandleMirrorsMessage(Isolate* isolate, |
1201 Dart_Port reply_port, | 1238 Dart_Port reply_port, |
1202 const Instance& message) { | 1239 const Instance& message) { |
1203 UNIMPLEMENTED(); | 1240 UNIMPLEMENTED(); |
1204 } | 1241 } |
1205 | 1242 |
1206 } // namespace dart | 1243 } // namespace dart |
OLD | NEW |