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 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1054 } | 1070 } |
1055 Dart_SetReturnValue(args, mirror); | 1071 Dart_SetReturnValue(args, mirror); |
1056 Dart_ExitScope(); | 1072 Dart_ExitScope(); |
1057 } | 1073 } |
1058 | 1074 |
1059 | 1075 |
1060 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_invoke)( | 1076 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_invoke)( |
1061 Dart_NativeArguments args) { | 1077 Dart_NativeArguments args) { |
1062 Dart_EnterScope(); | 1078 Dart_EnterScope(); |
1063 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); | 1079 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); |
1064 Dart_Handle member = Dart_GetNativeArgument(args, 1); | 1080 Dart_Handle member_name = Dart_GetNativeArgument(args, 1); |
1065 // The wrapped arguments are either simple values or instance mirrors. | 1081 // The arguments are either simple values or instance mirrors. |
1066 Dart_Handle wrapped_invoke_args = Dart_GetNativeArgument(args, 2); | 1082 Dart_Handle positional_arguments = Dart_GetNativeArgument(args, 2); |
| 1083 Dart_Handle async = Dart_GetNativeArgument(args, 3); |
1067 | 1084 |
1068 Dart_Handle reflectee = UnwrapMirror(mirror); | 1085 Dart_Handle reflectee = UnwrapMirror(mirror); |
| 1086 Dart_Handle result; |
1069 GrowableArray<Dart_Handle> invoke_args; | 1087 GrowableArray<Dart_Handle> invoke_args; |
1070 Dart_Handle result = UnwrapArgList(wrapped_invoke_args, &invoke_args); | 1088 if (Dart_IdentityEquals(async, Dart_True())) { |
| 1089 result = UnwrapArgList(positional_arguments, &invoke_args); |
| 1090 } else { |
| 1091 result = UnpackLocalArgList(positional_arguments, &invoke_args); |
| 1092 } |
1071 if (Dart_IsError(result)) { | 1093 if (Dart_IsError(result)) { |
1072 Dart_PropagateError(result); | 1094 Dart_PropagateError(result); |
1073 } | 1095 } |
1074 result = | 1096 result = Dart_Invoke(reflectee, |
1075 Dart_Invoke(reflectee, member, invoke_args.length(), invoke_args.data()); | 1097 member_name, |
| 1098 invoke_args.length(), |
| 1099 invoke_args.data()); |
1076 if (Dart_IsError(result)) { | 1100 if (Dart_IsError(result)) { |
1077 // Instead of propagating the error from an invoke directly, we | 1101 // Instead of propagating the error from an invoke directly, we |
1078 // provide reflective access to the error. | 1102 // provide reflective access to the error. |
1079 Dart_PropagateError(CreateMirroredError(result)); | 1103 Dart_PropagateError(CreateMirroredError(result)); |
1080 } | 1104 } |
1081 | 1105 |
1082 Dart_Handle wrapped_result = CreateInstanceMirror(result); | 1106 Dart_Handle wrapped_result = CreateInstanceMirror(result); |
1083 if (Dart_IsError(wrapped_result)) { | 1107 if (Dart_IsError(wrapped_result)) { |
1084 Dart_PropagateError(wrapped_result); | 1108 Dart_PropagateError(wrapped_result); |
1085 } | 1109 } |
(...skipping 23 matching lines...) Expand all Loading... |
1109 Dart_SetReturnValue(args, wrapped_result); | 1133 Dart_SetReturnValue(args, wrapped_result); |
1110 Dart_ExitScope(); | 1134 Dart_ExitScope(); |
1111 } | 1135 } |
1112 | 1136 |
1113 | 1137 |
1114 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_setField)( | 1138 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_setField)( |
1115 Dart_NativeArguments args) { | 1139 Dart_NativeArguments args) { |
1116 Dart_EnterScope(); | 1140 Dart_EnterScope(); |
1117 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); | 1141 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); |
1118 Dart_Handle fieldName = Dart_GetNativeArgument(args, 1); | 1142 Dart_Handle fieldName = Dart_GetNativeArgument(args, 1); |
1119 // The wrapped argument is either a simple value or instance mirror. | 1143 Dart_Handle value = Dart_GetNativeArgument(args, 2); |
1120 Dart_Handle wrapped_arg = Dart_GetNativeArgument(args, 2); | 1144 Dart_Handle async = Dart_GetNativeArgument(args, 3); |
1121 | 1145 |
1122 Dart_Handle reflectee = UnwrapMirror(mirror); | 1146 Dart_Handle reflectee = UnwrapMirror(mirror); |
1123 Dart_Handle set_arg = UnwrapArg(wrapped_arg); | 1147 Dart_Handle set_arg; |
| 1148 if (Dart_IdentityEquals(async, Dart_True())) { |
| 1149 set_arg = UnwrapArg(value); |
| 1150 } else { |
| 1151 set_arg = value; |
| 1152 } |
1124 if (Dart_IsError(set_arg)) { | 1153 if (Dart_IsError(set_arg)) { |
1125 Dart_PropagateError(set_arg); | 1154 Dart_PropagateError(set_arg); |
1126 } | 1155 } |
1127 Dart_Handle result = Dart_SetField(reflectee, fieldName, set_arg); | 1156 Dart_Handle result = Dart_SetField(reflectee, fieldName, set_arg); |
1128 if (Dart_IsError(result)) { | 1157 if (Dart_IsError(result)) { |
1129 // Instead of propagating the error from a SetField directly, we | 1158 // Instead of propagating the error from a SetField directly, we |
1130 // provide reflective access to the error. | 1159 // provide reflective access to the error. |
1131 Dart_PropagateError(CreateMirroredError(result)); | 1160 Dart_PropagateError(CreateMirroredError(result)); |
1132 } | 1161 } |
1133 | 1162 |
1134 Dart_Handle wrapped_result = CreateInstanceMirror(result); | 1163 Dart_Handle wrapped_result = CreateInstanceMirror(result); |
1135 if (Dart_IsError(wrapped_result)) { | 1164 if (Dart_IsError(wrapped_result)) { |
1136 Dart_PropagateError(wrapped_result); | 1165 Dart_PropagateError(wrapped_result); |
1137 } | 1166 } |
1138 Dart_SetReturnValue(args, wrapped_result); | 1167 Dart_SetReturnValue(args, wrapped_result); |
1139 Dart_ExitScope(); | 1168 Dart_ExitScope(); |
1140 } | 1169 } |
1141 | 1170 |
1142 | 1171 |
1143 void NATIVE_ENTRY_FUNCTION(LocalClosureMirrorImpl_apply)( | 1172 void NATIVE_ENTRY_FUNCTION(LocalClosureMirrorImpl_apply)( |
1144 Dart_NativeArguments args) { | 1173 Dart_NativeArguments args) { |
1145 Dart_EnterScope(); | 1174 Dart_EnterScope(); |
1146 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); | 1175 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); |
1147 // The wrapped arguments are either simple values or instance mirrors. | 1176 // The arguments are either simple values or instance mirrors. |
1148 Dart_Handle wrapped_invoke_args = Dart_GetNativeArgument(args, 1); | 1177 Dart_Handle positional_arguments = Dart_GetNativeArgument(args, 1); |
| 1178 Dart_Handle async = Dart_GetNativeArgument(args, 2); |
1149 | 1179 |
1150 Dart_Handle reflectee = UnwrapMirror(mirror); | 1180 Dart_Handle reflectee = UnwrapMirror(mirror); |
1151 GrowableArray<Dart_Handle> invoke_args; | 1181 GrowableArray<Dart_Handle> invoke_args; |
1152 Dart_Handle result = UnwrapArgList(wrapped_invoke_args, &invoke_args); | 1182 Dart_Handle result; |
| 1183 if (Dart_IdentityEquals(async, Dart_True())) { |
| 1184 result = UnwrapArgList(positional_arguments, &invoke_args); |
| 1185 } else { |
| 1186 result = UnpackLocalArgList(positional_arguments, &invoke_args); |
| 1187 } |
1153 if (Dart_IsError(result)) { | 1188 if (Dart_IsError(result)) { |
1154 Dart_PropagateError(result); | 1189 Dart_PropagateError(result); |
1155 } | 1190 } |
1156 result = | 1191 result = |
1157 Dart_InvokeClosure(reflectee, invoke_args.length(), invoke_args.data()); | 1192 Dart_InvokeClosure(reflectee, invoke_args.length(), invoke_args.data()); |
1158 if (Dart_IsError(result)) { | 1193 if (Dart_IsError(result)) { |
1159 // Instead of propagating the error from an apply directly, we | 1194 // Instead of propagating the error from an apply directly, we |
1160 // provide reflective access to the error. | 1195 // provide reflective access to the error. |
1161 Dart_PropagateError(CreateMirroredError(result)); | 1196 Dart_PropagateError(CreateMirroredError(result)); |
1162 } | 1197 } |
1163 | 1198 |
1164 Dart_Handle wrapped_result = CreateInstanceMirror(result); | 1199 Dart_Handle wrapped_result = CreateInstanceMirror(result); |
1165 if (Dart_IsError(wrapped_result)) { | 1200 if (Dart_IsError(wrapped_result)) { |
1166 Dart_PropagateError(wrapped_result); | 1201 Dart_PropagateError(wrapped_result); |
1167 } | 1202 } |
1168 Dart_SetReturnValue(args, wrapped_result); | 1203 Dart_SetReturnValue(args, wrapped_result); |
1169 Dart_ExitScope(); | 1204 Dart_ExitScope(); |
1170 } | 1205 } |
1171 | 1206 |
1172 | 1207 |
1173 void NATIVE_ENTRY_FUNCTION(LocalClassMirrorImpl_invokeConstructor)( | 1208 void NATIVE_ENTRY_FUNCTION(LocalClassMirrorImpl_invokeConstructor)( |
1174 Dart_NativeArguments args) { | 1209 Dart_NativeArguments args) { |
1175 Dart_EnterScope(); | 1210 Dart_EnterScope(); |
1176 Dart_Handle klass_mirror = Dart_GetNativeArgument(args, 0); | 1211 Dart_Handle klass_mirror = Dart_GetNativeArgument(args, 0); |
1177 Dart_Handle constructor_name = Dart_GetNativeArgument(args, 1); | 1212 Dart_Handle constructor_name = Dart_GetNativeArgument(args, 1); |
1178 // The wrapped arguments are either simple values or instance mirrors. | 1213 // The arguments are either simple values or instance mirrors. |
1179 Dart_Handle wrapped_invoke_args = Dart_GetNativeArgument(args, 2); | 1214 Dart_Handle positional_arguments = Dart_GetNativeArgument(args, 2); |
| 1215 Dart_Handle async = Dart_GetNativeArgument(args, 3); |
1180 | 1216 |
1181 Dart_Handle klass = UnwrapMirror(klass_mirror); | 1217 Dart_Handle klass = UnwrapMirror(klass_mirror); |
1182 GrowableArray<Dart_Handle> invoke_args; | 1218 GrowableArray<Dart_Handle> invoke_args; |
1183 Dart_Handle result = UnwrapArgList(wrapped_invoke_args, &invoke_args); | 1219 Dart_Handle result; |
| 1220 if (Dart_IdentityEquals(async, Dart_True())) { |
| 1221 result = UnwrapArgList(positional_arguments, &invoke_args); |
| 1222 } else { |
| 1223 result = UnpackLocalArgList(positional_arguments, &invoke_args); |
| 1224 } |
1184 if (Dart_IsError(result)) { | 1225 if (Dart_IsError(result)) { |
1185 Dart_PropagateError(result); | 1226 Dart_PropagateError(result); |
1186 } | 1227 } |
1187 result = Dart_New(klass, | 1228 result = Dart_New(klass, |
1188 constructor_name, | 1229 constructor_name, |
1189 invoke_args.length(), | 1230 invoke_args.length(), |
1190 invoke_args.data()); | 1231 invoke_args.data()); |
1191 if (Dart_IsError(result)) { | 1232 if (Dart_IsError(result)) { |
1192 // Instead of propagating the error from an invoke directly, we | 1233 // Instead of propagating the error from an invoke directly, we |
1193 // provide reflective access to the error. | 1234 // provide reflective access to the error. |
1194 Dart_PropagateError(CreateMirroredError(result)); | 1235 Dart_PropagateError(CreateMirroredError(result)); |
1195 } | 1236 } |
1196 | 1237 |
1197 Dart_Handle wrapped_result = CreateInstanceMirror(result); | 1238 Dart_Handle wrapped_result = CreateInstanceMirror(result); |
1198 if (Dart_IsError(wrapped_result)) { | 1239 if (Dart_IsError(wrapped_result)) { |
1199 Dart_PropagateError(wrapped_result); | 1240 Dart_PropagateError(wrapped_result); |
1200 } | 1241 } |
1201 Dart_SetReturnValue(args, wrapped_result); | 1242 Dart_SetReturnValue(args, wrapped_result); |
1202 Dart_ExitScope(); | 1243 Dart_ExitScope(); |
1203 } | 1244 } |
1204 | 1245 |
1205 | 1246 |
1206 void HandleMirrorsMessage(Isolate* isolate, | 1247 void HandleMirrorsMessage(Isolate* isolate, |
1207 Dart_Port reply_port, | 1248 Dart_Port reply_port, |
1208 const Instance& message) { | 1249 const Instance& message) { |
1209 UNIMPLEMENTED(); | 1250 UNIMPLEMENTED(); |
1210 } | 1251 } |
1211 | 1252 |
1212 } // namespace dart | 1253 } // namespace dart |
OLD | NEW |