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_STACK_H 17 #define ECMASCRIPT_CONTAINERS_CONTAINERS_STACK_H 18 19 #include "ecmascript/base/builtins_base.h" 20 #include "ecmascript/ecma_runtime_call_info.h" 21 22 // List of functions in Stack.prototype, excluding the constructor and '@@' properties. 23 // V(name, func, length, stubIndex) 24 // where ContainersStack::func refers to the native implementation of Stack.prototype[name]. 25 #define CONTAINER_STACK_PROTOTYPE_FUNCTIONS(V) \ 26 V("push", Push, 1, INVALID) \ 27 V("isEmpty", IsEmpty, 0, INVALID) \ 28 V("peek", Peek, 0, INVALID) \ 29 V("pop", Pop, 0, INVALID) \ 30 V("locate", Locate, 1, INVALID) \ 31 V("forEach", ForEach, 2, StackForEach) 32 33 namespace panda::ecmascript::containers { 34 class ContainersStack : public base::BuiltinsBase { 35 public: 36 static JSTaggedValue StackConstructor(EcmaRuntimeCallInfo *argv); 37 static JSTaggedValue Iterator(EcmaRuntimeCallInfo *argv); 38 static JSTaggedValue IsEmpty(EcmaRuntimeCallInfo *argv); 39 static JSTaggedValue Push(EcmaRuntimeCallInfo *argv); 40 static JSTaggedValue Peek(EcmaRuntimeCallInfo *argv); 41 static JSTaggedValue Pop(EcmaRuntimeCallInfo *argv); 42 static JSTaggedValue Locate(EcmaRuntimeCallInfo *argv); 43 static JSTaggedValue ForEach(EcmaRuntimeCallInfo *argv); 44 static JSTaggedValue GetLength(EcmaRuntimeCallInfo *argv); 45 46 // Excluding the constructor and '@@' internal properties. GetStackPrototypeFunctions()47 static Span<const base::BuiltinFunctionEntry> GetStackPrototypeFunctions() 48 { 49 return Span<const base::BuiltinFunctionEntry>(STACK_PROTOTYPE_FUNCTIONS); 50 } 51 52 private: 53 #define CONTAINER_STACK_FUNCTION_ENTRY(name, method, length, id) \ 54 base::BuiltinFunctionEntry::Create(name, ContainersStack::method, length, BUILTINS_STUB_ID(id)), 55 56 static constexpr std::array STACK_PROTOTYPE_FUNCTIONS = { 57 CONTAINER_STACK_PROTOTYPE_FUNCTIONS(CONTAINER_STACK_FUNCTION_ENTRY) 58 }; 59 #undef CONTAINER_STACK_FUNCTION_ENTRY 60 }; 61 } // namespace panda::ecmascript::containers 62 #endif // ECMASCRIPT_CONTAINERS_CONTAINERS_STACK_H 63