mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-11-23 01:59:58 +00:00
!10305 ASON stringify map 回退
Merge pull request !10305 from xusen/ason_20241119_rollback
This commit is contained in:
commit
6e75c61ed6
@ -17,15 +17,8 @@
|
||||
|
||||
#include "ecmascript/global_dictionary-inl.h"
|
||||
#include "ecmascript/interpreter/interpreter.h"
|
||||
#include "ecmascript/js_api/js_api_hashmap.h"
|
||||
#include "ecmascript/js_api/js_api_hashset.h"
|
||||
#include "ecmascript/js_map.h"
|
||||
#include "ecmascript/js_primitive_ref.h"
|
||||
#include "ecmascript/js_set.h"
|
||||
#include "ecmascript/object_fast_operator-inl.h"
|
||||
#include "ecmascript/shared_objects/js_shared_map.h"
|
||||
#include "ecmascript/shared_objects/js_shared_set.h"
|
||||
#include "ecmascript/tagged_hash_array.h"
|
||||
|
||||
namespace panda::ecmascript::base {
|
||||
constexpr int GAP_MAX_LEN = 10;
|
||||
@ -332,66 +325,6 @@ JSTaggedValue JsonStringifier::SerializeJSONProperty(const JSHandle<JSTaggedValu
|
||||
result_ += "{}";
|
||||
return tagValue;
|
||||
}
|
||||
case JSType::JS_SHARED_MAP: {
|
||||
if (transformType_ == TransformType::SENDABLE) {
|
||||
CheckStackPushSameValue(valHandle);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_);
|
||||
SerializeJSONSharedMap(valHandle, replacer);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_);
|
||||
return tagValue;
|
||||
}
|
||||
[[fallthrough]];
|
||||
}
|
||||
case JSType::JS_MAP: {
|
||||
if (transformType_ == TransformType::SENDABLE) {
|
||||
CheckStackPushSameValue(valHandle);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_);
|
||||
SerializeJSONMap(valHandle, replacer);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_);
|
||||
return tagValue;
|
||||
}
|
||||
[[fallthrough]];
|
||||
}
|
||||
case JSType::JS_SET: {
|
||||
if (transformType_ == TransformType::SENDABLE) {
|
||||
CheckStackPushSameValue(valHandle);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_);
|
||||
SerializeJSONSet(valHandle, replacer);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_);
|
||||
return tagValue;
|
||||
}
|
||||
[[fallthrough]];
|
||||
}
|
||||
case JSType::JS_SHARED_SET: {
|
||||
if (transformType_ == TransformType::SENDABLE) {
|
||||
CheckStackPushSameValue(valHandle);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_);
|
||||
SerializeJSONSharedSet(valHandle, replacer);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_);
|
||||
return tagValue;
|
||||
}
|
||||
[[fallthrough]];
|
||||
}
|
||||
case JSType::JS_API_HASH_MAP: {
|
||||
if (transformType_ == TransformType::SENDABLE) {
|
||||
CheckStackPushSameValue(valHandle);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_);
|
||||
SerializeJSONHashMap(valHandle, replacer);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_);
|
||||
return tagValue;
|
||||
}
|
||||
[[fallthrough]];
|
||||
}
|
||||
case JSType::JS_API_HASH_SET: {
|
||||
if (transformType_ == TransformType::SENDABLE) {
|
||||
CheckStackPushSameValue(valHandle);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_);
|
||||
SerializeJSONHashSet(valHandle, replacer);
|
||||
RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_);
|
||||
return tagValue;
|
||||
}
|
||||
[[fallthrough]];
|
||||
}
|
||||
default: {
|
||||
if (!tagValue.IsCallable()) {
|
||||
JSHClass *jsHclass = tagValue.GetTaggedObject()->GetClass();
|
||||
@ -537,204 +470,6 @@ bool JsonStringifier::SerializeJSONObject(const JSHandle<JSTaggedValue> &value,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JsonStringifier::SerializeJSONSharedMap(const JSHandle<JSTaggedValue> &value,
|
||||
const JSHandle<JSTaggedValue> &replacer)
|
||||
{
|
||||
CString stepback = indent_;
|
||||
result_ += "{";
|
||||
JSHandle<JSSharedMap> sharedMap(value);
|
||||
uint32_t mapSize = JSSharedMap::GetSize(thread_, sharedMap);
|
||||
JSMutableHandle<JSTaggedValue> keyHandle(thread_, JSTaggedValue::Undefined());
|
||||
JSMutableHandle<JSTaggedValue> valHandle(thread_, JSTaggedValue::Undefined());
|
||||
if (mapSize > 0) {
|
||||
uint32_t lastEntry = mapSize - 1;
|
||||
for (uint32_t entry = 0; entry <= lastEntry; ++entry) {
|
||||
JSTaggedValue keyTagValue = JSSharedMap::GetKey(thread_, sharedMap, entry);
|
||||
keyHandle.Update(keyTagValue);
|
||||
if (UNLIKELY(!keyHandle->IsString())) {
|
||||
result_ += "\"";
|
||||
SerializeJSONProperty(keyHandle, replacer);
|
||||
result_ += "\"";
|
||||
} else {
|
||||
SerializeJSONProperty(keyHandle, replacer);
|
||||
}
|
||||
result_ += ":";
|
||||
JSTaggedValue valueTagValue = JSSharedMap::GetValue(thread_, sharedMap, entry);
|
||||
valHandle.Update(valueTagValue);
|
||||
SerializeJSONProperty(valHandle, replacer);
|
||||
if (entry != lastEntry) {
|
||||
result_ += ",";
|
||||
}
|
||||
}
|
||||
}
|
||||
result_ += "}";
|
||||
PopValue();
|
||||
indent_ = stepback;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JsonStringifier::SerializeJSONSharedSet(const JSHandle<JSTaggedValue> &value,
|
||||
const JSHandle<JSTaggedValue> &replacer)
|
||||
{
|
||||
CString stepback = indent_;
|
||||
result_ += "[";
|
||||
JSHandle<JSSharedSet> sharedSet(value);
|
||||
uint32_t setSize = JSSharedSet::GetSize(thread_, sharedSet);
|
||||
JSMutableHandle<JSTaggedValue> valHandle(thread_, JSTaggedValue::Undefined());
|
||||
if (setSize > 0) {
|
||||
uint32_t lastEntry = setSize - 1;
|
||||
for (uint32_t entry = 0; entry <= lastEntry; ++entry) {
|
||||
JSTaggedValue valueTagValue = JSSharedSet::GetValue(thread_, sharedSet, entry);
|
||||
valHandle.Update(valueTagValue);
|
||||
SerializeJSONProperty(valHandle, replacer);
|
||||
if (entry != lastEntry) {
|
||||
result_ += ",";
|
||||
}
|
||||
}
|
||||
}
|
||||
result_ += "]";
|
||||
PopValue();
|
||||
indent_ = stepback;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JsonStringifier::SerializeJSONMap(const JSHandle<JSTaggedValue> &value,
|
||||
const JSHandle<JSTaggedValue> &replacer)
|
||||
{
|
||||
CString stepback = indent_;
|
||||
result_ += "{";
|
||||
JSHandle<JSMap> jsMap(value);
|
||||
uint32_t mapSize = jsMap->GetSize();
|
||||
JSMutableHandle<JSTaggedValue> keyHandle(thread_, JSTaggedValue::Undefined());
|
||||
JSMutableHandle<JSTaggedValue> valHandle(thread_, JSTaggedValue::Undefined());
|
||||
if (mapSize > 0) {
|
||||
uint32_t lastEntry = mapSize - 1;
|
||||
for (uint32_t entry = 0; entry <= lastEntry; ++entry) {
|
||||
JSTaggedValue keyTagValue = jsMap->GetKey(entry);
|
||||
keyHandle.Update(keyTagValue);
|
||||
if (UNLIKELY(!keyHandle->IsString())) {
|
||||
result_ += "\"";
|
||||
SerializeJSONProperty(keyHandle, replacer);
|
||||
result_ += "\"";
|
||||
} else {
|
||||
SerializeJSONProperty(keyHandle, replacer);
|
||||
}
|
||||
result_ += ":";
|
||||
JSTaggedValue valueTagValue = jsMap->GetValue(entry);
|
||||
valHandle.Update(valueTagValue);
|
||||
SerializeJSONProperty(valHandle, replacer);
|
||||
if (entry != lastEntry) {
|
||||
result_ += ",";
|
||||
}
|
||||
}
|
||||
}
|
||||
result_ += "}";
|
||||
PopValue();
|
||||
indent_ = stepback;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JsonStringifier::SerializeJSONSet(const JSHandle<JSTaggedValue> &value,
|
||||
const JSHandle<JSTaggedValue> &replacer)
|
||||
{
|
||||
CString stepback = indent_;
|
||||
result_ += "[";
|
||||
JSHandle<JSSet> jsSet(value);
|
||||
uint32_t setSize = jsSet->GetSize();
|
||||
JSMutableHandle<JSTaggedValue> valHandle(thread_, JSTaggedValue::Undefined());
|
||||
if (setSize > 0) {
|
||||
uint32_t lastEntry = setSize - 1;
|
||||
for (uint32_t entry = 0; entry <= lastEntry; ++entry) {
|
||||
JSTaggedValue valueTagValue = jsSet->GetValue(entry);
|
||||
valHandle.Update(valueTagValue);
|
||||
SerializeJSONProperty(valHandle, replacer);
|
||||
if (entry != lastEntry) {
|
||||
result_ += ",";
|
||||
}
|
||||
}
|
||||
}
|
||||
result_ += "]";
|
||||
PopValue();
|
||||
indent_ = stepback;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JsonStringifier::SerializeJSONHashMap(const JSHandle<JSTaggedValue> &value,
|
||||
const JSHandle<JSTaggedValue> &replacer)
|
||||
{
|
||||
CString stepback = indent_;
|
||||
result_ += "{";
|
||||
JSHandle<JSAPIHashMap> hashMap(value);
|
||||
JSHandle<TaggedHashArray> table(thread_, hashMap->GetTable());
|
||||
uint32_t len = table->GetLength();
|
||||
ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory();
|
||||
JSMutableHandle<TaggedQueue> queue(thread_, factory->NewTaggedQueue(0));
|
||||
JSMutableHandle<TaggedNode> node(thread_, JSTaggedValue::Undefined());
|
||||
JSMutableHandle<JSTaggedValue> keyHandle(thread_, JSTaggedValue::Undefined());
|
||||
JSMutableHandle<JSTaggedValue> valueHandle(thread_, JSTaggedValue::Undefined());
|
||||
uint32_t index = 0;
|
||||
bool needRemove = false;
|
||||
while (index < len) {
|
||||
node.Update(TaggedHashArray::GetCurrentNode(thread_, queue, table, index));
|
||||
if (node.GetTaggedValue().IsHole()) {
|
||||
continue;
|
||||
}
|
||||
keyHandle.Update(node->GetKey());
|
||||
if (UNLIKELY(!keyHandle->IsString())) {
|
||||
result_ += "\"";
|
||||
SerializeJSONProperty(keyHandle, replacer);
|
||||
result_ += "\"";
|
||||
} else {
|
||||
SerializeJSONProperty(keyHandle, replacer);
|
||||
}
|
||||
result_ += ":";
|
||||
valueHandle.Update(node->GetValue());
|
||||
SerializeJSONProperty(valueHandle, replacer);
|
||||
result_ += ",";
|
||||
needRemove = true;
|
||||
}
|
||||
if (needRemove) {
|
||||
result_.pop_back();
|
||||
}
|
||||
result_ += "}";
|
||||
PopValue();
|
||||
indent_ = stepback;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JsonStringifier::SerializeJSONHashSet(const JSHandle<JSTaggedValue> &value,
|
||||
const JSHandle<JSTaggedValue> &replacer)
|
||||
{
|
||||
CString stepback = indent_;
|
||||
result_ += "[";
|
||||
JSHandle<JSAPIHashSet> hashSet(value);
|
||||
JSHandle<TaggedHashArray> table(thread_, hashSet->GetTable());
|
||||
uint32_t len = table->GetLength();
|
||||
ObjectFactory *factory = thread_->GetEcmaVM()->GetFactory();
|
||||
JSMutableHandle<TaggedQueue> queue(thread_, factory->NewTaggedQueue(0));
|
||||
JSMutableHandle<TaggedNode> node(thread_, JSTaggedValue::Undefined());
|
||||
JSMutableHandle<JSTaggedValue> currentKey(thread_, JSTaggedValue::Undefined());
|
||||
uint32_t index = 0;
|
||||
bool needRemove = false;
|
||||
while (index < len) {
|
||||
node.Update(TaggedHashArray::GetCurrentNode(thread_, queue, table, index));
|
||||
if (node.GetTaggedValue().IsHole()) {
|
||||
continue;
|
||||
}
|
||||
currentKey.Update(node->GetKey());
|
||||
SerializeJSONProperty(currentKey, replacer);
|
||||
result_ += ",";
|
||||
needRemove = true;
|
||||
}
|
||||
if (needRemove) {
|
||||
result_.pop_back();
|
||||
}
|
||||
result_ += "]";
|
||||
PopValue();
|
||||
indent_ = stepback;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool JsonStringifier::SerializeJSProxy(const JSHandle<JSTaggedValue> &object, const JSHandle<JSTaggedValue> &replacer)
|
||||
{
|
||||
bool isContain = PushValue(object);
|
||||
|
@ -49,18 +49,6 @@ private:
|
||||
|
||||
bool SerializeJSONObject(const JSHandle<JSTaggedValue> &value, const JSHandle<JSTaggedValue> &replacer);
|
||||
|
||||
bool SerializeJSONSharedMap(const JSHandle<JSTaggedValue> &value, const JSHandle<JSTaggedValue> &replacer);
|
||||
|
||||
bool SerializeJSONSharedSet(const JSHandle<JSTaggedValue> &value, const JSHandle<JSTaggedValue> &replacer);
|
||||
|
||||
bool SerializeJSONMap(const JSHandle<JSTaggedValue> &value, const JSHandle<JSTaggedValue> &replacer);
|
||||
|
||||
bool SerializeJSONSet(const JSHandle<JSTaggedValue> &value, const JSHandle<JSTaggedValue> &replacer);
|
||||
|
||||
bool SerializeJSONHashMap(const JSHandle<JSTaggedValue> &value, const JSHandle<JSTaggedValue> &replacer);
|
||||
|
||||
bool SerializeJSONHashSet(const JSHandle<JSTaggedValue> &value, const JSHandle<JSTaggedValue> &replacer);
|
||||
|
||||
bool SerializeJSArray(const JSHandle<JSTaggedValue> &value, const JSHandle<JSTaggedValue> &replacer);
|
||||
|
||||
bool SerializeJSProxy(const JSHandle<JSTaggedValue> &object, const JSHandle<JSTaggedValue> &replacer);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
@ -13,27 +13,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ecmascript/base/json_helper.h"
|
||||
#include "ecmascript/base/json_stringifier.h"
|
||||
#include "ecmascript/js_api/js_api_hashmap.h"
|
||||
#include "ecmascript/js_api/js_api_hashset.h"
|
||||
#include "ecmascript/js_array.h"
|
||||
#include "ecmascript/js_map.h"
|
||||
#include "ecmascript/js_set.h"
|
||||
#include "ecmascript/linked_hash_table.h"
|
||||
#include "ecmascript/object_factory.h"
|
||||
#include "ecmascript/tests/test_helper.h"
|
||||
#include "ecmascript/shared_objects/js_shared_map.h"
|
||||
#include "ecmascript/shared_objects/js_shared_set.h"
|
||||
#include "ecmascript/tests/ecma_test_common.h"
|
||||
|
||||
using namespace panda::ecmascript;
|
||||
using namespace panda::ecmascript::base;
|
||||
|
||||
namespace panda::test {
|
||||
class JsonStringifierTest : public BaseTestWithScope<false> {
|
||||
public:
|
||||
using TransformType = base::JsonHelper::TransformType;
|
||||
};
|
||||
|
||||
static JSTaggedValue CreateBaseJSObject(JSThread *thread, const CString keyCStr)
|
||||
@ -63,79 +51,6 @@ static JSTaggedValue CreateBaseJSObject(JSThread *thread, const CString keyCStr)
|
||||
return jsObject.GetTaggedValue();
|
||||
}
|
||||
|
||||
static JSHandle<JSSharedMap> CreateSharedMap(JSThread *thread)
|
||||
{
|
||||
auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
|
||||
JSHandle<JSTaggedValue> proto = globalEnv->GetSharedMapPrototype();
|
||||
auto emptySLayout = thread->GlobalConstants()->GetHandledEmptySLayoutInfo();
|
||||
auto vm = thread->GetEcmaVM();
|
||||
ObjectFactory *factory = vm->GetFactory();
|
||||
JSHandle<JSHClass> mapClass = factory->NewSEcmaHClass(JSSharedMap::SIZE, 0,
|
||||
JSType::JS_SHARED_MAP, proto,
|
||||
emptySLayout);
|
||||
JSHandle<JSObject> obj = factory->NewSharedOldSpaceJSObjectWithInit(mapClass);
|
||||
JSHandle<JSSharedMap> jsMap = JSHandle<JSSharedMap>::Cast(obj);
|
||||
JSHandle<LinkedHashMap> linkedMap(
|
||||
LinkedHashMap::Create(thread, LinkedHashMap::MIN_CAPACITY, MemSpaceKind::SHARED));
|
||||
jsMap->SetLinkedMap(thread, linkedMap);
|
||||
jsMap->SetModRecord(0);
|
||||
return jsMap;
|
||||
}
|
||||
|
||||
static JSHandle<JSSharedSet> CreateJSSharedSet(JSThread *thread)
|
||||
{
|
||||
auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
|
||||
auto vm = thread->GetEcmaVM();
|
||||
ObjectFactory *factory = vm->GetFactory();
|
||||
JSHandle<JSTaggedValue> proto = globalEnv->GetSFunctionPrototype();
|
||||
auto emptySLayout = thread->GlobalConstants()->GetHandledEmptySLayoutInfo();
|
||||
JSHandle<JSHClass> setClass = factory->NewSEcmaHClass(JSSharedSet::SIZE, 0,
|
||||
JSType::JS_SHARED_SET, proto, emptySLayout);
|
||||
JSHandle<JSSharedSet> jsSet = JSHandle<JSSharedSet>::Cast(factory->NewJSObjectWithInit(setClass));
|
||||
JSHandle<LinkedHashSet> linkedSet(
|
||||
LinkedHashSet::Create(thread, LinkedHashSet::MIN_CAPACITY, MemSpaceKind::SHARED));
|
||||
jsSet->SetLinkedSet(thread, linkedSet);
|
||||
jsSet->SetModRecord(0);
|
||||
return jsSet;
|
||||
}
|
||||
|
||||
static JSHandle<JSMap> CreateJSMap(JSThread *thread)
|
||||
{
|
||||
auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
|
||||
auto vm = thread->GetEcmaVM();
|
||||
ObjectFactory *factory = vm->GetFactory();
|
||||
JSHandle<JSTaggedValue> constructor = globalEnv->GetBuiltinsMapFunction();
|
||||
JSHandle<JSMap> map =
|
||||
JSHandle<JSMap>::Cast(factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), constructor));
|
||||
JSHandle<LinkedHashMap> linkedMap = LinkedHashMap::Create(thread);
|
||||
map->SetLinkedMap(thread, linkedMap);
|
||||
return JSHandle<JSMap>(thread, *map);
|
||||
}
|
||||
|
||||
static JSHandle<JSSet> CreateJSSet(JSThread *thread)
|
||||
{
|
||||
auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv();
|
||||
JSHandle<JSTaggedValue> proto = globalEnv->GetFunctionPrototype();
|
||||
auto vm = thread->GetEcmaVM();
|
||||
ObjectFactory *factory = vm->GetFactory();
|
||||
JSHandle<JSHClass> hclass = factory->NewEcmaHClass(JSSet::SIZE, JSType::JS_SET, proto);
|
||||
JSHandle<JSObject> jsSetObject = factory->NewJSObjectWithInit(hclass);
|
||||
JSHandle<JSSet> jsSet = JSHandle<JSSet>::Cast(jsSetObject);
|
||||
JSHandle<LinkedHashSet> linkedSet(LinkedHashSet::Create(thread));
|
||||
jsSet->SetLinkedSet(thread, linkedSet);
|
||||
return jsSet;
|
||||
}
|
||||
|
||||
static JSAPIHashMap *CreateHashMap(JSThread *thread)
|
||||
{
|
||||
return EcmaContainerCommon::CreateHashMap(thread);
|
||||
}
|
||||
|
||||
static JSAPIHashSet *CreateHashSet(JSThread *thread)
|
||||
{
|
||||
return EcmaContainerCommon::CreateHashSet(thread);
|
||||
}
|
||||
|
||||
static JSTaggedValue TestForStringfy1([[maybe_unused]] EcmaRuntimeCallInfo *argv)
|
||||
{
|
||||
// false: test case
|
||||
@ -464,196 +379,4 @@ HWTEST_F_L0(JsonStringifierTest, Stringify_009)
|
||||
JSHandle<EcmaString> handleEcmaStr(resultString);
|
||||
EXPECT_STREQ("{\"key1\":{},\"key2\":\"abc\"}", EcmaStringAccessor(handleEcmaStr).ToCString().c_str());
|
||||
}
|
||||
|
||||
HWTEST_F_L0(JsonStringifierTest, Stringify_010)
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
JsonStringifier stringifier(thread, TransformType::SENDABLE);
|
||||
JSHandle<JSSharedMap> sharedMap = CreateSharedMap(thread);
|
||||
JSHandle<JSTaggedValue> handleMap = JSHandle<JSTaggedValue>(sharedMap);
|
||||
JSHandle<JSTaggedValue> handleReplacer(thread, JSTaggedValue::Undefined());
|
||||
JSHandle<JSTaggedValue> handleGap(thread, JSTaggedValue::Undefined());
|
||||
JSHandle<JSTaggedValue> resultString = stringifier.Stringify(handleMap, handleReplacer, handleGap);
|
||||
EXPECT_TRUE(resultString->IsString());
|
||||
JSHandle<EcmaString> handleEcmaStr(resultString);
|
||||
EXPECT_STREQ("{}", EcmaStringAccessor(handleEcmaStr).ToCString().c_str());
|
||||
|
||||
JsonStringifier stringifier1(thread, TransformType::SENDABLE);
|
||||
JSHandle<JSSharedMap> sharedMap1 = CreateSharedMap(thread);
|
||||
JSHandle<JSTaggedValue> key1(factory->NewFromASCII("key1"));
|
||||
JSHandle<JSTaggedValue> value1(factory->NewFromASCII("abc"));
|
||||
JSSharedMap::Set(thread, sharedMap1, key1, value1);
|
||||
|
||||
JSHandle<JSTaggedValue> key2(factory->NewFromASCII("key2"));
|
||||
JSHandle<JSTaggedValue> value2(factory->NewFromASCII("val"));
|
||||
JSSharedMap::Set(thread, sharedMap1, key2, value2);
|
||||
|
||||
JSHandle<JSTaggedValue> handleMap1 = JSHandle<JSTaggedValue>(sharedMap1);
|
||||
JSHandle<JSTaggedValue> handleReplacer1(thread, JSTaggedValue::Undefined());
|
||||
JSHandle<JSTaggedValue> handleGap1(thread, JSTaggedValue::Undefined());
|
||||
EXPECT_TRUE(*handleMap1 != nullptr);
|
||||
JSHandle<JSTaggedValue> resultString1 = stringifier1.Stringify(handleMap1, handleReplacer1, handleGap1);
|
||||
EXPECT_TRUE(resultString1->IsString());
|
||||
JSHandle<EcmaString> handleEcmaStr1(resultString1);
|
||||
EXPECT_STREQ("{\"key1\":\"abc\",\"key2\":\"val\"}", EcmaStringAccessor(handleEcmaStr1).ToCString().c_str());
|
||||
}
|
||||
|
||||
HWTEST_F_L0(JsonStringifierTest, Stringify_011)
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
JsonStringifier stringifier(thread, TransformType::SENDABLE);
|
||||
JSHandle<JSMap> jsMap = CreateJSMap(thread);
|
||||
JSHandle<JSTaggedValue> handleMap = JSHandle<JSTaggedValue>(jsMap);
|
||||
JSHandle<JSTaggedValue> handleReplacer(thread, JSTaggedValue::Undefined());
|
||||
JSHandle<JSTaggedValue> handleGap(thread, JSTaggedValue::Undefined());
|
||||
JSHandle<JSTaggedValue> resultString = stringifier.Stringify(handleMap, handleReplacer, handleGap);
|
||||
EXPECT_TRUE(resultString->IsString());
|
||||
JSHandle<EcmaString> handleEcmaStr(resultString);
|
||||
EXPECT_STREQ("{}", EcmaStringAccessor(handleEcmaStr).ToCString().c_str());
|
||||
|
||||
JsonStringifier stringifier1(thread, TransformType::SENDABLE);
|
||||
JSHandle<JSMap> jsMap1 = CreateJSMap(thread);
|
||||
JSHandle<JSTaggedValue> key1(factory->NewFromASCII("key1"));
|
||||
JSHandle<JSTaggedValue> value1(factory->NewFromASCII("abc"));
|
||||
JSMap::Set(thread, jsMap1, key1, value1);
|
||||
|
||||
JSHandle<JSTaggedValue> key2(factory->NewFromASCII("key2"));
|
||||
JSHandle<JSTaggedValue> value2(factory->NewFromASCII("val"));
|
||||
JSMap::Set(thread, jsMap1, key2, value2);
|
||||
|
||||
JSHandle<JSTaggedValue> handleMap1 = JSHandle<JSTaggedValue>(jsMap1);
|
||||
JSHandle<JSTaggedValue> handleReplacer1(thread, JSTaggedValue::Undefined());
|
||||
JSHandle<JSTaggedValue> handleGap1(thread, JSTaggedValue::Undefined());
|
||||
EXPECT_TRUE(*handleMap1 != nullptr);
|
||||
JSHandle<JSTaggedValue> resultString1 = stringifier1.Stringify(handleMap1, handleReplacer1, handleGap1);
|
||||
EXPECT_TRUE(resultString1->IsString());
|
||||
JSHandle<EcmaString> handleEcmaStr1(resultString1);
|
||||
EXPECT_STREQ("{\"key1\":\"abc\",\"key2\":\"val\"}", EcmaStringAccessor(handleEcmaStr1).ToCString().c_str());
|
||||
}
|
||||
|
||||
HWTEST_F_L0(JsonStringifierTest, Stringify_012)
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
JsonStringifier stringifier(thread, TransformType::SENDABLE);
|
||||
JSHandle<JSSharedSet> sharedSet = CreateJSSharedSet(thread);
|
||||
JSHandle<JSTaggedValue> handleSet = JSHandle<JSTaggedValue>(sharedSet);
|
||||
JSHandle<JSTaggedValue> handleReplacer(thread, JSTaggedValue::Undefined());
|
||||
JSHandle<JSTaggedValue> handleGap(thread, JSTaggedValue::Undefined());
|
||||
JSHandle<JSTaggedValue> resultString = stringifier.Stringify(handleSet, handleReplacer, handleGap);
|
||||
EXPECT_TRUE(resultString->IsString());
|
||||
JSHandle<EcmaString> handleEcmaStr(resultString);
|
||||
EXPECT_STREQ("[]", EcmaStringAccessor(handleEcmaStr).ToCString().c_str());
|
||||
|
||||
JsonStringifier stringifier1(thread, TransformType::SENDABLE);
|
||||
JSHandle<JSSharedSet> sharedSet1 = CreateJSSharedSet(thread);
|
||||
JSHandle<JSTaggedValue> value1(factory->NewFromASCII("abc"));
|
||||
JSSharedSet::Add(thread, sharedSet1, value1);
|
||||
|
||||
JSHandle<JSTaggedValue> value2(factory->NewFromASCII("val"));
|
||||
JSSharedSet::Add(thread, sharedSet1, value2);
|
||||
|
||||
JSHandle<JSTaggedValue> handleSet1 = JSHandle<JSTaggedValue>(sharedSet1);
|
||||
JSHandle<JSTaggedValue> handleReplacer1(thread, JSTaggedValue::Undefined());
|
||||
JSHandle<JSTaggedValue> handleGap1(thread, JSTaggedValue::Undefined());
|
||||
EXPECT_TRUE(*handleSet1 != nullptr);
|
||||
JSHandle<JSTaggedValue> resultString1 = stringifier1.Stringify(handleSet1, handleReplacer1, handleGap1);
|
||||
EXPECT_TRUE(resultString1->IsString());
|
||||
JSHandle<EcmaString> handleEcmaStr1(resultString1);
|
||||
EXPECT_STREQ("[\"abc\",\"val\"]", EcmaStringAccessor(handleEcmaStr1).ToCString().c_str());
|
||||
}
|
||||
|
||||
HWTEST_F_L0(JsonStringifierTest, Stringify_013)
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
JsonStringifier stringifier(thread, TransformType::SENDABLE);
|
||||
JSHandle<JSSet> jsSet = CreateJSSet(thread);
|
||||
JSHandle<JSTaggedValue> handleSet = JSHandle<JSTaggedValue>(jsSet);
|
||||
JSHandle<JSTaggedValue> handleReplacer(thread, JSTaggedValue::Undefined());
|
||||
JSHandle<JSTaggedValue> handleGap(thread, JSTaggedValue::Undefined());
|
||||
JSHandle<JSTaggedValue> resultString = stringifier.Stringify(handleSet, handleReplacer, handleGap);
|
||||
EXPECT_TRUE(resultString->IsString());
|
||||
JSHandle<EcmaString> handleEcmaStr(resultString);
|
||||
EXPECT_STREQ("[]", EcmaStringAccessor(handleEcmaStr).ToCString().c_str());
|
||||
|
||||
JsonStringifier stringifier1(thread, TransformType::SENDABLE);
|
||||
JSHandle<JSSet> jsSet1 = CreateJSSet(thread);
|
||||
JSHandle<JSTaggedValue> value1(factory->NewFromASCII("abc"));
|
||||
JSSet::Add(thread, jsSet1, value1);
|
||||
|
||||
JSHandle<JSTaggedValue> value2(factory->NewFromASCII("val"));
|
||||
JSSet::Add(thread, jsSet1, value2);
|
||||
|
||||
JSHandle<JSTaggedValue> handleSet1 = JSHandle<JSTaggedValue>(jsSet1);
|
||||
JSHandle<JSTaggedValue> handleReplacer1(thread, JSTaggedValue::Undefined());
|
||||
JSHandle<JSTaggedValue> handleGap1(thread, JSTaggedValue::Undefined());
|
||||
EXPECT_TRUE(*handleSet1 != nullptr);
|
||||
JSHandle<JSTaggedValue> resultString1 = stringifier1.Stringify(handleSet1, handleReplacer1, handleGap1);
|
||||
EXPECT_TRUE(resultString1->IsString());
|
||||
JSHandle<EcmaString> handleEcmaStr1(resultString1);
|
||||
EXPECT_STREQ("[\"abc\",\"val\"]", EcmaStringAccessor(handleEcmaStr1).ToCString().c_str());
|
||||
}
|
||||
|
||||
HWTEST_F_L0(JsonStringifierTest, Stringify_014)
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
JsonStringifier stringifier(thread, TransformType::SENDABLE);
|
||||
JSHandle<JSAPIHashMap> hashMap(thread, CreateHashMap(thread));
|
||||
JSHandle<JSTaggedValue> handleMap = JSHandle<JSTaggedValue>(hashMap);
|
||||
JSHandle<JSTaggedValue> handleReplacer(thread, JSTaggedValue::Undefined());
|
||||
JSHandle<JSTaggedValue> handleGap(thread, JSTaggedValue::Undefined());
|
||||
JSHandle<JSTaggedValue> resultString = stringifier.Stringify(handleMap, handleReplacer, handleGap);
|
||||
EXPECT_TRUE(resultString->IsString());
|
||||
JSHandle<EcmaString> handleEcmaStr(resultString);
|
||||
EXPECT_STREQ("{}", EcmaStringAccessor(handleEcmaStr).ToCString().c_str());
|
||||
|
||||
JsonStringifier stringifier1(thread, TransformType::SENDABLE);
|
||||
JSHandle<JSAPIHashMap> hashMap1(thread, CreateHashMap(thread));
|
||||
JSHandle<JSTaggedValue> key1(factory->NewFromASCII("key1"));
|
||||
JSHandle<JSTaggedValue> value1(factory->NewFromASCII("abc"));
|
||||
JSAPIHashMap::Set(thread, hashMap1, key1, value1);
|
||||
|
||||
JSHandle<JSTaggedValue> key2(factory->NewFromASCII("key2"));
|
||||
JSHandle<JSTaggedValue> value2(factory->NewFromASCII("val"));
|
||||
JSAPIHashMap::Set(thread, hashMap1, key2, value2);
|
||||
|
||||
JSHandle<JSTaggedValue> handleMap1 = JSHandle<JSTaggedValue>(hashMap1);
|
||||
JSHandle<JSTaggedValue> handleReplacer1(thread, JSTaggedValue::Undefined());
|
||||
JSHandle<JSTaggedValue> handleGap1(thread, JSTaggedValue::Undefined());
|
||||
EXPECT_TRUE(*handleMap1 != nullptr);
|
||||
JSHandle<JSTaggedValue> resultString1 = stringifier1.Stringify(handleMap1, handleReplacer1, handleGap1);
|
||||
EXPECT_TRUE(resultString1->IsString());
|
||||
JSHandle<EcmaString> handleEcmaStr1(resultString1);
|
||||
EXPECT_STRNE("{}", EcmaStringAccessor(handleEcmaStr1).ToCString().c_str());
|
||||
}
|
||||
|
||||
HWTEST_F_L0(JsonStringifierTest, Stringify_015)
|
||||
{
|
||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||
JsonStringifier stringifier(thread, TransformType::SENDABLE);
|
||||
JSHandle<JSAPIHashSet> hashSet(thread, CreateHashSet(thread));
|
||||
JSHandle<JSTaggedValue> handleSet = JSHandle<JSTaggedValue>(hashSet);
|
||||
JSHandle<JSTaggedValue> handleReplacer(thread, JSTaggedValue::Undefined());
|
||||
JSHandle<JSTaggedValue> handleGap(thread, JSTaggedValue::Undefined());
|
||||
JSHandle<JSTaggedValue> resultString = stringifier.Stringify(handleSet, handleReplacer, handleGap);
|
||||
EXPECT_TRUE(resultString->IsString());
|
||||
JSHandle<EcmaString> handleEcmaStr(resultString);
|
||||
EXPECT_STREQ("[]", EcmaStringAccessor(handleEcmaStr).ToCString().c_str());
|
||||
|
||||
JsonStringifier stringifier1(thread, TransformType::SENDABLE);
|
||||
JSHandle<JSAPIHashSet> hashSet1(thread, CreateHashSet(thread));
|
||||
JSHandle<JSTaggedValue> value1(factory->NewFromASCII("abc"));
|
||||
JSAPIHashSet::Add(thread, hashSet1, value1);
|
||||
|
||||
JSHandle<JSTaggedValue> value2(factory->NewFromASCII("val"));
|
||||
JSAPIHashSet::Add(thread, hashSet1, value2);
|
||||
|
||||
JSHandle<JSTaggedValue> handleSet1 = JSHandle<JSTaggedValue>(hashSet1);
|
||||
JSHandle<JSTaggedValue> handleReplacer1(thread, JSTaggedValue::Undefined());
|
||||
JSHandle<JSTaggedValue> handleGap1(thread, JSTaggedValue::Undefined());
|
||||
EXPECT_TRUE(*handleSet1 != nullptr);
|
||||
JSHandle<JSTaggedValue> resultString1 = stringifier1.Stringify(handleSet1, handleReplacer1, handleGap1);
|
||||
EXPECT_TRUE(resultString1->IsString());
|
||||
JSHandle<EcmaString> handleEcmaStr1(resultString1);
|
||||
EXPECT_STRNE("[]", EcmaStringAccessor(handleEcmaStr1).ToCString().c_str());
|
||||
}
|
||||
} // namespace panda::test
|
||||
|
@ -102,28 +102,3 @@ ASON parse asonstr2: 89
|
||||
ASON parse asonstr3: eetrue1123
|
||||
{"123":"1","124":"123","1234":"bb","xx":"yy","aaa":"ee","success":"true"}
|
||||
0
|
||||
{"text":"ASON support MAP Test Start","largeNumber":112233445566778899,"people":{"name":"Mary","sex":"1","height":"165"}}
|
||||
{"args1":true,"args2":false,"args3":null}
|
||||
{"people":{"name":"Mary","sex":"1","height":165,"args":{"arr":[1,2,3],"check":true,"num":null}}}
|
||||
{"features":{"ut":{"args":{"bizType":"SQYK","isChecked":false,"packageId":9223372036854775806}}}}
|
||||
["foo","bar","baz"]
|
||||
["foo","bar","baz"]
|
||||
{"foo":1,"bar":2,"baz":3}
|
||||
true
|
||||
true
|
||||
{"arr1":[1,2,3,4],"arr2":[3,5,7,9]}
|
||||
{}
|
||||
{"v":100,"map":{"arr1":[1,2,3,4],"arr2":[3,5,7,9]}}
|
||||
{"v":100,"map":{}}
|
||||
[{"v":100,"map":{"arr1":[1,2,3,4],"arr2":[3,5,7,9]}}]
|
||||
{}
|
||||
{"arr3":[1,2,3,4],"arr4":[3,5,7,9]}
|
||||
{}
|
||||
{"v":200,"map":{"arr3":[1,2,3,4],"arr4":[3,5,7,9]}}
|
||||
{"v":200,"map":{}}
|
||||
[{"v":200,"map":{"arr3":[1,2,3,4],"arr4":[3,5,7,9]}}]
|
||||
{}
|
||||
{"set":[{"v":200,"map":{"arr3":[1,2,3,4],"arr4":[3,5,7,9]}}]}
|
||||
{}
|
||||
[{"set":[{"v":200,"map":{"arr3":[1,2,3,4],"arr4":[3,5,7,9]}}]}]
|
||||
{}
|
||||
|
@ -329,143 +329,6 @@ function testJSONBigIntZero() {
|
||||
print(obj.id);
|
||||
}
|
||||
|
||||
function testASONStringifyMapAndSet() {
|
||||
let jsonText1 = '{"text":"ASON support MAP Test Start","largeNumber":112233445566778899,"people":{"name":"Mary","sex":"1","height":"165"}}';
|
||||
let options1 = {
|
||||
bigIntMode: BigIntMode.PARSE_AS_BIGINT,
|
||||
parseReturnType: ParseReturnType.MAP,
|
||||
}
|
||||
let map1 = JSON.parseSendable(jsonText1, undefined, options1);
|
||||
let output1 = JSON.stringifySendable(map1);
|
||||
print(output1);
|
||||
|
||||
let jsonText2 = '{"args1":true,"args2":false,"args3":null}';
|
||||
let map2 = JSON.parseSendable(jsonText2, undefined, options1);
|
||||
let output2 = JSON.stringifySendable(map2);
|
||||
print(output2);
|
||||
|
||||
let jsonText3 = '{"people":{"name":"Mary","sex":"1","height":165,"args":{"arr":[1,2,3],"check":true,"num":null}}}';
|
||||
let map3 = JSON.parseSendable(jsonText3, undefined, options1);
|
||||
let output3 = JSON.stringifySendable(map3);
|
||||
print(output3);
|
||||
|
||||
let jsonText4 = '{"features":{"ut":{"args":{"bizType":"SQYK","isChecked":false,"packageId":9223372036854775806}}}}';
|
||||
let map4 = JSON.parseSendable(jsonText4, undefined, options1);
|
||||
let output4 = JSON.stringifySendable(map4);
|
||||
print(output4);
|
||||
|
||||
let set = new Set(['foo', 'bar', 'baz']);
|
||||
let output5 = JSON.stringifySendable(set);
|
||||
print(output5);
|
||||
|
||||
let sharedSet = new SendableSet(['foo', 'bar', 'baz']);
|
||||
let output6 = JSON.stringifySendable(sharedSet);
|
||||
print(output6);
|
||||
|
||||
let map5 = new Map([['foo', 1], ['bar', 2], ['baz', 3]]);
|
||||
let output7 = JSON.stringifySendable(map5);
|
||||
print(output7);
|
||||
|
||||
let arkPrivate = globalThis.ArkPrivate;
|
||||
var HashMap = arkPrivate.Load(arkPrivate.HashMap);
|
||||
let hashMap = new HashMap();
|
||||
hashMap.set('foo', 1);
|
||||
hashMap.set('bar', 2);
|
||||
hashMap.set('baz', 3);
|
||||
let output8 = JSON.stringifySendable(hashMap);
|
||||
print(output8 != '{}');
|
||||
|
||||
var HashSet = arkPrivate.Load(arkPrivate.HashSet);
|
||||
let hashSet = new HashSet();
|
||||
hashSet.add('foo');
|
||||
hashSet.add('bar');
|
||||
hashSet.add('baz');
|
||||
let output9 = JSON.stringifySendable(hashSet);
|
||||
print(output9 != '{}' && output9 != '[]');
|
||||
}
|
||||
|
||||
class SharedA {
|
||||
v: number;
|
||||
map: SendableMap<string, SendableArray<number>>;
|
||||
constructor() {
|
||||
'use sendable'
|
||||
}
|
||||
}
|
||||
|
||||
class A {
|
||||
v: number;
|
||||
map: Map<string, Array<number>>;
|
||||
constructor() {
|
||||
}
|
||||
}
|
||||
|
||||
function testASONStringifyMapAndSetAndObj() {
|
||||
let array1 = new SendableArray<number>(1, 2, 3, 4);
|
||||
let array2 = new SendableArray<number>(3, 5, 7, 9);
|
||||
let sharedMap = new SendableMap();
|
||||
sharedMap.set('arr1', array1);
|
||||
sharedMap.set('arr2', array2);
|
||||
let output1 = JSON.stringifySendable(sharedMap);
|
||||
let output2 = JSON.stringify(sharedMap);
|
||||
print(output1);
|
||||
print(output2);
|
||||
|
||||
let sharedA = new SharedA();
|
||||
sharedA.v = 100;
|
||||
sharedA.map = sharedMap;
|
||||
let output3 = JSON.stringifySendable(sharedA);
|
||||
print(output3);
|
||||
let output4 = JSON.stringify(sharedA);
|
||||
print(output4);
|
||||
|
||||
let sharedSet = new SendableSet([sharedA]);
|
||||
let output5 = JSON.stringifySendable(sharedSet);
|
||||
print(output5);
|
||||
let output6 = JSON.stringify(sharedSet);
|
||||
print(output6);
|
||||
|
||||
let array3 = new Array<number>(1, 2, 3, 4);
|
||||
let array4 = new Array<number>(3, 5, 7, 9);
|
||||
let set = new Set();
|
||||
let map = new Map();
|
||||
map.set('arr3', array3);
|
||||
map.set('arr4', array4);
|
||||
let output7 = JSON.stringifySendable(map);
|
||||
print(output7);
|
||||
let output8 = JSON.stringify(map);
|
||||
print(output8);
|
||||
|
||||
let a = new A();
|
||||
a.v = 200;
|
||||
a.map = map;
|
||||
let output9 = JSON.stringifySendable(a);
|
||||
print(output9);
|
||||
let output10 = JSON.stringify(a);
|
||||
print(output10);
|
||||
set.add(a);
|
||||
let output11 = JSON.stringifySendable(set);
|
||||
print(output11);
|
||||
let output12 = JSON.stringify(set);
|
||||
print(output12);
|
||||
|
||||
let arkPrivate = globalThis.ArkPrivate;
|
||||
var HashMap = arkPrivate.Load(arkPrivate.HashMap);
|
||||
let hashMap = new HashMap();
|
||||
hashMap.set('set', set);
|
||||
let output13 = JSON.stringifySendable(hashMap);
|
||||
print(output13);
|
||||
let output14 = JSON.stringify(hashMap);
|
||||
print(output14);
|
||||
|
||||
var HashSet = arkPrivate.Load(arkPrivate.HashSet);
|
||||
let hashSet = new HashSet();
|
||||
hashSet.add(hashMap);
|
||||
let output15 = JSON.stringifySendable(hashSet);
|
||||
print(output15);
|
||||
let output16 = JSON.stringify(hashSet);
|
||||
print(output16);
|
||||
}
|
||||
|
||||
testJSONParseSendable();
|
||||
jsonRepeatCall();
|
||||
testASONBigInt();
|
||||
@ -476,5 +339,3 @@ testJSONZeroDeci();
|
||||
testASONMap();
|
||||
testIndexASON();
|
||||
testJSONBigIntZero();
|
||||
testASONStringifyMapAndSet();
|
||||
testASONStringifyMapAndSetAndObj();
|
||||
|
Loading…
Reference in New Issue
Block a user