Chromium Code Reviews| Index: runtime/vm/service.cc |
| =================================================================== |
| --- runtime/vm/service.cc (revision 33387) |
| +++ runtime/vm/service.cc (working copy) |
| @@ -797,6 +797,40 @@ |
| } |
| +static bool HandleClassesTypes(Isolate* isolate, const Class& cls, |
| + JSONStream* js) { |
| + if (js->num_arguments() == 3) { |
| + JSONObject jsobj(js); |
| + jsobj.AddProperty("type", "TypeList"); |
| + JSONArray members(&jsobj, "members"); |
| + const intptr_t num_types = cls.NumCanonicalTypes(); |
| + Type& type = Type::Handle(); |
| + for (intptr_t i = 0; i < num_types; i++) { |
| + type = cls.CanonicalTypeFromIndex(i); |
| + members.AddValue(type); |
| + } |
| + return true; |
| + } |
| + intptr_t id; |
| + if (js->num_arguments() > 4) { |
| + PrintError(js, "Command too long"); |
| + return true; |
| + } |
| + if (!GetIntegerId(js->GetArgument(3), &id)) { |
| + PrintError(js, "Must specify collection object id: types/id"); |
| + return true; |
| + } |
| + Type& type = Type::Handle(); |
| + type ^= cls.CanonicalTypeFromIndex(id); |
| + if (type.IsNull()) { |
| + PrintError(js, "Canonical type %" Pd " not found", id); |
| + return true; |
| + } |
| + type.PrintToJSONStream(js, false); |
| + return true; |
| +} |
| + |
| + |
| static bool HandleClasses(Isolate* isolate, JSONStream* js) { |
| if (js->num_arguments() == 1) { |
| ClassTable* table = isolate->class_table(); |
| @@ -811,7 +845,7 @@ |
| } |
| ClassTable* table = isolate->class_table(); |
| if (!table->IsValidIndex(id)) { |
| - PrintError(js, "%" Pd " is not a valid class id.", id);; |
| + PrintError(js, "%" Pd " is not a valid class id.", id); |
| return true; |
| } |
| Class& cls = Class::Handle(table->At(id)); |
| @@ -830,6 +864,8 @@ |
| return HandleClassesImplicitClosures(isolate, cls, js); |
| } else if (strcmp(second, "dispatchers") == 0) { |
| return HandleClassesDispatchers(isolate, cls, js); |
| + } else if (!strcmp(second, "types")) { |
| + return HandleClassesTypes(isolate, cls, js); |
| } else { |
| PrintError(js, "Invalid sub collection %s", second); |
| return true; |
| @@ -1169,6 +1205,65 @@ |
| } |
| +static bool HandleTypeArguments(Isolate* isolate, JSONStream* js, |
| + bool only_with_instantiations) { |
| + ObjectStore* object_store = isolate->object_store(); |
| + const Array& table = Array::Handle(object_store->canonical_type_arguments()); |
| + ASSERT(table.Length() > 0); |
| + TypeArguments& type_args = TypeArguments::Handle(); |
| + const intptr_t table_size = table.Length() - 1; |
| + const intptr_t table_used = Smi::Value(Smi::RawCast(table.At(table_size))); |
| + if (js->num_arguments() == 1) { |
| + JSONObject jsobj(js); |
| + jsobj.AddProperty("type", "TypeArgumentsList"); |
| + jsobj.AddProperty("table_size", table_size); |
| + jsobj.AddProperty("table_used", table_used); |
| + const char* members_kind = only_with_instantiations ? |
| + "members with instantiations" : "members"; |
|
Cutch
2014/03/11 13:50:01
This should always be "members". Also, please do n
regis
2014/03/14 23:52:07
Done.
|
| + JSONArray members(&jsobj, members_kind); |
| + for (intptr_t i = 0; i < table_size; i++) { |
| + type_args ^= table.At(i); |
| + if (!type_args.IsNull()) { |
| + if (!only_with_instantiations || type_args.HasInstantiations()) { |
| + members.AddValue(type_args); |
| + } |
| + } |
| + } |
| + return true; |
| + } |
| + ASSERT(js->num_arguments() >= 2); |
| + if (only_with_instantiations) { |
| + PrintError(js, "Command too long"); |
| + return true; |
| + } |
| + intptr_t id; |
| + if (!GetIntegerId(js->GetArgument(1), &id)) { |
| + // Note that the table index of the canonical type arguments will change |
| + // when the table grows. Should we not support this access at all? |
| + PrintError(js, "Must specify collection object id: /typearguments/id"); |
| + return true; |
| + } |
| + if ((id < 0) || (id >= table_size) || (table.At(id) == Object::null())) { |
| + PrintError(js, "%" Pd " is not a valid typearguments id.", id); |
| + return true; |
| + } |
| + type_args ^= table.At(id); |
| + type_args.PrintToJSONStream(js, false); |
| + return true; |
| +} |
| + |
| + |
| +static bool HandleTypeArgumentsAll(Isolate* isolate, JSONStream* js) { |
| + return HandleTypeArguments(isolate, js, false); |
| +} |
| + |
| + |
| +static bool HandleTypeArgumentsWithInstantiations(Isolate* isolate, |
| + JSONStream* js) { |
| + return HandleTypeArguments(isolate, js, true); |
| +} |
| + |
| + |
| static IsolateMessageHandlerEntry isolate_handlers[] = { |
| { "_echo", HandleIsolateEcho }, |
| { "", HandleIsolate }, |
| @@ -1184,6 +1279,8 @@ |
| { "unpin", HandleUnpin }, |
| { "scripts", HandleScripts }, |
| { "stacktrace", HandleStackTrace }, |
| + { "typearguments", HandleTypeArgumentsAll }, |
| + { "typeargumentswithinstantiations", HandleTypeArgumentsWithInstantiations }, |
|
Cutch
2014/03/11 13:50:01
Does it make sense to make the "withinstantiations
regis
2014/03/14 23:52:07
Good idea. Done.
|
| }; |