14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci 164514f5e3Sopenharmony_ci#ifndef ECMASCRIPT_BUILTINS_BUILTINS_SHARED_SET_H 174514f5e3Sopenharmony_ci#define ECMASCRIPT_BUILTINS_BUILTINS_SHARED_SET_H 184514f5e3Sopenharmony_ci 194514f5e3Sopenharmony_ci#include "ecmascript/base/builtins_base.h" 204514f5e3Sopenharmony_ci#include "ecmascript/ecma_runtime_call_info.h" 214514f5e3Sopenharmony_ci 224514f5e3Sopenharmony_ci// List of functions in Set, excluding the constructor and '@@' properties. 234514f5e3Sopenharmony_ci// V(name, func, length, stubIndex) 244514f5e3Sopenharmony_ci// where BuiltinsSet::func refers to the native implementation of Set.prototype[name]. 254514f5e3Sopenharmony_ci// kungfu::BuiltinsStubCSigns::stubIndex refers to the builtin stub index, or INVALID if no stub available. 264514f5e3Sopenharmony_ci// The following functions are not listed: 274514f5e3Sopenharmony_ci// - Set.prototype.keys ( ), which is strictly equal to Set.prototype.values 284514f5e3Sopenharmony_ci#define BUILTIN_SET_PROTOTYPE_FUNCTIONS(V) \ 294514f5e3Sopenharmony_ci /* Set.prototype.add ( value ) */ \ 304514f5e3Sopenharmony_ci V("add", Add, 1, SetAdd) \ 314514f5e3Sopenharmony_ci /* Set.prototype.clear ( ) */ \ 324514f5e3Sopenharmony_ci V("clear", Clear, 0, SetClear) \ 334514f5e3Sopenharmony_ci /* Set.prototype.delete ( value ) */ \ 344514f5e3Sopenharmony_ci V("delete", Delete, 1, SetDelete) \ 354514f5e3Sopenharmony_ci /* Set.prototype.entries ( ) */ \ 364514f5e3Sopenharmony_ci V("entries", Entries, 0, SetEntries) \ 374514f5e3Sopenharmony_ci /* Set.prototype.forEach ( callbackfn [ , thisArg ] ) */ \ 384514f5e3Sopenharmony_ci V("forEach", ForEach, 1, SetForEach) \ 394514f5e3Sopenharmony_ci /* Set.prototype.has ( value ) */ \ 404514f5e3Sopenharmony_ci V("has", Has, 1, SetHas) \ 414514f5e3Sopenharmony_ci /* Set.prototype.values ( ) */ \ 424514f5e3Sopenharmony_ci V("values", Values, 0, SetValues) 434514f5e3Sopenharmony_ci 444514f5e3Sopenharmony_cinamespace panda::ecmascript::builtins { 454514f5e3Sopenharmony_ciclass BuiltinsSharedSet : public base::BuiltinsBase { 464514f5e3Sopenharmony_cipublic: 474514f5e3Sopenharmony_ci static JSTaggedValue Constructor(EcmaRuntimeCallInfo *argv); 484514f5e3Sopenharmony_ci static JSTaggedValue Species(EcmaRuntimeCallInfo *argv); 494514f5e3Sopenharmony_ci static JSTaggedValue Add(EcmaRuntimeCallInfo *argv); 504514f5e3Sopenharmony_ci static JSTaggedValue Clear(EcmaRuntimeCallInfo *argv); 514514f5e3Sopenharmony_ci static JSTaggedValue Delete(EcmaRuntimeCallInfo *argv); 524514f5e3Sopenharmony_ci static JSTaggedValue Entries(EcmaRuntimeCallInfo *argv); 534514f5e3Sopenharmony_ci static JSTaggedValue ForEach(EcmaRuntimeCallInfo *argv); 544514f5e3Sopenharmony_ci static JSTaggedValue Has(EcmaRuntimeCallInfo *argv); 554514f5e3Sopenharmony_ci static JSTaggedValue GetSize(EcmaRuntimeCallInfo *argv); 564514f5e3Sopenharmony_ci static JSTaggedValue Values(EcmaRuntimeCallInfo *argv); 574514f5e3Sopenharmony_ci 584514f5e3Sopenharmony_ci // Excluding the '@@' internal properties 594514f5e3Sopenharmony_ci static Span<const base::BuiltinFunctionEntry> GetSetPrototypeFunctions() 604514f5e3Sopenharmony_ci { 614514f5e3Sopenharmony_ci return Span<const base::BuiltinFunctionEntry>(SET_PROTOTYPE_FUNCTIONS); 624514f5e3Sopenharmony_ci } 634514f5e3Sopenharmony_ci 644514f5e3Sopenharmony_ci static size_t GetNumPrototypeInlinedProperties() 654514f5e3Sopenharmony_ci { 664514f5e3Sopenharmony_ci // 5 : 5 more inline properties in Set.prototype 674514f5e3Sopenharmony_ci // (1) Set.prototype.constructor 684514f5e3Sopenharmony_ci // (2) Set.prototype [ @@toStringTag ] 694514f5e3Sopenharmony_ci // (3) Set.prototype [ @@iterator ] 704514f5e3Sopenharmony_ci // (4) get Set.prototype.size 714514f5e3Sopenharmony_ci // (5) Set.prototype.keys, which is not included in BuiltinsSharedSet::GetSetPrototypeFunctions() 724514f5e3Sopenharmony_ci return GetSetPrototypeFunctions().Size() + 5; 734514f5e3Sopenharmony_ci } 744514f5e3Sopenharmony_ci 754514f5e3Sopenharmony_ci static Span<const std::pair<std::string_view, bool>> GetPrototypeProperties() 764514f5e3Sopenharmony_ci { 774514f5e3Sopenharmony_ci return Span<const std::pair<std::string_view, bool>>(SET_PROTOTYPE_PROPERTIES); 784514f5e3Sopenharmony_ci } 794514f5e3Sopenharmony_ci 804514f5e3Sopenharmony_ci static Span<const std::pair<std::string_view, bool>> GetFunctionProperties() 814514f5e3Sopenharmony_ci { 824514f5e3Sopenharmony_ci return Span<const std::pair<std::string_view, bool>>(SET_FUNCTION_PROPERTIES); 834514f5e3Sopenharmony_ci } 844514f5e3Sopenharmony_ciprivate: 854514f5e3Sopenharmony_ci#define BUILTIN_SET_FUNCTION_ENTRY(name, func, length, id) \ 864514f5e3Sopenharmony_ci base::BuiltinFunctionEntry::Create(name, BuiltinsSharedSet::func, length, kungfu::BuiltinsStubCSigns::id), 874514f5e3Sopenharmony_ci 884514f5e3Sopenharmony_ci static constexpr std::array SET_PROTOTYPE_FUNCTIONS = { 894514f5e3Sopenharmony_ci BUILTIN_SET_PROTOTYPE_FUNCTIONS(BUILTIN_SET_FUNCTION_ENTRY) 904514f5e3Sopenharmony_ci }; 914514f5e3Sopenharmony_ci 924514f5e3Sopenharmony_ci#undef BUILTIN_SET_FUNCTION_ENTRY 934514f5e3Sopenharmony_ci 944514f5e3Sopenharmony_ci#define SET_PROPERTIES_PAIR(name, func, length, id) \ 954514f5e3Sopenharmony_ci std::pair<std::string_view, bool>(name, false), 964514f5e3Sopenharmony_ci 974514f5e3Sopenharmony_ci static constexpr std::array SET_PROTOTYPE_PROPERTIES = { 984514f5e3Sopenharmony_ci std::pair<std::string_view, bool>("constructor", false), 994514f5e3Sopenharmony_ci BUILTIN_SET_PROTOTYPE_FUNCTIONS(SET_PROPERTIES_PAIR) 1004514f5e3Sopenharmony_ci std::pair<std::string_view, bool>("keys", false), 1014514f5e3Sopenharmony_ci std::pair<std::string_view, bool>("[Symbol.toStringTag]", false), 1024514f5e3Sopenharmony_ci std::pair<std::string_view, bool>("size", true), 1034514f5e3Sopenharmony_ci std::pair<std::string_view, bool>("[Symbol.iterator]", false) 1044514f5e3Sopenharmony_ci }; 1054514f5e3Sopenharmony_ci 1064514f5e3Sopenharmony_ci static constexpr std::array SET_FUNCTION_PROPERTIES = { 1074514f5e3Sopenharmony_ci std::pair<std::string_view, bool>("length", false), 1084514f5e3Sopenharmony_ci std::pair<std::string_view, bool>("name", false), 1094514f5e3Sopenharmony_ci std::pair<std::string_view, bool>("prototype", false), 1104514f5e3Sopenharmony_ci std::pair<std::string_view, bool>("[Symbol.species]", true), 1114514f5e3Sopenharmony_ci }; 1124514f5e3Sopenharmony_ci#undef SET_PROPERTIES_PAIR 1134514f5e3Sopenharmony_ci}; 1144514f5e3Sopenharmony_ci} // namespace panda::ecmascript::builtins 1154514f5e3Sopenharmony_ci#endif // ECMASCRIPT_BUILTINS_BUILTINS_SHARED_SET_H 116