diff --git a/tooling/agent/runtime_impl.cpp b/tooling/agent/runtime_impl.cpp index 05f7701523412ea4127c770a3a4d16f0b16cf27e..b5b80670f9887f487670fb387e69b6cc01c56373 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 0e7d5329be3b4af7d1dca82933b7fd66d83081a7..ed7531be382e1f4d42baa12b8ae1dab94fa4cd31 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;