diff --git a/ecmascript/builtins/builtins.cpp b/ecmascript/builtins/builtins.cpp index 964fac54f4c1b0ea0cf9789670508ae2ebfe20fa..84208d9d4f13ec3ff36a8c77c3454c49705a8f45 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 4e36e30101f0ace2bad523d561e05fbc7139bdca..16832416c892e764ff645d1504467cb24e34cea8 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 9c193ec83226ea0f376e762467cf2daac4a8544d..2b1821995aa31d3f904f3892335b647d02d34aaa 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 c811fc00a622691fa4b780b01721aba9af38fd7f..dbe6f838114c45538b0a7f98fa7d6a7a7bf9df4e 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)