From b07e6882c4955ca40de7932f8277a08fc111264f Mon Sep 17 00:00:00 2001 From: huangtianzhi Date: Thu, 11 Sep 2025 20:34:45 +0800 Subject: [PATCH] Fix display of anonymous function in debugger Issue: ICXLXW Signed-off-by: huangtianzhi --- tooling/dynamic/base/pt_types.cpp | 8 +++++++- tooling/dynamic/base/pt_types.h | 2 ++ tooling/dynamic/test/pt_types_test.cpp | 12 ++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/tooling/dynamic/base/pt_types.cpp b/tooling/dynamic/base/pt_types.cpp index 7e06aa47..3ba7af5d 100644 --- a/tooling/dynamic/base/pt_types.cpp +++ b/tooling/dynamic/base/pt_types.cpp @@ -1350,7 +1350,13 @@ std::unique_ptr PropertyDescriptor::FromProperty(const EcmaV debuggerProperty->name_ = nameStr; if (property.HasValue()) { - debuggerProperty->value_ = RemoteObject::FromTagged(ecmaVm, property.GetValue(ecmaVm)); + auto propValue = property.GetValue(ecmaVm); + if (propValue->IsFunction(ecmaVm) && nameStr.empty()) { + // if the value is a function and missing function name, + // fill the name of the debuggerProperty with + debuggerProperty->name_ = ANONYMOUS_FUNCTION_NAME_PLACEHOLDER; + } + debuggerProperty->value_ = RemoteObject::FromTagged(ecmaVm, propValue); } if (property.HasWritable()) { debuggerProperty->writable_ = property.IsWritable(); diff --git a/tooling/dynamic/base/pt_types.h b/tooling/dynamic/base/pt_types.h index 682de66f..2907c0e5 100644 --- a/tooling/dynamic/base/pt_types.h +++ b/tooling/dynamic/base/pt_types.h @@ -900,6 +900,8 @@ public: PropertyDescriptor() = default; ~PropertyDescriptor() override = default; + static constexpr std::string_view ANONYMOUS_FUNCTION_NAME_PLACEHOLDER = ""; + static std::unique_ptr FromProperty(const EcmaVM *ecmaVm, Local name, const PropertyAttribute &property); static std::unique_ptr Create(const PtJson ¶ms); diff --git a/tooling/dynamic/test/pt_types_test.cpp b/tooling/dynamic/test/pt_types_test.cpp index 10fd698a..1a5f875f 100644 --- a/tooling/dynamic/test/pt_types_test.cpp +++ b/tooling/dynamic/test/pt_types_test.cpp @@ -750,6 +750,18 @@ HWTEST_F_L0(PtTypesTest, PropertyDescriptorFromPropertyTest) ASSERT_TRUE(result); } +HWTEST_F_L0(PtTypesTest, AnonymousFunctionPropertyNameTest) +{ + Local func = FunctionRef::New(ecmaVm, nullptr); + Local funcName = JSValueRef::Hole(ecmaVm); + PropertyAttribute property = PropertyAttribute::Default(); + property.SetValue(func); + std::unique_ptr result = + panda::ecmascript::tooling::PropertyDescriptor::FromProperty(ecmaVm, funcName, property); + ASSERT_TRUE(result->GetName() == + panda::ecmascript::tooling::PropertyDescriptor::ANONYMOUS_FUNCTION_NAME_PLACEHOLDER); +} + HWTEST_F_L0(PtTypesTest, PtEventsGetReasonString) { PauseReason reason = static_cast(50); -- Gitee