Index: runtime/vm/service.cc |
diff --git a/runtime/vm/service.cc b/runtime/vm/service.cc |
index 5404a3e174972accade51999bf47d4b80a087a98..5707da206d93330b48897669f0c326a1fe6fe5b8 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,36 @@ 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; |
+ } |
+ if (!result.IsFunction()) { |
+ PrintError(js, "source did not compile to a function.\n"); |
+ return true; |
+ } |
+ |
+ // 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 +1329,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; |
} |
} |