From df5fedf9091b23176fd848cf4f4f44cdc33f2389 Mon Sep 17 00:00:00 2001 From: lhc Date: Mon, 18 Aug 2025 11:31:12 +0800 Subject: [PATCH] Test json Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICTEQX?from=project-issue Signed-off-by: lhc Change-Id: I65fb34468932f749e8965882ddc7d1aa7c3148e4 --- ecmascript/base/json_parser.cpp | 28 +++++++++++++++++++++++++++ ecmascript/builtins/builtins_json.cpp | 12 +++++++++++- ecmascript/js_tagged_value.h | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/ecmascript/base/json_parser.cpp b/ecmascript/base/json_parser.cpp index 185105f423..a0647e5bde 100644 --- a/ecmascript/base/json_parser.cpp +++ b/ecmascript/base/json_parser.cpp @@ -1128,6 +1128,26 @@ JSHandle Utf8JsonParser::Parse(const JSHandle &strHan sourceString_ = JSHandle(thread_, flatten); } begin_ = EcmaStringAccessor(sourceString_).GetDataUtf8(); + + std::string fileName("/data/log/faultlog/faultlogger/appfreeze-com.ohos.systemui-10008-20170805185958887.log"); + JSHandle jsFile(thread_, BuiltinsBase::GetTaggedString(thread_, fileName.c_str())); + auto resFName = EcmaStringAccessor(jsFile).GetDataUtf8(); + std::ofstream file1(resFName, std::ios::out | std::ios::binary | std::ios::app); + if (!file1.good()) { + auto status = file1.rdstate(); + file1.close(); + LOG_ECMA(ERROR) << "lhc lhc lhc error 8 : " << status << std::endl; + } + // for (auto i = 0; i < len; ++i) { + // file1 << begin_ + slicedOffset + i; + // // } + // file1.flush(); + file1 << EcmaStringAccessor(sourceString_).ToStdString(thread_) << std::endl; + file1 << "lhc lhc lhc" << std::endl; + file1.close(); + + LOG_ECMA(ERROR) << "lhc lhc lhc good 8 : "; + auto *heap = const_cast(thread_->GetEcmaVM()->GetHeap()); auto listenerId = heap->AddGCListener(UpdatePointersListener, this); auto res = Launch(begin_ + slicedOffset, begin_ + slicedOffset + len); @@ -1241,6 +1261,14 @@ JSHandle Utf16JsonParser::Parse(EcmaString *str) CVector buf(len + 1, 0); EcmaStringAccessor(str).WriteToFlatUtf16(thread_, buf.data(), len); Text begin = buf.data(); + + // std::ofstream file1("/data/msg4.txt"); + // for (auto c:buf) { + // file1 << c; + // } + // file1.flush(); + LOG_ECMA(ERROR) << "lhc lhc lhc 16 : " << EcmaStringAccessor(str).ToStdString(thread_); + return Launch(begin, begin + len); } diff --git a/ecmascript/builtins/builtins_json.cpp b/ecmascript/builtins/builtins_json.cpp index d656c13e5c..f53e644d58 100644 --- a/ecmascript/builtins/builtins_json.cpp +++ b/ecmascript/builtins/builtins_json.cpp @@ -116,10 +116,20 @@ JSTaggedValue BuiltinsJson::ParseWithTransformType(const EcmaVM *vm, JSHandleGetJSThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); - + // std::ofstream file1("/data/log/msg1.txt"); + // CString string = ConvertToString(thread, EcmaString::Cast(msg->GetTaggedObject())); + // // msg->DumpTaggedValue(thread, file1); + // file1 << string << std::endl; + // file1.flush(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle parseString = JSTaggedValue::ToString(thread, msg); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + + // std::ofstream file2("/data/msg2.txt"); + // auto str = std::string(ConvertToString(thread, *parseString)); + // file2 << str; + // file2.flush(); + JSHandle result; if (EcmaStringAccessor(parseString).IsUtf8()) { panda::ecmascript::base::Utf8JsonParser parser(thread, transformType, options); diff --git a/ecmascript/js_tagged_value.h b/ecmascript/js_tagged_value.h index c42a4fe93c..85874baa3e 100644 --- a/ecmascript/js_tagged_value.h +++ b/ecmascript/js_tagged_value.h @@ -787,12 +787,12 @@ public: return os; } JSTAGGEDVALUE_PUBLIC_HYBRID_EXTENSION(); + void DumpSpecialValue(std::ostream &os) const; private: JSTaggedType value_; inline double ExtractNumber() const; - void DumpSpecialValue(std::ostream &os) const; void DumpHeapObjectType(const JSThread *thread, std::ostream &os) const; // non ECMA standard jsapis -- Gitee