OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/service.h" | 5 #include "vm/service.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/globals.h" | 8 #include "platform/globals.h" |
9 | 9 |
10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
11 #include "vm/coverage.h" | 11 #include "vm/coverage.h" |
12 #include "vm/cpu.h" | 12 #include "vm/cpu.h" |
13 #include "vm/dart_api_impl.h" | 13 #include "vm/dart_api_impl.h" |
14 #include "vm/dart_entry.h" | 14 #include "vm/dart_entry.h" |
15 #include "vm/debugger.h" | 15 #include "vm/debugger.h" |
16 #include "vm/isolate.h" | 16 #include "vm/isolate.h" |
17 #include "vm/message.h" | 17 #include "vm/message.h" |
18 #include "vm/message_handler.h" | 18 #include "vm/message_handler.h" |
19 #include "vm/native_entry.h" | 19 #include "vm/native_entry.h" |
20 #include "vm/native_arguments.h" | 20 #include "vm/native_arguments.h" |
21 #include "vm/object.h" | 21 #include "vm/object.h" |
22 #include "vm/object_graph.h" | 22 #include "vm/object_graph.h" |
23 #include "vm/object_id_ring.h" | 23 #include "vm/object_id_ring.h" |
24 #include "vm/object_store.h" | 24 #include "vm/object_store.h" |
| 25 #include "vm/parser.h" |
25 #include "vm/port.h" | 26 #include "vm/port.h" |
26 #include "vm/profiler.h" | 27 #include "vm/profiler.h" |
27 #include "vm/reusable_handles.h" | 28 #include "vm/reusable_handles.h" |
28 #include "vm/stack_frame.h" | 29 #include "vm/stack_frame.h" |
29 #include "vm/symbols.h" | 30 #include "vm/symbols.h" |
30 #include "vm/unicode.h" | 31 #include "vm/unicode.h" |
31 #include "vm/version.h" | 32 #include "vm/version.h" |
32 | 33 |
33 namespace dart { | 34 namespace dart { |
34 | 35 |
(...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 | 1270 |
1270 | 1271 |
1271 static bool HandleClassesFunctionsCoverage( | 1272 static bool HandleClassesFunctionsCoverage( |
1272 Isolate* isolate, const Function& func, JSONStream* js) { | 1273 Isolate* isolate, const Function& func, JSONStream* js) { |
1273 FunctionCoverageFilter filter(func); | 1274 FunctionCoverageFilter filter(func); |
1274 CodeCoverage::PrintJSON(isolate, js, &filter); | 1275 CodeCoverage::PrintJSON(isolate, js, &filter); |
1275 return true; | 1276 return true; |
1276 } | 1277 } |
1277 | 1278 |
1278 | 1279 |
| 1280 static bool HandleFunctionSetSource( |
| 1281 Isolate* isolate, const Class& cls, const Function& func, JSONStream* js) { |
| 1282 if (js->LookupOption("source") == NULL) { |
| 1283 PrintError(js, "set_source expects a 'source' option\n"); |
| 1284 return true; |
| 1285 } |
| 1286 const String& source = |
| 1287 String::Handle(String::New(js->LookupOption("source"))); |
| 1288 const Object& result = Object::Handle( |
| 1289 Parser::ParseFunctionFromSource(cls, source)); |
| 1290 if (result.IsError()) { |
| 1291 Error::Cast(result).PrintJSON(js, false); |
| 1292 return true; |
| 1293 } |
| 1294 if (!result.IsFunction()) { |
| 1295 PrintError(js, "source did not compile to a function.\n"); |
| 1296 return true; |
| 1297 } |
| 1298 |
| 1299 // Replace function. |
| 1300 cls.RemoveFunction(func); |
| 1301 cls.AddFunction(Function::Cast(result)); |
| 1302 |
| 1303 JSONObject jsobj(js); |
| 1304 jsobj.AddProperty("type", "Success"); |
| 1305 jsobj.AddProperty("id", ""); |
| 1306 return true; |
| 1307 } |
| 1308 |
| 1309 |
1279 static bool HandleClassesFunctions(Isolate* isolate, const Class& cls, | 1310 static bool HandleClassesFunctions(Isolate* isolate, const Class& cls, |
1280 JSONStream* js) { | 1311 JSONStream* js) { |
1281 if (js->num_arguments() != 4 && js->num_arguments() != 5) { | 1312 if (js->num_arguments() != 4 && js->num_arguments() != 5) { |
1282 PrintError(js, "Command should have 4 or 5 arguments"); | 1313 PrintError(js, "Command should have 4 or 5 arguments"); |
1283 return true; | 1314 return true; |
1284 } | 1315 } |
1285 const char* encoded_id = js->GetArgument(3); | 1316 const char* encoded_id = js->GetArgument(3); |
1286 String& id = String::Handle(isolate, String::New(encoded_id)); | 1317 String& id = String::Handle(isolate, String::New(encoded_id)); |
1287 id = String::DecodeIRI(id); | 1318 id = String::DecodeIRI(id); |
1288 if (id.IsNull()) { | 1319 if (id.IsNull()) { |
1289 PrintError(js, "Function id %s is malformed", encoded_id); | 1320 PrintError(js, "Function id %s is malformed", encoded_id); |
1290 return true; | 1321 return true; |
1291 } | 1322 } |
1292 Function& func = Function::Handle(cls.LookupFunction(id)); | 1323 Function& func = Function::Handle(cls.LookupFunction(id)); |
1293 if (func.IsNull()) { | 1324 if (func.IsNull()) { |
1294 PrintError(js, "Function %s not found", encoded_id); | 1325 PrintError(js, "Function %s not found", encoded_id); |
1295 return true; | 1326 return true; |
1296 } | 1327 } |
1297 if (js->num_arguments() == 4) { | 1328 if (js->num_arguments() == 4) { |
1298 func.PrintJSON(js, false); | 1329 func.PrintJSON(js, false); |
1299 return true; | 1330 return true; |
1300 } else { | 1331 } else { |
1301 const char* subcollection = js->GetArgument(4); | 1332 const char* subcommand = js->GetArgument(4); |
1302 if (strcmp(subcollection, "coverage") == 0) { | 1333 if (strcmp(subcommand, "coverage") == 0) { |
1303 return HandleClassesFunctionsCoverage(isolate, func, js); | 1334 return HandleClassesFunctionsCoverage(isolate, func, js); |
| 1335 } else if (strcmp(subcommand, "set_source") == 0) { |
| 1336 return HandleFunctionSetSource(isolate, cls, func, js); |
1304 } else { | 1337 } else { |
1305 PrintError(js, "Invalid sub collection %s", subcollection); | 1338 PrintError(js, "Invalid sub command %s", subcommand); |
1306 return true; | 1339 return true; |
1307 } | 1340 } |
1308 } | 1341 } |
1309 UNREACHABLE(); | 1342 UNREACHABLE(); |
1310 return true; | 1343 return true; |
1311 } | 1344 } |
1312 | 1345 |
1313 | 1346 |
1314 static bool HandleClassesImplicitClosures(Isolate* isolate, const Class& cls, | 1347 static bool HandleClassesImplicitClosures(Isolate* isolate, const Class& cls, |
1315 JSONStream* js) { | 1348 JSONStream* js) { |
(...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2746 while (current != NULL) { | 2779 while (current != NULL) { |
2747 if (strcmp(name, current->name()) == 0) { | 2780 if (strcmp(name, current->name()) == 0) { |
2748 return current; | 2781 return current; |
2749 } | 2782 } |
2750 current = current->next(); | 2783 current = current->next(); |
2751 } | 2784 } |
2752 return NULL; | 2785 return NULL; |
2753 } | 2786 } |
2754 | 2787 |
2755 } // namespace dart | 2788 } // namespace dart |
OLD | NEW |