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 ASSERT(result.IsFunction()); |
| 1295 |
| 1296 // Replace function. |
| 1297 cls.RemoveFunction(func); |
| 1298 cls.AddFunction(Function::Cast(result)); |
| 1299 |
| 1300 JSONObject jsobj(js); |
| 1301 jsobj.AddProperty("type", "Success"); |
| 1302 jsobj.AddProperty("id", ""); |
| 1303 return true; |
| 1304 } |
| 1305 |
| 1306 |
1279 static bool HandleClassesFunctions(Isolate* isolate, const Class& cls, | 1307 static bool HandleClassesFunctions(Isolate* isolate, const Class& cls, |
1280 JSONStream* js) { | 1308 JSONStream* js) { |
1281 if (js->num_arguments() != 4 && js->num_arguments() != 5) { | 1309 if (js->num_arguments() != 4 && js->num_arguments() != 5) { |
1282 PrintError(js, "Command should have 4 or 5 arguments"); | 1310 PrintError(js, "Command should have 4 or 5 arguments"); |
1283 return true; | 1311 return true; |
1284 } | 1312 } |
1285 const char* encoded_id = js->GetArgument(3); | 1313 const char* encoded_id = js->GetArgument(3); |
1286 String& id = String::Handle(isolate, String::New(encoded_id)); | 1314 String& id = String::Handle(isolate, String::New(encoded_id)); |
1287 id = String::DecodeIRI(id); | 1315 id = String::DecodeIRI(id); |
1288 if (id.IsNull()) { | 1316 if (id.IsNull()) { |
1289 PrintError(js, "Function id %s is malformed", encoded_id); | 1317 PrintError(js, "Function id %s is malformed", encoded_id); |
1290 return true; | 1318 return true; |
1291 } | 1319 } |
1292 Function& func = Function::Handle(cls.LookupFunction(id)); | 1320 Function& func = Function::Handle(cls.LookupFunction(id)); |
1293 if (func.IsNull()) { | 1321 if (func.IsNull()) { |
1294 PrintError(js, "Function %s not found", encoded_id); | 1322 PrintError(js, "Function %s not found", encoded_id); |
1295 return true; | 1323 return true; |
1296 } | 1324 } |
1297 if (js->num_arguments() == 4) { | 1325 if (js->num_arguments() == 4) { |
1298 func.PrintJSON(js, false); | 1326 func.PrintJSON(js, false); |
1299 return true; | 1327 return true; |
1300 } else { | 1328 } else { |
1301 const char* subcollection = js->GetArgument(4); | 1329 const char* subcommand = js->GetArgument(4); |
1302 if (strcmp(subcollection, "coverage") == 0) { | 1330 if (strcmp(subcommand, "coverage") == 0) { |
1303 return HandleClassesFunctionsCoverage(isolate, func, js); | 1331 return HandleClassesFunctionsCoverage(isolate, func, js); |
| 1332 } else if (strcmp(subcommand, "set_source") == 0) { |
| 1333 return HandleFunctionSetSource(isolate, cls, func, js); |
1304 } else { | 1334 } else { |
1305 PrintError(js, "Invalid sub collection %s", subcollection); | 1335 PrintError(js, "Invalid sub command %s", subcommand); |
1306 return true; | 1336 return true; |
1307 } | 1337 } |
1308 } | 1338 } |
1309 UNREACHABLE(); | 1339 UNREACHABLE(); |
1310 return true; | 1340 return true; |
1311 } | 1341 } |
1312 | 1342 |
1313 | 1343 |
1314 static bool HandleClassesImplicitClosures(Isolate* isolate, const Class& cls, | 1344 static bool HandleClassesImplicitClosures(Isolate* isolate, const Class& cls, |
1315 JSONStream* js) { | 1345 JSONStream* js) { |
(...skipping 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2745 while (current != NULL) { | 2775 while (current != NULL) { |
2746 if (strcmp(name, current->name()) == 0) { | 2776 if (strcmp(name, current->name()) == 0) { |
2747 return current; | 2777 return current; |
2748 } | 2778 } |
2749 current = current->next(); | 2779 current = current->next(); |
2750 } | 2780 } |
2751 return NULL; | 2781 return NULL; |
2752 } | 2782 } |
2753 | 2783 |
2754 } // namespace dart | 2784 } // namespace dart |
OLD | NEW |