• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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 #include "ecmascript/interpreter/interpreter.h"
22 #include "ecmascript/js_function.h"
23 namespace panda::ecmascript::containers {
24 using InitializeFunction = JSHandle<JSTaggedValue> (*)(JSThread *);
25 enum FuncLength : uint8_t { ZERO = 0, ONE, TWO, THREE, FOUR, FIVE };
26 enum ContainerTag : uint8_t {
27     ArrayList = 0,
28     Queue,
29     Deque,
30     Stack,
31     Vector,
32     List,
33     LinkedList,
34     TreeMap,
35     TreeSet,
36     HashMap,
37     HashSet,
38     LightWeightMap,
39     LightWeightSet,
40     PlainArray,
41     BitVector,
42     FastBuffer,
43     END
44 };
45 
46 // Using Lazy-loading container, including ArrayList, Queue, Stack, Vector, List, LinkedList, Deque,
47 // TreeMap, TreeSet, HashMap, HashSet, LightWeightMap, LightWeightSet, PlainArray.
48 // Use through ArkPrivate.Load([ContainerTag]) in js, ContainTag was declaerd in ArkPrivate like ArkPrivate::ArrayList.
49 class ContainersPrivate : public base::BuiltinsBase {
50 public:
51     static JSTaggedValue Load(EcmaRuntimeCallInfo *msg);
52 
53 private:
54     static JSHandle<JSFunction> NewContainerConstructor(JSThread *thread, const JSHandle<JSObject> &prototype,
55                                                         EcmaEntrypoint ctorFunc, const char *name, int length);
56     static JSHandle<JSFunction> NewFunction(JSThread *thread, const JSHandle<JSTaggedValue> &key, EcmaEntrypoint func,
57                                             int length, kungfu::BuiltinsStubCSigns::ID builtinId =
58                                             BUILTINS_STUB_ID(INVALID));
59     static void SetFrozenFunction(JSThread *thread, const JSHandle<JSObject> &obj, const char *key, EcmaEntrypoint func,
60                                   int length, kungfu::BuiltinsStubCSigns::ID builtinId =
61                                   BUILTINS_STUB_ID(INVALID));
62     static void SetFrozenConstructor(JSThread *thread, const JSHandle<JSObject> &obj, const char *keyChar,
63                                      JSHandle<JSTaggedValue> &value);
64     static JSHandle<JSTaggedValue> CreateGetter(JSThread *thread, EcmaEntrypoint func, const char *name,
65                                                 int length);
66     static void SetGetter(JSThread *thread, const JSHandle<JSObject> &obj,
67                           const JSHandle<JSTaggedValue> &key, const JSHandle<JSTaggedValue> &getter);
68     static void SetFunctionAtSymbol(JSThread *thread, const JSHandle<GlobalEnv> &env,
69                                     const JSHandle<JSObject> &obj, const JSHandle<JSTaggedValue> &symbol,
70                                     const char *name, EcmaEntrypoint func, int length);
71     static void SetStringTagSymbol(JSThread *thread, const JSHandle<GlobalEnv> &env,
72                                    const JSHandle<JSObject> &obj, const char *key);
73 
74     static JSTaggedValue InitializeContainer(JSThread *thread, const JSHandle<JSObject> &obj, InitializeFunction func,
75                                              const char *name);
76     static JSHandle<JSTaggedValue> InitializeArrayList(JSThread *thread);
77     static void InitializeArrayListIterator(JSThread *thread, const JSHandle<GlobalEnv> &env);
78     static JSHandle<JSTaggedValue> InitializeHashMap(JSThread *thread);
79     static void InitializeHashMapIterator(JSThread *thread);
80     static JSHandle<JSTaggedValue> InitializeHashSet(JSThread *thread);
81     static void InitializeHashSetIterator(JSThread *thread);
82     static JSHandle<JSTaggedValue> InitializeLightWeightMap(JSThread *thread);
83     static void InitializeLightWeightMapIterator(JSThread *thread);
84     static JSHandle<JSTaggedValue> InitializeLightWeightSet(JSThread *thread);
85     static void InitializeLightWeightSetIterator(JSThread *thread);
86     static JSHandle<JSTaggedValue> InitializeTreeMap(JSThread *thread);
87     static void InitializeTreeMapIterator(JSThread *thread);
88     static JSHandle<JSTaggedValue> InitializeTreeSet(JSThread *thread);
89     static void InitializeTreeSetIterator(JSThread *thread);
90     static JSHandle<JSTaggedValue> InitializePlainArray(JSThread *thread);
91     static void InitializePlainArrayIterator(JSThread *thread);
92     static JSHandle<JSTaggedValue> InitializeVector(JSThread *thread);
93     static void InitializeVectorIterator(JSThread *thread, const JSHandle<GlobalEnv> &env);
94     static JSHandle<JSTaggedValue> InitializeBitVector(JSThread *thread);
95     static void InitializeBitVectorIterator(JSThread *thread, const JSHandle<GlobalEnv> &env);
96     static JSHandle<JSTaggedValue> InitializeQueue(JSThread *thread);
97     static void InitializeQueueIterator(JSThread *thread, const JSHandle<GlobalEnv> &env);
98     static JSHandle<JSTaggedValue> InitializeDeque(JSThread *thread);
99     static void InitializeDequeIterator(JSThread *thread,  const JSHandle<GlobalEnv> &env);
100     static JSHandle<JSTaggedValue> InitializeStack(JSThread *thread);
101     static void InitializeStackIterator(JSThread *thread);
102     static JSHandle<JSTaggedValue> InitializeList(JSThread *thread);
103     static JSHandle<JSTaggedValue> InitializeLinkedList(JSThread *thread);
104     static void InitializeLinkedListIterator(JSThread *thread, const JSHandle<GlobalEnv> &env);
105     static void InitializeListIterator(JSThread *thread, const JSHandle<GlobalEnv> &env);
106     static JSHandle<JSTaggedValue> InitializeBuffer(JSThread *thread);
107 };
108 }  // namespace panda::ecmascript::containers
109 
110 #endif  // ECMASCRIPT_CONTAINERS_CONTAINERS_PRIVATE_H
111