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_LIGHTWEIGHTMAP_H 17 #define ECMASCRIPT_CONTAINERS_CONTAINERS_LIGHTWEIGHTMAP_H 18 19 #include "ecmascript/base/builtins_base.h" 20 #include "ecmascript/ecma_runtime_call_info.h" 21 22 // List of functions in LightWeightMap.prototype, excluding the constructor and '@@' properties. 23 // V(name, func, length, stubIndex) 24 // where ContainersLightWeightMap::func refers to the native implementation of LightWeightMap.prototype[name]. 25 #define CONTAINER_LIGHTWEIGHTMAP_PROTOTYPE_FUNCTIONS(V) \ 26 V("hasAll", HasAll, 1, INVALID) \ 27 V("hasKey", HasKey, 1, INVALID) \ 28 V("hasValue", HasValue, 1, INVALID) \ 29 V("increaseCapacityTo", IncreaseCapacityTo, 1, INVALID) \ 30 V("entries", Entries, 0, INVALID) \ 31 V("get", Get, 1, INVALID) \ 32 V("getIndexOfKey", GetIndexOfKey, 1, INVALID) \ 33 V("getIndexOfValue", GetIndexOfValue, 1, INVALID) \ 34 V("isEmpty", IsEmpty, 0, INVALID) \ 35 V("getKeyAt", GetKeyAt, 1, INVALID) \ 36 V("keys", Keys, 0, INVALID) \ 37 V("setAll", SetAll, 1, INVALID) \ 38 V("set", Set, 2, INVALID) \ 39 V("remove", Remove, 1, INVALID) \ 40 V("removeAt", RemoveAt, 1, INVALID) \ 41 V("clear", Clear, 0, INVALID) \ 42 V("setValueAt", SetValueAt, 2, INVALID) \ 43 V("toString", ToString, 0, INVALID) \ 44 V("getValueAt", GetValueAt, 1, INVALID) \ 45 V("values", Values, 0, INVALID) \ 46 V("forEach", ForEach, 2, LightWeightMapForEach) 47 48 namespace panda::ecmascript::containers { 49 class ContainersLightWeightMap : public base::BuiltinsBase { 50 public: 51 static JSTaggedValue LightWeightMapConstructor(EcmaRuntimeCallInfo *argv); 52 static JSTaggedValue Length(EcmaRuntimeCallInfo *argv); 53 static JSTaggedValue HasAll(EcmaRuntimeCallInfo *argv); 54 static JSTaggedValue HasKey(EcmaRuntimeCallInfo *argv); 55 static JSTaggedValue HasValue(EcmaRuntimeCallInfo *argv); 56 static JSTaggedValue IncreaseCapacityTo(EcmaRuntimeCallInfo *argv); 57 static JSTaggedValue Entries(EcmaRuntimeCallInfo *argv); 58 static JSTaggedValue Get(EcmaRuntimeCallInfo *argv); 59 static JSTaggedValue GetIndexOfKey(EcmaRuntimeCallInfo *argv); 60 static JSTaggedValue GetIndexOfValue(EcmaRuntimeCallInfo *argv); 61 static JSTaggedValue IsEmpty(EcmaRuntimeCallInfo *argv); 62 static JSTaggedValue GetKeyAt(EcmaRuntimeCallInfo *argv); 63 static JSTaggedValue Keys(EcmaRuntimeCallInfo *argv); 64 static JSTaggedValue SetAll(EcmaRuntimeCallInfo *argv); 65 static JSTaggedValue Set(EcmaRuntimeCallInfo *argv); 66 static JSTaggedValue Remove(EcmaRuntimeCallInfo *argv); 67 static JSTaggedValue RemoveAt(EcmaRuntimeCallInfo *argv); 68 static JSTaggedValue Clear(EcmaRuntimeCallInfo *argv); 69 static JSTaggedValue SetValueAt(EcmaRuntimeCallInfo *argv); 70 static JSTaggedValue ForEach(EcmaRuntimeCallInfo *argv); 71 static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); 72 static JSTaggedValue GetValueAt(EcmaRuntimeCallInfo *argv); 73 static JSTaggedValue Values(EcmaRuntimeCallInfo *argv); 74 static JSTaggedValue GetIteratorObj(EcmaRuntimeCallInfo *argv); 75 76 // Excluding the constructor and '@@' internal properties. GetLightWeightMapPrototypeFunctions()77 static Span<const base::BuiltinFunctionEntry> GetLightWeightMapPrototypeFunctions() 78 { 79 return Span<const base::BuiltinFunctionEntry>(LIGHTWEIGHTMAP_PROTOTYPE_FUNCTIONS); 80 } 81 82 private: 83 #define CONTAINER_LIGHTWEIGHTMAP_FUNCTION_ENTRY(name, method, length, id) \ 84 base::BuiltinFunctionEntry::Create(name, ContainersLightWeightMap::method, length, kungfu::BuiltinsStubCSigns::id), 85 86 static constexpr std::array LIGHTWEIGHTMAP_PROTOTYPE_FUNCTIONS = { 87 CONTAINER_LIGHTWEIGHTMAP_PROTOTYPE_FUNCTIONS(CONTAINER_LIGHTWEIGHTMAP_FUNCTION_ENTRY) 88 }; 89 #undef CONTAINER_LIGHTWEIGHTMAP_FUNCTION_ENTRY 90 }; 91 } // namespace panda::ecmascript::containers 92 #endif // ECMASCRIPT_CONTAINERS_CONTAINERS_LIGHTWEIGHTMAP_H 93