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_HASHSET_H 17 #define ECMASCRIPT_CONTAINERS_CONTAINERS_HASHSET_H 18 19 #include "ecmascript/base/builtins_base.h" 20 #include "ecmascript/ecma_runtime_call_info.h" 21 22 // List of functions in HashSet.prototype, excluding the constructor and '@@' properties. 23 // V(name, func, length, stubIndex) 24 // where ContainersHashSet::func refers to the native implementation of HashSet.prototype[name]. 25 #define CONTAINER_HASHSET_PROTOTYPE_FUNCTIONS(V) \ 26 V("isEmpty", IsEmpty, 0, INVALID) \ 27 V("has", Has, 1, INVALID) \ 28 V("add", Add, 1, INVALID) \ 29 V("remove", Remove, 1, INVALID) \ 30 V("clear", Clear, 0, INVALID) \ 31 V("values", Values, 0, INVALID) \ 32 V("entries", Entries, 0, INVALID) \ 33 V("forEach", ForEach, 2, HashSetForEach) 34 35 namespace panda::ecmascript::containers { 36 class ContainersHashSet : public base::BuiltinsBase { 37 public: 38 static JSTaggedValue HashSetConstructor(EcmaRuntimeCallInfo *argv); 39 static JSTaggedValue IsEmpty(EcmaRuntimeCallInfo *argv); 40 static JSTaggedValue Has(EcmaRuntimeCallInfo *argv); 41 static JSTaggedValue Add(EcmaRuntimeCallInfo *argv); 42 static JSTaggedValue Remove(EcmaRuntimeCallInfo *argv); 43 static JSTaggedValue Clear(EcmaRuntimeCallInfo *argv); 44 static JSTaggedValue GetLength(EcmaRuntimeCallInfo *argv); 45 static JSTaggedValue GetIteratorObj(EcmaRuntimeCallInfo *argv); 46 static JSTaggedValue Values(EcmaRuntimeCallInfo *argv); 47 static JSTaggedValue Entries(EcmaRuntimeCallInfo *argv); 48 static JSTaggedValue ForEach(EcmaRuntimeCallInfo *argv); 49 50 // Excluding the constructor and '@@' internal properties. GetHashSetPrototypeFunctions()51 static Span<const base::BuiltinFunctionEntry> GetHashSetPrototypeFunctions() 52 { 53 return Span<const base::BuiltinFunctionEntry>(HASHSET_PROTOTYPE_FUNCTIONS); 54 } 55 56 private: 57 #define CONTAINER_HASHSET_FUNCTION_ENTRY(name, method, length, id) \ 58 base::BuiltinFunctionEntry::Create(name, ContainersHashSet::method, length, kungfu::BuiltinsStubCSigns::id), 59 60 static constexpr std::array HASHSET_PROTOTYPE_FUNCTIONS = { 61 CONTAINER_HASHSET_PROTOTYPE_FUNCTIONS(CONTAINER_HASHSET_FUNCTION_ENTRY) 62 }; 63 #undef CONTAINER_HASHSET_FUNCTION_ENTRY 64 }; 65 } // namespace panda::ecmascript::containers 66 #endif // ECMASCRIPT_CONTAINERS_CONTAINERS_HASHSET_H 67