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_PLAIN_ARRAY_H 17 #define ECMASCRIPT_CONTAINERS_CONTAINERS_PLAIN_ARRAY_H 18 19 #include "ecmascript/base/builtins_base.h" 20 #include "ecmascript/ecma_runtime_call_info.h" 21 22 // List of functions in PlainArray.prototype, excluding the constructor and '@@' properties. 23 // V(name, func, length, stubIndex) 24 // where ContainersPlainArray::func refers to the native implementation of PlainArray.prototype[name]. 25 #define CONTAINER_PLAINARRAY_PROTOTYPE_FUNCTIONS(V) \ 26 V("add", Add, 2, INVALID) \ 27 V("clear", Clear, 0, INVALID) \ 28 V("clone", Clone, 0, INVALID) \ 29 V("has", Has, 1, INVALID) \ 30 V("get", Get, 1, INVALID) \ 31 V("forEach", ForEach, 2, PlainArrayForEach) \ 32 V("toString", ToString, 0, INVALID) \ 33 V("getIndexOfKey", GetIndexOfKey, 1, INVALID) \ 34 V("getIndexOfValue", GetIndexOfValue, 1, INVALID) \ 35 V("isEmpty", IsEmpty, 0, INVALID) \ 36 V("getKeyAt", GetKeyAt, 1, INVALID) \ 37 V("remove", Remove, 1, INVALID) \ 38 V("removeAt", RemoveAt, 1, INVALID) \ 39 V("removeRangeFrom", RemoveRangeFrom, 2, INVALID) \ 40 V("setValueAt", SetValueAt, 2, INVALID) \ 41 V("getValueAt", GetValueAt, 1, INVALID) 42 43 namespace panda::ecmascript::containers { 44 class ContainersPlainArray : public base::BuiltinsBase { 45 public: 46 static JSTaggedValue PlainArrayConstructor(EcmaRuntimeCallInfo *argv); 47 static JSTaggedValue Add(EcmaRuntimeCallInfo *argv); 48 static JSTaggedValue Clear(EcmaRuntimeCallInfo *argv); 49 static JSTaggedValue Clone(EcmaRuntimeCallInfo *argv); 50 static JSTaggedValue Has(EcmaRuntimeCallInfo *argv); 51 static JSTaggedValue Get(EcmaRuntimeCallInfo *argv); 52 static JSTaggedValue GetIteratorObj(EcmaRuntimeCallInfo *argv); 53 static JSTaggedValue ForEach(EcmaRuntimeCallInfo *argv); 54 static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); 55 static JSTaggedValue GetIndexOfKey(EcmaRuntimeCallInfo *argv); 56 static JSTaggedValue GetIndexOfValue(EcmaRuntimeCallInfo *argv); 57 static JSTaggedValue IsEmpty(EcmaRuntimeCallInfo *argv); 58 static JSTaggedValue GetKeyAt(EcmaRuntimeCallInfo *argv); 59 static JSTaggedValue Remove(EcmaRuntimeCallInfo *argv); 60 static JSTaggedValue RemoveAt(EcmaRuntimeCallInfo *argv); 61 static JSTaggedValue RemoveRangeFrom(EcmaRuntimeCallInfo *argv); 62 static JSTaggedValue SetValueAt(EcmaRuntimeCallInfo *argv); 63 static JSTaggedValue GetValueAt(EcmaRuntimeCallInfo *argv); 64 static JSTaggedValue GetSize(EcmaRuntimeCallInfo *argv); 65 66 // Excluding the constructor and '@@' internal properties. GetPlainArrayPrototypeFunctions()67 static Span<const base::BuiltinFunctionEntry> GetPlainArrayPrototypeFunctions() 68 { 69 return Span<const base::BuiltinFunctionEntry>(PLAINARRAY_PROTOTYPE_FUNCTIONS); 70 } 71 72 private: 73 #define CONTAINER_PLAINARRAY_FUNCTION_ENTRY(name, method, length, id) \ 74 base::BuiltinFunctionEntry::Create(name, ContainersPlainArray::method, length, BUILTINS_STUB_ID(id)), 75 76 static constexpr std::array PLAINARRAY_PROTOTYPE_FUNCTIONS = { 77 CONTAINER_PLAINARRAY_PROTOTYPE_FUNCTIONS(CONTAINER_PLAINARRAY_FUNCTION_ENTRY) 78 }; 79 #undef CONTAINER_PLAINARRAY_FUNCTION_ENTRY 80 }; 81 } // namespace panda::ecmascript::containers 82 #endif // ECMASCRIPT_CONTAINERS_CONTAINERS_PLAIN_ARRAY_H 83