Index: runtime/vm/service.cc |
diff --git a/runtime/vm/service.cc b/runtime/vm/service.cc |
index 67dbae49f239a72f58f6b6e7f6f748b12051b18d..7468e6a5bd409dea0b18ea334ecd8a6446c00af4 100644 |
--- a/runtime/vm/service.cc |
+++ b/runtime/vm/service.cc |
@@ -22,6 +22,7 @@ |
#include "vm/object_graph.h" |
#include "vm/object_id_ring.h" |
#include "vm/object_store.h" |
+#include "vm/parser.h" |
#include "vm/port.h" |
#include "vm/profiler.h" |
#include "vm/reusable_handles.h" |
@@ -1276,6 +1277,33 @@ static bool HandleClassesFunctionsCoverage( |
} |
+static bool HandleFunctionSetSource( |
+ Isolate* isolate, const Class& cls, const Function& func, JSONStream* js) { |
+ if (js->LookupOption("source") == NULL) { |
+ PrintError(js, "set_source expects a 'source' option\n"); |
+ return true; |
+ } |
+ const String& source = |
+ String::Handle(String::New(js->LookupOption("source"))); |
+ const Object& result = Object::Handle( |
+ Parser::ParseFunctionFromSource(cls, source)); |
+ if (result.IsError()) { |
+ Error::Cast(result).PrintJSON(js, false); |
+ return true; |
+ } |
+ ASSERT(result.IsFunction()); |
+ |
+ // Replace function. |
+ cls.RemoveFunction(func); |
+ cls.AddFunction(Function::Cast(result)); |
+ |
+ JSONObject jsobj(js); |
+ jsobj.AddProperty("type", "Success"); |
+ jsobj.AddProperty("id", ""); |
+ return true; |
+} |
+ |
+ |
static bool HandleClassesFunctions(Isolate* isolate, const Class& cls, |
JSONStream* js) { |
if (js->num_arguments() != 4 && js->num_arguments() != 5) { |
@@ -1298,11 +1326,13 @@ static bool HandleClassesFunctions(Isolate* isolate, const Class& cls, |
func.PrintJSON(js, false); |
return true; |
} else { |
- const char* subcollection = js->GetArgument(4); |
- if (strcmp(subcollection, "coverage") == 0) { |
+ const char* subcommand = js->GetArgument(4); |
+ if (strcmp(subcommand, "coverage") == 0) { |
return HandleClassesFunctionsCoverage(isolate, func, js); |
+ } else if (strcmp(subcommand, "set_source") == 0) { |
+ return HandleFunctionSetSource(isolate, cls, func, js); |
} else { |
- PrintError(js, "Invalid sub collection %s", subcollection); |
+ PrintError(js, "Invalid sub command %s", subcommand); |
return true; |
} |
} |