From c9829cb363211fff7e86ebbb1c11076d436bcacc Mon Sep 17 00:00:00 2001 From: yang-19970325 Date: Wed, 7 Jun 2023 20:16:22 +0800 Subject: [PATCH] Support the display of container class Issue:#I7BR91 Signed-off-by: yang-19970325 Change-Id: Ia233100db28fc94ac84cf83b14717a624752aac9 --- tooling/agent/runtime_impl.cpp | 373 ++++++++++++++++++++++++++++++++- tooling/agent/runtime_impl.h | 29 +++ 2 files changed, 399 insertions(+), 3 deletions(-) diff --git a/tooling/agent/runtime_impl.cpp b/tooling/agent/runtime_impl.cpp index 60d1a5ff..11b24b6e 100644 --- a/tooling/agent/runtime_impl.cpp +++ b/tooling/agent/runtime_impl.cpp @@ -231,7 +231,56 @@ DispatchResponse RuntimeImpl::GetProperties(const GetPropertiesParams ¶ms, GetRegExpValue(value, outPropertyDesc); } else if (value->IsSet()) { GetSetValue(value, outPropertyDesc); + } else if (value->IsHashMap()) { + GetHashMapValue(value, outPropertyDesc); + } else if (value->IsHashSet()) { + GetHashSetValue(value, outPropertyDesc); + } else if (value->IsLightWeightMap()) { + GetLightWeightMapValue(value, outPropertyDesc); + } else if (value->IsLightWeightSet()) { + GetLightWeightSetValue(value, outPropertyDesc); + } else if (value->IsLinkedList()) { + GetLinkedListValue(value, outPropertyDesc); + } else if (value->IsList()) { + GetListValue(value, outPropertyDesc); + } else if (value->IsPlainArray()) { + GetPlainArrayValue(value, outPropertyDesc); + } else if (value->IsTreeMap()) { + GetTreeMapValue(value, outPropertyDesc); + } else if (value->IsTreeSet()) { + GetTreeSetValue(value, outPropertyDesc); + } else if (value->IsArrayList()) { + GetArrayListValue(value, outPropertyDesc); + if (!skipProto) { + GetProtoOrProtoType(value, isOwn, isAccessorOnly, outPropertyDesc); + } + return DispatchResponse::Ok(); + } else if (value->IsDeque()) { + GetDequeValue(value, outPropertyDesc); + if (!skipProto) { + GetProtoOrProtoType(value, isOwn, isAccessorOnly, outPropertyDesc); + } + return DispatchResponse::Ok(); + } else if (value->IsQueue()) { + GetQueueValue(value, outPropertyDesc); + if (!skipProto) { + GetProtoOrProtoType(value, isOwn, isAccessorOnly, outPropertyDesc); + } + return DispatchResponse::Ok(); + } else if (value->IsStack()) { + GetStackValue(value, outPropertyDesc); + if (!skipProto) { + GetProtoOrProtoType(value, isOwn, isAccessorOnly, outPropertyDesc); + } + return DispatchResponse::Ok(); + } else if (value->IsVector()) { + GetVectorValue(value, outPropertyDesc); + if (!skipProto) { + GetProtoOrProtoType(value, isOwn, isAccessorOnly, outPropertyDesc); + } + return DispatchResponse::Ok(); } + Local keys = Local(value)->GetOwnPropertyNames(vm_); int32_t length = keys->Length(vm_); Local name = JSValueRef::Undefined(vm_); @@ -406,7 +455,7 @@ void RuntimeImpl::GetAdditionalProperties(Local value, LOG_DEBUGGER(ERROR) << "The length of the TypedArray is non-compliant or unsupported."; return; } - for (uint32_t i = 0; i < lengthTypedArray; i++) { + for (uint32_t i = 0; i < lengthTypedArray; ++i) { Local localValRefElement = localTypedArrayRef->Get(vm_, i); std::unique_ptr remoteObjElement = RemoteObject::FromTagged(vm_, localValRefElement); remoteObjElement->SetObjectId(curObjectId_); @@ -562,7 +611,7 @@ void RuntimeImpl::GetMapValue(Local value, Local jsValueRef = NumberRef::New(vm_, size); SetKeyValue(jsValueRef, outPropertyDesc, "size"); jsValueRef = ArrayRef::New(vm_, size); - for (int32_t i = 0; i < len; i++) { + for (int32_t i = 0; i < len; ++i) { Local jsKey = mapRef->GetKey(vm_, i); if (jsKey->IsHole()) { continue; @@ -588,7 +637,7 @@ void RuntimeImpl::GetSetValue(Local value, Local jsValueRef = NumberRef::New(vm_, size); SetKeyValue(jsValueRef, outPropertyDesc, "size"); jsValueRef = ArrayRef::New(vm_, size); - for (int32_t i = 0; i < len; i++) { + for (int32_t i = 0; i < len; ++i) { Local elementRef = setRef->GetValue(vm_, i); if (elementRef->IsHole()) { continue; @@ -629,4 +678,322 @@ void RuntimeImpl::GetRegExpValue(Local value, jsValueRef = StringRef::NewFromUtf8(vm_, strSource.c_str()); SetKeyValue(jsValueRef, outPropertyDesc, "source"); } + +void RuntimeImpl::GetArrayListValue(Local value, + std::vector> *outPropertyDesc) +{ + Local arrayListRef = value->ToObject(vm_); + int32_t size = arrayListRef->GetSize(); + int32_t index = 0; + Local jsValueRef = NumberRef::New(vm_, size); + SetKeyValue(jsValueRef, outPropertyDesc, "size"); + jsValueRef = ArrayRef::New(vm_, size); + for (int32_t i = 0; i < size; ++i) { + Local elementRef = arrayListRef->GetValue(vm_, i); + if (elementRef->IsHole()) { + continue; + } + ArrayRef::SetValueAt(vm_, jsValueRef, index++, elementRef); + } + AddInternalProperties(jsValueRef, ArkInternalValueType::Entry); + SetKeyValue(jsValueRef, outPropertyDesc, "[[ArrayList]]"); +} + +void RuntimeImpl::GetDequeValue(Local value, + std::vector> *outPropertyDesc) +{ + Local dequeRef = value->ToObject(vm_); + int32_t size = dequeRef->GetSize(); + int32_t index = 0; + Local jsValueRef = NumberRef::New(vm_, size); + SetKeyValue(jsValueRef, outPropertyDesc, "size"); + jsValueRef = ArrayRef::New(vm_, size); + for (int32_t i = 0; i < size; ++i) { + Local elementRef = dequeRef->GetValue(vm_, i); + if (elementRef->IsHole()) { + continue; + } + ArrayRef::SetValueAt(vm_, jsValueRef, index++, elementRef); + } + AddInternalProperties(jsValueRef, ArkInternalValueType::Entry); + SetKeyValue(jsValueRef, outPropertyDesc, "[[Deque]]"); +} + +void RuntimeImpl::GetHashMapValue(Local value, + std::vector> *outPropertyDesc) +{ + Local hashMapRef = value->ToObject(vm_); + int32_t size = hashMapRef->GetSize(); + int32_t index = 0; + Local jsValueRef = NumberRef::New(vm_, size); + SetKeyValue(jsValueRef, outPropertyDesc, "size"); + jsValueRef = ArrayRef::New(vm_, size); + for (int32_t i = 0; i < size; ++i) { + Local jsKey = hashMapRef->GetKey(vm_, i); + if (jsKey->IsHole()) { + continue; + } + Local jsValue = hashMapRef->GetValue(vm_, jsKey); + Local objRef = ObjectRef::New(vm_); + objRef->Set(vm_, StringRef::NewFromUtf8(vm_, "key"), jsKey); + objRef->Set(vm_, StringRef::NewFromUtf8(vm_, "value"), jsValue); + AddInternalProperties(objRef, ArkInternalValueType::Entry); + ArrayRef::SetValueAt(vm_, jsValueRef, index++, objRef); + } + AddInternalProperties(jsValueRef, ArkInternalValueType::Entry); + SetKeyValue(jsValueRef, outPropertyDesc, "[[HashMap]]"); +} + +void RuntimeImpl::GetHashSetValue(Local value, + std::vector> *outPropertyDesc) +{ + Local hashSetRef = value->ToObject(vm_); + int32_t size = hashSetRef->GetSize(); + int32_t index = 0; + Local jsValueRef = NumberRef::New(vm_, size); + SetKeyValue(jsValueRef, outPropertyDesc, "size"); + jsValueRef = ArrayRef::New(vm_, size); + for (int32_t i = 0; i < size; ++i) { + Local elementRef = hashSetRef->GetValue(vm_, i); + if (elementRef->IsHole()) { + continue; + } else if (elementRef->IsObject()) { + Local objRef = ObjectRef::New(vm_); + objRef->Set(vm_, StringRef::NewFromUtf8(vm_, "value"), elementRef); + AddInternalProperties(objRef, ArkInternalValueType::Entry); + ArrayRef::SetValueAt(vm_, jsValueRef, index++, objRef); + } else { + ArrayRef::SetValueAt(vm_, jsValueRef, index++, elementRef); + } + } + AddInternalProperties(jsValueRef, ArkInternalValueType::Entry); + SetKeyValue(jsValueRef, outPropertyDesc, "[[HashSet]]"); +} + +void RuntimeImpl::GetLightWeightMapValue(Local value, + std::vector> *outPropertyDesc) +{ + Local lightWeightMapRef = value->ToObject(vm_); + int32_t size = lightWeightMapRef->GetSize(); + int32_t index = 0; + Local jsValueRef = NumberRef::New(vm_, size); + SetKeyValue(jsValueRef, outPropertyDesc, "size"); + jsValueRef = ArrayRef::New(vm_, size); + for (int32_t i = 0; i < size; ++i) { + Local jsKey = lightWeightMapRef->GetKey(vm_, i); + if (jsKey->IsHole()) { + continue; + } + Local jsValue = lightWeightMapRef->GetValue(vm_, i); + Local objRef = ObjectRef::New(vm_); + objRef->Set(vm_, StringRef::NewFromUtf8(vm_, "key"), jsKey); + objRef->Set(vm_, StringRef::NewFromUtf8(vm_, "value"), jsValue); + AddInternalProperties(objRef, ArkInternalValueType::Entry); + ArrayRef::SetValueAt(vm_, jsValueRef, index++, objRef); + } + AddInternalProperties(jsValueRef, ArkInternalValueType::Entry); + SetKeyValue(jsValueRef, outPropertyDesc, "[[LightWeightMap]]"); +} + +void RuntimeImpl::GetLightWeightSetValue(Local value, + std::vector> *outPropertyDesc) +{ + Local lightWeightSetRef = value->ToObject(vm_); + int32_t size = lightWeightSetRef->GetSize(); + int32_t index = 0; + Local jsValueRef = NumberRef::New(vm_, size); + SetKeyValue(jsValueRef, outPropertyDesc, "size"); + jsValueRef = ArrayRef::New(vm_, size); + for (int32_t i = 0; i < size; ++i) { + Local elementRef = lightWeightSetRef->GetValue(vm_, i); + if (elementRef->IsHole()) { + continue; + } else if (elementRef->IsObject()) { + Local objRef = ObjectRef::New(vm_); + objRef->Set(vm_, StringRef::NewFromUtf8(vm_, "value"), elementRef); + AddInternalProperties(objRef, ArkInternalValueType::Entry); + ArrayRef::SetValueAt(vm_, jsValueRef, index++, objRef); + } else { + ArrayRef::SetValueAt(vm_, jsValueRef, index++, elementRef); + } + } + AddInternalProperties(jsValueRef, ArkInternalValueType::Entry); + SetKeyValue(jsValueRef, outPropertyDesc, "[[LightWeightSet]]"); +} + +void RuntimeImpl::GetLinkedListValue(Local value, + std::vector> *outPropertyDesc) +{ + Local linkedListRef = value->ToObject(vm_); + int32_t size = linkedListRef->GetSize(); + int32_t index = 0; + Local jsValueRef = NumberRef::New(vm_, size); + SetKeyValue(jsValueRef, outPropertyDesc, "size"); + jsValueRef = ArrayRef::New(vm_, size); + for (int32_t i = 0; i < size; ++i) { + Local elementRef = linkedListRef->GetValue(vm_, i); + if (elementRef->IsHole()) { + continue; + } + ArrayRef::SetValueAt(vm_, jsValueRef, index++, elementRef); + } + AddInternalProperties(jsValueRef, ArkInternalValueType::Entry); + SetKeyValue(jsValueRef, outPropertyDesc, "[[LinkedList]]"); +} + +void RuntimeImpl::GetListValue(Local value, + std::vector> *outPropertyDesc) +{ + Local listRef = value->ToObject(vm_); + int32_t size = listRef->GetSize(); + int32_t index = 0; + Local jsValueRef = NumberRef::New(vm_, size); + SetKeyValue(jsValueRef, outPropertyDesc, "size"); + jsValueRef = ArrayRef::New(vm_, size); + for (int32_t i = 0; i < size; ++i) { + Local elementRef = listRef->GetValue(vm_, i); + if (elementRef->IsHole()) { + continue; + } + ArrayRef::SetValueAt(vm_, jsValueRef, index++, elementRef); + } + AddInternalProperties(jsValueRef, ArkInternalValueType::Entry); + SetKeyValue(jsValueRef, outPropertyDesc, "[[List]]"); +} + +void RuntimeImpl::GetPlainArrayValue(Local value, + std::vector> *outPropertyDesc) +{ + Local plainArrayRef = value->ToObject(vm_); + int32_t size = plainArrayRef->GetSize(); + int32_t index = 0; + Local jsValueRef = NumberRef::New(vm_, size); + SetKeyValue(jsValueRef, outPropertyDesc, "size"); + jsValueRef = ArrayRef::New(vm_, size); + for (int32_t i = 0; i < size; ++i) { + Local jsKey = plainArrayRef->GetKey(vm_, i); + if (jsKey->IsHole()) { + continue; + } + Local jsValue = plainArrayRef->GetValue(vm_, i); + Local objRef = ObjectRef::New(vm_); + objRef->Set(vm_, StringRef::NewFromUtf8(vm_, "key"), jsKey); + objRef->Set(vm_, StringRef::NewFromUtf8(vm_, "value"), jsValue); + AddInternalProperties(objRef, ArkInternalValueType::Entry); + ArrayRef::SetValueAt(vm_, jsValueRef, index++, objRef); + } + AddInternalProperties(jsValueRef, ArkInternalValueType::Entry); + SetKeyValue(jsValueRef, outPropertyDesc, "[[PlainArray]]"); +} + +void RuntimeImpl::GetQueueValue(Local value, + std::vector> *outPropertyDesc) +{ + Local queueRef = value->ToObject(vm_); + int32_t size = queueRef->GetSize(); + int32_t index = 0; + Local jsValueRef = NumberRef::New(vm_, size); + SetKeyValue(jsValueRef, outPropertyDesc, "size"); + jsValueRef = ArrayRef::New(vm_, size); + for (int32_t i = 0; i < size; ++i) { + Local elementRef = queueRef->GetValue(vm_, i); + if (elementRef->IsHole()) { + continue; + } + ArrayRef::SetValueAt(vm_, jsValueRef, index++, elementRef); + } + AddInternalProperties(jsValueRef, ArkInternalValueType::Entry); + SetKeyValue(jsValueRef, outPropertyDesc, "[[Queue]]"); +} + +void RuntimeImpl::GetStackValue(Local value, + std::vector> *outPropertyDesc) +{ + Local stackRef = value->ToObject(vm_); + int32_t size = stackRef->GetSize() + 1; + int32_t index = 0; + Local jsValueRef = NumberRef::New(vm_, size); + SetKeyValue(jsValueRef, outPropertyDesc, "size"); + jsValueRef = ArrayRef::New(vm_, size); + for (int32_t i = 0; i < size; i++) { + Local elementRef = stackRef->GetValue(vm_, i); + if (elementRef->IsHole()) { + continue; + } + ArrayRef::SetValueAt(vm_, jsValueRef, index++, elementRef); + } + AddInternalProperties(jsValueRef, ArkInternalValueType::Entry); + SetKeyValue(jsValueRef, outPropertyDesc, "[[Stack]]"); +} + +void RuntimeImpl::GetTreeMapValue(Local value, + std::vector> *outPropertyDesc) +{ + Local treeMapRef = value->ToObject(vm_); + int32_t size = treeMapRef->GetSize(); + int32_t index = 0; + Local jsValueRef = NumberRef::New(vm_, size); + SetKeyValue(jsValueRef, outPropertyDesc, "size"); + jsValueRef = ArrayRef::New(vm_, size); + for (int32_t i = 0; i < size; ++i) { + Local jsKey = treeMapRef->GetKey(vm_, i); + if (jsKey->IsHole()) { + continue; + } + Local jsValue = treeMapRef->GetValue(vm_, i); + Local objRef = ObjectRef::New(vm_); + objRef->Set(vm_, StringRef::NewFromUtf8(vm_, "key"), jsKey); + objRef->Set(vm_, StringRef::NewFromUtf8(vm_, "value"), jsValue); + AddInternalProperties(objRef, ArkInternalValueType::Entry); + ArrayRef::SetValueAt(vm_, jsValueRef, index++, objRef); + } + AddInternalProperties(jsValueRef, ArkInternalValueType::Entry); + SetKeyValue(jsValueRef, outPropertyDesc, "[[TreeMap]]"); +} + +void RuntimeImpl::GetTreeSetValue(Local value, + std::vector> *outPropertyDesc) +{ + Local treeSetRef = value->ToObject(vm_); + int32_t size = treeSetRef->GetSize(); + int32_t index = 0; + Local jsValueRef = NumberRef::New(vm_, size); + SetKeyValue(jsValueRef, outPropertyDesc, "size"); + jsValueRef = ArrayRef::New(vm_, size); + for (int32_t i = 0; i < size; ++i) { + Local elementRef = treeSetRef->GetValue(vm_, i); + if (elementRef->IsHole()) { + continue; + } else if (elementRef->IsObject()) { + Local objRef = ObjectRef::New(vm_); + objRef->Set(vm_, StringRef::NewFromUtf8(vm_, "value"), elementRef); + AddInternalProperties(objRef, ArkInternalValueType::Entry); + ArrayRef::SetValueAt(vm_, jsValueRef, index++, objRef); + } else { + ArrayRef::SetValueAt(vm_, jsValueRef, index++, elementRef); + } + } + AddInternalProperties(jsValueRef, ArkInternalValueType::Entry); + SetKeyValue(jsValueRef, outPropertyDesc, "[[TreeSet]]"); +} + +void RuntimeImpl::GetVectorValue(Local value, + std::vector> *outPropertyDesc) +{ + Local vectorRef = value->ToObject(vm_); + int32_t size = vectorRef->GetSize(); + int32_t index = 0; + Local jsValueRef = NumberRef::New(vm_, size); + SetKeyValue(jsValueRef, outPropertyDesc, "size"); + jsValueRef = ArrayRef::New(vm_, size); + for (int32_t i = 0; i < size; ++i) { + Local elementRef = vectorRef->GetValue(vm_, i); + if (elementRef->IsHole()) { + continue; + } + ArrayRef::SetValueAt(vm_, jsValueRef, index++, elementRef); + } + AddInternalProperties(jsValueRef, ArkInternalValueType::Entry); + SetKeyValue(jsValueRef, outPropertyDesc, "[[Vector]]"); +} } // namespace panda::ecmascript::tooling \ No newline at end of file diff --git a/tooling/agent/runtime_impl.h b/tooling/agent/runtime_impl.h index cf6b0c8a..5cc8688d 100644 --- a/tooling/agent/runtime_impl.h +++ b/tooling/agent/runtime_impl.h @@ -114,6 +114,35 @@ private: std::vector> *outPropertyDesc); void GetRegExpValue(Local value, std::vector> *outPropertyDesc); + void GetArrayListValue(Local value, + std::vector> *outPropertyDesc); + void GetDequeValue(Local value, + std::vector> *outPropertyDesc); + void GetHashMapValue(Local value, + std::vector> *outPropertyDesc); + void GetHashSetValue(Local value, + std::vector> *outPropertyDesc); + void GetLightWeightMapValue(Local value, + std::vector> *outPropertyDesc); + void GetLightWeightSetValue(Local value, + std::vector> *outPropertyDesc); + void GetLinkedListValue(Local value, + std::vector> *outPropertyDesc); + void GetListValue(Local value, + std::vector> *outPropertyDesc); + void GetStackValue(Local value, + std::vector> *outPropertyDesc); + void GetPlainArrayValue(Local value, + std::vector> *outPropertyDesc); + void GetQueueValue(Local value, + std::vector> *outPropertyDesc); + void GetTreeMapValue(Local value, + std::vector> *outPropertyDesc); + void GetTreeSetValue(Local value, + std::vector> *outPropertyDesc); + void GetVectorValue(Local value, + std::vector> *outPropertyDesc); + class Frontend { public: explicit Frontend(ProtocolChannel *channel) : channel_(channel) {} -- Gitee