From 401855fdd9e5d3c7a460791da7714257e36f6e0f Mon Sep 17 00:00:00 2001 From: huangfeijie Date: Fri, 14 Oct 2022 14:30:20 +0800 Subject: [PATCH] Issue: https://gitee.com/openharmony/arkcompiler_toolchain/issues/I5VQOK fix the value of Map and Set when delete elements in debugger fix the value of Map and Set when delete elements in debugger Signed-off-by: huangfeijie --- tooling/agent/runtime_impl.cpp | 29 +++++++++++++++++++---------- tooling/base/pt_types.cpp | 23 +++++++++++++++++------ 2 files changed, 36 insertions(+), 16 deletions(-) diff --git a/tooling/agent/runtime_impl.cpp b/tooling/agent/runtime_impl.cpp index 05f77015..b5b80670 100644 --- a/tooling/agent/runtime_impl.cpp +++ b/tooling/agent/runtime_impl.cpp @@ -556,18 +556,23 @@ void RuntimeImpl::GetMapValue(Local value, std::vector> *outPropertyDesc) { Local mapRef = value->ToObject(vm_); - int32_t len = mapRef->GetSize(); - Local jsValueRef = NumberRef::New(vm_, len); + int32_t size = mapRef->GetSize(); + int32_t len = mapRef->GetTotalElements(); + int32_t index = 0; + Local jsValueRef = NumberRef::New(vm_, size); SetKeyValue(jsValueRef, outPropertyDesc, "size"); - jsValueRef = ArrayRef::New(vm_, len); + jsValueRef = ArrayRef::New(vm_, size); for (int32_t i = 0; i < len; i++) { Local jsKey = mapRef->GetKey(vm_, i); + if (jsKey->IsHole()) { + continue; + } Local jsValue = mapRef->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, i, objRef); + ArrayRef::SetValueAt(vm_, jsValueRef, index++, objRef); } AddInternalProperties(jsValueRef, ArkInternalValueType::Entry); SetKeyValue(jsValueRef, outPropertyDesc, "[[Entries]]"); @@ -577,19 +582,23 @@ void RuntimeImpl::GetSetValue(Local value, std::vector> *outPropertyDesc) { Local setRef = value->ToObject(vm_); - int32_t len = setRef->GetSize(); - Local jsValueRef = NumberRef::New(vm_, len); + int32_t size = setRef->GetSize(); + int32_t len = setRef->GetTotalElements(); + int32_t index = 0; + Local jsValueRef = NumberRef::New(vm_, size); SetKeyValue(jsValueRef, outPropertyDesc, "size"); - jsValueRef = ArrayRef::New(vm_, len); + jsValueRef = ArrayRef::New(vm_, size); for (int32_t i = 0; i < len; i++) { Local elementRef = setRef->GetValue(vm_, i); - if (elementRef->IsObject()) { + 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, i, objRef); + ArrayRef::SetValueAt(vm_, jsValueRef, index++, objRef); } else { - ArrayRef::SetValueAt(vm_, jsValueRef, i, elementRef); + ArrayRef::SetValueAt(vm_, jsValueRef, index++, elementRef); } } AddInternalProperties(jsValueRef, ArkInternalValueType::Entry); diff --git a/tooling/base/pt_types.cpp b/tooling/base/pt_types.cpp index 0e7d5329..ed7531be 100644 --- a/tooling/base/pt_types.cpp +++ b/tooling/base/pt_types.cpp @@ -396,7 +396,8 @@ std::string ObjectRemoteObject::DescriptionForDate(const EcmaVM *ecmaVm, Local tagged) { - int32_t len = tagged->GetSize(); + int32_t len = tagged->GetTotalElements(); + int32_t index = 0; std::string description = "Map(" + std::to_string(len) + ")"; if (!len) { return description; @@ -406,6 +407,10 @@ std::string ObjectRemoteObject::DescriptionForMap(const EcmaVM *ecmaVm, Local jsVKey = tagged->GetKey(ecmaVm, i); + if (jsVKey->IsHole()) { + continue; + } + Local jsVValue = tagged->GetValue(ecmaVm, i); if (jsVKey->IsObject()) { description += "Object"; @@ -424,11 +429,12 @@ std::string ObjectRemoteObject::DescriptionForMap(const EcmaVM *ecmaVm, LocalToString(ecmaVm)->ToString(); } - if (i == len - 1 || i >= 4) { // 4:The count of elements - description += len > 5 ? ", ..." : ""; // 5:The count of elements + if (index == tagged->GetSize() - 1 || index >= 4) { // 4:The count of elements + description += tagged->GetSize() > 5 ? ", ..." : ""; // 5:The count of elements break; } description += ", "; + index++; } description += "}"; return description; @@ -436,7 +442,8 @@ std::string ObjectRemoteObject::DescriptionForMap(const EcmaVM *ecmaVm, Local tagged) { - int32_t len = tagged->GetSize(); + int32_t len = tagged->GetTotalElements(); + int32_t index = 0; std::string description = ("Set(" + std::to_string(tagged->GetSize()) + ")"); if (!len) { return description; @@ -446,6 +453,9 @@ std::string ObjectRemoteObject::DescriptionForSet(const EcmaVM *ecmaVm, Local jsValue = tagged->GetValue(ecmaVm, i); + if (jsValue->IsHole()) { + continue; + } // add Value if (jsValue->IsObject()) { description += "Object"; @@ -454,11 +464,12 @@ std::string ObjectRemoteObject::DescriptionForSet(const EcmaVM *ecmaVm, LocalToString(ecmaVm)->ToString(); } - if (i == len - 1 || i >= 4) { // 4:The count of elements - description += len > 5 ? ", ..." : ""; // 5:The count of elements + if (index == tagged->GetSize() - 1 || index >= 4) { // 4:The count of elements + description += tagged->GetSize() > 5 ? ", ..." : ""; // 5:The count of elements break; } description += ", "; + index++; } description += "}"; return description; -- Gitee