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 "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 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1044 Dart_Handle reflectee = Dart_GetNativeArgument(args, 0); | 1060 Dart_Handle reflectee = Dart_GetNativeArgument(args, 0); |
| 1045 Dart_Handle mirror = CreateInstanceMirror(reflectee); | 1061 Dart_Handle mirror = CreateInstanceMirror(reflectee); |
| 1046 if (Dart_IsError(mirror)) { | 1062 if (Dart_IsError(mirror)) { |
| 1047 Dart_PropagateError(mirror); | 1063 Dart_PropagateError(mirror); |
| 1048 } | 1064 } |
| 1049 Dart_SetReturnValue(args, mirror); | 1065 Dart_SetReturnValue(args, mirror); |
| 1050 Dart_ExitScope(); | 1066 Dart_ExitScope(); |
| 1051 } | 1067 } |
| 1052 | 1068 |
| 1053 | 1069 |
| 1054 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_invoke)( | 1070 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_invokeAsync)( |
| 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); |
| 1061 | 1077 |
| 1062 Dart_Handle reflectee = UnwrapMirror(mirror); | 1078 Dart_Handle reflectee = UnwrapMirror(mirror); |
| 1063 GrowableArray<Dart_Handle> invoke_args; | 1079 GrowableArray<Dart_Handle> invoke_args; |
| 1064 Dart_Handle result = UnwrapArgList(wrapped_invoke_args, &invoke_args); | 1080 Dart_Handle result = UnwrapArgList(wrapped_invoke_args, &invoke_args); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1098 | 1114 |
| 1099 Dart_Handle wrapped_result = CreateInstanceMirror(result); | 1115 Dart_Handle wrapped_result = CreateInstanceMirror(result); |
| 1100 if (Dart_IsError(wrapped_result)) { | 1116 if (Dart_IsError(wrapped_result)) { |
| 1101 Dart_PropagateError(wrapped_result); | 1117 Dart_PropagateError(wrapped_result); |
| 1102 } | 1118 } |
| 1103 Dart_SetReturnValue(args, wrapped_result); | 1119 Dart_SetReturnValue(args, wrapped_result); |
| 1104 Dart_ExitScope(); | 1120 Dart_ExitScope(); |
| 1105 } | 1121 } |
| 1106 | 1122 |
| 1107 | 1123 |
| 1108 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_setField)( | 1124 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_setFieldAsync)( |
| 1109 Dart_NativeArguments args) { | 1125 Dart_NativeArguments args) { |
| 1110 Dart_EnterScope(); | 1126 Dart_EnterScope(); |
| 1111 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); | 1127 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); |
| 1112 Dart_Handle fieldName = Dart_GetNativeArgument(args, 1); | 1128 Dart_Handle fieldName = Dart_GetNativeArgument(args, 1); |
| 1113 // The wrapped argument is either a simple value or instance mirror. | 1129 // The wrapped argument is either a simple value or instance mirror. |
| 1114 Dart_Handle wrapped_arg = Dart_GetNativeArgument(args, 2); | 1130 Dart_Handle wrapped_arg = Dart_GetNativeArgument(args, 2); |
| 1115 | 1131 |
| 1116 Dart_Handle reflectee = UnwrapMirror(mirror); | 1132 Dart_Handle reflectee = UnwrapMirror(mirror); |
| 1117 Dart_Handle set_arg = UnwrapArg(wrapped_arg); | 1133 Dart_Handle set_arg = UnwrapArg(wrapped_arg); |
| 1118 if (Dart_IsError(set_arg)) { | 1134 if (Dart_IsError(set_arg)) { |
| 1119 Dart_PropagateError(set_arg); | 1135 Dart_PropagateError(set_arg); |
| 1120 } | 1136 } |
| 1121 Dart_Handle result = Dart_SetField(reflectee, fieldName, set_arg); | 1137 Dart_Handle result = Dart_SetField(reflectee, fieldName, set_arg); |
| 1122 if (Dart_IsError(result)) { | 1138 if (Dart_IsError(result)) { |
| 1123 // Instead of propagating the error from a SetField directly, we | 1139 // Instead of propagating the error from a SetField directly, we |
| 1124 // provide reflective access to the error. | 1140 // provide reflective access to the error. |
| 1125 Dart_PropagateError(CreateMirroredError(result)); | 1141 Dart_PropagateError(CreateMirroredError(result)); |
| 1126 } | 1142 } |
| 1127 | 1143 |
| 1128 Dart_Handle wrapped_result = CreateInstanceMirror(result); | 1144 Dart_Handle wrapped_result = CreateInstanceMirror(result); |
| 1129 if (Dart_IsError(wrapped_result)) { | 1145 if (Dart_IsError(wrapped_result)) { |
| 1130 Dart_PropagateError(wrapped_result); | 1146 Dart_PropagateError(wrapped_result); |
| 1131 } | 1147 } |
| 1132 Dart_SetReturnValue(args, wrapped_result); | 1148 Dart_SetReturnValue(args, wrapped_result); |
| 1133 Dart_ExitScope(); | 1149 Dart_ExitScope(); |
| 1134 } | 1150 } |
| 1135 | 1151 |
| 1136 | 1152 |
| 1137 void NATIVE_ENTRY_FUNCTION(LocalClosureMirrorImpl_apply)( | 1153 void NATIVE_ENTRY_FUNCTION(LocalClosureMirrorImpl_applyAsync)( |
| 1138 Dart_NativeArguments args) { | 1154 Dart_NativeArguments args) { |
| 1139 Dart_EnterScope(); | 1155 Dart_EnterScope(); |
| 1140 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); | 1156 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); |
| 1141 // The wrapped arguments are either simple values or instance mirrors. | 1157 // The wrapped arguments are either simple values or instance mirrors. |
| 1142 Dart_Handle wrapped_invoke_args = Dart_GetNativeArgument(args, 1); | 1158 Dart_Handle wrapped_invoke_args = Dart_GetNativeArgument(args, 1); |
| 1143 | 1159 |
| 1144 Dart_Handle reflectee = UnwrapMirror(mirror); | 1160 Dart_Handle reflectee = UnwrapMirror(mirror); |
| 1145 GrowableArray<Dart_Handle> invoke_args; | 1161 GrowableArray<Dart_Handle> invoke_args; |
| 1146 Dart_Handle result = UnwrapArgList(wrapped_invoke_args, &invoke_args); | 1162 Dart_Handle result = UnwrapArgList(wrapped_invoke_args, &invoke_args); |
| 1147 if (Dart_IsError(result)) { | 1163 if (Dart_IsError(result)) { |
| 1148 Dart_PropagateError(result); | 1164 Dart_PropagateError(result); |
| 1149 } | 1165 } |
| 1150 result = | 1166 result = |
| 1151 Dart_InvokeClosure(reflectee, invoke_args.length(), invoke_args.data()); | 1167 Dart_InvokeClosure(reflectee, invoke_args.length(), invoke_args.data()); |
| 1152 if (Dart_IsError(result)) { | 1168 if (Dart_IsError(result)) { |
| 1153 // Instead of propagating the error from an apply directly, we | 1169 // Instead of propagating the error from an apply directly, we |
| 1154 // provide reflective access to the error. | 1170 // provide reflective access to the error. |
| 1155 Dart_PropagateError(CreateMirroredError(result)); | 1171 Dart_PropagateError(CreateMirroredError(result)); |
| 1156 } | 1172 } |
| 1157 | 1173 |
| 1158 Dart_Handle wrapped_result = CreateInstanceMirror(result); | 1174 Dart_Handle wrapped_result = CreateInstanceMirror(result); |
| 1159 if (Dart_IsError(wrapped_result)) { | 1175 if (Dart_IsError(wrapped_result)) { |
| 1160 Dart_PropagateError(wrapped_result); | 1176 Dart_PropagateError(wrapped_result); |
| 1161 } | 1177 } |
| 1162 Dart_SetReturnValue(args, wrapped_result); | 1178 Dart_SetReturnValue(args, wrapped_result); |
| 1163 Dart_ExitScope(); | 1179 Dart_ExitScope(); |
| 1164 } | 1180 } |
| 1165 | 1181 |
| 1166 | 1182 |
| 1167 void NATIVE_ENTRY_FUNCTION(LocalClassMirrorImpl_invokeConstructor)( | 1183 void NATIVE_ENTRY_FUNCTION(LocalClassMirrorImpl_invokeConstructorAsync)( |
| 1168 Dart_NativeArguments args) { | 1184 Dart_NativeArguments args) { |
| 1169 Dart_EnterScope(); | 1185 Dart_EnterScope(); |
| 1170 Dart_Handle klass_mirror = Dart_GetNativeArgument(args, 0); | 1186 Dart_Handle klass_mirror = Dart_GetNativeArgument(args, 0); |
| 1171 Dart_Handle constructor_name = Dart_GetNativeArgument(args, 1); | 1187 Dart_Handle constructor_name = Dart_GetNativeArgument(args, 1); |
| 1172 // The wrapped arguments are either simple values or instance mirrors. | 1188 // The wrapped arguments are either simple values or instance mirrors. |
| 1173 Dart_Handle wrapped_invoke_args = Dart_GetNativeArgument(args, 2); | 1189 Dart_Handle wrapped_invoke_args = Dart_GetNativeArgument(args, 2); |
| 1174 | 1190 |
| 1175 Dart_Handle klass = UnwrapMirror(klass_mirror); | 1191 Dart_Handle klass = UnwrapMirror(klass_mirror); |
| 1176 GrowableArray<Dart_Handle> invoke_args; | 1192 GrowableArray<Dart_Handle> invoke_args; |
| 1177 Dart_Handle result = UnwrapArgList(wrapped_invoke_args, &invoke_args); | 1193 Dart_Handle result = UnwrapArgList(wrapped_invoke_args, &invoke_args); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1188 Dart_PropagateError(CreateMirroredError(result)); | 1204 Dart_PropagateError(CreateMirroredError(result)); |
| 1189 } | 1205 } |
| 1190 | 1206 |
| 1191 Dart_Handle wrapped_result = CreateInstanceMirror(result); | 1207 Dart_Handle wrapped_result = CreateInstanceMirror(result); |
| 1192 if (Dart_IsError(wrapped_result)) { | 1208 if (Dart_IsError(wrapped_result)) { |
| 1193 Dart_PropagateError(wrapped_result); | 1209 Dart_PropagateError(wrapped_result); |
| 1194 } | 1210 } |
| 1195 Dart_SetReturnValue(args, wrapped_result); | 1211 Dart_SetReturnValue(args, wrapped_result); |
| 1196 Dart_ExitScope(); | 1212 Dart_ExitScope(); |
| 1197 } | 1213 } |
| 1198 | 1214 |
|
Ivan Posva
2013/04/12 21:15:26
Two lines.
| |
| 1215 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_invoke)( | |
| 1216 Dart_NativeArguments args) { | |
| 1217 Dart_EnterScope(); | |
| 1218 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); | |
| 1219 Dart_Handle member = Dart_GetNativeArgument(args, 1); | |
| 1220 | |
|
Ivan Posva
2013/04/12 21:15:26
Want to add a comment here that the wrapped argume
| |
| 1221 Dart_Handle wrapped_invoke_args = Dart_GetNativeArgument(args, 2); | |
| 1222 | |
| 1223 Dart_Handle reflectee = UnwrapMirror(mirror); | |
| 1224 GrowableArray<Dart_Handle> invoke_args; | |
| 1225 Dart_Handle result = UnpackLocalArgList(wrapped_invoke_args, &invoke_args); | |
| 1226 if (Dart_IsError(result)) { | |
| 1227 Dart_PropagateError(result); | |
| 1228 } | |
| 1229 result = | |
| 1230 Dart_Invoke(reflectee, member, invoke_args.length(), invoke_args.data()); | |
| 1231 if (Dart_IsError(result)) { | |
| 1232 // Instead of propagating the error from an invoke directly, we | |
| 1233 // provide reflective access to the error. | |
| 1234 Dart_PropagateError(CreateMirroredError(result)); | |
| 1235 } | |
| 1236 | |
| 1237 Dart_Handle wrapped_result = CreateInstanceMirror(result); | |
| 1238 if (Dart_IsError(wrapped_result)) { | |
| 1239 Dart_PropagateError(wrapped_result); | |
| 1240 } | |
| 1241 Dart_SetReturnValue(args, wrapped_result); | |
| 1242 Dart_ExitScope(); | |
| 1243 } | |
| 1244 | |
|
Ivan Posva
2013/04/12 21:15:26
ditto
| |
| 1245 void NATIVE_ENTRY_FUNCTION(LocalObjectMirrorImpl_setField)( | |
|
Ivan Posva
2013/04/12 21:15:26
What is the difference between this and the Async
| |
| 1246 Dart_NativeArguments args) { | |
| 1247 Dart_EnterScope(); | |
| 1248 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); | |
| 1249 Dart_Handle fieldName = Dart_GetNativeArgument(args, 1); | |
| 1250 | |
| 1251 Dart_Handle set_arg = Dart_GetNativeArgument(args, 2); | |
| 1252 | |
| 1253 Dart_Handle reflectee = UnwrapMirror(mirror); | |
| 1254 if (Dart_IsError(set_arg)) { | |
| 1255 Dart_PropagateError(set_arg); | |
| 1256 } | |
| 1257 Dart_Handle result = Dart_SetField(reflectee, fieldName, set_arg); | |
| 1258 if (Dart_IsError(result)) { | |
| 1259 // Instead of propagating the error from a SetField directly, we | |
| 1260 // provide reflective access to the error. | |
| 1261 Dart_PropagateError(CreateMirroredError(result)); | |
| 1262 } | |
| 1263 | |
| 1264 Dart_Handle wrapped_result = CreateInstanceMirror(result); | |
| 1265 if (Dart_IsError(wrapped_result)) { | |
| 1266 Dart_PropagateError(wrapped_result); | |
| 1267 } | |
| 1268 Dart_SetReturnValue(args, wrapped_result); | |
| 1269 Dart_ExitScope(); | |
| 1270 } | |
| 1271 | |
| 1272 | |
| 1273 void NATIVE_ENTRY_FUNCTION(LocalClosureMirrorImpl_apply)( | |
| 1274 Dart_NativeArguments args) { | |
| 1275 Dart_EnterScope(); | |
| 1276 Dart_Handle mirror = Dart_GetNativeArgument(args, 0); | |
| 1277 | |
| 1278 Dart_Handle wrapped_invoke_args = Dart_GetNativeArgument(args, 1); | |
| 1279 | |
| 1280 Dart_Handle reflectee = UnwrapMirror(mirror); | |
| 1281 GrowableArray<Dart_Handle> invoke_args; | |
| 1282 Dart_Handle result = UnpackLocalArgList(wrapped_invoke_args, &invoke_args); | |
| 1283 if (Dart_IsError(result)) { | |
| 1284 Dart_PropagateError(result); | |
| 1285 } | |
| 1286 result = | |
| 1287 Dart_InvokeClosure(reflectee, invoke_args.length(), invoke_args.data()); | |
| 1288 if (Dart_IsError(result)) { | |
| 1289 // Instead of propagating the error from an apply directly, we | |
| 1290 // provide reflective access to the error. | |
| 1291 Dart_PropagateError(CreateMirroredError(result)); | |
| 1292 } | |
| 1293 | |
| 1294 Dart_Handle wrapped_result = CreateInstanceMirror(result); | |
| 1295 if (Dart_IsError(wrapped_result)) { | |
| 1296 Dart_PropagateError(wrapped_result); | |
| 1297 } | |
| 1298 Dart_SetReturnValue(args, wrapped_result); | |
| 1299 Dart_ExitScope(); | |
| 1300 } | |
| 1301 | |
| 1302 | |
| 1303 void NATIVE_ENTRY_FUNCTION(LocalClassMirrorImpl_invokeConstructor)( | |
| 1304 Dart_NativeArguments args) { | |
| 1305 Dart_EnterScope(); | |
| 1306 Dart_Handle klass_mirror = Dart_GetNativeArgument(args, 0); | |
| 1307 Dart_Handle constructor_name = Dart_GetNativeArgument(args, 1); | |
| 1308 | |
| 1309 Dart_Handle wrapped_invoke_args = Dart_GetNativeArgument(args, 2); | |
| 1310 | |
| 1311 Dart_Handle klass = UnwrapMirror(klass_mirror); | |
| 1312 GrowableArray<Dart_Handle> invoke_args; | |
| 1313 Dart_Handle result = UnpackLocalArgList(wrapped_invoke_args, &invoke_args); | |
| 1314 if (Dart_IsError(result)) { | |
| 1315 Dart_PropagateError(result); | |
| 1316 } | |
| 1317 result = Dart_New(klass, | |
| 1318 constructor_name, | |
| 1319 invoke_args.length(), | |
| 1320 invoke_args.data()); | |
| 1321 if (Dart_IsError(result)) { | |
| 1322 // Instead of propagating the error from an invoke directly, we | |
| 1323 // provide reflective access to the error. | |
| 1324 Dart_PropagateError(CreateMirroredError(result)); | |
| 1325 } | |
| 1326 | |
| 1327 Dart_Handle wrapped_result = CreateInstanceMirror(result); | |
| 1328 if (Dart_IsError(wrapped_result)) { | |
| 1329 Dart_PropagateError(wrapped_result); | |
| 1330 } | |
| 1331 Dart_SetReturnValue(args, wrapped_result); | |
| 1332 Dart_ExitScope(); | |
| 1333 } | |
| 1334 | |
| 1199 | 1335 |
| 1200 void HandleMirrorsMessage(Isolate* isolate, | 1336 void HandleMirrorsMessage(Isolate* isolate, |
| 1201 Dart_Port reply_port, | 1337 Dart_Port reply_port, |
| 1202 const Instance& message) { | 1338 const Instance& message) { |
| 1203 UNIMPLEMENTED(); | 1339 UNIMPLEMENTED(); |
| 1204 } | 1340 } |
| 1205 | 1341 |
| 1206 } // namespace dart | 1342 } // namespace dart |
| OLD | NEW |