mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2025-02-17 10:18:13 +00:00
commit
66cb954d49
@ -292,6 +292,8 @@ JSTaggedValue JsonStringifier::SerializeJSONProperty(const JSHandle<JSTaggedValu
|
||||
}
|
||||
case JSType::JS_API_LINKED_LIST: {
|
||||
JSHandle listHandle = JSHandle<JSAPILinkedList>(thread_, tagValue);
|
||||
CheckStackPushSameValue(valHandle);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_);
|
||||
valHandle = JSHandle<JSTaggedValue>(thread_, JSAPILinkedList::ConvertToArray(thread_, listHandle));
|
||||
SerializeJSONObject(valHandle, replacer);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_);
|
||||
@ -299,6 +301,8 @@ JSTaggedValue JsonStringifier::SerializeJSONProperty(const JSHandle<JSTaggedValu
|
||||
}
|
||||
case JSType::JS_API_LIST: {
|
||||
JSHandle listHandle = JSHandle<JSAPIList>(thread_, tagValue);
|
||||
CheckStackPushSameValue(valHandle);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_);
|
||||
valHandle = JSHandle<JSTaggedValue>(thread_, JSAPIList::ConvertToArray(thread_, listHandle));
|
||||
SerializeJSONObject(valHandle, replacer);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_);
|
||||
@ -346,6 +350,8 @@ JSTaggedValue JsonStringifier::SerializeJSONProperty(const JSHandle<JSTaggedValu
|
||||
SerializeJSProxy(valHandle, replacer);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_);
|
||||
} else {
|
||||
CheckStackPushSameValue(valHandle);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_);
|
||||
SerializeJSONObject(valHandle, replacer);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_);
|
||||
}
|
||||
@ -406,11 +412,6 @@ void JsonStringifier::PopValue()
|
||||
|
||||
bool JsonStringifier::SerializeJSONObject(const JSHandle<JSTaggedValue> &value, const JSHandle<JSTaggedValue> &replacer)
|
||||
{
|
||||
bool isContain = PushValue(value);
|
||||
if (isContain) {
|
||||
THROW_TYPE_ERROR_AND_RETURN(thread_, "stack contains value, usually caused by circular structure", true);
|
||||
}
|
||||
|
||||
CString stepback = indent_;
|
||||
indent_ += gap_;
|
||||
|
||||
@ -939,4 +940,14 @@ bool JsonStringifier::AppendJsonString(const JSHandle<JSObject> &obj, const JSHa
|
||||
}
|
||||
return hasContent;
|
||||
}
|
||||
|
||||
bool JsonStringifier::CheckStackPushSameValue(JSHandle<JSTaggedValue> value)
|
||||
{
|
||||
bool isContain = PushValue(value);
|
||||
if (isContain) {
|
||||
THROW_TYPE_ERROR_AND_RETURN(thread_, "stack contains value, usually caused by circular structure", true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace panda::ecmascript::base
|
||||
|
@ -70,6 +70,7 @@ private:
|
||||
bool SerializeKeys(const JSHandle<JSObject> &obj, const JSHandle<JSTaggedValue> &replacer, bool hasContent);
|
||||
JSHandle<JSTaggedValue> SerializeHolder(const JSHandle<JSTaggedValue> &object,
|
||||
const JSHandle<JSTaggedValue> &value);
|
||||
bool CheckStackPushSameValue(JSHandle<JSTaggedValue> value);
|
||||
CString gap_;
|
||||
CString result_;
|
||||
CString indent_;
|
||||
|
@ -41,3 +41,4 @@ true
|
||||
{"a":"a","b":"b"}
|
||||
TypeError
|
||||
true
|
||||
TypeError: stack contains value, usually caused by circular structure
|
||||
|
@ -247,3 +247,13 @@ try {
|
||||
print(err.name);
|
||||
print(err.message.includes("circular structure"));
|
||||
}
|
||||
|
||||
try {
|
||||
let arkPrivate = globalThis.ArkPrivate;
|
||||
var List = arkPrivate.Load(arkPrivate.List);
|
||||
const v10 = new List();
|
||||
v10.add(v10);
|
||||
print(JSON.stringify(v10));
|
||||
} catch (err) {
|
||||
print(err);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user