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_LIST_H 17 #define ECMASCRIPT_CONTAINERS_CONTAINERS_LIST_H 18 19 #include "ecmascript/base/builtins_base.h" 20 #include "ecmascript/ecma_runtime_call_info.h" 21 22 // List of functions in List.prototype, excluding the constructor and '@@' properties. 23 // V(name, func, length, stubIndex) 24 // where ContainersList::func refers to the native implementation of List.prototype[name]. 25 #define CONTAINER_LIST_PROTOTYPE_FUNCTIONS(V) \ 26 V("add", Add, 1, INVALID) \ 27 V("getFirst", GetFirst, 0, INVALID) \ 28 V("getLast", GetLast, 0, INVALID) \ 29 V("insert", Insert, 2, INVALID) \ 30 V("clear", Clear, 0, INVALID) \ 31 V("removeByIndex", RemoveByIndex, 1, INVALID) \ 32 V("remove", Remove, 1, INVALID) \ 33 V("has", Has, 1, INVALID) \ 34 V("isEmpty", IsEmpty, 0, INVALID) \ 35 V("get", Get, 1, INVALID) \ 36 V("getIndexOf", GetIndexOf, 1, INVALID) \ 37 V("getLastIndexOf", GetLastIndexOf, 1, INVALID) \ 38 V("set", Set, 2, INVALID) \ 39 V("forEach", ForEach, 2, ListForEach) \ 40 V("replaceAllElements", ReplaceAllElements, 2, INVALID) \ 41 V("equal", Equal, 1, INVALID) \ 42 V("sort", Sort, 1, INVALID) \ 43 V("convertToArray", ConvertToArray, 0, INVALID) \ 44 V("getSubList", GetSubList, 2, INVALID) 45 46 namespace panda::ecmascript::containers { 47 class ContainersList : public base::BuiltinsBase { 48 public: 49 static JSTaggedValue ListConstructor(EcmaRuntimeCallInfo *argv); 50 static JSTaggedValue Add(EcmaRuntimeCallInfo *argv); 51 static JSTaggedValue GetFirst(EcmaRuntimeCallInfo *argv); 52 static JSTaggedValue GetLast(EcmaRuntimeCallInfo *argv); 53 static JSTaggedValue Insert(EcmaRuntimeCallInfo *argv); 54 static JSTaggedValue Clear(EcmaRuntimeCallInfo *argv); 55 static JSTaggedValue RemoveByIndex(EcmaRuntimeCallInfo *argv); 56 static JSTaggedValue Remove(EcmaRuntimeCallInfo *argv); 57 static JSTaggedValue Has(EcmaRuntimeCallInfo *argv); 58 static JSTaggedValue IsEmpty(EcmaRuntimeCallInfo *argv); 59 static JSTaggedValue Get(EcmaRuntimeCallInfo *argv); 60 static JSTaggedValue GetIndexOf(EcmaRuntimeCallInfo *argv); 61 static JSTaggedValue GetLastIndexOf(EcmaRuntimeCallInfo *argv); 62 static JSTaggedValue Set(EcmaRuntimeCallInfo *argv); 63 static JSTaggedValue ForEach(EcmaRuntimeCallInfo *argv); 64 static JSTaggedValue ReplaceAllElements(EcmaRuntimeCallInfo *argv); 65 static JSTaggedValue GetIteratorObj(EcmaRuntimeCallInfo *argv); 66 static JSTaggedValue Equal(EcmaRuntimeCallInfo *argv); 67 static JSTaggedValue Sort(EcmaRuntimeCallInfo *argv); 68 static JSTaggedValue ConvertToArray(EcmaRuntimeCallInfo *argv); 69 static JSTaggedValue GetSubList(EcmaRuntimeCallInfo *argv); 70 static JSTaggedValue Length(EcmaRuntimeCallInfo *argv); 71 72 // Excluding the constructor and '@@' internal properties. GetListPrototypeFunctions()73 static Span<const base::BuiltinFunctionEntry> GetListPrototypeFunctions() 74 { 75 return Span<const base::BuiltinFunctionEntry>(LIST_PROTOTYPE_FUNCTIONS); 76 } 77 78 private: 79 #define CONTAINER_LIST_FUNCTION_ENTRY(name, method, length, id) \ 80 base::BuiltinFunctionEntry::Create(name, ContainersList::method, length, kungfu::BuiltinsStubCSigns::id), 81 82 static constexpr std::array LIST_PROTOTYPE_FUNCTIONS = { 83 CONTAINER_LIST_PROTOTYPE_FUNCTIONS(CONTAINER_LIST_FUNCTION_ENTRY) 84 }; 85 #undef CONTAINER_LIST_FUNCTION_ENTRY 86 }; 87 } // namespace panda::ecmascript::containers 88 #endif // ECMASCRIPT_CONTAINERS_CONTAINERS_LIST_H 89