14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License.
54514f5e3Sopenharmony_ci * You may obtain a copy of the License at
64514f5e3Sopenharmony_ci *
74514f5e3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
84514f5e3Sopenharmony_ci *
94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and
134514f5e3Sopenharmony_ci * limitations under the License.
144514f5e3Sopenharmony_ci */
154514f5e3Sopenharmony_ci
164514f5e3Sopenharmony_ci#include "ecmascript/jspandafile/literal_data_extractor.h"
174514f5e3Sopenharmony_ci
184514f5e3Sopenharmony_ci#include "ecmascript/compiler/aot_file/aot_file_manager.h"
194514f5e3Sopenharmony_ci#include "ecmascript/global_env.h"
204514f5e3Sopenharmony_ci#include "ecmascript/module/js_shared_module_manager.h"
214514f5e3Sopenharmony_ci#include "ecmascript/patch/quick_fix_helper.h"
224514f5e3Sopenharmony_ci
234514f5e3Sopenharmony_cinamespace panda::ecmascript {
244514f5e3Sopenharmony_ciusing LiteralTag = panda_file::LiteralTag;
254514f5e3Sopenharmony_ciusing StringData = panda_file::StringData;
264514f5e3Sopenharmony_ciusing LiteralDataAccessor = panda_file::LiteralDataAccessor;
274514f5e3Sopenharmony_ciusing LiteralValue = panda_file::LiteralDataAccessor::LiteralValue;
284514f5e3Sopenharmony_ci
294514f5e3Sopenharmony_civoid LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const JSPandaFile *jsPandaFile, size_t index,
304514f5e3Sopenharmony_ci                                              JSMutableHandle<TaggedArray> elements,
314514f5e3Sopenharmony_ci                                              JSMutableHandle<TaggedArray> properties,
324514f5e3Sopenharmony_ci                                              JSHandle<ConstantPool> constpool,
334514f5e3Sopenharmony_ci                                              const CString &entryPoint)
344514f5e3Sopenharmony_ci{
354514f5e3Sopenharmony_ci    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
364514f5e3Sopenharmony_ci    LiteralDataAccessor lda = jsPandaFile->GetLiteralDataAccessor();
374514f5e3Sopenharmony_ci    uint32_t num = lda.GetLiteralValsNum(index) / 2;  // 2: half
384514f5e3Sopenharmony_ci    elements.Update(factory->NewOldSpaceTaggedArray(num).GetTaggedValue());
394514f5e3Sopenharmony_ci    properties.Update(factory->NewOldSpaceTaggedArray(num).GetTaggedValue());
404514f5e3Sopenharmony_ci    uint32_t epos = 0;
414514f5e3Sopenharmony_ci    uint32_t ppos = 0;
424514f5e3Sopenharmony_ci    const uint8_t pairSize = 2;
434514f5e3Sopenharmony_ci    uint32_t methodId = 0;
444514f5e3Sopenharmony_ci    FunctionKind kind;
454514f5e3Sopenharmony_ci    lda.EnumerateLiteralVals(
464514f5e3Sopenharmony_ci        index, [elements, properties, &epos, &ppos, factory, thread, jsPandaFile,
474514f5e3Sopenharmony_ci                &methodId, &kind, &constpool, &entryPoint](const LiteralValue &value, const LiteralTag &tag) {
484514f5e3Sopenharmony_ci        JSTaggedValue jt = JSTaggedValue::Null();
494514f5e3Sopenharmony_ci        bool flag = false;
504514f5e3Sopenharmony_ci        switch (tag) {
514514f5e3Sopenharmony_ci            case LiteralTag::INTEGER: {
524514f5e3Sopenharmony_ci                jt = JSTaggedValue(std::get<uint32_t>(value));
534514f5e3Sopenharmony_ci                break;
544514f5e3Sopenharmony_ci            }
554514f5e3Sopenharmony_ci            case LiteralTag::DOUBLE: {
564514f5e3Sopenharmony_ci                jt = JSTaggedValue(std::get<double>(value));
574514f5e3Sopenharmony_ci                break;
584514f5e3Sopenharmony_ci            }
594514f5e3Sopenharmony_ci            case LiteralTag::BOOL: {
604514f5e3Sopenharmony_ci                jt = JSTaggedValue(std::get<bool>(value));
614514f5e3Sopenharmony_ci                break;
624514f5e3Sopenharmony_ci            }
634514f5e3Sopenharmony_ci            case LiteralTag::STRING: {
644514f5e3Sopenharmony_ci                StringData sd = jsPandaFile->GetStringData(EntityId(std::get<uint32_t>(value)));
654514f5e3Sopenharmony_ci                EcmaString *str = factory->GetRawStringFromStringTable(sd, MemSpaceType::SHARED_OLD_SPACE);
664514f5e3Sopenharmony_ci                jt = JSTaggedValue(str);
674514f5e3Sopenharmony_ci                uint32_t elementIndex = 0;
684514f5e3Sopenharmony_ci                if (JSTaggedValue::ToElementIndex(jt, &elementIndex) && ppos % pairSize == 0) {
694514f5e3Sopenharmony_ci                    flag = true;
704514f5e3Sopenharmony_ci                }
714514f5e3Sopenharmony_ci                break;
724514f5e3Sopenharmony_ci            }
734514f5e3Sopenharmony_ci            case LiteralTag::METHOD: {
744514f5e3Sopenharmony_ci                methodId = std::get<uint32_t>(value);
754514f5e3Sopenharmony_ci                kind = FunctionKind::NORMAL_FUNCTION;
764514f5e3Sopenharmony_ci                break;
774514f5e3Sopenharmony_ci            }
784514f5e3Sopenharmony_ci            case LiteralTag::GETTER: {
794514f5e3Sopenharmony_ci                methodId = std::get<uint32_t>(value);
804514f5e3Sopenharmony_ci                kind = FunctionKind::GETTER_FUNCTION;
814514f5e3Sopenharmony_ci                break;
824514f5e3Sopenharmony_ci            }
834514f5e3Sopenharmony_ci            case LiteralTag::SETTER: {
844514f5e3Sopenharmony_ci                methodId = std::get<uint32_t>(value);
854514f5e3Sopenharmony_ci                kind = FunctionKind::SETTER_FUNCTION;
864514f5e3Sopenharmony_ci                break;
874514f5e3Sopenharmony_ci            }
884514f5e3Sopenharmony_ci            case LiteralTag::GENERATORMETHOD: {
894514f5e3Sopenharmony_ci                methodId = std::get<uint32_t>(value);
904514f5e3Sopenharmony_ci                kind = FunctionKind::GENERATOR_FUNCTION;
914514f5e3Sopenharmony_ci                break;
924514f5e3Sopenharmony_ci            }
934514f5e3Sopenharmony_ci            case LiteralTag::ASYNCGENERATORMETHOD: {
944514f5e3Sopenharmony_ci                methodId = std::get<uint32_t>(value);
954514f5e3Sopenharmony_ci                kind = FunctionKind::ASYNC_GENERATOR_FUNCTION;
964514f5e3Sopenharmony_ci                break;
974514f5e3Sopenharmony_ci            }
984514f5e3Sopenharmony_ci            case LiteralTag::METHODAFFILIATE: {
994514f5e3Sopenharmony_ci                uint16_t length = std::get<uint16_t>(value);
1004514f5e3Sopenharmony_ci                JSHandle<JSFunction> jsFunc =
1014514f5e3Sopenharmony_ci                    DefineMethodInLiteral(thread, jsPandaFile, methodId, constpool, kind, length, entryPoint);
1024514f5e3Sopenharmony_ci                jt = jsFunc.GetTaggedValue();
1034514f5e3Sopenharmony_ci                break;
1044514f5e3Sopenharmony_ci            }
1054514f5e3Sopenharmony_ci            case LiteralTag::ACCESSOR: {
1064514f5e3Sopenharmony_ci                JSHandle<AccessorData> accessor = factory->NewAccessorData();
1074514f5e3Sopenharmony_ci                jt = accessor.GetTaggedValue();
1084514f5e3Sopenharmony_ci                break;
1094514f5e3Sopenharmony_ci            }
1104514f5e3Sopenharmony_ci            case LiteralTag::NULLVALUE: {
1114514f5e3Sopenharmony_ci                break;
1124514f5e3Sopenharmony_ci            }
1134514f5e3Sopenharmony_ci            default: {
1144514f5e3Sopenharmony_ci                LOG_ECMA(FATAL) << "this branch is unreachable";
1154514f5e3Sopenharmony_ci                UNREACHABLE();
1164514f5e3Sopenharmony_ci                break;
1174514f5e3Sopenharmony_ci            }
1184514f5e3Sopenharmony_ci        }
1194514f5e3Sopenharmony_ci        if (tag != LiteralTag::METHOD && tag != LiteralTag::GETTER && tag != LiteralTag::SETTER &&
1204514f5e3Sopenharmony_ci            tag != LiteralTag::GENERATORMETHOD && tag != LiteralTag::ASYNCGENERATORMETHOD) {
1214514f5e3Sopenharmony_ci            if (epos % pairSize == 0 && !flag) {
1224514f5e3Sopenharmony_ci                properties->Set(thread, ppos++, jt);
1234514f5e3Sopenharmony_ci            } else {
1244514f5e3Sopenharmony_ci                elements->Set(thread, epos++, jt);
1254514f5e3Sopenharmony_ci            }
1264514f5e3Sopenharmony_ci        }
1274514f5e3Sopenharmony_ci    });
1284514f5e3Sopenharmony_ci}
1294514f5e3Sopenharmony_ci
1304514f5e3Sopenharmony_ciJSHandle<TaggedArray> LiteralDataExtractor::GetDatasIgnoreTypeForClass(JSThread *thread,
1314514f5e3Sopenharmony_ci    const JSPandaFile *jsPandaFile, size_t index, JSHandle<ConstantPool> constpool, const CString &entryPoint)
1324514f5e3Sopenharmony_ci{
1334514f5e3Sopenharmony_ci    LiteralDataAccessor lda = jsPandaFile->GetLiteralDataAccessor();
1344514f5e3Sopenharmony_ci    uint32_t num = lda.GetLiteralValsNum(index) / 2;  // 2: half
1354514f5e3Sopenharmony_ci    // The num is 1, indicating that the current class has no member variable.
1364514f5e3Sopenharmony_ci    if (num == 1) {
1374514f5e3Sopenharmony_ci        ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1384514f5e3Sopenharmony_ci        return factory->EmptyArray();
1394514f5e3Sopenharmony_ci    }
1404514f5e3Sopenharmony_ci    return EnumerateLiteralVals(thread, lda, jsPandaFile, index, constpool, entryPoint);
1414514f5e3Sopenharmony_ci}
1424514f5e3Sopenharmony_ci
1434514f5e3Sopenharmony_ciJSHandle<TaggedArray> LiteralDataExtractor::GetDatasIgnoreType(JSThread *thread, const JSPandaFile *jsPandaFile,
1444514f5e3Sopenharmony_ci                                                               size_t index, JSHandle<ConstantPool> constpool,
1454514f5e3Sopenharmony_ci                                                               const CString &entryPoint)
1464514f5e3Sopenharmony_ci{
1474514f5e3Sopenharmony_ci    LiteralDataAccessor lda = jsPandaFile->GetLiteralDataAccessor();
1484514f5e3Sopenharmony_ci    return EnumerateLiteralVals(thread, lda, jsPandaFile, index, constpool, entryPoint);
1494514f5e3Sopenharmony_ci}
1504514f5e3Sopenharmony_ci
1514514f5e3Sopenharmony_ciJSHandle<TaggedArray> LiteralDataExtractor::EnumerateLiteralVals(JSThread *thread, LiteralDataAccessor &lda,
1524514f5e3Sopenharmony_ci    const JSPandaFile *jsPandaFile, size_t index, JSHandle<ConstantPool> constpool, const CString &entryPoint)
1534514f5e3Sopenharmony_ci{
1544514f5e3Sopenharmony_ci    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1554514f5e3Sopenharmony_ci    uint32_t num = lda.GetLiteralValsNum(index) / 2;  // 2: half
1564514f5e3Sopenharmony_ci    JSHandle<TaggedArray> literals = factory->NewOldSpaceTaggedArray(num);
1574514f5e3Sopenharmony_ci    uint32_t pos = 0;
1584514f5e3Sopenharmony_ci    uint32_t methodId = 0;
1594514f5e3Sopenharmony_ci    FunctionKind kind;
1604514f5e3Sopenharmony_ci    lda.EnumerateLiteralVals(
1614514f5e3Sopenharmony_ci        index, [literals, &pos, factory, thread, jsPandaFile, &methodId, &kind, &constpool, &entryPoint]
1624514f5e3Sopenharmony_ci        (const LiteralValue &value, const LiteralTag &tag) {
1634514f5e3Sopenharmony_ci            JSTaggedValue jt = JSTaggedValue::Null();
1644514f5e3Sopenharmony_ci            switch (tag) {
1654514f5e3Sopenharmony_ci                case LiteralTag::INTEGER: {
1664514f5e3Sopenharmony_ci                    jt = JSTaggedValue(std::get<uint32_t>(value));
1674514f5e3Sopenharmony_ci                    break;
1684514f5e3Sopenharmony_ci                }
1694514f5e3Sopenharmony_ci                case LiteralTag::DOUBLE: {
1704514f5e3Sopenharmony_ci                    jt = JSTaggedValue(std::get<double>(value));
1714514f5e3Sopenharmony_ci                    break;
1724514f5e3Sopenharmony_ci                }
1734514f5e3Sopenharmony_ci                case LiteralTag::BOOL: {
1744514f5e3Sopenharmony_ci                    jt = JSTaggedValue(std::get<bool>(value));
1754514f5e3Sopenharmony_ci                    break;
1764514f5e3Sopenharmony_ci                }
1774514f5e3Sopenharmony_ci                case LiteralTag::STRING: {
1784514f5e3Sopenharmony_ci                    StringData sd = jsPandaFile->GetStringData(EntityId(std::get<uint32_t>(value)));
1794514f5e3Sopenharmony_ci                    EcmaString *str = factory->GetRawStringFromStringTable(sd, MemSpaceType::SHARED_OLD_SPACE);
1804514f5e3Sopenharmony_ci                    jt = JSTaggedValue(str);
1814514f5e3Sopenharmony_ci                    break;
1824514f5e3Sopenharmony_ci                }
1834514f5e3Sopenharmony_ci                case LiteralTag::METHOD: {
1844514f5e3Sopenharmony_ci                    methodId = std::get<uint32_t>(value);
1854514f5e3Sopenharmony_ci                    kind = FunctionKind::NORMAL_FUNCTION;
1864514f5e3Sopenharmony_ci                    break;
1874514f5e3Sopenharmony_ci                }
1884514f5e3Sopenharmony_ci                case LiteralTag::GETTER: {
1894514f5e3Sopenharmony_ci                    methodId = std::get<uint32_t>(value);
1904514f5e3Sopenharmony_ci                    kind = FunctionKind::GETTER_FUNCTION;
1914514f5e3Sopenharmony_ci                    break;
1924514f5e3Sopenharmony_ci                }
1934514f5e3Sopenharmony_ci                case LiteralTag::SETTER: {
1944514f5e3Sopenharmony_ci                    methodId = std::get<uint32_t>(value);
1954514f5e3Sopenharmony_ci                    kind = FunctionKind::SETTER_FUNCTION;
1964514f5e3Sopenharmony_ci                    break;
1974514f5e3Sopenharmony_ci                }
1984514f5e3Sopenharmony_ci                case LiteralTag::GENERATORMETHOD: {
1994514f5e3Sopenharmony_ci                    methodId = std::get<uint32_t>(value);
2004514f5e3Sopenharmony_ci                    kind = FunctionKind::GENERATOR_FUNCTION;
2014514f5e3Sopenharmony_ci                    break;
2024514f5e3Sopenharmony_ci                }
2034514f5e3Sopenharmony_ci                case LiteralTag::ASYNCGENERATORMETHOD: {
2044514f5e3Sopenharmony_ci                    methodId = std::get<uint32_t>(value);
2054514f5e3Sopenharmony_ci                    kind = FunctionKind::ASYNC_GENERATOR_FUNCTION;
2064514f5e3Sopenharmony_ci                    break;
2074514f5e3Sopenharmony_ci                }
2084514f5e3Sopenharmony_ci                case LiteralTag::METHODAFFILIATE: {
2094514f5e3Sopenharmony_ci                    uint16_t length = std::get<uint16_t>(value);
2104514f5e3Sopenharmony_ci                    JSHandle<FunctionTemplate> jsFunc =
2114514f5e3Sopenharmony_ci                        DefineFunctionTemplate(thread, jsPandaFile, methodId, constpool, kind, length, entryPoint);
2124514f5e3Sopenharmony_ci                    jt = jsFunc.GetTaggedValue();
2134514f5e3Sopenharmony_ci                    break;
2144514f5e3Sopenharmony_ci                }
2154514f5e3Sopenharmony_ci                case LiteralTag::ACCESSOR: {
2164514f5e3Sopenharmony_ci                    JSHandle<AccessorData> accessor = factory->NewAccessorData();
2174514f5e3Sopenharmony_ci                    jt = accessor.GetTaggedValue();
2184514f5e3Sopenharmony_ci                    break;
2194514f5e3Sopenharmony_ci                }
2204514f5e3Sopenharmony_ci                case LiteralTag::NULLVALUE: {
2214514f5e3Sopenharmony_ci                    break;
2224514f5e3Sopenharmony_ci                }
2234514f5e3Sopenharmony_ci                default: {
2244514f5e3Sopenharmony_ci                    LOG_ECMA(FATAL) << "this branch is unreachable";
2254514f5e3Sopenharmony_ci                    UNREACHABLE();
2264514f5e3Sopenharmony_ci                    break;
2274514f5e3Sopenharmony_ci                }
2284514f5e3Sopenharmony_ci            }
2294514f5e3Sopenharmony_ci            if (tag != LiteralTag::METHOD && tag != LiteralTag::GETTER && tag != LiteralTag::SETTER &&
2304514f5e3Sopenharmony_ci                tag != LiteralTag::GENERATORMETHOD && tag != LiteralTag::ASYNCGENERATORMETHOD) {
2314514f5e3Sopenharmony_ci                literals->Set(thread, pos++, jt);
2324514f5e3Sopenharmony_ci            } else {
2334514f5e3Sopenharmony_ci                uint32_t oldLength = literals->GetLength();
2344514f5e3Sopenharmony_ci                ASSERT(oldLength > 0);
2354514f5e3Sopenharmony_ci                literals->Trim(thread, oldLength - 1);
2364514f5e3Sopenharmony_ci            }
2374514f5e3Sopenharmony_ci        });
2384514f5e3Sopenharmony_ci    return literals;
2394514f5e3Sopenharmony_ci}
2404514f5e3Sopenharmony_ci
2414514f5e3Sopenharmony_ciJSHandle<FunctionTemplate> LiteralDataExtractor::DefineFunctionTemplate(JSThread *thread,
2424514f5e3Sopenharmony_ci                                                                        const JSPandaFile *jsPandaFile,
2434514f5e3Sopenharmony_ci                                                                        uint32_t offset,
2444514f5e3Sopenharmony_ci                                                                        JSHandle<ConstantPool> constpool,
2454514f5e3Sopenharmony_ci                                                                        FunctionKind kind, uint16_t length,
2464514f5e3Sopenharmony_ci                                                                        const CString &entryPoint,
2474514f5e3Sopenharmony_ci                                                                        bool isLoadedAOT, uint32_t entryIndex,
2484514f5e3Sopenharmony_ci                                                                        JSHandle<JSTaggedValue> sendableEnv,
2494514f5e3Sopenharmony_ci                                                                        ClassKind classKind)
2504514f5e3Sopenharmony_ci{
2514514f5e3Sopenharmony_ci    EcmaVM *vm = thread->GetEcmaVM();
2524514f5e3Sopenharmony_ci    ObjectFactory *factory = vm->GetFactory();
2534514f5e3Sopenharmony_ci
2544514f5e3Sopenharmony_ci    // New Method
2554514f5e3Sopenharmony_ci    auto methodLiteral = jsPandaFile->FindMethodLiteral(offset);
2564514f5e3Sopenharmony_ci    CHECK_INPUT_NULLPTR(methodLiteral,
2574514f5e3Sopenharmony_ci                        "DefineFunctionTemplate:methodLiteral is nullptr, offset: " + std::to_string(offset));
2584514f5e3Sopenharmony_ci    FunctionKind literalKind = methodLiteral->GetFunctionKind();
2594514f5e3Sopenharmony_ci    if (literalKind == FunctionKind::NONE_FUNCTION || classKind == ClassKind::SENDABLE) {
2604514f5e3Sopenharmony_ci        methodLiteral->SetFunctionKind(kind);
2614514f5e3Sopenharmony_ci    } else {
2624514f5e3Sopenharmony_ci        kind = literalKind;
2634514f5e3Sopenharmony_ci    }
2644514f5e3Sopenharmony_ci    JSHandle<Method> method = factory->NewSMethod(jsPandaFile, methodLiteral, constpool, entryIndex, isLoadedAOT);
2654514f5e3Sopenharmony_ci    if (classKind == ClassKind::SENDABLE) {
2664514f5e3Sopenharmony_ci        method->SetIsSendable(true);
2674514f5e3Sopenharmony_ci    }
2684514f5e3Sopenharmony_ci
2694514f5e3Sopenharmony_ci    // Generate Module
2704514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> module = SharedModuleManager::GetInstance()->GenerateFuncModule(thread, jsPandaFile,
2714514f5e3Sopenharmony_ci                                                                                            entryPoint, classKind);
2724514f5e3Sopenharmony_ci    if (module->IsSourceTextModule()) {
2734514f5e3Sopenharmony_ci        SourceTextModule::Cast(module->GetTaggedObject())->SetSendableEnv(thread, sendableEnv);
2744514f5e3Sopenharmony_ci    }
2754514f5e3Sopenharmony_ci
2764514f5e3Sopenharmony_ci    // New FunctionTemplate
2774514f5e3Sopenharmony_ci    JSHandle<FunctionTemplate> funcTemp;
2784514f5e3Sopenharmony_ci    if (classKind == ClassKind::SENDABLE) {
2794514f5e3Sopenharmony_ci        funcTemp = factory->NewSFunctionTemplate(method, module, length);
2804514f5e3Sopenharmony_ci    } else {
2814514f5e3Sopenharmony_ci        funcTemp = factory->NewFunctionTemplate(method, module, length);
2824514f5e3Sopenharmony_ci    }
2834514f5e3Sopenharmony_ci    return funcTemp;
2844514f5e3Sopenharmony_ci}
2854514f5e3Sopenharmony_ci
2864514f5e3Sopenharmony_ciJSHandle<JSFunction> LiteralDataExtractor::CreateJSFunctionInLiteral(EcmaVM *vm,
2874514f5e3Sopenharmony_ci                                                                     const JSHandle<Method> &method,
2884514f5e3Sopenharmony_ci                                                                     FunctionKind kind,
2894514f5e3Sopenharmony_ci                                                                     ClassKind classKind)
2904514f5e3Sopenharmony_ci{
2914514f5e3Sopenharmony_ci    ObjectFactory *factory = vm->GetFactory();
2924514f5e3Sopenharmony_ci    JSHandle<GlobalEnv> env = vm->GetGlobalEnv();
2934514f5e3Sopenharmony_ci    JSHandle<JSFunction> jsFunc;
2944514f5e3Sopenharmony_ci    JSHandle<JSHClass> functionClass;
2954514f5e3Sopenharmony_ci    if (classKind == ClassKind::SENDABLE) {
2964514f5e3Sopenharmony_ci        if (kind == FunctionKind::NORMAL_FUNCTION ||
2974514f5e3Sopenharmony_ci            kind == FunctionKind::GETTER_FUNCTION ||
2984514f5e3Sopenharmony_ci            kind == FunctionKind::SETTER_FUNCTION) {
2994514f5e3Sopenharmony_ci            functionClass = JSHandle<JSHClass>::Cast(env->GetSFunctionClassWithoutProto());
3004514f5e3Sopenharmony_ci        } else if (kind == FunctionKind::ASYNC_FUNCTION) {
3014514f5e3Sopenharmony_ci            functionClass = JSHandle<JSHClass>::Cast(env->GetAsyncFunctionClass());
3024514f5e3Sopenharmony_ci        } else {
3034514f5e3Sopenharmony_ci            functionClass = JSHandle<JSHClass>::Cast(env->GetGeneratorFunctionClass());
3044514f5e3Sopenharmony_ci        }
3054514f5e3Sopenharmony_ci        jsFunc = factory->NewSFunctionByHClass(method, functionClass);
3064514f5e3Sopenharmony_ci    } else {
3074514f5e3Sopenharmony_ci        if (kind == FunctionKind::NORMAL_FUNCTION ||
3084514f5e3Sopenharmony_ci            kind == FunctionKind::GETTER_FUNCTION ||
3094514f5e3Sopenharmony_ci            kind == FunctionKind::SETTER_FUNCTION) {
3104514f5e3Sopenharmony_ci            functionClass = JSHandle<JSHClass>::Cast(env->GetFunctionClassWithoutProto());
3114514f5e3Sopenharmony_ci        } else if (kind == FunctionKind::ASYNC_FUNCTION) {
3124514f5e3Sopenharmony_ci            functionClass = JSHandle<JSHClass>::Cast(env->GetAsyncFunctionClass());
3134514f5e3Sopenharmony_ci        } else {
3144514f5e3Sopenharmony_ci            functionClass = JSHandle<JSHClass>::Cast(env->GetGeneratorFunctionClass());
3154514f5e3Sopenharmony_ci        }
3164514f5e3Sopenharmony_ci        jsFunc = factory->NewJSFunctionByHClass(method, functionClass, MemSpaceType::OLD_SPACE);
3174514f5e3Sopenharmony_ci    }
3184514f5e3Sopenharmony_ci    return jsFunc;
3194514f5e3Sopenharmony_ci}
3204514f5e3Sopenharmony_ci
3214514f5e3Sopenharmony_ciJSHandle<JSFunction> LiteralDataExtractor::DefineMethodInLiteral(JSThread *thread, const JSPandaFile *jsPandaFile,
3224514f5e3Sopenharmony_ci                                                                 uint32_t offset, JSHandle<ConstantPool> constpool,
3234514f5e3Sopenharmony_ci                                                                 FunctionKind kind, uint16_t length,
3244514f5e3Sopenharmony_ci                                                                 const CString &entryPoint,
3254514f5e3Sopenharmony_ci                                                                 bool isLoadedAOT, uint32_t entryIndex,
3264514f5e3Sopenharmony_ci                                                                 JSHandle<JSTaggedValue> sendableEnv,
3274514f5e3Sopenharmony_ci                                                                 ClassKind classKind)
3284514f5e3Sopenharmony_ci{
3294514f5e3Sopenharmony_ci    EcmaVM *vm = thread->GetEcmaVM();
3304514f5e3Sopenharmony_ci    ObjectFactory *factory = vm->GetFactory();
3314514f5e3Sopenharmony_ci
3324514f5e3Sopenharmony_ci    auto methodLiteral = jsPandaFile->FindMethodLiteral(offset);
3334514f5e3Sopenharmony_ci    CHECK_INPUT_NULLPTR(methodLiteral,
3344514f5e3Sopenharmony_ci                        "DefineMethodInLiteral:methodLiteral is nullptr, offset: " + std::to_string(offset));
3354514f5e3Sopenharmony_ci    FunctionKind literalKind = methodLiteral->GetFunctionKind();
3364514f5e3Sopenharmony_ci    if (literalKind == FunctionKind::NONE_FUNCTION || classKind == ClassKind::SENDABLE) {
3374514f5e3Sopenharmony_ci        methodLiteral->SetFunctionKind(kind);
3384514f5e3Sopenharmony_ci    } else {
3394514f5e3Sopenharmony_ci        kind = literalKind;
3404514f5e3Sopenharmony_ci    }
3414514f5e3Sopenharmony_ci    bool canFastCall = false;
3424514f5e3Sopenharmony_ci    JSHandle<Method> method =
3434514f5e3Sopenharmony_ci        factory->NewSMethod(jsPandaFile, methodLiteral, constpool, entryIndex, isLoadedAOT, &canFastCall);
3444514f5e3Sopenharmony_ci    if (classKind == ClassKind::SENDABLE) {
3454514f5e3Sopenharmony_ci        method->SetIsSendable(true);
3464514f5e3Sopenharmony_ci    }
3474514f5e3Sopenharmony_ci    JSHandle<JSHClass> functionClass;
3484514f5e3Sopenharmony_ci    JSHandle<JSFunction> jsFunc = CreateJSFunctionInLiteral(vm, method, kind, classKind);
3494514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> module = SharedModuleManager::GetInstance()->GenerateFuncModule(thread, jsPandaFile,
3504514f5e3Sopenharmony_ci                                                                                            entryPoint, classKind);
3514514f5e3Sopenharmony_ci    if (module->IsSourceTextModule()) {
3524514f5e3Sopenharmony_ci        SourceTextModule::Cast(module->GetTaggedObject())->SetSendableEnv(thread, sendableEnv);
3534514f5e3Sopenharmony_ci    }
3544514f5e3Sopenharmony_ci
3554514f5e3Sopenharmony_ci    jsFunc->SetModule(thread, module.GetTaggedValue());
3564514f5e3Sopenharmony_ci    jsFunc->SetLength(length);
3574514f5e3Sopenharmony_ci    return jsFunc;
3584514f5e3Sopenharmony_ci}
3594514f5e3Sopenharmony_ci
3604514f5e3Sopenharmony_civoid LiteralDataExtractor::GetMethodOffsets(const JSPandaFile *jsPandaFile, size_t index,
3614514f5e3Sopenharmony_ci                                            std::vector<uint32_t> &methodOffsets)
3624514f5e3Sopenharmony_ci{
3634514f5e3Sopenharmony_ci    LiteralDataAccessor lda = jsPandaFile->GetLiteralDataAccessor();
3644514f5e3Sopenharmony_ci    lda.EnumerateLiteralVals(index, [&methodOffsets](const LiteralValue &value, const LiteralTag &tag) {
3654514f5e3Sopenharmony_ci        switch (tag) {
3664514f5e3Sopenharmony_ci            case LiteralTag::METHOD:
3674514f5e3Sopenharmony_ci            case LiteralTag::GETTER:
3684514f5e3Sopenharmony_ci            case LiteralTag::SETTER:
3694514f5e3Sopenharmony_ci            case LiteralTag::ASYNCGENERATORMETHOD:
3704514f5e3Sopenharmony_ci            case LiteralTag::GENERATORMETHOD: {
3714514f5e3Sopenharmony_ci                methodOffsets.emplace_back(std::get<uint32_t>(value));
3724514f5e3Sopenharmony_ci                break;
3734514f5e3Sopenharmony_ci            }
3744514f5e3Sopenharmony_ci            default: {
3754514f5e3Sopenharmony_ci                break;
3764514f5e3Sopenharmony_ci            }
3774514f5e3Sopenharmony_ci        }
3784514f5e3Sopenharmony_ci    });
3794514f5e3Sopenharmony_ci}
3804514f5e3Sopenharmony_ci
3814514f5e3Sopenharmony_civoid LiteralDataExtractor::GetMethodOffsets(const JSPandaFile *jsPandaFile, EntityId id,
3824514f5e3Sopenharmony_ci                                            std::vector<uint32_t> &methodOffsets)
3834514f5e3Sopenharmony_ci{
3844514f5e3Sopenharmony_ci    LiteralDataAccessor lda = jsPandaFile->GetLiteralDataAccessor();
3854514f5e3Sopenharmony_ci    lda.EnumerateLiteralVals(id, [&methodOffsets](const LiteralValue &value, const LiteralTag &tag) {
3864514f5e3Sopenharmony_ci        switch (tag) {
3874514f5e3Sopenharmony_ci            case LiteralTag::METHOD:
3884514f5e3Sopenharmony_ci            case LiteralTag::GETTER:
3894514f5e3Sopenharmony_ci            case LiteralTag::SETTER:
3904514f5e3Sopenharmony_ci            case LiteralTag::ASYNCGENERATORMETHOD:
3914514f5e3Sopenharmony_ci            case LiteralTag::GENERATORMETHOD: {
3924514f5e3Sopenharmony_ci                methodOffsets.emplace_back(std::get<uint32_t>(value));
3934514f5e3Sopenharmony_ci                break;
3944514f5e3Sopenharmony_ci            }
3954514f5e3Sopenharmony_ci            default: {
3964514f5e3Sopenharmony_ci                break;
3974514f5e3Sopenharmony_ci            }
3984514f5e3Sopenharmony_ci        }
3994514f5e3Sopenharmony_ci    });
4004514f5e3Sopenharmony_ci}
4014514f5e3Sopenharmony_ci
4024514f5e3Sopenharmony_civoid LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const JSPandaFile *jsPandaFile, EntityId id,
4034514f5e3Sopenharmony_ci                                              JSMutableHandle<TaggedArray> elements,
4044514f5e3Sopenharmony_ci                                              JSMutableHandle<TaggedArray> properties,
4054514f5e3Sopenharmony_ci                                              JSHandle<ConstantPool> constpool, const CString &entry,
4064514f5e3Sopenharmony_ci                                              bool isLoadedAOT, JSHandle<AOTLiteralInfo> entryIndexes)
4074514f5e3Sopenharmony_ci{
4084514f5e3Sopenharmony_ci    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
4094514f5e3Sopenharmony_ci    LiteralDataAccessor lda = jsPandaFile->GetLiteralDataAccessor();
4104514f5e3Sopenharmony_ci    uint32_t num = lda.GetLiteralValsNum(id) / 2;  // 2: half
4114514f5e3Sopenharmony_ci    elements.Update(factory->NewOldSpaceTaggedArray(num).GetTaggedValue());
4124514f5e3Sopenharmony_ci    properties.Update(factory->NewOldSpaceTaggedArray(num).GetTaggedValue());
4134514f5e3Sopenharmony_ci    uint32_t epos = 0;
4144514f5e3Sopenharmony_ci    uint32_t ppos = 0;
4154514f5e3Sopenharmony_ci    const uint8_t pairSize = 2;
4164514f5e3Sopenharmony_ci    uint32_t methodId = 0;
4174514f5e3Sopenharmony_ci    int pos = 0;
4184514f5e3Sopenharmony_ci    FunctionKind kind;
4194514f5e3Sopenharmony_ci    lda.EnumerateLiteralVals(
4204514f5e3Sopenharmony_ci        id, [elements, properties, &entryIndexes, &pos, &epos, &ppos, factory, thread, jsPandaFile,
4214514f5e3Sopenharmony_ci                &methodId, &kind, &constpool, &entry, &isLoadedAOT](const LiteralValue &value, const LiteralTag &tag) {
4224514f5e3Sopenharmony_ci        JSTaggedValue jt = JSTaggedValue::Null();
4234514f5e3Sopenharmony_ci        bool flag = false;
4244514f5e3Sopenharmony_ci        switch (tag) {
4254514f5e3Sopenharmony_ci            case LiteralTag::INTEGER: {
4264514f5e3Sopenharmony_ci                jt = JSTaggedValue(static_cast<int32_t>(std::get<uint32_t>(value)));
4274514f5e3Sopenharmony_ci                break;
4284514f5e3Sopenharmony_ci            }
4294514f5e3Sopenharmony_ci            case LiteralTag::DOUBLE: {
4304514f5e3Sopenharmony_ci                jt = JSTaggedValue(std::get<double>(value));
4314514f5e3Sopenharmony_ci                break;
4324514f5e3Sopenharmony_ci            }
4334514f5e3Sopenharmony_ci            case LiteralTag::BOOL: {
4344514f5e3Sopenharmony_ci                jt = JSTaggedValue(std::get<bool>(value));
4354514f5e3Sopenharmony_ci                break;
4364514f5e3Sopenharmony_ci            }
4374514f5e3Sopenharmony_ci            case LiteralTag::STRING: {
4384514f5e3Sopenharmony_ci                StringData sd = jsPandaFile->GetStringData(EntityId(std::get<uint32_t>(value)));
4394514f5e3Sopenharmony_ci                EcmaString *str = factory->GetRawStringFromStringTable(sd, MemSpaceType::SHARED_OLD_SPACE);
4404514f5e3Sopenharmony_ci                jt = JSTaggedValue(str);
4414514f5e3Sopenharmony_ci                uint32_t elementIndex = 0;
4424514f5e3Sopenharmony_ci                if (JSTaggedValue::ToElementIndex(jt, &elementIndex) && ppos % pairSize == 0) {
4434514f5e3Sopenharmony_ci                    flag = true;
4444514f5e3Sopenharmony_ci                }
4454514f5e3Sopenharmony_ci                break;
4464514f5e3Sopenharmony_ci            }
4474514f5e3Sopenharmony_ci            case LiteralTag::METHOD: {
4484514f5e3Sopenharmony_ci                methodId = std::get<uint32_t>(value);
4494514f5e3Sopenharmony_ci                kind = FunctionKind::NORMAL_FUNCTION;
4504514f5e3Sopenharmony_ci                break;
4514514f5e3Sopenharmony_ci            }
4524514f5e3Sopenharmony_ci            case LiteralTag::GETTER: {
4534514f5e3Sopenharmony_ci                methodId = std::get<uint32_t>(value);
4544514f5e3Sopenharmony_ci                kind = FunctionKind::GETTER_FUNCTION;
4554514f5e3Sopenharmony_ci                break;
4564514f5e3Sopenharmony_ci            }
4574514f5e3Sopenharmony_ci            case LiteralTag::SETTER: {
4584514f5e3Sopenharmony_ci                methodId = std::get<uint32_t>(value);
4594514f5e3Sopenharmony_ci                kind = FunctionKind::SETTER_FUNCTION;
4604514f5e3Sopenharmony_ci                break;
4614514f5e3Sopenharmony_ci            }
4624514f5e3Sopenharmony_ci            case LiteralTag::GENERATORMETHOD: {
4634514f5e3Sopenharmony_ci                methodId = std::get<uint32_t>(value);
4644514f5e3Sopenharmony_ci                kind = FunctionKind::GENERATOR_FUNCTION;
4654514f5e3Sopenharmony_ci                break;
4664514f5e3Sopenharmony_ci            }
4674514f5e3Sopenharmony_ci
4684514f5e3Sopenharmony_ci            case LiteralTag::ASYNCGENERATORMETHOD: {
4694514f5e3Sopenharmony_ci                methodId = std::get<uint32_t>(value);
4704514f5e3Sopenharmony_ci                kind = FunctionKind::ASYNC_GENERATOR_FUNCTION;
4714514f5e3Sopenharmony_ci                break;
4724514f5e3Sopenharmony_ci            }
4734514f5e3Sopenharmony_ci
4744514f5e3Sopenharmony_ci            case LiteralTag::METHODAFFILIATE: {
4754514f5e3Sopenharmony_ci                uint16_t length = std::get<uint16_t>(value);
4764514f5e3Sopenharmony_ci                int entryIndex = 0;
4774514f5e3Sopenharmony_ci                bool needSetAotFlag = (isLoadedAOT && (epos % pairSize == 0) && !flag);
4784514f5e3Sopenharmony_ci                if (needSetAotFlag) {
4794514f5e3Sopenharmony_ci                    entryIndex = entryIndexes->GetObjectFromCache(pos++).GetInt();
4804514f5e3Sopenharmony_ci                    // -1 : this jsfunction is a large function
4814514f5e3Sopenharmony_ci                    if (entryIndex == -1) {
4824514f5e3Sopenharmony_ci                        needSetAotFlag = false;
4834514f5e3Sopenharmony_ci                    }
4844514f5e3Sopenharmony_ci                }
4854514f5e3Sopenharmony_ci                JSHandle<JSFunction> jsFunc =
4864514f5e3Sopenharmony_ci                    DefineMethodInLiteral(thread, jsPandaFile, methodId, constpool, kind,
4874514f5e3Sopenharmony_ci                                          length, entry, needSetAotFlag, entryIndex);
4884514f5e3Sopenharmony_ci                jt = jsFunc.GetTaggedValue();
4894514f5e3Sopenharmony_ci                break;
4904514f5e3Sopenharmony_ci            }
4914514f5e3Sopenharmony_ci            case LiteralTag::ACCESSOR: {
4924514f5e3Sopenharmony_ci                JSHandle<AccessorData> accessor = factory->NewAccessorData();
4934514f5e3Sopenharmony_ci                jt = accessor.GetTaggedValue();
4944514f5e3Sopenharmony_ci                break;
4954514f5e3Sopenharmony_ci            }
4964514f5e3Sopenharmony_ci            case LiteralTag::NULLVALUE: {
4974514f5e3Sopenharmony_ci                break;
4984514f5e3Sopenharmony_ci            }
4994514f5e3Sopenharmony_ci            default: {
5004514f5e3Sopenharmony_ci                LOG_ECMA(FATAL) << "this branch is unreachable";
5014514f5e3Sopenharmony_ci                UNREACHABLE();
5024514f5e3Sopenharmony_ci                break;
5034514f5e3Sopenharmony_ci            }
5044514f5e3Sopenharmony_ci        }
5054514f5e3Sopenharmony_ci        if (tag != LiteralTag::METHOD && tag != LiteralTag::GETTER && tag != LiteralTag::SETTER &&
5064514f5e3Sopenharmony_ci            tag != LiteralTag::GENERATORMETHOD && tag != LiteralTag::ASYNCGENERATORMETHOD) {
5074514f5e3Sopenharmony_ci            if ((epos % pairSize == 0) && !flag) {
5084514f5e3Sopenharmony_ci                properties->Set(thread, ppos++, jt);
5094514f5e3Sopenharmony_ci            } else {
5104514f5e3Sopenharmony_ci                elements->Set(thread, epos++, jt);
5114514f5e3Sopenharmony_ci            }
5124514f5e3Sopenharmony_ci        }
5134514f5e3Sopenharmony_ci    });
5144514f5e3Sopenharmony_ci}
5154514f5e3Sopenharmony_ci
5164514f5e3Sopenharmony_ciJSHandle<TaggedArray> LiteralDataExtractor::GetDatasIgnoreTypeForClass(JSThread *thread, const JSPandaFile *jsPandaFile,
5174514f5e3Sopenharmony_ci                                                                       EntityId id, JSHandle<ConstantPool> constpool,
5184514f5e3Sopenharmony_ci                                                                       const CString &entryPoint, bool isLoadedAOT,
5194514f5e3Sopenharmony_ci                                                                       JSHandle<AOTLiteralInfo> entryIndexes,
5204514f5e3Sopenharmony_ci                                                                       ElementsKind *newKind,
5214514f5e3Sopenharmony_ci                                                                       JSHandle<JSTaggedValue> sendableEnv,
5224514f5e3Sopenharmony_ci                                                                       ClassKind classKind)
5234514f5e3Sopenharmony_ci{
5244514f5e3Sopenharmony_ci    ASSERT(jsPandaFile != nullptr);
5254514f5e3Sopenharmony_ci    LiteralDataAccessor lda = jsPandaFile->GetLiteralDataAccessor();
5264514f5e3Sopenharmony_ci    uint32_t num = lda.GetLiteralValsNum(id) / 2;  // 2: half
5274514f5e3Sopenharmony_ci    // The num is 1, indicating that the current class has no member variable.
5284514f5e3Sopenharmony_ci    if (num == 1) {
5294514f5e3Sopenharmony_ci        ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
5304514f5e3Sopenharmony_ci        return factory->EmptyArray();
5314514f5e3Sopenharmony_ci    }
5324514f5e3Sopenharmony_ci    return GetDatasIgnoreType(
5334514f5e3Sopenharmony_ci        thread, jsPandaFile, id, constpool, entryPoint, isLoadedAOT, entryIndexes, newKind, sendableEnv, classKind);
5344514f5e3Sopenharmony_ci}
5354514f5e3Sopenharmony_ci
5364514f5e3Sopenharmony_ciJSHandle<TaggedArray> LiteralDataExtractor::GetDatasIgnoreType(JSThread *thread, const JSPandaFile *jsPandaFile,
5374514f5e3Sopenharmony_ci                                                               EntityId id, JSHandle<ConstantPool> constpool,
5384514f5e3Sopenharmony_ci                                                               const CString &entryPoint, bool isLoadedAOT,
5394514f5e3Sopenharmony_ci                                                               JSHandle<AOTLiteralInfo> entryIndexes,
5404514f5e3Sopenharmony_ci                                                               ElementsKind *newKind,
5414514f5e3Sopenharmony_ci                                                               JSHandle<JSTaggedValue> sendableEnv,
5424514f5e3Sopenharmony_ci                                                               ClassKind classKind)
5434514f5e3Sopenharmony_ci{
5444514f5e3Sopenharmony_ci    ASSERT(jsPandaFile != nullptr);
5454514f5e3Sopenharmony_ci    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
5464514f5e3Sopenharmony_ci    LiteralDataAccessor lda = jsPandaFile->GetLiteralDataAccessor();
5474514f5e3Sopenharmony_ci    uint32_t num = lda.GetLiteralValsNum(id) / 2;  // 2: half
5484514f5e3Sopenharmony_ci    JSHandle<TaggedArray> literals;
5494514f5e3Sopenharmony_ci    if (classKind == ClassKind::SENDABLE) {
5504514f5e3Sopenharmony_ci        literals = JSHandle<TaggedArray>(factory->NewSCOWTaggedArray(num));
5514514f5e3Sopenharmony_ci    } else {
5524514f5e3Sopenharmony_ci        literals = JSHandle<TaggedArray>(factory->NewCOWTaggedArray(num));
5534514f5e3Sopenharmony_ci    }
5544514f5e3Sopenharmony_ci    uint32_t pos = 0;
5554514f5e3Sopenharmony_ci    uint32_t methodId = 0;
5564514f5e3Sopenharmony_ci    FunctionKind kind;
5574514f5e3Sopenharmony_ci    int index = 0;
5584514f5e3Sopenharmony_ci    lda.EnumerateLiteralVals(
5594514f5e3Sopenharmony_ci        id, [literals, &pos, factory, thread, jsPandaFile, &methodId, &kind, &constpool,
5604514f5e3Sopenharmony_ci            &entryPoint, &entryIndexes, &index, isLoadedAOT, newKind, classKind, &sendableEnv]
5614514f5e3Sopenharmony_ci        (const LiteralValue &value, const LiteralTag &tag) {
5624514f5e3Sopenharmony_ci            JSTaggedValue jt = JSTaggedValue::Null();
5634514f5e3Sopenharmony_ci            switch (tag) {
5644514f5e3Sopenharmony_ci                case LiteralTag::INTEGER: {
5654514f5e3Sopenharmony_ci                    jt = JSTaggedValue(std::get<uint32_t>(value));
5664514f5e3Sopenharmony_ci                    break;
5674514f5e3Sopenharmony_ci                }
5684514f5e3Sopenharmony_ci                case LiteralTag::DOUBLE: {
5694514f5e3Sopenharmony_ci                    jt = JSTaggedValue(std::get<double>(value));
5704514f5e3Sopenharmony_ci                    break;
5714514f5e3Sopenharmony_ci                }
5724514f5e3Sopenharmony_ci                case LiteralTag::BOOL: {
5734514f5e3Sopenharmony_ci                    jt = JSTaggedValue(std::get<bool>(value));
5744514f5e3Sopenharmony_ci                    break;
5754514f5e3Sopenharmony_ci                }
5764514f5e3Sopenharmony_ci                case LiteralTag::STRING: {
5774514f5e3Sopenharmony_ci                    StringData sd = jsPandaFile->GetStringData(EntityId(std::get<uint32_t>(value)));
5784514f5e3Sopenharmony_ci                    EcmaString *str = factory->GetRawStringFromStringTable(sd, MemSpaceType::SHARED_OLD_SPACE);
5794514f5e3Sopenharmony_ci                    jt = JSTaggedValue(str);
5804514f5e3Sopenharmony_ci                    break;
5814514f5e3Sopenharmony_ci                }
5824514f5e3Sopenharmony_ci                case LiteralTag::METHOD: {
5834514f5e3Sopenharmony_ci                    methodId = std::get<uint32_t>(value);
5844514f5e3Sopenharmony_ci                    kind = FunctionKind::NORMAL_FUNCTION;
5854514f5e3Sopenharmony_ci                    break;
5864514f5e3Sopenharmony_ci                }
5874514f5e3Sopenharmony_ci                case LiteralTag::GETTER: {
5884514f5e3Sopenharmony_ci                    methodId = std::get<uint32_t>(value);
5894514f5e3Sopenharmony_ci                    kind = FunctionKind::GETTER_FUNCTION;
5904514f5e3Sopenharmony_ci                    break;
5914514f5e3Sopenharmony_ci                }
5924514f5e3Sopenharmony_ci                case LiteralTag::SETTER: {
5934514f5e3Sopenharmony_ci                    methodId = std::get<uint32_t>(value);
5944514f5e3Sopenharmony_ci                    kind = FunctionKind::SETTER_FUNCTION;
5954514f5e3Sopenharmony_ci                    break;
5964514f5e3Sopenharmony_ci                }
5974514f5e3Sopenharmony_ci                case LiteralTag::GENERATORMETHOD: {
5984514f5e3Sopenharmony_ci                    methodId = std::get<uint32_t>(value);
5994514f5e3Sopenharmony_ci                    kind = FunctionKind::GENERATOR_FUNCTION;
6004514f5e3Sopenharmony_ci                    break;
6014514f5e3Sopenharmony_ci                }
6024514f5e3Sopenharmony_ci                case LiteralTag::ASYNCGENERATORMETHOD: {
6034514f5e3Sopenharmony_ci                    methodId = std::get<uint32_t>(value);
6044514f5e3Sopenharmony_ci                    kind = FunctionKind::ASYNC_GENERATOR_FUNCTION;
6054514f5e3Sopenharmony_ci                    break;
6064514f5e3Sopenharmony_ci                }
6074514f5e3Sopenharmony_ci                case LiteralTag::METHODAFFILIATE: {
6084514f5e3Sopenharmony_ci                    uint16_t length = std::get<uint16_t>(value);
6094514f5e3Sopenharmony_ci                    int entryIndex = 0;
6104514f5e3Sopenharmony_ci                    bool needSetAotFlag = isLoadedAOT;
6114514f5e3Sopenharmony_ci                    if (isLoadedAOT) {
6124514f5e3Sopenharmony_ci                        entryIndex = entryIndexes->GetObjectFromCache(index++).GetInt();
6134514f5e3Sopenharmony_ci                        if (entryIndex == -1) {
6144514f5e3Sopenharmony_ci                            needSetAotFlag = false;
6154514f5e3Sopenharmony_ci                        }
6164514f5e3Sopenharmony_ci                    }
6174514f5e3Sopenharmony_ci                    JSHandle<FunctionTemplate> funcTemp = DefineFunctionTemplate(thread, jsPandaFile, methodId,
6184514f5e3Sopenharmony_ci                        constpool, kind, length, entryPoint, needSetAotFlag, entryIndex, sendableEnv, classKind);
6194514f5e3Sopenharmony_ci                    jt = funcTemp.GetTaggedValue();
6204514f5e3Sopenharmony_ci                    break;
6214514f5e3Sopenharmony_ci                }
6224514f5e3Sopenharmony_ci                case LiteralTag::ACCESSOR: {
6234514f5e3Sopenharmony_ci                    JSHandle<AccessorData> accessor = factory->NewAccessorData();
6244514f5e3Sopenharmony_ci                    jt = accessor.GetTaggedValue();
6254514f5e3Sopenharmony_ci                    break;
6264514f5e3Sopenharmony_ci                }
6274514f5e3Sopenharmony_ci                case LiteralTag::LITERALARRAY: {
6284514f5e3Sopenharmony_ci                    jt = JSTaggedValue(std::get<uint32_t>(value));
6294514f5e3Sopenharmony_ci                    break;
6304514f5e3Sopenharmony_ci                }
6314514f5e3Sopenharmony_ci                case LiteralTag::NULLVALUE: {
6324514f5e3Sopenharmony_ci                    break;
6334514f5e3Sopenharmony_ci                }
6344514f5e3Sopenharmony_ci                default: {
6354514f5e3Sopenharmony_ci                    LOG_ECMA(FATAL) << "this branch is unreachable";
6364514f5e3Sopenharmony_ci                    UNREACHABLE();
6374514f5e3Sopenharmony_ci                    break;
6384514f5e3Sopenharmony_ci                }
6394514f5e3Sopenharmony_ci            }
6404514f5e3Sopenharmony_ci            if (tag != LiteralTag::METHOD && tag != LiteralTag::GETTER && tag != LiteralTag::SETTER &&
6414514f5e3Sopenharmony_ci                tag != LiteralTag::GENERATORMETHOD && tag != LiteralTag::ASYNCGENERATORMETHOD) {
6424514f5e3Sopenharmony_ci                if (newKind != nullptr) {
6434514f5e3Sopenharmony_ci                    *newKind = Elements::ToElementsKind(jt, *newKind);
6444514f5e3Sopenharmony_ci                }
6454514f5e3Sopenharmony_ci                literals->Set(thread, pos++, jt);
6464514f5e3Sopenharmony_ci            } else {
6474514f5e3Sopenharmony_ci                uint32_t oldLength = literals->GetLength();
6484514f5e3Sopenharmony_ci                ASSERT(oldLength > 0);
6494514f5e3Sopenharmony_ci                literals->Trim(thread, oldLength - 1);
6504514f5e3Sopenharmony_ci            }
6514514f5e3Sopenharmony_ci        });
6524514f5e3Sopenharmony_ci    return literals;
6534514f5e3Sopenharmony_ci}
6544514f5e3Sopenharmony_ci}  // namespace panda::ecmascript
655