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_DEQUE_H 17 #define ECMASCRIPT_CONTAINERS_CONTAINERS_DEQUE_H 18 19 #include "ecmascript/base/builtins_base.h" 20 #include "ecmascript/ecma_runtime_call_info.h" 21 22 // List of functions in Deque.prototype, excluding the constructor and '@@' properties. 23 // V(name, func, length, stubIndex) 24 // where ContainersDeque::func refers to the native implementation of Deque.prototype[name]. 25 #define CONTAINER_DEQUE_PROTOTYPE_FUNCTIONS(V) \ 26 V("insertFront", InsertFront, 1, INVALID) \ 27 V("insertEnd", InsertEnd, 1, INVALID) \ 28 V("getFirst", GetFirst, 0, INVALID) \ 29 V("getLast", GetLast, 0, INVALID) \ 30 V("has", Has, 1, INVALID) \ 31 V("popFirst", PopFirst, 0, INVALID) \ 32 V("popLast", PopLast, 0, INVALID) \ 33 V("forEach", ForEach, 2, DequeForEach) 34 35 namespace panda::ecmascript::containers { 36 class ContainersDeque : public base::BuiltinsBase { 37 public: 38 static JSTaggedValue DequeConstructor(EcmaRuntimeCallInfo *argv); 39 40 static JSTaggedValue InsertFront(EcmaRuntimeCallInfo *argv); 41 static JSTaggedValue InsertEnd(EcmaRuntimeCallInfo *argv); 42 static JSTaggedValue GetFirst(EcmaRuntimeCallInfo *argv); 43 static JSTaggedValue GetLast(EcmaRuntimeCallInfo *argv); 44 static JSTaggedValue Has(EcmaRuntimeCallInfo *argv); 45 static JSTaggedValue PopFirst(EcmaRuntimeCallInfo *argv); 46 static JSTaggedValue PopLast(EcmaRuntimeCallInfo *argv); 47 static JSTaggedValue ForEach(EcmaRuntimeCallInfo *argv); 48 static JSTaggedValue GetIteratorObj(EcmaRuntimeCallInfo *argv); 49 static JSTaggedValue GetSize(EcmaRuntimeCallInfo *argv); 50 51 // Excluding the constructor and '@@' internal properties. GetDequePrototypeFunctions()52 static Span<const base::BuiltinFunctionEntry> GetDequePrototypeFunctions() 53 { 54 return Span<const base::BuiltinFunctionEntry>(DEQUE_PROTOTYPE_FUNCTIONS); 55 } 56 57 private: 58 #define CONTAINER_DEQUE_FUNCTION_ENTRY(name, method, length, id) \ 59 base::BuiltinFunctionEntry::Create(name, ContainersDeque::method, length, kungfu::BuiltinsStubCSigns::id), 60 61 static constexpr std::array DEQUE_PROTOTYPE_FUNCTIONS = { 62 CONTAINER_DEQUE_PROTOTYPE_FUNCTIONS(CONTAINER_DEQUE_FUNCTION_ENTRY) 63 }; 64 #undef CONTAINER_DEQUE_FUNCTION_ENTRY 65 }; 66 } // namespace panda::ecmascript::containers 67 #endif // ECMASCRIPT_CONTAINERS_CONTAINERS_DEQUE_H 68