• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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_JS_API_JS_API_LIST_H
17 #define ECMASCRIPT_JS_API_JS_API_LIST_H
18 
19 #include "ecmascript/js_object.h"
20 #include "ecmascript/js_tagged_value-inl.h"
21 #include "ecmascript/tagged_list.h"
22 
23 namespace panda::ecmascript {
24 class JSAPIList : public JSObject {
25 public:
26     static constexpr uint32_t DEFAULT_CAPACITY_LENGTH = 10;
Cast(TaggedObject * object)27     static JSAPIList *Cast(TaggedObject *object)
28     {
29         ASSERT(JSTaggedValue(object).IsJSAPIList());
30         return static_cast<JSAPIList *>(object);
31     }
32 
33     static void Add(JSThread *thread, const JSHandle<JSAPIList> &list, const JSHandle<JSTaggedValue> &value);
34     static JSTaggedValue Insert(JSThread *thread, const JSHandle<JSAPIList> &list,
35                                 const JSHandle<JSTaggedValue> &value, const int index);
36     static JSTaggedValue Set(JSThread *thread, const JSHandle<JSAPIList> &list,
37                              const int index, const JSHandle<JSTaggedValue> &value);
38     static JSTaggedValue ReplaceAllElements(JSThread *thread, const JSHandle<JSTaggedValue> &thisHandle,
39                                             const JSHandle<JSTaggedValue> &callbackFn,
40                                             const JSHandle<JSTaggedValue> &thisArg);
41     static JSTaggedValue Sort(JSThread *thread, const JSHandle<JSTaggedValue> &thisHandle,
42                               const JSHandle<JSTaggedValue> &callbackFn);
43     static JSTaggedValue ConvertToArray(const JSThread *thread, const JSHandle<JSAPIList> &list);
44     static JSTaggedValue GetSubList(JSThread *thread, const JSHandle<JSAPIList> &list,
45                                     const int fromIndex, const int toIndex);
46     static JSTaggedValue RemoveByIndex(JSThread *thread, const JSHandle<JSAPIList> &list, const int &index);
47     static JSHandle<TaggedArray> OwnKeys(JSThread *thread, const JSHandle<JSAPIList> &list);
48     static bool GetOwnProperty(JSThread *thread, const JSHandle<JSAPIList> &list,
49                                const JSHandle<JSTaggedValue> &key);
50     static OperationResult GetProperty(JSThread *thread, const JSHandle<JSAPIList> &list,
51                                        const JSHandle<JSTaggedValue> &key);
52     static bool SetProperty(JSThread *thread, const JSHandle<JSAPIList> &obj,
53                             const JSHandle<JSTaggedValue> &key,
54                             const JSHandle<JSTaggedValue> &value);
55 
56     JSTaggedValue GetFirst();
57     JSTaggedValue GetLast();
58     bool IsEmpty();
59     JSTaggedValue Get(const int index);
60     bool Has(const JSTaggedValue &element);
61     JSTaggedValue GetIndexOf(const JSTaggedValue &element);
62     JSTaggedValue GetLastIndexOf(const JSTaggedValue &element);
63     JSTaggedValue Equal(JSThread *thread, const JSHandle<JSAPIList> &list);
64     void Clear(JSThread *thread);
65     JSTaggedValue Remove(JSThread *thread, const JSTaggedValue &element);
Length()66     inline uint32_t Length()
67     {
68         return TaggedSingleList::Cast(GetSingleList().GetTaggedObject())->Length();
69     }
70 
71     static constexpr size_t SINGLY_LIST_OFFSET = JSObject::SIZE;
72     ACCESSORS(SingleList, SINGLY_LIST_OFFSET, SIZE);
73     DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, SINGLY_LIST_OFFSET, SIZE)
74     DECL_DUMP()
75 };
76 }  // namespace panda::ecmascript
77 
78 #endif  // ECMASCRIPT_JS_API_JS_API_LIST_H
79