Chromium Code Reviews| Index: runtime/vm/service.cc |
| diff --git a/runtime/vm/service.cc b/runtime/vm/service.cc |
| index d7cea4991ad05a93a842f2cf3b49552bc598a68a..a01f87285843786e83a20e26a7ec38f86858fd5e 100644 |
| --- a/runtime/vm/service.cc |
| +++ b/runtime/vm/service.cc |
| @@ -149,6 +149,14 @@ static void PrintCollectionErrorResponse(const char* collection_name, |
| } |
| +static void PrintGenericError(JSONStream* js) { |
| + JSONObject jsobj(js); |
| + jsobj.AddProperty("type", "error"); |
| + jsobj.AddProperty("text", "Invalid request."); |
| + PrintArgumentsAndOptions(jsobj, js); |
| +} |
| + |
| + |
| static void HandleName(Isolate* isolate, JSONStream* js) { |
| JSONObject jsobj(js); |
| jsobj.AddProperty("type", "IsolateName"); |
| @@ -197,6 +205,7 @@ static void HandleEcho(Isolate* isolate, JSONStream* js) { |
| PrintArgumentsAndOptions(jsobj, js); |
| } |
| + |
| // Print an error message if there is no ID argument. |
| #define REQUIRE_COLLECTION_ID(collection) \ |
| if (js->num_arguments() == 1) { \ |
| @@ -204,46 +213,46 @@ static void HandleEcho(Isolate* isolate, JSONStream* js) { |
| return; \ |
| } |
| -// Print a Dart object to the stream if found in ring. Otherwise print null. |
| -#define PRINT_RING_OBJ(type) \ |
| - ASSERT(js->num_arguments() >= 2); \ |
| - ObjectIdRing* ring = isolate->object_id_ring(); \ |
| - ASSERT(ring != NULL); \ |
| - intptr_t id = atoi(js->GetArgument(1)); \ |
| - Object& obj = Object::Handle(ring->GetObjectForId(id)); \ |
| - if (!obj.Is##type()) { \ |
| - /* Object is not type, replace with null. */ \ |
| - obj = Object::null(); \ |
| - } \ |
| - obj.PrintToJSONStream(js, false) |
| - |
| - |
| -static void HandleLibraries(Isolate* isolate, JSONStream* js) { |
| + |
| +static void HandleClasses(Isolate* isolate, JSONStream* js) { |
| if (js->num_arguments() == 1) { |
| - const Library& lib = |
| - Library::Handle(isolate->object_store()->root_library()); |
| - lib.PrintToJSONStream(js, true); |
| + ClassTable* table = isolate->class_table(); |
| + table->PrintToJSONStream(js); |
| + return; |
| + } |
| + REQUIRE_COLLECTION_ID("classes"); |
|
siva
2013/09/17 17:25:33
We have already checked and processed for
'if (js-
Cutch
2013/09/19 23:57:39
Done.
|
| + ASSERT(js->num_arguments() >= 2); |
| + intptr_t id = atoi(js->GetArgument(1)); |
| + ClassTable* table = isolate->class_table(); |
| + if (!table->IsValidIndex(id)) { |
| + Object& obj = Object::Handle(Object::null()); |
| + obj.PrintToJSONStream(js, false); |
|
siva
2013/09/17 17:25:33
You could do this as:
Object::null_object().Print
Cutch
2013/09/19 23:57:39
Done.
|
| } else { |
| - PRINT_RING_OBJ(Library); |
| + Class& cls = Class::Handle(table->At(id)); |
| + cls.PrintToJSONStream(js, false); |
| } |
| } |
| -static void HandleFunctions(Isolate* isolate, JSONStream* js) { |
| - REQUIRE_COLLECTION_ID("functions"); |
| - PRINT_RING_OBJ(Function); |
| -} |
| - |
| - |
| -static void HandleClasses(Isolate* isolate, JSONStream* js) { |
| - REQUIRE_COLLECTION_ID("classes"); |
| - PRINT_RING_OBJ(Class); |
| +static void HandleLibrary(Isolate* isolate, JSONStream* js) { |
| + if (js->num_arguments() == 1) { |
| + const Library& lib = |
| + Library::Handle(isolate->object_store()->root_library()); |
| + lib.PrintToJSONStream(js, false); |
| + return; |
| + } |
| + PrintGenericError(js); |
| } |
| -static void HandleCodes(Isolate* isolate, JSONStream* js) { |
| - REQUIRE_COLLECTION_ID("codes"); |
| - PRINT_RING_OBJ(Code); |
| +static void HandleObjects(Isolate* isolate, JSONStream* js) { |
| + REQUIRE_COLLECTION_ID("objects"); |
| + ASSERT(js->num_arguments() >= 2); |
| + ObjectIdRing* ring = isolate->object_id_ring(); |
| + ASSERT(ring != NULL); |
| + intptr_t id = atoi(js->GetArgument(1)); |
| + Object& obj = Object::Handle(ring->GetObjectForId(id)); |
| + obj.PrintToJSONStream(js, false); |
| } |
| @@ -251,10 +260,9 @@ static ServiceMessageHandlerEntry __message_handlers[] = { |
| { "name", HandleName }, |
| { "stacktrace", HandleStackTrace }, |
| { "objecthistogram", HandleObjectHistogram}, |
| - { "libraries", HandleLibraries }, |
| - { "functions", HandleFunctions }, |
| + { "library", HandleLibrary }, |
| { "classes", HandleClasses }, |
| - { "codes", HandleCodes }, |
| + { "objects", HandleObjects }, |
| { "_echo", HandleEcho }, |
| }; |