From d6b3b8a6be8a42f7a85222b5a9cbb4657cb4c6a2 Mon Sep 17 00:00:00 2001 From: Alexander Markov Date: Mon, 19 Sep 2022 19:28:02 +0000 Subject: [PATCH] [vm] Initial vm-service support for records TEST=ci Issue: https://github.com/dart-lang/sdk/issues/49724 Change-Id: I8012390db004d3b9dd52a460a04bce79af3df365 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/259881 Reviewed-by: Ben Konyi Commit-Queue: Alexander Markov --- runtime/vm/object_service.cc | 43 +++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/runtime/vm/object_service.cc b/runtime/vm/object_service.cc index bdcc20c3625..de767c9b105 100644 --- a/runtime/vm/object_service.cc +++ b/runtime/vm/object_service.cc @@ -1243,7 +1243,7 @@ void FunctionType::PrintJSONImpl(JSONStream* stream, bool ref) const { void RecordType::PrintJSONImpl(JSONStream* stream, bool ref) const { JSONObject jsobj(stream); PrintSharedInstanceJSON(&jsobj, ref); - jsobj.AddProperty("kind", "RecordType"); + jsobj.AddProperty("kind", "_RecordType"); { JSONArray arr(&jsobj, "fields"); @@ -1258,6 +1258,8 @@ void RecordType::PrintJSONImpl(JSONStream* stream, bool ref) const { if (i >= num_positional_fields) { name = FieldNameAt(i - num_positional_fields); field.AddProperty("name", name.ToCString()); + } else { + field.AddProperty("pos", i); } } } @@ -1643,8 +1645,43 @@ void Closure::PrintJSONImpl(JSONStream* stream, bool ref) const { } void Record::PrintJSONImpl(JSONStream* stream, bool ref) const { - Instance::PrintJSONImpl(stream, ref); - // TODO(dartbug.com/49724) + JSONObject jsobj(stream); + PrintSharedInstanceJSON(&jsobj, ref); + jsobj.AddProperty("kind", "_Record"); + jsobj.AddProperty("numFields", num_fields()); + jsobj.AddServiceId(*this); + if (ref) { + return; + } + intptr_t offset; + intptr_t count; + stream->ComputeOffsetAndCount(num_fields(), &offset, &count); + if (offset > 0) { + jsobj.AddProperty("offset", offset); + } + if (count < num_fields()) { + jsobj.AddProperty("count", count); + } + intptr_t limit = offset + count; + ASSERT(limit <= num_fields()); + { + JSONArray jsarr(&jsobj, "fields"); + Object& obj = Object::Handle(); + String& name = String::Handle(); + const intptr_t num_positional_fields = NumPositionalFields(); + const Array& field_names = Array::Handle(this->field_names()); + for (intptr_t index = offset; index < limit; ++index) { + JSONObject field(&jsarr); + obj = FieldAt(index); + field.AddProperty("value", obj); + if (index >= num_positional_fields) { + name ^= field_names.At(index - num_positional_fields); + field.AddProperty("name", name); + } else { + field.AddProperty("pos", index); + } + } + } } void StackTrace::PrintJSONImpl(JSONStream* stream, bool ref) const {