From a65cdac516f749874a635ad3a30596a674c83b7f Mon Sep 17 00:00:00 2001 From: chenkeyu Date: Fri, 4 Jul 2025 15:10:55 +0800 Subject: [PATCH] remove the checkof override field Issue: https://gitee.com/openharmony/arkcompiler_runtime_core/issues/ICK7PG?from=project-issue Signed-off-by: chenkeyu --- .../ets/runtime/intrinsics/helpers/json_helper.cpp | 10 ++-------- .../ets/runtime/intrinsics/helpers/json_helper.h | 3 +-- .../ets_func_tests/escompat/JsonAnnotationTest.ets | 6 +++++- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/static_core/plugins/ets/runtime/intrinsics/helpers/json_helper.cpp b/static_core/plugins/ets/runtime/intrinsics/helpers/json_helper.cpp index caf3225b43..53261eb7c0 100644 --- a/static_core/plugins/ets/runtime/intrinsics/helpers/json_helper.cpp +++ b/static_core/plugins/ets/runtime/intrinsics/helpers/json_helper.cpp @@ -75,13 +75,12 @@ void JSONStringifier::AppendJSONPointPrimitive(const PandaString &value, bool ha bool JSONStringifier::SerializeFields(EtsHandle &value) { bool hasContent = false; - auto keys = PandaUnorderedSet(); bool isSuccessful = false; value->GetClass()->EnumerateBaseClasses([&](EtsClass *c) { auto fields = c->GetRuntimeClass()->GetFields(); for (auto &field : fields) { - if (!HandleField(value, EtsField::FromRuntimeField(&field), hasContent, keys)) { + if (!HandleField(value, EtsField::FromRuntimeField(&field), hasContent)) { isSuccessful = false; return true; } @@ -522,8 +521,7 @@ bool JSONStringifier::SerializeObject(EtsHandle &value) } // CC-OFFNXT(huge_method[C++], G.FUN.01-CPP) solid logic -bool JSONStringifier::HandleField(EtsHandle &obj, EtsField *etsField, bool &hasContent, - PandaUnorderedSet &keys) +bool JSONStringifier::HandleField(EtsHandle &obj, EtsField *etsField, bool &hasContent) { if (etsField->IsStatic()) { return true; @@ -533,10 +531,6 @@ bool JSONStringifier::HandleField(EtsHandle &obj, EtsField *etsField, return false; } key_ = ResolveDisplayName(etsField); - if (keys.find(key_) != keys.end()) { - return false; - } - keys.insert(key_); auto coro = EtsCoroutine::GetCurrent(); auto etsType = etsField->GetEtsType(); diff --git a/static_core/plugins/ets/runtime/intrinsics/helpers/json_helper.h b/static_core/plugins/ets/runtime/intrinsics/helpers/json_helper.h index 2f40433b2c..e1c7f79c60 100644 --- a/static_core/plugins/ets/runtime/intrinsics/helpers/json_helper.h +++ b/static_core/plugins/ets/runtime/intrinsics/helpers/json_helper.h @@ -80,8 +80,7 @@ private: PandaString ResolveDisplayName(const EtsField *field); bool SerializeObject(EtsHandle &value); - bool HandleField(EtsHandle &obj, EtsField *field, bool &hasContent, - PandaUnorderedSet &keys); + bool HandleField(EtsHandle &obj, EtsField *field, bool &hasContent); bool CheckUnsupportedAnnotation(EtsField *field); diff --git a/static_core/plugins/ets/tests/ets_func_tests/escompat/JsonAnnotationTest.ets b/static_core/plugins/ets/tests/ets_func_tests/escompat/JsonAnnotationTest.ets index aaf8f5a328..ef1c814321 100644 --- a/static_core/plugins/ets/tests/ets_func_tests/escompat/JsonAnnotationTest.ets +++ b/static_core/plugins/ets/tests/ets_func_tests/escompat/JsonAnnotationTest.ets @@ -193,7 +193,11 @@ function jsonStringifyExtend() { let obj6: TestClass6 = new TestClass6() let obj7: TestClass7 = new TestClass7() let json6 = JSON.stringify(obj6) - arktest.assertEQ(json6, '{"name1":"class6","nickname":"class6_nickname"}') + /** + * Attention: after the overriding fields problem is solved, we should only have field in subclass + * the expected output should be "{"name1":"class6","nickname":"class6_nickname"}" + */ + arktest.assertEQ(json6, '{"name1":"class5","name1":"class6","nickname":"class6_nickname"}') let json7 = JSON.stringify(obj7) /** * Attention: after the overriding fields problem is solved, we should only have field in subclass -- Gitee