• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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, kungfu::BuiltinsStubCSigns::ID builtinId =
54                                             kungfu::BuiltinsStubCSigns::INVALID);
55     static void SetFrozenFunction(JSThread *thread, const JSHandle<JSObject> &obj, const char *key, EcmaEntrypoint func,
56                                   int length, kungfu::BuiltinsStubCSigns::ID builtinId =
57                                   kungfu::BuiltinsStubCSigns::INVALID);
58     static void SetFrozenConstructor(JSThread *thread, const JSHandle<JSObject> &obj, const char *keyChar,
59                                      JSHandle<JSTaggedValue> &value);
60     static JSHandle<JSTaggedValue> CreateGetter(JSThread *thread, EcmaEntrypoint func, const char *name,
61                                                 int length);
62     static void SetGetter(JSThread *thread, const JSHandle<JSObject> &obj,
63                           const JSHandle<JSTaggedValue> &key, const JSHandle<JSTaggedValue> &getter);
64     static void SetFunctionAtSymbol(JSThread *thread, const JSHandle<GlobalEnv> &env,
65                                     const JSHandle<JSObject> &obj, const JSHandle<JSTaggedValue> &symbol,
66                                     const char *name, EcmaEntrypoint func, int length);
67     static void SetStringTagSymbol(JSThread *thread, const JSHandle<GlobalEnv> &env,
68                                    const JSHandle<JSObject> &obj, const char *key);
69 
70     static JSTaggedValue InitializeContainer(JSThread *thread, const JSHandle<JSObject> &obj, InitializeFunction func,
71                                              const char *name);
72     static JSHandle<JSTaggedValue> InitializeArrayList(JSThread *thread);
73     static void InitializeArrayListIterator(JSThread *thread, const JSHandle<GlobalEnv> &env,
74                                             GlobalEnvConstants *globalConst);
75     static JSHandle<JSTaggedValue> InitializeHashMap(JSThread *thread);
76     static void InitializeHashMapIterator(JSThread *thread);
77     static JSHandle<JSTaggedValue> InitializeHashSet(JSThread *thread);
78     static void InitializeHashSetIterator(JSThread *thread);
79     static JSHandle<JSTaggedValue> InitializeLightWeightMap(JSThread *thread);
80     static void InitializeLightWeightMapIterator(JSThread *thread);
81     static JSHandle<JSTaggedValue> InitializeLightWeightSet(JSThread *thread);
82     static void InitializeLightWeightSetIterator(JSThread *thread);
83     static JSHandle<JSTaggedValue> InitializeTreeMap(JSThread *thread);
84     static void InitializeTreeMapIterator(JSThread *thread);
85     static JSHandle<JSTaggedValue> InitializeTreeSet(JSThread *thread);
86     static void InitializeTreeSetIterator(JSThread *thread);
87     static JSHandle<JSTaggedValue> InitializePlainArray(JSThread *thread);
88     static void InitializePlainArrayIterator(JSThread *thread);
89     static JSHandle<JSTaggedValue> InitializeVector(JSThread *thread);
90     static void InitializeVectorIterator(JSThread *thread, const JSHandle<GlobalEnv> &env,
91                                          GlobalEnvConstants *globalConst);
92     static JSHandle<JSTaggedValue> InitializeQueue(JSThread *thread);
93     static void InitializeQueueIterator(JSThread *thread, const JSHandle<GlobalEnv> &env,
94                                         GlobalEnvConstants *globalConst);
95     static JSHandle<JSTaggedValue> InitializeDeque(JSThread *thread);
96     static void InitializeDequeIterator(JSThread *thread,  const JSHandle<GlobalEnv> &env,
97                                         GlobalEnvConstants *globalConst);
98     static JSHandle<JSTaggedValue> InitializeStack(JSThread *thread);
99     static void InitializeStackIterator(JSThread *thread, GlobalEnvConstants *globalConst);
100     static JSHandle<JSTaggedValue> InitializeList(JSThread *thread);
101     static JSHandle<JSTaggedValue> InitializeLinkedList(JSThread *thread);
102     static void InitializeLinkedListIterator(JSThread *thread, const JSHandle<GlobalEnv> &env);
103     static void InitializeListIterator(JSThread *thread, const JSHandle<GlobalEnv> &env);
104 };
105 }  // namespace panda::ecmascript::containers
106 
107 #endif  // ECMASCRIPT_CONTAINERS_CONTAINERS_PRIVATE_H
108