1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef ECMASCRIPT_CONTAINERS_CONTAINERS_PRIVATE_H 17 #define ECMASCRIPT_CONTAINERS_CONTAINERS_PRIVATE_H 18 19 #include "ecmascript/base/builtins_base.h" 20 21 namespace panda::ecmascript::containers { 22 using InitializeFunction = JSHandle<JSTaggedValue> (*)(JSThread *); 23 enum FuncLength : uint8_t { ZERO = 0, ONE, TWO, THREE, FOUR }; 24 enum ContainerTag : uint8_t { 25 ArrayList = 0, 26 Queue, 27 Deque, 28 Stack, 29 Vector, 30 List, 31 LinkedList, 32 TreeMap, 33 TreeSet, 34 HashMap, 35 HashSet, 36 LightWeightMap, 37 LightWeightSet, 38 PlainArray, 39 END 40 }; 41 42 // Using Lazy-loading container, including ArrayList, Queue, Stack, Vector, List, LinkedList, Deque, 43 // TreeMap, TreeSet, HashMap, HashSet, LightWeightMap, LightWeightSet, PlainArray. 44 // Use through ArkPrivate.Load([ContainerTag]) in js, ContainTag was declaerd in ArkPrivate like ArkPrivate::ArrayList. 45 class ContainersPrivate : public base::BuiltinsBase { 46 public: 47 static JSTaggedValue Load(EcmaRuntimeCallInfo *msg); 48 49 private: 50 static JSHandle<JSFunction> NewContainerConstructor(JSThread *thread, const JSHandle<JSObject> &prototype, 51 EcmaEntrypoint ctorFunc, const char *name, int length); 52 static JSHandle<JSFunction> NewFunction(JSThread *thread, const JSHandle<JSTaggedValue> &key, EcmaEntrypoint func, 53 int length); 54 static void SetFrozenFunction(JSThread *thread, const JSHandle<JSObject> &obj, const char *key, EcmaEntrypoint func, 55 int length); 56 static void SetFrozenConstructor(JSThread *thread, const JSHandle<JSObject> &obj, const char *keyChar, 57 JSHandle<JSTaggedValue> &value); 58 static JSHandle<JSTaggedValue> CreateGetter(JSThread *thread, EcmaEntrypoint func, const char *name, 59 int length); 60 static void SetGetter(JSThread *thread, const JSHandle<JSObject> &obj, 61 const JSHandle<JSTaggedValue> &key, const JSHandle<JSTaggedValue> &getter); 62 static void SetFunctionAtSymbol(JSThread *thread, const JSHandle<GlobalEnv> &env, 63 const JSHandle<JSObject> &obj, const JSHandle<JSTaggedValue> &symbol, 64 const char *name, EcmaEntrypoint func, int length); 65 static void SetStringTagSymbol(JSThread *thread, const JSHandle<GlobalEnv> &env, 66 const JSHandle<JSObject> &obj, const char *key); 67 68 static JSTaggedValue InitializeContainer(JSThread *thread, const JSHandle<JSObject> &obj, InitializeFunction func, 69 const char *name); 70 static JSHandle<JSTaggedValue> InitializeArrayList(JSThread *thread); 71 static void InitializeArrayListIterator(JSThread *thread, const JSHandle<GlobalEnv> &env, 72 GlobalEnvConstants *globalConst); 73 static JSHandle<JSTaggedValue> InitializeTreeMap(JSThread *thread); 74 static void InitializeTreeMapIterator(JSThread *thread); 75 static JSHandle<JSTaggedValue> InitializeTreeSet(JSThread *thread); 76 static void InitializeTreeSetIterator(JSThread *thread); 77 }; 78 } // namespace panda::ecmascript::containers 79 80 #endif // ECMASCRIPT_CONTAINERS_CONTAINERS_PRIVATE_H 81