14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 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#ifndef ECMASCRIPT_COMPILER_BUILTINS_CONTAINERS_STUB_BUILDER_H
174514f5e3Sopenharmony_ci#define ECMASCRIPT_COMPILER_BUILTINS_CONTAINERS_STUB_BUILDER_H
184514f5e3Sopenharmony_ci#include "ecmascript/compiler/builtins/containers_arraylist_stub_builder.h"
194514f5e3Sopenharmony_ci#include "ecmascript/compiler/builtins/containers_deque_stub_builder.h"
204514f5e3Sopenharmony_ci#include "ecmascript/compiler/builtins/containers_hashmap_stub_builder.h"
214514f5e3Sopenharmony_ci#include "ecmascript/compiler/builtins/containers_hashset_stub_builder.h"
224514f5e3Sopenharmony_ci#include "ecmascript/compiler/builtins/containers_lightweightmap_stub_builder.h"
234514f5e3Sopenharmony_ci#include "ecmascript/compiler/builtins/containers_lightweightset_stub_builder.h"
244514f5e3Sopenharmony_ci#include "ecmascript/compiler/builtins/containers_linkedlist_stub_builder.h"
254514f5e3Sopenharmony_ci#include "ecmascript/compiler/builtins/containers_list_stub_builder.h"
264514f5e3Sopenharmony_ci#include "ecmascript/compiler/builtins/containers_plainarray_stub_builder.h"
274514f5e3Sopenharmony_ci#include "ecmascript/compiler/builtins/containers_queue_stub_builder.h"
284514f5e3Sopenharmony_ci#include "ecmascript/compiler/builtins/containers_stack_stub_builder.h"
294514f5e3Sopenharmony_ci#include "ecmascript/compiler/builtins/containers_vector_stub_builder.h"
304514f5e3Sopenharmony_ci#include "ecmascript/compiler/builtins/builtins_stubs.h"
314514f5e3Sopenharmony_ci#include "ecmascript/js_api/js_api_vector.h"
324514f5e3Sopenharmony_ci
334514f5e3Sopenharmony_cinamespace panda::ecmascript::kungfu {
344514f5e3Sopenharmony_ci// enumerate container functions that use function call
354514f5e3Sopenharmony_cienum class ContainersType : uint8_t {
364514f5e3Sopenharmony_ci    VECTOR_FOREACH = 0,
374514f5e3Sopenharmony_ci    VECTOR_REPLACEALLELEMENTS,
384514f5e3Sopenharmony_ci    STACK_FOREACH,
394514f5e3Sopenharmony_ci    PLAINARRAY_FOREACH,
404514f5e3Sopenharmony_ci    QUEUE_FOREACH,
414514f5e3Sopenharmony_ci    DEQUE_FOREACH,
424514f5e3Sopenharmony_ci    LIGHTWEIGHTMAP_FOREACH,
434514f5e3Sopenharmony_ci    LIGHTWEIGHTSET_FOREACH,
444514f5e3Sopenharmony_ci    HASHMAP_FOREACH,
454514f5e3Sopenharmony_ci    HASHSET_FOREACH,
464514f5e3Sopenharmony_ci    LINKEDLIST_FOREACH,
474514f5e3Sopenharmony_ci    LIST_FOREACH,
484514f5e3Sopenharmony_ci    ARRAYLIST_FOREACH,
494514f5e3Sopenharmony_ci    ARRAYLIST_REPLACEALLELEMENTS,
504514f5e3Sopenharmony_ci};
514514f5e3Sopenharmony_ci
524514f5e3Sopenharmony_ciclass ContainersStubBuilder : public BuiltinsStubBuilder {
534514f5e3Sopenharmony_cipublic:
544514f5e3Sopenharmony_ci    explicit ContainersStubBuilder(StubBuilder *parent)
554514f5e3Sopenharmony_ci        : BuiltinsStubBuilder(parent) {}
564514f5e3Sopenharmony_ci    ~ContainersStubBuilder() override = default;
574514f5e3Sopenharmony_ci    NO_MOVE_SEMANTIC(ContainersStubBuilder);
584514f5e3Sopenharmony_ci    NO_COPY_SEMANTIC(ContainersStubBuilder);
594514f5e3Sopenharmony_ci    void GenerateCircuit() override {}
604514f5e3Sopenharmony_ci
614514f5e3Sopenharmony_ci    void ContainersCommonFuncCall(GateRef glue, GateRef thisValue, GateRef numArgs,
624514f5e3Sopenharmony_ci        Variable* result, Label *exit, Label *slowPath, ContainersType type);
634514f5e3Sopenharmony_ci
644514f5e3Sopenharmony_ci    void QueueCommonFuncCall(GateRef glue, GateRef thisValue, GateRef numArgs,
654514f5e3Sopenharmony_ci        Variable* result, Label *exit, Label *slowPath, ContainersType type);
664514f5e3Sopenharmony_ci
674514f5e3Sopenharmony_ci    void DequeCommonFuncCall(GateRef glue, GateRef thisValue, GateRef numArgs,
684514f5e3Sopenharmony_ci        Variable* result, Label *exit, Label *slowPath, ContainersType type);
694514f5e3Sopenharmony_ci
704514f5e3Sopenharmony_ci    void ContainersLightWeightCall(GateRef glue, GateRef thisValue, GateRef numArgs,
714514f5e3Sopenharmony_ci        Variable* result, Label *exit, Label *slowPath, ContainersType type);
724514f5e3Sopenharmony_ci
734514f5e3Sopenharmony_ci    void ContainersHashCall(GateRef glue, GateRef thisValue, GateRef numArgs,
744514f5e3Sopenharmony_ci        Variable* result, Label *exit, Label *slowPath, ContainersType type);
754514f5e3Sopenharmony_ci
764514f5e3Sopenharmony_ci    void ContainersLinkedListCall(GateRef glue, GateRef thisValue, GateRef numArgs,
774514f5e3Sopenharmony_ci        Variable* result, Label *exit, Label *slowPath, ContainersType type);
784514f5e3Sopenharmony_ci
794514f5e3Sopenharmony_ci    GateRef IsContainer(GateRef obj, ContainersType type)
804514f5e3Sopenharmony_ci    {
814514f5e3Sopenharmony_ci        switch (type) {
824514f5e3Sopenharmony_ci            case ContainersType::VECTOR_FOREACH:
834514f5e3Sopenharmony_ci            case ContainersType::VECTOR_REPLACEALLELEMENTS:
844514f5e3Sopenharmony_ci                return IsJSAPIVector(obj);
854514f5e3Sopenharmony_ci            case ContainersType::STACK_FOREACH:
864514f5e3Sopenharmony_ci                return IsJSAPIStack(obj);
874514f5e3Sopenharmony_ci            case ContainersType::PLAINARRAY_FOREACH:
884514f5e3Sopenharmony_ci                return IsJSAPIPlainArray(obj);
894514f5e3Sopenharmony_ci            case ContainersType::QUEUE_FOREACH:
904514f5e3Sopenharmony_ci                return IsJSAPIQueue(obj);
914514f5e3Sopenharmony_ci            case ContainersType::DEQUE_FOREACH:
924514f5e3Sopenharmony_ci                return IsJSAPIDeque(obj);
934514f5e3Sopenharmony_ci            case ContainersType::LIGHTWEIGHTMAP_FOREACH:
944514f5e3Sopenharmony_ci                return IsJSAPILightWeightMap(obj);
954514f5e3Sopenharmony_ci            case ContainersType::LIGHTWEIGHTSET_FOREACH:
964514f5e3Sopenharmony_ci                return IsJSAPILightWeightSet(obj);
974514f5e3Sopenharmony_ci            case ContainersType::HASHMAP_FOREACH:
984514f5e3Sopenharmony_ci                return IsJSAPIHashMap(obj);
994514f5e3Sopenharmony_ci            case ContainersType::HASHSET_FOREACH:
1004514f5e3Sopenharmony_ci                return IsJSAPIHashSet(obj);
1014514f5e3Sopenharmony_ci            case ContainersType::LINKEDLIST_FOREACH:
1024514f5e3Sopenharmony_ci                return IsJSAPILinkedList(obj);
1034514f5e3Sopenharmony_ci            case ContainersType::LIST_FOREACH:
1044514f5e3Sopenharmony_ci                return IsJSAPIList(obj);
1054514f5e3Sopenharmony_ci            case ContainersType::ARRAYLIST_FOREACH:
1064514f5e3Sopenharmony_ci            case ContainersType::ARRAYLIST_REPLACEALLELEMENTS:
1074514f5e3Sopenharmony_ci                return IsJSAPIArrayList(obj);
1084514f5e3Sopenharmony_ci            default:
1094514f5e3Sopenharmony_ci                LOG_ECMA(FATAL) << "this branch is unreachable";
1104514f5e3Sopenharmony_ci                UNREACHABLE();
1114514f5e3Sopenharmony_ci        }
1124514f5e3Sopenharmony_ci        return False();
1134514f5e3Sopenharmony_ci    }
1144514f5e3Sopenharmony_ci
1154514f5e3Sopenharmony_ci    bool IsReplaceAllElements(ContainersType type)
1164514f5e3Sopenharmony_ci    {
1174514f5e3Sopenharmony_ci        switch (type) {
1184514f5e3Sopenharmony_ci            case ContainersType::STACK_FOREACH:
1194514f5e3Sopenharmony_ci            case ContainersType::VECTOR_FOREACH:
1204514f5e3Sopenharmony_ci            case ContainersType::PLAINARRAY_FOREACH:
1214514f5e3Sopenharmony_ci            case ContainersType::QUEUE_FOREACH:
1224514f5e3Sopenharmony_ci            case ContainersType::DEQUE_FOREACH:
1234514f5e3Sopenharmony_ci            case ContainersType::ARRAYLIST_FOREACH:
1244514f5e3Sopenharmony_ci                return false;
1254514f5e3Sopenharmony_ci            case ContainersType::VECTOR_REPLACEALLELEMENTS:
1264514f5e3Sopenharmony_ci            case ContainersType::ARRAYLIST_REPLACEALLELEMENTS:
1274514f5e3Sopenharmony_ci                return true;
1284514f5e3Sopenharmony_ci            default:
1294514f5e3Sopenharmony_ci                LOG_ECMA(FATAL) << "this branch is unreachable";
1304514f5e3Sopenharmony_ci                UNREACHABLE();
1314514f5e3Sopenharmony_ci        }
1324514f5e3Sopenharmony_ci        return false;
1334514f5e3Sopenharmony_ci    }
1344514f5e3Sopenharmony_ci
1354514f5e3Sopenharmony_ci    bool IsPlainArray(ContainersType type)
1364514f5e3Sopenharmony_ci    {
1374514f5e3Sopenharmony_ci        switch (type) {
1384514f5e3Sopenharmony_ci            case ContainersType::STACK_FOREACH:
1394514f5e3Sopenharmony_ci            case ContainersType::VECTOR_FOREACH:
1404514f5e3Sopenharmony_ci            case ContainersType::VECTOR_REPLACEALLELEMENTS:
1414514f5e3Sopenharmony_ci            case ContainersType::QUEUE_FOREACH:
1424514f5e3Sopenharmony_ci            case ContainersType::DEQUE_FOREACH:
1434514f5e3Sopenharmony_ci            case ContainersType::ARRAYLIST_FOREACH:
1444514f5e3Sopenharmony_ci            case ContainersType::ARRAYLIST_REPLACEALLELEMENTS:
1454514f5e3Sopenharmony_ci                return false;
1464514f5e3Sopenharmony_ci            case ContainersType::PLAINARRAY_FOREACH:
1474514f5e3Sopenharmony_ci                return true;
1484514f5e3Sopenharmony_ci            default:
1494514f5e3Sopenharmony_ci                LOG_ECMA(FATAL) << "this branch is unreachable";
1504514f5e3Sopenharmony_ci                UNREACHABLE();
1514514f5e3Sopenharmony_ci        }
1524514f5e3Sopenharmony_ci        return false;
1534514f5e3Sopenharmony_ci    }
1544514f5e3Sopenharmony_ci
1554514f5e3Sopenharmony_ci    bool IsArrayListReplaceAllelements(ContainersType type)
1564514f5e3Sopenharmony_ci    {
1574514f5e3Sopenharmony_ci        switch (type) {
1584514f5e3Sopenharmony_ci            case ContainersType::STACK_FOREACH:
1594514f5e3Sopenharmony_ci            case ContainersType::VECTOR_FOREACH:
1604514f5e3Sopenharmony_ci            case ContainersType::VECTOR_REPLACEALLELEMENTS:
1614514f5e3Sopenharmony_ci            case ContainersType::QUEUE_FOREACH:
1624514f5e3Sopenharmony_ci            case ContainersType::DEQUE_FOREACH:
1634514f5e3Sopenharmony_ci            case ContainersType::ARRAYLIST_FOREACH:
1644514f5e3Sopenharmony_ci            case ContainersType::PLAINARRAY_FOREACH:
1654514f5e3Sopenharmony_ci                return false;
1664514f5e3Sopenharmony_ci            case ContainersType::ARRAYLIST_REPLACEALLELEMENTS:
1674514f5e3Sopenharmony_ci                return true;
1684514f5e3Sopenharmony_ci            default:
1694514f5e3Sopenharmony_ci                LOG_ECMA(FATAL) << "this branch is unreachable";
1704514f5e3Sopenharmony_ci                UNREACHABLE();
1714514f5e3Sopenharmony_ci        }
1724514f5e3Sopenharmony_ci        return false;
1734514f5e3Sopenharmony_ci    }
1744514f5e3Sopenharmony_ci
1754514f5e3Sopenharmony_ci    void ContainerSet(GateRef glue, GateRef obj, GateRef index, GateRef value, ContainersType type)
1764514f5e3Sopenharmony_ci    {
1774514f5e3Sopenharmony_ci        switch (type) {
1784514f5e3Sopenharmony_ci            case ContainersType::VECTOR_REPLACEALLELEMENTS: {
1794514f5e3Sopenharmony_ci                ContainersVectorStubBuilder vectorBuilder(this);
1804514f5e3Sopenharmony_ci                vectorBuilder.Set(glue, obj, index, value);
1814514f5e3Sopenharmony_ci                break;
1824514f5e3Sopenharmony_ci            }
1834514f5e3Sopenharmony_ci            case ContainersType::ARRAYLIST_REPLACEALLELEMENTS: {
1844514f5e3Sopenharmony_ci                ContainersArrayListStubBuilder arrayListBuilder(this);
1854514f5e3Sopenharmony_ci                arrayListBuilder.Set(glue, obj, index, value);
1864514f5e3Sopenharmony_ci                break;
1874514f5e3Sopenharmony_ci            }
1884514f5e3Sopenharmony_ci            default:
1894514f5e3Sopenharmony_ci                LOG_ECMA(FATAL) << "this branch is unreachable";
1904514f5e3Sopenharmony_ci                UNREACHABLE();
1914514f5e3Sopenharmony_ci        }
1924514f5e3Sopenharmony_ci    }
1934514f5e3Sopenharmony_ci
1944514f5e3Sopenharmony_ci    GateRef ContainerGetSize(GateRef obj, ContainersType type)
1954514f5e3Sopenharmony_ci    {
1964514f5e3Sopenharmony_ci        switch (type) {
1974514f5e3Sopenharmony_ci            case ContainersType::VECTOR_FOREACH:
1984514f5e3Sopenharmony_ci            case ContainersType::VECTOR_REPLACEALLELEMENTS: {
1994514f5e3Sopenharmony_ci                ContainersVectorStubBuilder vectorBuilder(this);
2004514f5e3Sopenharmony_ci                return vectorBuilder.GetSize(obj);
2014514f5e3Sopenharmony_ci            }
2024514f5e3Sopenharmony_ci            case ContainersType::STACK_FOREACH: {
2034514f5e3Sopenharmony_ci                ContainersStackStubBuilder stackBuilder(this);
2044514f5e3Sopenharmony_ci                return stackBuilder.GetSize(obj);
2054514f5e3Sopenharmony_ci            }
2064514f5e3Sopenharmony_ci            case ContainersType::PLAINARRAY_FOREACH: {
2074514f5e3Sopenharmony_ci                ContainersPlainArrayStubBuilder plainArrayBuilder(this);
2084514f5e3Sopenharmony_ci                return plainArrayBuilder.GetSize(obj);
2094514f5e3Sopenharmony_ci            }
2104514f5e3Sopenharmony_ci            case ContainersType::QUEUE_FOREACH: {
2114514f5e3Sopenharmony_ci                ContainersQueueStubBuilder queueBuilder(this);
2124514f5e3Sopenharmony_ci                return queueBuilder.GetArrayLength(obj);
2134514f5e3Sopenharmony_ci            }
2144514f5e3Sopenharmony_ci            case ContainersType::DEQUE_FOREACH: {
2154514f5e3Sopenharmony_ci                ContainersDequeStubBuilder dequeBuilder(this);
2164514f5e3Sopenharmony_ci                return dequeBuilder.GetSize(obj);
2174514f5e3Sopenharmony_ci            }
2184514f5e3Sopenharmony_ci            case ContainersType::LIGHTWEIGHTMAP_FOREACH: {
2194514f5e3Sopenharmony_ci                ContainersLightWeightMapStubBuilder lightWeightMapBuilder(this);
2204514f5e3Sopenharmony_ci                return lightWeightMapBuilder.GetSize(obj);
2214514f5e3Sopenharmony_ci            }
2224514f5e3Sopenharmony_ci            case ContainersType::LIGHTWEIGHTSET_FOREACH: {
2234514f5e3Sopenharmony_ci                ContainersLightWeightSetStubBuilder lightWeightSetBuilder(this);
2244514f5e3Sopenharmony_ci                return lightWeightSetBuilder.GetSize(obj);
2254514f5e3Sopenharmony_ci            }
2264514f5e3Sopenharmony_ci            case ContainersType::HASHMAP_FOREACH: {
2274514f5e3Sopenharmony_ci                ContainersHashMapStubBuilder hashMapBuilder(this);
2284514f5e3Sopenharmony_ci                return hashMapBuilder.GetTableLength(obj);
2294514f5e3Sopenharmony_ci            }
2304514f5e3Sopenharmony_ci            case ContainersType::HASHSET_FOREACH: {
2314514f5e3Sopenharmony_ci                ContainersHashSetStubBuilder hashSetBuilder(this);
2324514f5e3Sopenharmony_ci                return hashSetBuilder.GetTableLength(obj);
2334514f5e3Sopenharmony_ci            }
2344514f5e3Sopenharmony_ci            case ContainersType::LINKEDLIST_FOREACH: {
2354514f5e3Sopenharmony_ci                ContainersLinkedListStubBuilder linkedListBuilder(this);
2364514f5e3Sopenharmony_ci                return linkedListBuilder.GetTableLength(obj);
2374514f5e3Sopenharmony_ci            }
2384514f5e3Sopenharmony_ci            case ContainersType::LIST_FOREACH: {
2394514f5e3Sopenharmony_ci                ContainersListStubBuilder listBuilder(this);
2404514f5e3Sopenharmony_ci                return listBuilder.GetTableLength(obj);
2414514f5e3Sopenharmony_ci            }
2424514f5e3Sopenharmony_ci            case ContainersType::ARRAYLIST_REPLACEALLELEMENTS:
2434514f5e3Sopenharmony_ci            case ContainersType::ARRAYLIST_FOREACH: {
2444514f5e3Sopenharmony_ci                ContainersArrayListStubBuilder arrayListBuilder(this);
2454514f5e3Sopenharmony_ci                return arrayListBuilder.GetSize(obj);
2464514f5e3Sopenharmony_ci            }
2474514f5e3Sopenharmony_ci            default:
2484514f5e3Sopenharmony_ci                LOG_ECMA(FATAL) << "this branch is unreachable";
2494514f5e3Sopenharmony_ci                UNREACHABLE();
2504514f5e3Sopenharmony_ci        }
2514514f5e3Sopenharmony_ci        return False();
2524514f5e3Sopenharmony_ci    }
2534514f5e3Sopenharmony_ci
2544514f5e3Sopenharmony_ci    GateRef ContainerGetValue(GateRef obj, GateRef index, ContainersType type)
2554514f5e3Sopenharmony_ci    {
2564514f5e3Sopenharmony_ci        switch (type) {
2574514f5e3Sopenharmony_ci            case ContainersType::VECTOR_FOREACH:
2584514f5e3Sopenharmony_ci            case ContainersType::VECTOR_REPLACEALLELEMENTS: {
2594514f5e3Sopenharmony_ci                ContainersVectorStubBuilder vectorBuilder(this);
2604514f5e3Sopenharmony_ci                return vectorBuilder.Get(obj, index);
2614514f5e3Sopenharmony_ci            }
2624514f5e3Sopenharmony_ci            case ContainersType::STACK_FOREACH: {
2634514f5e3Sopenharmony_ci                ContainersStackStubBuilder stackBuilder(this);
2644514f5e3Sopenharmony_ci                return stackBuilder.Get(obj, index);
2654514f5e3Sopenharmony_ci            }
2664514f5e3Sopenharmony_ci            case ContainersType::PLAINARRAY_FOREACH: {
2674514f5e3Sopenharmony_ci                ContainersPlainArrayStubBuilder plainArrayBuilder(this);
2684514f5e3Sopenharmony_ci                return plainArrayBuilder.Get(obj, index);
2694514f5e3Sopenharmony_ci            }
2704514f5e3Sopenharmony_ci            case ContainersType::QUEUE_FOREACH: {
2714514f5e3Sopenharmony_ci                ContainersQueueStubBuilder queueBuilder(this);
2724514f5e3Sopenharmony_ci                return queueBuilder.Get(obj, index);
2734514f5e3Sopenharmony_ci            }
2744514f5e3Sopenharmony_ci            case ContainersType::DEQUE_FOREACH: {
2754514f5e3Sopenharmony_ci                ContainersDequeStubBuilder dequeBuilder(this);
2764514f5e3Sopenharmony_ci                return dequeBuilder.Get(obj, index);
2774514f5e3Sopenharmony_ci            }
2784514f5e3Sopenharmony_ci            case ContainersType::LIGHTWEIGHTMAP_FOREACH: {
2794514f5e3Sopenharmony_ci                ContainersLightWeightMapStubBuilder lightWeightMapBuilder(this);
2804514f5e3Sopenharmony_ci                return lightWeightMapBuilder.GetValue(obj, index);
2814514f5e3Sopenharmony_ci            }
2824514f5e3Sopenharmony_ci            case ContainersType::LIGHTWEIGHTSET_FOREACH: {
2834514f5e3Sopenharmony_ci                ContainersLightWeightSetStubBuilder lightWeightSetBuilder(this);
2844514f5e3Sopenharmony_ci                return lightWeightSetBuilder.GetValue(obj, index);
2854514f5e3Sopenharmony_ci            }
2864514f5e3Sopenharmony_ci            case ContainersType::ARRAYLIST_REPLACEALLELEMENTS:
2874514f5e3Sopenharmony_ci            case ContainersType::ARRAYLIST_FOREACH: {
2884514f5e3Sopenharmony_ci                ContainersArrayListStubBuilder arrayListBuilder(this);
2894514f5e3Sopenharmony_ci                return arrayListBuilder.Get(obj, index);
2904514f5e3Sopenharmony_ci            }
2914514f5e3Sopenharmony_ci            default:
2924514f5e3Sopenharmony_ci                LOG_ECMA(FATAL) << "this branch is unreachable";
2934514f5e3Sopenharmony_ci                UNREACHABLE();
2944514f5e3Sopenharmony_ci        }
2954514f5e3Sopenharmony_ci        return False();
2964514f5e3Sopenharmony_ci    }
2974514f5e3Sopenharmony_ci
2984514f5e3Sopenharmony_ci    GateRef ContainerGetKey(GateRef obj, GateRef index, ContainersType type)
2994514f5e3Sopenharmony_ci    {
3004514f5e3Sopenharmony_ci        switch (type) {
3014514f5e3Sopenharmony_ci            case ContainersType::LIGHTWEIGHTMAP_FOREACH: {
3024514f5e3Sopenharmony_ci                ContainersLightWeightMapStubBuilder lightWeightMapBuilder(this);
3034514f5e3Sopenharmony_ci                return lightWeightMapBuilder.GetKey(obj, index);
3044514f5e3Sopenharmony_ci            }
3054514f5e3Sopenharmony_ci            case ContainersType::LIGHTWEIGHTSET_FOREACH: {
3064514f5e3Sopenharmony_ci                ContainersLightWeightSetStubBuilder lightWeightSetBuilder(this);
3074514f5e3Sopenharmony_ci                return lightWeightSetBuilder.GetKey(obj, index);
3084514f5e3Sopenharmony_ci            }
3094514f5e3Sopenharmony_ci            default:
3104514f5e3Sopenharmony_ci                LOG_ECMA(FATAL) << "this branch is unreachable";
3114514f5e3Sopenharmony_ci                UNREACHABLE();
3124514f5e3Sopenharmony_ci        }
3134514f5e3Sopenharmony_ci        return False();
3144514f5e3Sopenharmony_ci    }
3154514f5e3Sopenharmony_ci
3164514f5e3Sopenharmony_ci    GateRef ContainerGetNode(GateRef obj, GateRef index, ContainersType type)
3174514f5e3Sopenharmony_ci    {
3184514f5e3Sopenharmony_ci        switch (type) {
3194514f5e3Sopenharmony_ci            case ContainersType::HASHMAP_FOREACH: {
3204514f5e3Sopenharmony_ci                ContainersHashMapStubBuilder hashMapBuilder(this);
3214514f5e3Sopenharmony_ci                return hashMapBuilder.GetNode(obj, index);
3224514f5e3Sopenharmony_ci            }
3234514f5e3Sopenharmony_ci            case ContainersType::HASHSET_FOREACH: {
3244514f5e3Sopenharmony_ci                ContainersHashSetStubBuilder hashSetBuilder(this);
3254514f5e3Sopenharmony_ci                return hashSetBuilder.GetNode(obj, index);
3264514f5e3Sopenharmony_ci            }
3274514f5e3Sopenharmony_ci            case ContainersType::LINKEDLIST_FOREACH: {
3284514f5e3Sopenharmony_ci                ContainersLinkedListStubBuilder linkedListBuilder(this);
3294514f5e3Sopenharmony_ci                return linkedListBuilder.GetNode(obj, index);
3304514f5e3Sopenharmony_ci            }
3314514f5e3Sopenharmony_ci            case ContainersType::LIST_FOREACH: {
3324514f5e3Sopenharmony_ci                ContainersListStubBuilder listBuilder(this);
3334514f5e3Sopenharmony_ci                return listBuilder.GetNode(obj, index);
3344514f5e3Sopenharmony_ci            }
3354514f5e3Sopenharmony_ci            default:
3364514f5e3Sopenharmony_ci                LOG_ECMA(FATAL) << "this branch is unreachable";
3374514f5e3Sopenharmony_ci                UNREACHABLE();
3384514f5e3Sopenharmony_ci        }
3394514f5e3Sopenharmony_ci        return False();
3404514f5e3Sopenharmony_ci    }
3414514f5e3Sopenharmony_ci
3424514f5e3Sopenharmony_ci    GateRef PlainArrayGetKey(GateRef obj, GateRef index)
3434514f5e3Sopenharmony_ci    {
3444514f5e3Sopenharmony_ci        ContainersPlainArrayStubBuilder plainArrayBuilder(this);
3454514f5e3Sopenharmony_ci        return plainArrayBuilder.GetKey(obj, index);
3464514f5e3Sopenharmony_ci    }
3474514f5e3Sopenharmony_ci
3484514f5e3Sopenharmony_ci    GateRef QueueGetNextPosition(GateRef obj, GateRef index)
3494514f5e3Sopenharmony_ci    {
3504514f5e3Sopenharmony_ci        ContainersQueueStubBuilder queueBuilder(this);
3514514f5e3Sopenharmony_ci        return queueBuilder.GetNextPosition(obj, index);
3524514f5e3Sopenharmony_ci    }
3534514f5e3Sopenharmony_ci
3544514f5e3Sopenharmony_ci    GateRef QueueGetCurrentFront(GateRef obj)
3554514f5e3Sopenharmony_ci    {
3564514f5e3Sopenharmony_ci        ContainersQueueStubBuilder queueBuilder(this);
3574514f5e3Sopenharmony_ci        return queueBuilder.GetCurrentFront(obj);
3584514f5e3Sopenharmony_ci    }
3594514f5e3Sopenharmony_ci};
3604514f5e3Sopenharmony_ci}  // namespace panda::ecmascript::kungfu
3614514f5e3Sopenharmony_ci#endif  // ECMASCRIPT_COMPILER_BUILTINS_CONTAINERS_STUB_BUILDER_H