Bug Fix in JsonStringifier::SerializeKeys , Modified jshclass but did not convert to dictionary mode

Get all keys to arrKeys,Iterate over the arrKeys, taking advantage of the key values in the arrKeys, and update the jshclass after executing the get function。

issue : https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I894O5

Signed-off-by: hecunmao <hecunmao@huawei.com>
Change-Id: Ib2d84f9485fc3cab17afdd438fe86f944f51b2c9
This commit is contained in:
hecunmao 2023-10-18 18:32:00 +08:00 committed by 贺存茂
parent 7d95d4778c
commit 368fa0f66b
3 changed files with 13 additions and 1 deletions

View File

@ -777,6 +777,7 @@ bool JsonStringifier::SerializeKeys(const JSHandle<JSObject> &obj, const JSHandl
hasChangedToDictionaryMode = true;
propertiesArr = JSHandle<TaggedArray>(thread_, obj->GetProperties());
}
jsHclass = JSHandle<JSHClass>(thread_, obj->GetJSHClass());
}
handleValue_.Update(value);
hasContent = JsonStringifier::AppendJsonString(obj, replacer, hasContent);
@ -789,7 +790,7 @@ bool JsonStringifier::SerializeKeys(const JSHandle<JSObject> &obj, const JSHandl
continue;
}
PropertyAttributes attr = nameDic->GetAttributes(index);
if (!attr.IsEnumerable()) {
if (!attr.IsEnumerable() || index < 0) {
continue;
}
JSTaggedValue value = nameDic->GetValue(index);
@ -797,6 +798,7 @@ bool JsonStringifier::SerializeKeys(const JSHandle<JSObject> &obj, const JSHandl
if (UNLIKELY(value.IsAccessor())) {
value = JSObject::CallGetter(thread_, AccessorData::Cast(value.GetTaggedObject()),
JSHandle<JSTaggedValue>(obj));
jsHclass = JSHandle<JSHClass>(thread_, obj->GetJSHClass());
}
handleValue_.Update(value);
hasContent = JsonStringifier::AppendJsonString(obj, replacer, hasContent);

View File

@ -15,3 +15,4 @@ test successful
{"2147483648":2289}
{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0}
{"g":9,"f1":1,"f2":1,"f3":1,"f4":1,"f5":1,"f6":1,"f7":1,"f8":1}
{"g":8,"f2":1}

View File

@ -57,3 +57,12 @@ let o = {
"f8":1,
}
print(JSON.stringify(o))
let o2 = {
get g() {
delete this.f1;
return 8;
},
"f1":1,
"f2":1,
}
print(JSON.stringify(o2))