From 78800ea0fb9d567ab3b8409c2efd3c8894d0cc92 Mon Sep 17 00:00:00 2001 From: yaochaonan Date: Sat, 30 Aug 2025 09:34:16 +0800 Subject: [PATCH] Fix jsonParse doesn't use function call Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/ICVJ19?from=project-issue Signed-off-by: yaochaonan Change-Id: I09c33ac81defb3144411bd7ce369b53ed757e950 --- ecmascript/builtins/builtins.cpp | 4 +++- ecmascript/global_env_fields.h | 1 + ecmascript/js_type_metadata/global_env.json | 2 +- ecmascript/module/module_data_extractor.cpp | 8 +++++--- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ecmascript/builtins/builtins.cpp b/ecmascript/builtins/builtins.cpp index 964fac54f4..84208d9d4f 100644 --- a/ecmascript/builtins/builtins.cpp +++ b/ecmascript/builtins/builtins.cpp @@ -1757,7 +1757,7 @@ void Builtins::InitializeJson(const JSHandle &env, const JSHandle jsonHClass = factory_->NewEcmaHClass(JSObject::SIZE, JSType::JS_OBJECT, objFuncPrototypeVal); JSHandle jsonObject = factory_->NewJSObjectWithInit(jsonHClass); - SetFunction(env, jsonObject, "parse", Json::Parse, FunctionLength::TWO); + JSHandle parseFunc = SetAndReturnFunction(env, jsonObject, "parse", Json::Parse, FunctionLength::TWO); SetFunction(env, jsonObject, "parseSendable", SendableJson::Parse, FunctionLength::THREE); SetFunction(env, jsonObject, "parseBigInt", BigIntJson::Parse, FunctionLength::THREE); SetFunction(env, jsonObject, "stringify", Json::Stringify, FunctionLength::THREE, BUILTINS_STUB_ID(JsonStringify)); @@ -1768,6 +1768,8 @@ void Builtins::InitializeJson(const JSHandle &env, const JSHandle jsonString(factory_->NewFromASCIIReadOnly("JSON")); JSHandle globalObject(thread_, env->GetGlobalObject()); JSObject::DefineOwnProperty(thread_, globalObject, jsonString, jsonDesc); + // set json Parse Function + env->SetJsonParseFunction(thread_, parseFunc); // @@ToStringTag SetStringTagSymbol(env, jsonObject, "JSON"); env->SetJsonFunction(thread_, jsonObject); diff --git a/ecmascript/global_env_fields.h b/ecmascript/global_env_fields.h index 4e36e30101..16832416c8 100644 --- a/ecmascript/global_env_fields.h +++ b/ecmascript/global_env_fields.h @@ -149,6 +149,7 @@ V(JSTaggedValue, MathFunctionClass, MATH_FUNCTION_CLASS_INDEX) \ V(JSTaggedValue, AtomicsFunction, ATOMICS_FUNCTION_INDEX) \ V(JSTaggedValue, JsonFunction, JSON_FUNCTION_INDEX) \ + V(JSTaggedValue, JsonParseFunction, JSON_PARSE_FUNCTION_INDEX) \ V(JSTaggedValue, StringFunction, STRING_FUNCTION_INDEX) \ V(JSTaggedValue, StringPrototype, STRING_PROTOTYPE_INDEX) \ V(JSTaggedValue, ProxyFunction, PROXY_FUNCTION_INDEX) \ diff --git a/ecmascript/js_type_metadata/global_env.json b/ecmascript/js_type_metadata/global_env.json index 9c193ec832..2b1821995a 100644 --- a/ecmascript/js_type_metadata/global_env.json +++ b/ecmascript/js_type_metadata/global_env.json @@ -1 +1 @@ -{"name": "GLOBAL_ENV", "offsets": [], "end_offset": 4360, "parents": ["TAGGED_ARRAY"]} +{"name": "GLOBAL_ENV", "offsets": [], "end_offset": 4368, "parents": ["TAGGED_ARRAY"]} diff --git a/ecmascript/module/module_data_extractor.cpp b/ecmascript/module/module_data_extractor.cpp index c811fc00a6..dbe6f83811 100644 --- a/ecmascript/module/module_data_extractor.cpp +++ b/ecmascript/module/module_data_extractor.cpp @@ -16,7 +16,9 @@ #include "ecmascript/module/module_data_extractor.h" #include "ecmascript/builtins/builtins_json.h" +#include "ecmascript/global_env.h" #include "ecmascript/interpreter/interpreter.h" +#include "ecmascript/js_function.h" #include "ecmascript/module/accessor/module_data_accessor.h" namespace panda::ecmascript { @@ -165,16 +167,16 @@ JSHandle ModuleDataExtractor::ParseNativeModule(JSThread *thread, JSTaggedValue ModuleDataExtractor::JsonParse(JSThread *thread, const JSPandaFile *jsPandaFile, CString entryPoint) { JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); + JSHandle jsonParseFunc(thread->GetEcmaVM()->GetGlobalEnv()->GetJsonParseFunction()); EcmaRuntimeCallInfo *info = - EcmaInterpreter::NewRuntimeCallInfo( - thread, undefined, undefined, undefined, 1); // 1 : argument numbers + EcmaInterpreter::NewRuntimeCallInfo(thread, jsonParseFunc, undefined, undefined, 1); // 1 : argument numbers RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSRecordInfo *recordInfo = jsPandaFile->CheckAndGetRecordInfo(entryPoint); ASSERT(recordInfo != nullptr); StringData sd = jsPandaFile->GetStringData(EntityId(recordInfo->jsonStringId)); JSTaggedValue value(thread->GetEcmaVM()->GetFactory()->GetRawStringFromStringTable(sd)); info->SetCallArg(value); - return BuiltinsJson::Parse(info); + return JSFunction::Call(info); } bool* ModuleDataExtractor::ModuleLazyImportFlagAccessor(const JSPandaFile *pandaFile, EntityId lazyImportFlagId) -- Gitee