| Index: runtime/vm/service.cc
|
| diff --git a/runtime/vm/service.cc b/runtime/vm/service.cc
|
| index bc77d04549fc2ab599b4a720b1b6748964416372..f964f963ea3356b65f12ae630afa602895293f7d 100644
|
| --- a/runtime/vm/service.cc
|
| +++ b/runtime/vm/service.cc
|
| @@ -738,6 +738,29 @@ static bool HandleClassesClosures(Isolate* isolate, const Class& cls,
|
| }
|
|
|
|
|
| +static bool HandleClassesEval(Isolate* isolate, const Class& cls,
|
| + JSONStream* js) {
|
| + if (js->num_arguments() > 3) {
|
| + PrintError(js, "Command too long");
|
| + return true;
|
| + }
|
| + const char* expr = js->LookupOption("expr");
|
| + if (expr == NULL) {
|
| + PrintError(js, "eval expects an 'expr' option\n",
|
| + js->num_arguments());
|
| + return true;
|
| + }
|
| + const String& expr_str = String::Handle(isolate, String::New(expr));
|
| + const Object& result = Object::Handle(cls.Evaluate(expr_str));
|
| + if (result.IsNull()) {
|
| + Object::null_instance().PrintToJSONStream(js, true);
|
| + } else {
|
| + result.PrintToJSONStream(js, true);
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +
|
| static bool HandleClassesDispatchers(Isolate* isolate, const Class& cls,
|
| JSONStream* js) {
|
| intptr_t id;
|
| @@ -848,7 +871,9 @@ static bool HandleClasses(Isolate* isolate, JSONStream* js) {
|
| return true;
|
| } else if (js->num_arguments() >= 3) {
|
| const char* second = js->GetArgument(2);
|
| - if (strcmp(second, "closures") == 0) {
|
| + if (strcmp(second, "eval") == 0) {
|
| + return HandleClassesEval(isolate, cls, js);
|
| + } else if (strcmp(second, "closures") == 0) {
|
| return HandleClassesClosures(isolate, cls, js);
|
| } else if (strcmp(second, "fields") == 0) {
|
| return HandleClassesFields(isolate, cls, js);
|
| @@ -868,6 +893,29 @@ static bool HandleClasses(Isolate* isolate, JSONStream* js) {
|
| }
|
|
|
|
|
| +static bool HandleLibrariesEval(Isolate* isolate, const Library& lib,
|
| + JSONStream* js) {
|
| + if (js->num_arguments() > 3) {
|
| + PrintError(js, "Command too long");
|
| + return true;
|
| + }
|
| + const char* expr = js->LookupOption("expr");
|
| + if (expr == NULL) {
|
| + PrintError(js, "eval expects an 'expr' option\n",
|
| + js->num_arguments());
|
| + return true;
|
| + }
|
| + const String& expr_str = String::Handle(isolate, String::New(expr));
|
| + const Object& result = Object::Handle(lib.Evaluate(expr_str));
|
| + if (result.IsNull()) {
|
| + Object::null_instance().PrintToJSONStream(js, true);
|
| + } else {
|
| + result.PrintToJSONStream(js, true);
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +
|
| static bool HandleLibraries(Isolate* isolate, JSONStream* js) {
|
| // TODO(johnmccutchan): Support fields and functions on libraries.
|
| REQUIRE_COLLECTION_ID("libraries");
|
| @@ -880,7 +928,19 @@ static bool HandleLibraries(Isolate* isolate, JSONStream* js) {
|
| Library& lib = Library::Handle();
|
| lib ^= libs.At(id);
|
| ASSERT(!lib.IsNull());
|
| - lib.PrintToJSONStream(js, false);
|
| + if (js->num_arguments() == 2) {
|
| + lib.PrintToJSONStream(js, false);
|
| + return true;
|
| + } else if (js->num_arguments() >= 3) {
|
| + const char* second = js->GetArgument(2);
|
| + if (strcmp(second, "eval") == 0) {
|
| + return HandleLibrariesEval(isolate, lib, js);
|
| + } else {
|
| + PrintError(js, "Invalid sub collection %s", second);
|
| + return true;
|
| + }
|
| + }
|
| + UNREACHABLE();
|
| return true;
|
| }
|
|
|
| @@ -1049,7 +1109,11 @@ static bool HandleObjects(Isolate* isolate, JSONStream* js) {
|
| ASSERT(obj.IsInstance());
|
| const Instance& instance = Instance::Cast(obj);
|
| const Object& result = Object::Handle(instance.Evaluate(expr_str));
|
| - result.PrintToJSONStream(js, true);
|
| + if (result.IsNull()) {
|
| + Object::null_instance().PrintToJSONStream(js, true);
|
| + } else {
|
| + result.PrintToJSONStream(js, true);
|
| + }
|
| return true;
|
| }
|
|
|
|
|