Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Unified Diff: runtime/vm/service.cc

Issue 751183003: Expose set_source service command for functions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/parser.cc ('k') | runtime/vm/service_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
}
« no previous file with comments | « runtime/vm/parser.cc ('k') | runtime/vm/service_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698