diff --git a/tooling/dynamic/base/pt_types.cpp b/tooling/dynamic/base/pt_types.cpp index 7e06aa47ae7ef7d879716a326450c0fc881c493f..3ba7af5df5fd687a85d11876d7a45132034c3e4b 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 682de66fe3a28da1a0a5e1b16b2b0a29707fb890..2907c0e5d213b00243733b3fa1905862d5546b01 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 10fd698a39a4951163fe33b5a0a5d9cdb47ebce6..1a5f875feddf092c3bfd87272399c78cdb7f4e8b 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);